]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
[PATCH 2/57][Arm][GAS] Add support for MVE instructions: vpst, vadd, vsub and vabd
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
82704155 2 Copyright (C) 1994-2019 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b
RE
34#include "opcode/arm.h"
35
b99bd4ef
NC
36#ifdef OBJ_ELF
37#include "elf/arm.h"
a394c00f 38#include "dw2gencfi.h"
b99bd4ef
NC
39#endif
40
f0927246
NC
41#include "dwarf2dbg.h"
42
7ed4c4c5
NC
43#ifdef OBJ_ELF
44/* Must be at least the size of the largest unwind opcode (currently two). */
45#define ARM_OPCODE_CHUNK_SIZE 8
46
47/* This structure holds the unwinding state. */
48
49static struct
50{
c19d1205
ZW
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
7ed4c4c5 55 /* The segment containing the function. */
c19d1205
ZW
56 segT saved_seg;
57 subsegT saved_subseg;
7ed4c4c5
NC
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
c19d1205
ZW
60 int opcode_count;
61 int opcode_alloc;
7ed4c4c5 62 /* The number of bytes pushed to the stack. */
c19d1205 63 offsetT frame_size;
7ed4c4c5
NC
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
c19d1205 67 offsetT pending_offset;
7ed4c4c5 68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
7ed4c4c5 72 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 73 unsigned fp_used:1;
7ed4c4c5 74 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 75 unsigned sp_restored:1;
7ed4c4c5
NC
76} unwind;
77
18a20338
CL
78/* Whether --fdpic was given. */
79static int arm_fdpic;
80
8b1ad454
NC
81#endif /* OBJ_ELF */
82
4962c51a
MS
83/* Results from operand parsing worker functions. */
84
85typedef enum
86{
87 PARSE_OPERAND_SUCCESS,
88 PARSE_OPERAND_FAIL,
89 PARSE_OPERAND_FAIL_NO_BACKTRACK
90} parse_operand_result;
91
33a392fb
PB
92enum arm_float_abi
93{
94 ARM_FLOAT_ABI_HARD,
95 ARM_FLOAT_ABI_SOFTFP,
96 ARM_FLOAT_ABI_SOFT
97};
98
c19d1205 99/* Types of processor to assemble for. */
b99bd4ef 100#ifndef CPU_DEFAULT
8a59fff3 101/* The code that was here used to select a default CPU depending on compiler
fa94de6b 102 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
103 changing gas' default behaviour depending upon the build host.
104
105 If you have a target that requires a default CPU option then the you
106 should define CPU_DEFAULT here. */
b99bd4ef
NC
107#endif
108
109#ifndef FPU_DEFAULT
c820d418
MM
110# ifdef TE_LINUX
111# define FPU_DEFAULT FPU_ARCH_FPA
112# elif defined (TE_NetBSD)
113# ifdef OBJ_ELF
114# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
115# else
116 /* Legacy a.out format. */
117# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
118# endif
4e7fd91e
PB
119# elif defined (TE_VXWORKS)
120# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
121# else
122 /* For backwards compatibility, default to FPA. */
123# define FPU_DEFAULT FPU_ARCH_FPA
124# endif
125#endif /* ifndef FPU_DEFAULT */
b99bd4ef 126
c19d1205 127#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 128
4d354d8b
TP
129/* Current set of feature bits available (CPU+FPU). Different from
130 selected_cpu + selected_fpu in case of autodetection since the CPU
131 feature bits are then all set. */
e74cfd16 132static arm_feature_set cpu_variant;
4d354d8b
TP
133/* Feature bits used in each execution state. Used to set build attribute
134 (in particular Tag_*_ISA_use) in CPU autodetection mode. */
e74cfd16
PB
135static arm_feature_set arm_arch_used;
136static arm_feature_set thumb_arch_used;
b99bd4ef 137
b99bd4ef 138/* Flags stored in private area of BFD structure. */
c19d1205
ZW
139static int uses_apcs_26 = FALSE;
140static int atpcs = FALSE;
b34976b6
AM
141static int support_interwork = FALSE;
142static int uses_apcs_float = FALSE;
c19d1205 143static int pic_code = FALSE;
845b51d6 144static int fix_v4bx = FALSE;
278df34e
NS
145/* Warn on using deprecated features. */
146static int warn_on_deprecated = TRUE;
147
2e6976a8
DG
148/* Understand CodeComposer Studio assembly syntax. */
149bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
150
151/* Variables that we set while parsing command-line options. Once all
152 options have been read we re-process these values to set the real
153 assembly flags. */
4d354d8b
TP
154
155/* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1
156 instead of -mcpu=arm1). */
157static const arm_feature_set *legacy_cpu = NULL;
158static const arm_feature_set *legacy_fpu = NULL;
159
160/* CPU, extension and FPU feature bits selected by -mcpu. */
161static const arm_feature_set *mcpu_cpu_opt = NULL;
162static arm_feature_set *mcpu_ext_opt = NULL;
163static const arm_feature_set *mcpu_fpu_opt = NULL;
164
165/* CPU, extension and FPU feature bits selected by -march. */
166static const arm_feature_set *march_cpu_opt = NULL;
167static arm_feature_set *march_ext_opt = NULL;
168static const arm_feature_set *march_fpu_opt = NULL;
169
170/* Feature bits selected by -mfpu. */
171static const arm_feature_set *mfpu_opt = NULL;
e74cfd16
PB
172
173/* Constants for known architecture features. */
174static const arm_feature_set fpu_default = FPU_DEFAULT;
f85d59c3 175static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 176static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
177static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
178static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
e74cfd16
PB
179static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
180static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
69c9e028 181#ifdef OBJ_ELF
e74cfd16 182static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
69c9e028 183#endif
e74cfd16
PB
184static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
185
186#ifdef CPU_DEFAULT
187static const arm_feature_set cpu_default = CPU_DEFAULT;
188#endif
189
823d2571 190static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
4070243b 191static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
823d2571
TG
192static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
193static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
194static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
195static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
196static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
197static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 198static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
199 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
200static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
201static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
202static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
203static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
204static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
205static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
206static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
55e8aae7
SP
207/* Only for compatability of hint instructions. */
208static const arm_feature_set arm_ext_v6k_v6t2 =
209 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2);
823d2571
TG
210static const arm_feature_set arm_ext_v6_notm =
211 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
212static const arm_feature_set arm_ext_v6_dsp =
213 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
214static const arm_feature_set arm_ext_barrier =
215 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
216static const arm_feature_set arm_ext_msr =
217 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
218static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
219static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
220static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
221static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 222#ifdef OBJ_ELF
e7d39ed3 223static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 224#endif
823d2571 225static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 226static const arm_feature_set arm_ext_m =
173205ca 227 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
16a1fa25 228 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
229static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
230static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
231static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
232static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
233static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 234static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 235static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
236static const arm_feature_set arm_ext_v8m_main =
237 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
e12437dc
AV
238static const arm_feature_set arm_ext_v8_1m_main =
239ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
16a1fa25
TP
240/* Instructions in ARMv8-M only found in M profile architectures. */
241static const arm_feature_set arm_ext_v8m_m_only =
242 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
243static const arm_feature_set arm_ext_v6t2_v8m =
244 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
245/* Instructions shared between ARMv8-A and ARMv8-M. */
246static const arm_feature_set arm_ext_atomics =
247 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 248#ifdef OBJ_ELF
15afaa63
TP
249/* DSP instructions Tag_DSP_extension refers to. */
250static const arm_feature_set arm_ext_dsp =
251 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 252#endif
4d1464f2
MW
253static const arm_feature_set arm_ext_ras =
254 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
255/* FP16 instructions. */
256static const arm_feature_set arm_ext_fp16 =
257 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
01f48020
TC
258static const arm_feature_set arm_ext_fp16_fml =
259 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
dec41383
JW
260static const arm_feature_set arm_ext_v8_2 =
261 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
49e8a725
SN
262static const arm_feature_set arm_ext_v8_3 =
263 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
7fadb25d
SD
264static const arm_feature_set arm_ext_sb =
265 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
dad0c3bf
SD
266static const arm_feature_set arm_ext_predres =
267 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
e74cfd16
PB
268
269static const arm_feature_set arm_arch_any = ARM_ANY;
49fa50ef 270#ifdef OBJ_ELF
2c6b98ea 271static const arm_feature_set fpu_any = FPU_ANY;
49fa50ef 272#endif
f85d59c3 273static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
274static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
275static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
276
2d447fca 277static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 278 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 279static const arm_feature_set arm_cext_iwmmxt =
823d2571 280 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 281static const arm_feature_set arm_cext_xscale =
823d2571 282 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 283static const arm_feature_set arm_cext_maverick =
823d2571
TG
284 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
285static const arm_feature_set fpu_fpa_ext_v1 =
286 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
287static const arm_feature_set fpu_fpa_ext_v2 =
288 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 289static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
290 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
291static const arm_feature_set fpu_vfp_ext_v1 =
292 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
293static const arm_feature_set fpu_vfp_ext_v2 =
294 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
295static const arm_feature_set fpu_vfp_ext_v3xd =
296 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
297static const arm_feature_set fpu_vfp_ext_v3 =
298 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 299static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
300 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
301static const arm_feature_set fpu_neon_ext_v1 =
302 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 303static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 304 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
a7ad558c
AV
305static const arm_feature_set mve_ext =
306 ARM_FEATURE_COPROC (FPU_MVE);
307static const arm_feature_set mve_fp_ext =
308 ARM_FEATURE_COPROC (FPU_MVE_FP);
69c9e028 309#ifdef OBJ_ELF
823d2571
TG
310static const arm_feature_set fpu_vfp_fp16 =
311 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
312static const arm_feature_set fpu_neon_ext_fma =
313 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 314#endif
823d2571
TG
315static const arm_feature_set fpu_vfp_ext_fma =
316 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 317static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 318 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 319static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 320 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 321static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 322 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 323static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 324 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 325static const arm_feature_set crc_ext_armv8 =
823d2571 326 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 327static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 328 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
329static const arm_feature_set fpu_neon_ext_dotprod =
330 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 331
33a392fb 332static int mfloat_abi_opt = -1;
4d354d8b
TP
333/* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
334 directive. */
335static arm_feature_set selected_arch = ARM_ARCH_NONE;
336/* Extension feature bits selected by the last -mcpu/-march or .arch_extension
337 directive. */
338static arm_feature_set selected_ext = ARM_ARCH_NONE;
339/* Feature bits selected by the last -mcpu/-march or by the combination of the
340 last .cpu/.arch directive .arch_extension directives since that
341 directive. */
e74cfd16 342static arm_feature_set selected_cpu = ARM_ARCH_NONE;
4d354d8b
TP
343/* FPU feature bits selected by the last -mfpu or .fpu directive. */
344static arm_feature_set selected_fpu = FPU_NONE;
345/* Feature bits selected by the last .object_arch directive. */
346static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
ee065d83 347/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 348static char selected_cpu_name[20];
8d67f500 349
aacf0b33
KT
350extern FLONUM_TYPE generic_floating_point_number;
351
8d67f500
NC
352/* Return if no cpu was selected on command-line. */
353static bfd_boolean
354no_cpu_selected (void)
355{
823d2571 356 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
357}
358
7cc69913 359#ifdef OBJ_ELF
deeaaff8
DJ
360# ifdef EABI_DEFAULT
361static int meabi_flags = EABI_DEFAULT;
362# else
d507cf36 363static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 364# endif
e1da3f5b 365
ee3c0378
AS
366static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
367
e1da3f5b 368bfd_boolean
5f4273c7 369arm_is_eabi (void)
e1da3f5b
PB
370{
371 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
372}
7cc69913 373#endif
b99bd4ef 374
b99bd4ef 375#ifdef OBJ_ELF
c19d1205 376/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
377symbolS * GOT_symbol;
378#endif
379
b99bd4ef
NC
380/* 0: assemble for ARM,
381 1: assemble for Thumb,
382 2: assemble for Thumb even though target CPU does not support thumb
383 instructions. */
384static int thumb_mode = 0;
8dc2430f
NC
385/* A value distinct from the possible values for thumb_mode that we
386 can use to record whether thumb_mode has been copied into the
387 tc_frag_data field of a frag. */
388#define MODE_RECORDED (1 << 4)
b99bd4ef 389
e07e6e58
NC
390/* Specifies the intrinsic IT insn behavior mode. */
391enum implicit_it_mode
392{
393 IMPLICIT_IT_MODE_NEVER = 0x00,
394 IMPLICIT_IT_MODE_ARM = 0x01,
395 IMPLICIT_IT_MODE_THUMB = 0x02,
396 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
397};
398static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
399
c19d1205
ZW
400/* If unified_syntax is true, we are processing the new unified
401 ARM/Thumb syntax. Important differences from the old ARM mode:
402
403 - Immediate operands do not require a # prefix.
404 - Conditional affixes always appear at the end of the
405 instruction. (For backward compatibility, those instructions
406 that formerly had them in the middle, continue to accept them
407 there.)
408 - The IT instruction may appear, and if it does is validated
409 against subsequent conditional affixes. It does not generate
410 machine code.
411
412 Important differences from the old Thumb mode:
413
414 - Immediate operands do not require a # prefix.
415 - Most of the V6T2 instructions are only available in unified mode.
416 - The .N and .W suffixes are recognized and honored (it is an error
417 if they cannot be honored).
418 - All instructions set the flags if and only if they have an 's' affix.
419 - Conditional affixes may be used. They are validated against
420 preceding IT instructions. Unlike ARM mode, you cannot use a
421 conditional affix except in the scope of an IT instruction. */
422
423static bfd_boolean unified_syntax = FALSE;
b99bd4ef 424
bacebabc
RM
425/* An immediate operand can start with #, and ld*, st*, pld operands
426 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
427 before a [, which can appear as the first operand for pld.
428 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
429const char arm_symbol_chars[] = "#[]{}";
bacebabc 430
5287ad62
JB
431enum neon_el_type
432{
dcbf9037 433 NT_invtype,
5287ad62
JB
434 NT_untyped,
435 NT_integer,
436 NT_float,
437 NT_poly,
438 NT_signed,
dcbf9037 439 NT_unsigned
5287ad62
JB
440};
441
442struct neon_type_el
443{
444 enum neon_el_type type;
445 unsigned size;
446};
447
448#define NEON_MAX_TYPE_ELS 4
449
450struct neon_type
451{
452 struct neon_type_el el[NEON_MAX_TYPE_ELS];
453 unsigned elems;
454};
455
5ee91343 456enum pred_instruction_type
e07e6e58 457{
5ee91343
AV
458 OUTSIDE_PRED_INSN,
459 INSIDE_VPT_INSN,
e07e6e58
NC
460 INSIDE_IT_INSN,
461 INSIDE_IT_LAST_INSN,
462 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 463 if inside, should be the last one. */
e07e6e58 464 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 465 i.e. BKPT and NOP. */
5ee91343
AV
466 IT_INSN, /* The IT insn has been parsed. */
467 VPT_INSN, /* The VPT/VPST insn has been parsed. */
468 MVE_OUTSIDE_PRED_INSN /* Instruction to indicate a MVE instruction without
469 a predication code. */
e07e6e58
NC
470};
471
ad6cec43
MGD
472/* The maximum number of operands we need. */
473#define ARM_IT_MAX_OPERANDS 6
e2b0ab59 474#define ARM_IT_MAX_RELOCS 3
ad6cec43 475
b99bd4ef
NC
476struct arm_it
477{
c19d1205 478 const char * error;
b99bd4ef 479 unsigned long instruction;
c19d1205
ZW
480 int size;
481 int size_req;
482 int cond;
037e8744
JB
483 /* "uncond_value" is set to the value in place of the conditional field in
484 unconditional versions of the instruction, or -1 if nothing is
485 appropriate. */
486 int uncond_value;
5287ad62 487 struct neon_type vectype;
88714cb8
DG
488 /* This does not indicate an actual NEON instruction, only that
489 the mnemonic accepts neon-style type suffixes. */
490 int is_neon;
0110f2b8
PB
491 /* Set to the opcode if the instruction needs relaxation.
492 Zero if the instruction is not relaxed. */
493 unsigned long relax;
b99bd4ef
NC
494 struct
495 {
496 bfd_reloc_code_real_type type;
c19d1205
ZW
497 expressionS exp;
498 int pc_rel;
e2b0ab59 499 } relocs[ARM_IT_MAX_RELOCS];
b99bd4ef 500
5ee91343 501 enum pred_instruction_type pred_insn_type;
e07e6e58 502
c19d1205
ZW
503 struct
504 {
505 unsigned reg;
ca3f61f7 506 signed int imm;
dcbf9037 507 struct neon_type_el vectype;
ca3f61f7
NC
508 unsigned present : 1; /* Operand present. */
509 unsigned isreg : 1; /* Operand was a register. */
510 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
511 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
512 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 513 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
514 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
515 instructions. This allows us to disambiguate ARM <-> vector insns. */
516 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 517 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5ee91343 518 unsigned isquad : 1; /* Operand is SIMD quad register. */
037e8744 519 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
520 unsigned hasreloc : 1; /* Operand has relocation suffix. */
521 unsigned writeback : 1; /* Operand has trailing ! */
522 unsigned preind : 1; /* Preindexed address. */
523 unsigned postind : 1; /* Postindexed address. */
524 unsigned negative : 1; /* Index register was negated. */
525 unsigned shifted : 1; /* Shift applied to operation. */
526 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 527 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
528};
529
c19d1205 530static struct arm_it inst;
b99bd4ef
NC
531
532#define NUM_FLOAT_VALS 8
533
05d2d07e 534const char * fp_const[] =
b99bd4ef
NC
535{
536 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
537};
538
b99bd4ef
NC
539LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
540
541#define FAIL (-1)
542#define SUCCESS (0)
543
544#define SUFF_S 1
545#define SUFF_D 2
546#define SUFF_E 3
547#define SUFF_P 4
548
c19d1205
ZW
549#define CP_T_X 0x00008000
550#define CP_T_Y 0x00400000
b99bd4ef 551
c19d1205
ZW
552#define CONDS_BIT 0x00100000
553#define LOAD_BIT 0x00100000
b99bd4ef
NC
554
555#define DOUBLE_LOAD_FLAG 0x00000001
556
557struct asm_cond
558{
d3ce72d0 559 const char * template_name;
c921be7d 560 unsigned long value;
b99bd4ef
NC
561};
562
c19d1205 563#define COND_ALWAYS 0xE
b99bd4ef 564
b99bd4ef
NC
565struct asm_psr
566{
d3ce72d0 567 const char * template_name;
c921be7d 568 unsigned long field;
b99bd4ef
NC
569};
570
62b3e311
PB
571struct asm_barrier_opt
572{
e797f7e0
MGD
573 const char * template_name;
574 unsigned long value;
575 const arm_feature_set arch;
62b3e311
PB
576};
577
2d2255b5 578/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
579#define SPSR_BIT (1 << 22)
580
c19d1205
ZW
581/* The individual PSR flag bits. */
582#define PSR_c (1 << 16)
583#define PSR_x (1 << 17)
584#define PSR_s (1 << 18)
585#define PSR_f (1 << 19)
b99bd4ef 586
c19d1205 587struct reloc_entry
bfae80f2 588{
0198d5e6 589 const char * name;
c921be7d 590 bfd_reloc_code_real_type reloc;
bfae80f2
RE
591};
592
5287ad62 593enum vfp_reg_pos
bfae80f2 594{
5287ad62
JB
595 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
596 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
597};
598
599enum vfp_ldstm_type
600{
601 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
602};
603
dcbf9037
JB
604/* Bits for DEFINED field in neon_typed_alias. */
605#define NTA_HASTYPE 1
606#define NTA_HASINDEX 2
607
608struct neon_typed_alias
609{
c921be7d
NC
610 unsigned char defined;
611 unsigned char index;
612 struct neon_type_el eltype;
dcbf9037
JB
613};
614
c19d1205 615/* ARM register categories. This includes coprocessor numbers and various
5aa75429
TP
616 architecture extensions' registers. Each entry should have an error message
617 in reg_expected_msgs below. */
c19d1205 618enum arm_reg_type
bfae80f2 619{
c19d1205
ZW
620 REG_TYPE_RN,
621 REG_TYPE_CP,
622 REG_TYPE_CN,
623 REG_TYPE_FN,
624 REG_TYPE_VFS,
625 REG_TYPE_VFD,
5287ad62 626 REG_TYPE_NQ,
037e8744 627 REG_TYPE_VFSD,
5287ad62 628 REG_TYPE_NDQ,
dec41383 629 REG_TYPE_NSD,
037e8744 630 REG_TYPE_NSDQ,
c19d1205
ZW
631 REG_TYPE_VFC,
632 REG_TYPE_MVF,
633 REG_TYPE_MVD,
634 REG_TYPE_MVFX,
635 REG_TYPE_MVDX,
636 REG_TYPE_MVAX,
5ee91343 637 REG_TYPE_MQ,
c19d1205
ZW
638 REG_TYPE_DSPSC,
639 REG_TYPE_MMXWR,
640 REG_TYPE_MMXWC,
641 REG_TYPE_MMXWCG,
642 REG_TYPE_XSCALE,
5ee91343 643 REG_TYPE_RNB,
bfae80f2
RE
644};
645
dcbf9037
JB
646/* Structure for a hash table entry for a register.
647 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
648 information which states whether a vector type or index is specified (for a
649 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
650struct reg_entry
651{
c921be7d 652 const char * name;
90ec0d68 653 unsigned int number;
c921be7d
NC
654 unsigned char type;
655 unsigned char builtin;
656 struct neon_typed_alias * neon;
6c43fab6
RE
657};
658
c19d1205 659/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 660const char * const reg_expected_msgs[] =
c19d1205 661{
5aa75429
TP
662 [REG_TYPE_RN] = N_("ARM register expected"),
663 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
664 [REG_TYPE_CN] = N_("co-processor register expected"),
665 [REG_TYPE_FN] = N_("FPA register expected"),
666 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
667 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
668 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
669 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
670 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
671 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
672 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
673 " expected"),
674 [REG_TYPE_VFC] = N_("VFP system register expected"),
675 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
676 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
677 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
678 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
679 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
680 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
681 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
682 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
683 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
684 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
5ee91343 685 [REG_TYPE_MQ] = N_("MVE vector register expected"),
5aa75429 686 [REG_TYPE_RNB] = N_("")
6c43fab6
RE
687};
688
c19d1205 689/* Some well known registers that we refer to directly elsewhere. */
bd340a04 690#define REG_R12 12
c19d1205
ZW
691#define REG_SP 13
692#define REG_LR 14
693#define REG_PC 15
404ff6b5 694
b99bd4ef
NC
695/* ARM instructions take 4bytes in the object file, Thumb instructions
696 take 2: */
c19d1205 697#define INSN_SIZE 4
b99bd4ef
NC
698
699struct asm_opcode
700{
701 /* Basic string to match. */
d3ce72d0 702 const char * template_name;
c19d1205
ZW
703
704 /* Parameters to instruction. */
5be8be5d 705 unsigned int operands[8];
c19d1205
ZW
706
707 /* Conditional tag - see opcode_lookup. */
708 unsigned int tag : 4;
b99bd4ef
NC
709
710 /* Basic instruction code. */
c19d1205 711 unsigned int avalue : 28;
b99bd4ef 712
c19d1205
ZW
713 /* Thumb-format instruction code. */
714 unsigned int tvalue;
b99bd4ef 715
90e4755a 716 /* Which architecture variant provides this instruction. */
c921be7d
NC
717 const arm_feature_set * avariant;
718 const arm_feature_set * tvariant;
c19d1205
ZW
719
720 /* Function to call to encode instruction in ARM format. */
721 void (* aencode) (void);
b99bd4ef 722
c19d1205
ZW
723 /* Function to call to encode instruction in Thumb format. */
724 void (* tencode) (void);
5ee91343
AV
725
726 /* Indicates whether this instruction may be vector predicated. */
727 unsigned int mayBeVecPred : 1;
b99bd4ef
NC
728};
729
a737bd4d
NC
730/* Defines for various bits that we will want to toggle. */
731#define INST_IMMEDIATE 0x02000000
732#define OFFSET_REG 0x02000000
c19d1205 733#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
734#define SHIFT_BY_REG 0x00000010
735#define PRE_INDEX 0x01000000
736#define INDEX_UP 0x00800000
737#define WRITE_BACK 0x00200000
738#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 739#define CPSI_MMOD 0x00020000
90e4755a 740
a737bd4d
NC
741#define LITERAL_MASK 0xf000f000
742#define OPCODE_MASK 0xfe1fffff
743#define V4_STR_BIT 0x00000020
8335d6aa 744#define VLDR_VMOV_SAME 0x0040f000
90e4755a 745
efd81785
PB
746#define T2_SUBS_PC_LR 0xf3de8f00
747
a737bd4d 748#define DATA_OP_SHIFT 21
bada4342 749#define SBIT_SHIFT 20
90e4755a 750
ef8d22e6
PB
751#define T2_OPCODE_MASK 0xfe1fffff
752#define T2_DATA_OP_SHIFT 21
bada4342 753#define T2_SBIT_SHIFT 20
ef8d22e6 754
6530b175
NC
755#define A_COND_MASK 0xf0000000
756#define A_PUSH_POP_OP_MASK 0x0fff0000
757
758/* Opcodes for pushing/poping registers to/from the stack. */
759#define A1_OPCODE_PUSH 0x092d0000
760#define A2_OPCODE_PUSH 0x052d0004
761#define A2_OPCODE_POP 0x049d0004
762
a737bd4d
NC
763/* Codes to distinguish the arithmetic instructions. */
764#define OPCODE_AND 0
765#define OPCODE_EOR 1
766#define OPCODE_SUB 2
767#define OPCODE_RSB 3
768#define OPCODE_ADD 4
769#define OPCODE_ADC 5
770#define OPCODE_SBC 6
771#define OPCODE_RSC 7
772#define OPCODE_TST 8
773#define OPCODE_TEQ 9
774#define OPCODE_CMP 10
775#define OPCODE_CMN 11
776#define OPCODE_ORR 12
777#define OPCODE_MOV 13
778#define OPCODE_BIC 14
779#define OPCODE_MVN 15
90e4755a 780
ef8d22e6
PB
781#define T2_OPCODE_AND 0
782#define T2_OPCODE_BIC 1
783#define T2_OPCODE_ORR 2
784#define T2_OPCODE_ORN 3
785#define T2_OPCODE_EOR 4
786#define T2_OPCODE_ADD 8
787#define T2_OPCODE_ADC 10
788#define T2_OPCODE_SBC 11
789#define T2_OPCODE_SUB 13
790#define T2_OPCODE_RSB 14
791
a737bd4d
NC
792#define T_OPCODE_MUL 0x4340
793#define T_OPCODE_TST 0x4200
794#define T_OPCODE_CMN 0x42c0
795#define T_OPCODE_NEG 0x4240
796#define T_OPCODE_MVN 0x43c0
90e4755a 797
a737bd4d
NC
798#define T_OPCODE_ADD_R3 0x1800
799#define T_OPCODE_SUB_R3 0x1a00
800#define T_OPCODE_ADD_HI 0x4400
801#define T_OPCODE_ADD_ST 0xb000
802#define T_OPCODE_SUB_ST 0xb080
803#define T_OPCODE_ADD_SP 0xa800
804#define T_OPCODE_ADD_PC 0xa000
805#define T_OPCODE_ADD_I8 0x3000
806#define T_OPCODE_SUB_I8 0x3800
807#define T_OPCODE_ADD_I3 0x1c00
808#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 809
a737bd4d
NC
810#define T_OPCODE_ASR_R 0x4100
811#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
812#define T_OPCODE_LSR_R 0x40c0
813#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
814#define T_OPCODE_ASR_I 0x1000
815#define T_OPCODE_LSL_I 0x0000
816#define T_OPCODE_LSR_I 0x0800
b99bd4ef 817
a737bd4d
NC
818#define T_OPCODE_MOV_I8 0x2000
819#define T_OPCODE_CMP_I8 0x2800
820#define T_OPCODE_CMP_LR 0x4280
821#define T_OPCODE_MOV_HR 0x4600
822#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 823
a737bd4d
NC
824#define T_OPCODE_LDR_PC 0x4800
825#define T_OPCODE_LDR_SP 0x9800
826#define T_OPCODE_STR_SP 0x9000
827#define T_OPCODE_LDR_IW 0x6800
828#define T_OPCODE_STR_IW 0x6000
829#define T_OPCODE_LDR_IH 0x8800
830#define T_OPCODE_STR_IH 0x8000
831#define T_OPCODE_LDR_IB 0x7800
832#define T_OPCODE_STR_IB 0x7000
833#define T_OPCODE_LDR_RW 0x5800
834#define T_OPCODE_STR_RW 0x5000
835#define T_OPCODE_LDR_RH 0x5a00
836#define T_OPCODE_STR_RH 0x5200
837#define T_OPCODE_LDR_RB 0x5c00
838#define T_OPCODE_STR_RB 0x5400
c9b604bd 839
a737bd4d
NC
840#define T_OPCODE_PUSH 0xb400
841#define T_OPCODE_POP 0xbc00
b99bd4ef 842
2fc8bdac 843#define T_OPCODE_BRANCH 0xe000
b99bd4ef 844
a737bd4d 845#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 846#define THUMB_PP_PC_LR 0x0100
c19d1205 847#define THUMB_LOAD_BIT 0x0800
53365c0d 848#define THUMB2_LOAD_BIT 0x00100000
c19d1205 849
5ee91343 850#define BAD_SYNTAX _("syntax error")
c19d1205 851#define BAD_ARGS _("bad arguments to instruction")
fdfde340 852#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
853#define BAD_PC _("r15 not allowed here")
854#define BAD_COND _("instruction cannot be conditional")
855#define BAD_OVERLAP _("registers may not be the same")
856#define BAD_HIREG _("lo register required")
857#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 858#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5 859#define BAD_BRANCH _("branch must be last instruction in IT block")
e12437dc 860#define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
dfa9f0d5 861#define BAD_NOT_IT _("instruction not allowed in IT block")
5ee91343 862#define BAD_NOT_VPT _("instruction missing MVE vector predication code")
037e8744 863#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58 864#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
5ee91343
AV
865#define BAD_OUT_VPT \
866 _("vector predicated instruction should be in VPT/VPST block")
e07e6e58 867#define BAD_IT_COND _("incorrect condition in IT block")
5ee91343 868#define BAD_VPT_COND _("incorrect condition in VPT/VPST block")
e07e6e58 869#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 870#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
871#define BAD_PC_ADDRESSING \
872 _("cannot use register index with PC-relative addressing")
873#define BAD_PC_WRITEBACK \
874 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
875#define BAD_RANGE _("branch out of range")
876#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 877#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 878#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
5ee91343
AV
879#define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \
880 "block")
881#define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \
882 "block")
883#define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \
884 " operand")
885#define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \
886 " operand")
c19d1205 887
c921be7d
NC
888static struct hash_control * arm_ops_hsh;
889static struct hash_control * arm_cond_hsh;
5ee91343 890static struct hash_control * arm_vcond_hsh;
c921be7d
NC
891static struct hash_control * arm_shift_hsh;
892static struct hash_control * arm_psr_hsh;
893static struct hash_control * arm_v7m_psr_hsh;
894static struct hash_control * arm_reg_hsh;
895static struct hash_control * arm_reloc_hsh;
896static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 897
b99bd4ef
NC
898/* Stuff needed to resolve the label ambiguity
899 As:
900 ...
901 label: <insn>
902 may differ from:
903 ...
904 label:
5f4273c7 905 <insn> */
b99bd4ef
NC
906
907symbolS * last_label_seen;
b34976b6 908static int label_is_thumb_function_name = FALSE;
e07e6e58 909
3d0c9500
NC
910/* Literal pool structure. Held on a per-section
911 and per-sub-section basis. */
a737bd4d 912
c19d1205 913#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 914typedef struct literal_pool
b99bd4ef 915{
c921be7d
NC
916 expressionS literals [MAX_LITERAL_POOL_SIZE];
917 unsigned int next_free_entry;
918 unsigned int id;
919 symbolS * symbol;
920 segT section;
921 subsegT sub_section;
a8040cf2
NC
922#ifdef OBJ_ELF
923 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
924#endif
c921be7d 925 struct literal_pool * next;
8335d6aa 926 unsigned int alignment;
3d0c9500 927} literal_pool;
b99bd4ef 928
3d0c9500
NC
929/* Pointer to a linked list of literal pools. */
930literal_pool * list_of_pools = NULL;
e27ec89e 931
2e6976a8
DG
932typedef enum asmfunc_states
933{
934 OUTSIDE_ASMFUNC,
935 WAITING_ASMFUNC_NAME,
936 WAITING_ENDASMFUNC
937} asmfunc_states;
938
939static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
940
e07e6e58 941#ifdef OBJ_ELF
5ee91343 942# define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred
e07e6e58 943#else
5ee91343 944static struct current_pred now_pred;
e07e6e58
NC
945#endif
946
947static inline int
5ee91343 948now_pred_compatible (int cond)
e07e6e58 949{
5ee91343 950 return (cond & ~1) == (now_pred.cc & ~1);
e07e6e58
NC
951}
952
953static inline int
954conditional_insn (void)
955{
956 return inst.cond != COND_ALWAYS;
957}
958
5ee91343 959static int in_pred_block (void);
e07e6e58 960
5ee91343 961static int handle_pred_state (void);
e07e6e58
NC
962
963static void force_automatic_it_block_close (void);
964
c921be7d
NC
965static void it_fsm_post_encode (void);
966
5ee91343 967#define set_pred_insn_type(type) \
e07e6e58
NC
968 do \
969 { \
5ee91343
AV
970 inst.pred_insn_type = type; \
971 if (handle_pred_state () == FAIL) \
477330fc 972 return; \
e07e6e58
NC
973 } \
974 while (0)
975
5ee91343 976#define set_pred_insn_type_nonvoid(type, failret) \
c921be7d
NC
977 do \
978 { \
5ee91343
AV
979 inst.pred_insn_type = type; \
980 if (handle_pred_state () == FAIL) \
477330fc 981 return failret; \
c921be7d
NC
982 } \
983 while(0)
984
5ee91343 985#define set_pred_insn_type_last() \
e07e6e58
NC
986 do \
987 { \
988 if (inst.cond == COND_ALWAYS) \
5ee91343 989 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 990 else \
5ee91343 991 set_pred_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
992 } \
993 while (0)
994
c19d1205 995/* Pure syntax. */
b99bd4ef 996
c19d1205
ZW
997/* This array holds the chars that always start a comment. If the
998 pre-processor is disabled, these aren't very useful. */
2e6976a8 999char arm_comment_chars[] = "@";
3d0c9500 1000
c19d1205
ZW
1001/* This array holds the chars that only start a comment at the beginning of
1002 a line. If the line seems to have the form '# 123 filename'
1003 .line and .file directives will appear in the pre-processed output. */
1004/* Note that input_file.c hand checks for '#' at the beginning of the
1005 first line of the input file. This is because the compiler outputs
1006 #NO_APP at the beginning of its output. */
1007/* Also note that comments like this one will always work. */
1008const char line_comment_chars[] = "#";
3d0c9500 1009
2e6976a8 1010char arm_line_separator_chars[] = ";";
b99bd4ef 1011
c19d1205
ZW
1012/* Chars that can be used to separate mant
1013 from exp in floating point numbers. */
1014const char EXP_CHARS[] = "eE";
3d0c9500 1015
c19d1205
ZW
1016/* Chars that mean this number is a floating point constant. */
1017/* As in 0f12.456 */
1018/* or 0d1.2345e12 */
b99bd4ef 1019
c19d1205 1020const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 1021
c19d1205
ZW
1022/* Prefix characters that indicate the start of an immediate
1023 value. */
1024#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 1025
c19d1205
ZW
1026/* Separator character handling. */
1027
1028#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1029
1030static inline int
1031skip_past_char (char ** str, char c)
1032{
8ab8155f
NC
1033 /* PR gas/14987: Allow for whitespace before the expected character. */
1034 skip_whitespace (*str);
427d0db6 1035
c19d1205
ZW
1036 if (**str == c)
1037 {
1038 (*str)++;
1039 return SUCCESS;
3d0c9500 1040 }
c19d1205
ZW
1041 else
1042 return FAIL;
1043}
c921be7d 1044
c19d1205 1045#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 1046
c19d1205
ZW
1047/* Arithmetic expressions (possibly involving symbols). */
1048
1049/* Return TRUE if anything in the expression is a bignum. */
1050
0198d5e6 1051static bfd_boolean
c19d1205
ZW
1052walk_no_bignums (symbolS * sp)
1053{
1054 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 1055 return TRUE;
c19d1205
ZW
1056
1057 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 1058 {
c19d1205
ZW
1059 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1060 || (symbol_get_value_expression (sp)->X_op_symbol
1061 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
1062 }
1063
0198d5e6 1064 return FALSE;
3d0c9500
NC
1065}
1066
0198d5e6 1067static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
1068
1069/* Third argument to my_get_expression. */
1070#define GE_NO_PREFIX 0
1071#define GE_IMM_PREFIX 1
1072#define GE_OPT_PREFIX 2
5287ad62
JB
1073/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1074 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1075#define GE_OPT_PREFIX_BIG 3
a737bd4d 1076
b99bd4ef 1077static int
c19d1205 1078my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1079{
c19d1205 1080 char * save_in;
b99bd4ef 1081
c19d1205
ZW
1082 /* In unified syntax, all prefixes are optional. */
1083 if (unified_syntax)
5287ad62 1084 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1085 : GE_OPT_PREFIX;
b99bd4ef 1086
c19d1205 1087 switch (prefix_mode)
b99bd4ef 1088 {
c19d1205
ZW
1089 case GE_NO_PREFIX: break;
1090 case GE_IMM_PREFIX:
1091 if (!is_immediate_prefix (**str))
1092 {
1093 inst.error = _("immediate expression requires a # prefix");
1094 return FAIL;
1095 }
1096 (*str)++;
1097 break;
1098 case GE_OPT_PREFIX:
5287ad62 1099 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1100 if (is_immediate_prefix (**str))
1101 (*str)++;
1102 break;
0198d5e6
TC
1103 default:
1104 abort ();
c19d1205 1105 }
b99bd4ef 1106
c19d1205 1107 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1108
c19d1205
ZW
1109 save_in = input_line_pointer;
1110 input_line_pointer = *str;
0198d5e6 1111 in_my_get_expression = TRUE;
2ac93be7 1112 expression (ep);
0198d5e6 1113 in_my_get_expression = FALSE;
c19d1205 1114
f86adc07 1115 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1116 {
f86adc07 1117 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1118 *str = input_line_pointer;
1119 input_line_pointer = save_in;
1120 if (inst.error == NULL)
f86adc07
NS
1121 inst.error = (ep->X_op == O_absent
1122 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1123 return 1;
1124 }
b99bd4ef 1125
c19d1205
ZW
1126 /* Get rid of any bignums now, so that we don't generate an error for which
1127 we can't establish a line number later on. Big numbers are never valid
1128 in instructions, which is where this routine is always called. */
5287ad62
JB
1129 if (prefix_mode != GE_OPT_PREFIX_BIG
1130 && (ep->X_op == O_big
477330fc 1131 || (ep->X_add_symbol
5287ad62 1132 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1133 || (ep->X_op_symbol
5287ad62 1134 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1135 {
1136 inst.error = _("invalid constant");
1137 *str = input_line_pointer;
1138 input_line_pointer = save_in;
1139 return 1;
1140 }
b99bd4ef 1141
c19d1205
ZW
1142 *str = input_line_pointer;
1143 input_line_pointer = save_in;
0198d5e6 1144 return SUCCESS;
b99bd4ef
NC
1145}
1146
c19d1205
ZW
1147/* Turn a string in input_line_pointer into a floating point constant
1148 of type TYPE, and store the appropriate bytes in *LITP. The number
1149 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1150 returned, or NULL on OK.
b99bd4ef 1151
c19d1205
ZW
1152 Note that fp constants aren't represent in the normal way on the ARM.
1153 In big endian mode, things are as expected. However, in little endian
1154 mode fp constants are big-endian word-wise, and little-endian byte-wise
1155 within the words. For example, (double) 1.1 in big endian mode is
1156 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1157 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1158
c19d1205 1159 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1160
6d4af3c2 1161const char *
c19d1205
ZW
1162md_atof (int type, char * litP, int * sizeP)
1163{
1164 int prec;
1165 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1166 char *t;
1167 int i;
b99bd4ef 1168
c19d1205
ZW
1169 switch (type)
1170 {
1171 case 'f':
1172 case 'F':
1173 case 's':
1174 case 'S':
1175 prec = 2;
1176 break;
b99bd4ef 1177
c19d1205
ZW
1178 case 'd':
1179 case 'D':
1180 case 'r':
1181 case 'R':
1182 prec = 4;
1183 break;
b99bd4ef 1184
c19d1205
ZW
1185 case 'x':
1186 case 'X':
499ac353 1187 prec = 5;
c19d1205 1188 break;
b99bd4ef 1189
c19d1205
ZW
1190 case 'p':
1191 case 'P':
499ac353 1192 prec = 5;
c19d1205 1193 break;
a737bd4d 1194
c19d1205
ZW
1195 default:
1196 *sizeP = 0;
499ac353 1197 return _("Unrecognized or unsupported floating point constant");
c19d1205 1198 }
b99bd4ef 1199
c19d1205
ZW
1200 t = atof_ieee (input_line_pointer, type, words);
1201 if (t)
1202 input_line_pointer = t;
499ac353 1203 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1204
c19d1205
ZW
1205 if (target_big_endian)
1206 {
1207 for (i = 0; i < prec; i++)
1208 {
499ac353
NC
1209 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1210 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1211 }
1212 }
1213 else
1214 {
e74cfd16 1215 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1216 for (i = prec - 1; i >= 0; i--)
1217 {
499ac353
NC
1218 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1219 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1220 }
1221 else
1222 /* For a 4 byte float the order of elements in `words' is 1 0.
1223 For an 8 byte float the order is 1 0 3 2. */
1224 for (i = 0; i < prec; i += 2)
1225 {
499ac353
NC
1226 md_number_to_chars (litP, (valueT) words[i + 1],
1227 sizeof (LITTLENUM_TYPE));
1228 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1229 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1230 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1231 }
1232 }
b99bd4ef 1233
499ac353 1234 return NULL;
c19d1205 1235}
b99bd4ef 1236
c19d1205
ZW
1237/* We handle all bad expressions here, so that we can report the faulty
1238 instruction in the error message. */
0198d5e6 1239
c19d1205 1240void
91d6fa6a 1241md_operand (expressionS * exp)
c19d1205
ZW
1242{
1243 if (in_my_get_expression)
91d6fa6a 1244 exp->X_op = O_illegal;
b99bd4ef
NC
1245}
1246
c19d1205 1247/* Immediate values. */
b99bd4ef 1248
0198d5e6 1249#ifdef OBJ_ELF
c19d1205
ZW
1250/* Generic immediate-value read function for use in directives.
1251 Accepts anything that 'expression' can fold to a constant.
1252 *val receives the number. */
0198d5e6 1253
c19d1205
ZW
1254static int
1255immediate_for_directive (int *val)
b99bd4ef 1256{
c19d1205
ZW
1257 expressionS exp;
1258 exp.X_op = O_illegal;
b99bd4ef 1259
c19d1205
ZW
1260 if (is_immediate_prefix (*input_line_pointer))
1261 {
1262 input_line_pointer++;
1263 expression (&exp);
1264 }
b99bd4ef 1265
c19d1205
ZW
1266 if (exp.X_op != O_constant)
1267 {
1268 as_bad (_("expected #constant"));
1269 ignore_rest_of_line ();
1270 return FAIL;
1271 }
1272 *val = exp.X_add_number;
1273 return SUCCESS;
b99bd4ef 1274}
c19d1205 1275#endif
b99bd4ef 1276
c19d1205 1277/* Register parsing. */
b99bd4ef 1278
c19d1205
ZW
1279/* Generic register parser. CCP points to what should be the
1280 beginning of a register name. If it is indeed a valid register
1281 name, advance CCP over it and return the reg_entry structure;
1282 otherwise return NULL. Does not issue diagnostics. */
1283
1284static struct reg_entry *
1285arm_reg_parse_multi (char **ccp)
b99bd4ef 1286{
c19d1205
ZW
1287 char *start = *ccp;
1288 char *p;
1289 struct reg_entry *reg;
b99bd4ef 1290
477330fc
RM
1291 skip_whitespace (start);
1292
c19d1205
ZW
1293#ifdef REGISTER_PREFIX
1294 if (*start != REGISTER_PREFIX)
01cfc07f 1295 return NULL;
c19d1205
ZW
1296 start++;
1297#endif
1298#ifdef OPTIONAL_REGISTER_PREFIX
1299 if (*start == OPTIONAL_REGISTER_PREFIX)
1300 start++;
1301#endif
b99bd4ef 1302
c19d1205
ZW
1303 p = start;
1304 if (!ISALPHA (*p) || !is_name_beginner (*p))
1305 return NULL;
b99bd4ef 1306
c19d1205
ZW
1307 do
1308 p++;
1309 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1310
1311 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1312
1313 if (!reg)
1314 return NULL;
1315
1316 *ccp = p;
1317 return reg;
b99bd4ef
NC
1318}
1319
1320static int
dcbf9037 1321arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1322 enum arm_reg_type type)
b99bd4ef 1323{
c19d1205
ZW
1324 /* Alternative syntaxes are accepted for a few register classes. */
1325 switch (type)
1326 {
1327 case REG_TYPE_MVF:
1328 case REG_TYPE_MVD:
1329 case REG_TYPE_MVFX:
1330 case REG_TYPE_MVDX:
1331 /* Generic coprocessor register names are allowed for these. */
79134647 1332 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1333 return reg->number;
1334 break;
69b97547 1335
c19d1205
ZW
1336 case REG_TYPE_CP:
1337 /* For backward compatibility, a bare number is valid here. */
1338 {
1339 unsigned long processor = strtoul (start, ccp, 10);
1340 if (*ccp != start && processor <= 15)
1341 return processor;
1342 }
1a0670f3 1343 /* Fall through. */
6057a28f 1344
c19d1205
ZW
1345 case REG_TYPE_MMXWC:
1346 /* WC includes WCG. ??? I'm not sure this is true for all
1347 instructions that take WC registers. */
79134647 1348 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1349 return reg->number;
6057a28f 1350 break;
c19d1205 1351
6057a28f 1352 default:
c19d1205 1353 break;
6057a28f
NC
1354 }
1355
dcbf9037
JB
1356 return FAIL;
1357}
1358
1359/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1360 return value is the register number or FAIL. */
1361
1362static int
1363arm_reg_parse (char **ccp, enum arm_reg_type type)
1364{
1365 char *start = *ccp;
1366 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1367 int ret;
1368
1369 /* Do not allow a scalar (reg+index) to parse as a register. */
1370 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1371 return FAIL;
1372
1373 if (reg && reg->type == type)
1374 return reg->number;
1375
1376 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1377 return ret;
1378
c19d1205
ZW
1379 *ccp = start;
1380 return FAIL;
1381}
69b97547 1382
dcbf9037
JB
1383/* Parse a Neon type specifier. *STR should point at the leading '.'
1384 character. Does no verification at this stage that the type fits the opcode
1385 properly. E.g.,
1386
1387 .i32.i32.s16
1388 .s32.f32
1389 .u16
1390
1391 Can all be legally parsed by this function.
1392
1393 Fills in neon_type struct pointer with parsed information, and updates STR
1394 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1395 type, FAIL if not. */
1396
1397static int
1398parse_neon_type (struct neon_type *type, char **str)
1399{
1400 char *ptr = *str;
1401
1402 if (type)
1403 type->elems = 0;
1404
1405 while (type->elems < NEON_MAX_TYPE_ELS)
1406 {
1407 enum neon_el_type thistype = NT_untyped;
1408 unsigned thissize = -1u;
1409
1410 if (*ptr != '.')
1411 break;
1412
1413 ptr++;
1414
1415 /* Just a size without an explicit type. */
1416 if (ISDIGIT (*ptr))
1417 goto parsesize;
1418
1419 switch (TOLOWER (*ptr))
1420 {
1421 case 'i': thistype = NT_integer; break;
1422 case 'f': thistype = NT_float; break;
1423 case 'p': thistype = NT_poly; break;
1424 case 's': thistype = NT_signed; break;
1425 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1426 case 'd':
1427 thistype = NT_float;
1428 thissize = 64;
1429 ptr++;
1430 goto done;
dcbf9037
JB
1431 default:
1432 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1433 return FAIL;
1434 }
1435
1436 ptr++;
1437
1438 /* .f is an abbreviation for .f32. */
1439 if (thistype == NT_float && !ISDIGIT (*ptr))
1440 thissize = 32;
1441 else
1442 {
1443 parsesize:
1444 thissize = strtoul (ptr, &ptr, 10);
1445
1446 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1447 && thissize != 64)
1448 {
1449 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1450 return FAIL;
1451 }
1452 }
1453
037e8744 1454 done:
dcbf9037 1455 if (type)
477330fc
RM
1456 {
1457 type->el[type->elems].type = thistype;
dcbf9037
JB
1458 type->el[type->elems].size = thissize;
1459 type->elems++;
1460 }
1461 }
1462
1463 /* Empty/missing type is not a successful parse. */
1464 if (type->elems == 0)
1465 return FAIL;
1466
1467 *str = ptr;
1468
1469 return SUCCESS;
1470}
1471
1472/* Errors may be set multiple times during parsing or bit encoding
1473 (particularly in the Neon bits), but usually the earliest error which is set
1474 will be the most meaningful. Avoid overwriting it with later (cascading)
1475 errors by calling this function. */
1476
1477static void
1478first_error (const char *err)
1479{
1480 if (!inst.error)
1481 inst.error = err;
1482}
1483
1484/* Parse a single type, e.g. ".s32", leading period included. */
1485static int
1486parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1487{
1488 char *str = *ccp;
1489 struct neon_type optype;
1490
1491 if (*str == '.')
1492 {
1493 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1494 {
1495 if (optype.elems == 1)
1496 *vectype = optype.el[0];
1497 else
1498 {
1499 first_error (_("only one type should be specified for operand"));
1500 return FAIL;
1501 }
1502 }
dcbf9037 1503 else
477330fc
RM
1504 {
1505 first_error (_("vector type expected"));
1506 return FAIL;
1507 }
dcbf9037
JB
1508 }
1509 else
1510 return FAIL;
5f4273c7 1511
dcbf9037 1512 *ccp = str;
5f4273c7 1513
dcbf9037
JB
1514 return SUCCESS;
1515}
1516
1517/* Special meanings for indices (which have a range of 0-7), which will fit into
1518 a 4-bit integer. */
1519
1520#define NEON_ALL_LANES 15
1521#define NEON_INTERLEAVE_LANES 14
1522
5ee91343
AV
1523/* Record a use of the given feature. */
1524static void
1525record_feature_use (const arm_feature_set *feature)
1526{
1527 if (thumb_mode)
1528 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
1529 else
1530 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
1531}
1532
1533/* If the given feature available in the selected CPU, mark it as used.
1534 Returns TRUE iff feature is available. */
1535static bfd_boolean
1536mark_feature_used (const arm_feature_set *feature)
1537{
1538 /* Ensure the option is valid on the current architecture. */
1539 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
1540 return FALSE;
1541
1542 /* Add the appropriate architecture feature for the barrier option used.
1543 */
1544 record_feature_use (feature);
1545
1546 return TRUE;
1547}
1548
dcbf9037
JB
1549/* Parse either a register or a scalar, with an optional type. Return the
1550 register number, and optionally fill in the actual type of the register
1551 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1552 type/index information in *TYPEINFO. */
1553
1554static int
1555parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1556 enum arm_reg_type *rtype,
1557 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1558{
1559 char *str = *ccp;
1560 struct reg_entry *reg = arm_reg_parse_multi (&str);
1561 struct neon_typed_alias atype;
1562 struct neon_type_el parsetype;
1563
1564 atype.defined = 0;
1565 atype.index = -1;
1566 atype.eltype.type = NT_invtype;
1567 atype.eltype.size = -1;
1568
1569 /* Try alternate syntax for some types of register. Note these are mutually
1570 exclusive with the Neon syntax extensions. */
1571 if (reg == NULL)
1572 {
1573 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1574 if (altreg != FAIL)
477330fc 1575 *ccp = str;
dcbf9037 1576 if (typeinfo)
477330fc 1577 *typeinfo = atype;
dcbf9037
JB
1578 return altreg;
1579 }
1580
037e8744
JB
1581 /* Undo polymorphism when a set of register types may be accepted. */
1582 if ((type == REG_TYPE_NDQ
1583 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1584 || (type == REG_TYPE_VFSD
477330fc 1585 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1586 || (type == REG_TYPE_NSDQ
477330fc
RM
1587 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1588 || reg->type == REG_TYPE_NQ))
dec41383
JW
1589 || (type == REG_TYPE_NSD
1590 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
f512f76f
NC
1591 || (type == REG_TYPE_MMXWC
1592 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1593 type = (enum arm_reg_type) reg->type;
dcbf9037 1594
5ee91343
AV
1595 if (type == REG_TYPE_MQ)
1596 {
1597 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1598 return FAIL;
1599
1600 if (!reg || reg->type != REG_TYPE_NQ)
1601 return FAIL;
1602
1603 if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32))
1604 {
1605 first_error (_("expected MVE register [q0..q7]"));
1606 return FAIL;
1607 }
1608 type = REG_TYPE_NQ;
1609 }
1610 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
1611 && (type == REG_TYPE_NQ))
1612 return FAIL;
1613
1614
dcbf9037
JB
1615 if (type != reg->type)
1616 return FAIL;
1617
1618 if (reg->neon)
1619 atype = *reg->neon;
5f4273c7 1620
dcbf9037
JB
1621 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1622 {
1623 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1624 {
1625 first_error (_("can't redefine type for operand"));
1626 return FAIL;
1627 }
dcbf9037
JB
1628 atype.defined |= NTA_HASTYPE;
1629 atype.eltype = parsetype;
1630 }
5f4273c7 1631
dcbf9037
JB
1632 if (skip_past_char (&str, '[') == SUCCESS)
1633 {
dec41383
JW
1634 if (type != REG_TYPE_VFD
1635 && !(type == REG_TYPE_VFS
1636 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2)))
477330fc
RM
1637 {
1638 first_error (_("only D registers may be indexed"));
1639 return FAIL;
1640 }
5f4273c7 1641
dcbf9037 1642 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1643 {
1644 first_error (_("can't change index for operand"));
1645 return FAIL;
1646 }
dcbf9037
JB
1647
1648 atype.defined |= NTA_HASINDEX;
1649
1650 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1651 atype.index = NEON_ALL_LANES;
dcbf9037 1652 else
477330fc
RM
1653 {
1654 expressionS exp;
dcbf9037 1655
477330fc 1656 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1657
477330fc
RM
1658 if (exp.X_op != O_constant)
1659 {
1660 first_error (_("constant expression required"));
1661 return FAIL;
1662 }
dcbf9037 1663
477330fc
RM
1664 if (skip_past_char (&str, ']') == FAIL)
1665 return FAIL;
dcbf9037 1666
477330fc
RM
1667 atype.index = exp.X_add_number;
1668 }
dcbf9037 1669 }
5f4273c7 1670
dcbf9037
JB
1671 if (typeinfo)
1672 *typeinfo = atype;
5f4273c7 1673
dcbf9037
JB
1674 if (rtype)
1675 *rtype = type;
5f4273c7 1676
dcbf9037 1677 *ccp = str;
5f4273c7 1678
dcbf9037
JB
1679 return reg->number;
1680}
1681
efd6b359 1682/* Like arm_reg_parse, but also allow the following extra features:
dcbf9037
JB
1683 - If RTYPE is non-zero, return the (possibly restricted) type of the
1684 register (e.g. Neon double or quad reg when either has been requested).
1685 - If this is a Neon vector type with additional type information, fill
1686 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1687 This function will fault on encountering a scalar. */
dcbf9037
JB
1688
1689static int
1690arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1691 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1692{
1693 struct neon_typed_alias atype;
1694 char *str = *ccp;
1695 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1696
1697 if (reg == FAIL)
1698 return FAIL;
1699
0855e32b
NS
1700 /* Do not allow regname(... to parse as a register. */
1701 if (*str == '(')
1702 return FAIL;
1703
dcbf9037
JB
1704 /* Do not allow a scalar (reg+index) to parse as a register. */
1705 if ((atype.defined & NTA_HASINDEX) != 0)
1706 {
1707 first_error (_("register operand expected, but got scalar"));
1708 return FAIL;
1709 }
1710
1711 if (vectype)
1712 *vectype = atype.eltype;
1713
1714 *ccp = str;
1715
1716 return reg;
1717}
1718
1719#define NEON_SCALAR_REG(X) ((X) >> 4)
1720#define NEON_SCALAR_INDEX(X) ((X) & 15)
1721
5287ad62
JB
1722/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1723 have enough information to be able to do a good job bounds-checking. So, we
1724 just do easy checks here, and do further checks later. */
1725
1726static int
dcbf9037 1727parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1728{
dcbf9037 1729 int reg;
5287ad62 1730 char *str = *ccp;
dcbf9037 1731 struct neon_typed_alias atype;
dec41383
JW
1732 enum arm_reg_type reg_type = REG_TYPE_VFD;
1733
1734 if (elsize == 4)
1735 reg_type = REG_TYPE_VFS;
5f4273c7 1736
dec41383 1737 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
5f4273c7 1738
dcbf9037 1739 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1740 return FAIL;
5f4273c7 1741
dcbf9037 1742 if (atype.index == NEON_ALL_LANES)
5287ad62 1743 {
dcbf9037 1744 first_error (_("scalar must have an index"));
5287ad62
JB
1745 return FAIL;
1746 }
dcbf9037 1747 else if (atype.index >= 64 / elsize)
5287ad62 1748 {
dcbf9037 1749 first_error (_("scalar index out of range"));
5287ad62
JB
1750 return FAIL;
1751 }
5f4273c7 1752
dcbf9037
JB
1753 if (type)
1754 *type = atype.eltype;
5f4273c7 1755
5287ad62 1756 *ccp = str;
5f4273c7 1757
dcbf9037 1758 return reg * 16 + atype.index;
5287ad62
JB
1759}
1760
4b5a202f
AV
1761/* Types of registers in a list. */
1762
1763enum reg_list_els
1764{
1765 REGLIST_RN,
1766 REGLIST_CLRM,
1767 REGLIST_VFP_S,
efd6b359 1768 REGLIST_VFP_S_VPR,
4b5a202f 1769 REGLIST_VFP_D,
efd6b359 1770 REGLIST_VFP_D_VPR,
4b5a202f
AV
1771 REGLIST_NEON_D
1772};
1773
c19d1205 1774/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1775
c19d1205 1776static long
4b5a202f 1777parse_reg_list (char ** strp, enum reg_list_els etype)
c19d1205 1778{
4b5a202f
AV
1779 char *str = *strp;
1780 long range = 0;
1781 int another_range;
1782
1783 gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM);
a737bd4d 1784
c19d1205
ZW
1785 /* We come back here if we get ranges concatenated by '+' or '|'. */
1786 do
6057a28f 1787 {
477330fc
RM
1788 skip_whitespace (str);
1789
c19d1205 1790 another_range = 0;
a737bd4d 1791
c19d1205
ZW
1792 if (*str == '{')
1793 {
1794 int in_range = 0;
1795 int cur_reg = -1;
a737bd4d 1796
c19d1205
ZW
1797 str++;
1798 do
1799 {
1800 int reg;
4b5a202f
AV
1801 const char apsr_str[] = "apsr";
1802 int apsr_str_len = strlen (apsr_str);
6057a28f 1803
4b5a202f
AV
1804 reg = arm_reg_parse (&str, REGLIST_RN);
1805 if (etype == REGLIST_CLRM)
c19d1205 1806 {
4b5a202f
AV
1807 if (reg == REG_SP || reg == REG_PC)
1808 reg = FAIL;
1809 else if (reg == FAIL
1810 && !strncasecmp (str, apsr_str, apsr_str_len)
1811 && !ISALPHA (*(str + apsr_str_len)))
1812 {
1813 reg = 15;
1814 str += apsr_str_len;
1815 }
1816
1817 if (reg == FAIL)
1818 {
1819 first_error (_("r0-r12, lr or APSR expected"));
1820 return FAIL;
1821 }
1822 }
1823 else /* etype == REGLIST_RN. */
1824 {
1825 if (reg == FAIL)
1826 {
1827 first_error (_(reg_expected_msgs[REGLIST_RN]));
1828 return FAIL;
1829 }
c19d1205 1830 }
a737bd4d 1831
c19d1205
ZW
1832 if (in_range)
1833 {
1834 int i;
a737bd4d 1835
c19d1205
ZW
1836 if (reg <= cur_reg)
1837 {
dcbf9037 1838 first_error (_("bad range in register list"));
c19d1205
ZW
1839 return FAIL;
1840 }
40a18ebd 1841
c19d1205
ZW
1842 for (i = cur_reg + 1; i < reg; i++)
1843 {
1844 if (range & (1 << i))
1845 as_tsktsk
1846 (_("Warning: duplicated register (r%d) in register list"),
1847 i);
1848 else
1849 range |= 1 << i;
1850 }
1851 in_range = 0;
1852 }
a737bd4d 1853
c19d1205
ZW
1854 if (range & (1 << reg))
1855 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1856 reg);
1857 else if (reg <= cur_reg)
1858 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1859
c19d1205
ZW
1860 range |= 1 << reg;
1861 cur_reg = reg;
1862 }
1863 while (skip_past_comma (&str) != FAIL
1864 || (in_range = 1, *str++ == '-'));
1865 str--;
a737bd4d 1866
d996d970 1867 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1868 {
dcbf9037 1869 first_error (_("missing `}'"));
c19d1205
ZW
1870 return FAIL;
1871 }
1872 }
4b5a202f 1873 else if (etype == REGLIST_RN)
c19d1205 1874 {
91d6fa6a 1875 expressionS exp;
40a18ebd 1876
91d6fa6a 1877 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1878 return FAIL;
40a18ebd 1879
91d6fa6a 1880 if (exp.X_op == O_constant)
c19d1205 1881 {
91d6fa6a
NC
1882 if (exp.X_add_number
1883 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1884 {
1885 inst.error = _("invalid register mask");
1886 return FAIL;
1887 }
a737bd4d 1888
91d6fa6a 1889 if ((range & exp.X_add_number) != 0)
c19d1205 1890 {
91d6fa6a 1891 int regno = range & exp.X_add_number;
a737bd4d 1892
c19d1205
ZW
1893 regno &= -regno;
1894 regno = (1 << regno) - 1;
1895 as_tsktsk
1896 (_("Warning: duplicated register (r%d) in register list"),
1897 regno);
1898 }
a737bd4d 1899
91d6fa6a 1900 range |= exp.X_add_number;
c19d1205
ZW
1901 }
1902 else
1903 {
e2b0ab59 1904 if (inst.relocs[0].type != 0)
c19d1205
ZW
1905 {
1906 inst.error = _("expression too complex");
1907 return FAIL;
1908 }
a737bd4d 1909
e2b0ab59
AV
1910 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
1911 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
1912 inst.relocs[0].pc_rel = 0;
c19d1205
ZW
1913 }
1914 }
a737bd4d 1915
c19d1205
ZW
1916 if (*str == '|' || *str == '+')
1917 {
1918 str++;
1919 another_range = 1;
1920 }
a737bd4d 1921 }
c19d1205 1922 while (another_range);
a737bd4d 1923
c19d1205
ZW
1924 *strp = str;
1925 return range;
a737bd4d
NC
1926}
1927
c19d1205
ZW
1928/* Parse a VFP register list. If the string is invalid return FAIL.
1929 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1930 register. Parses registers of type ETYPE.
1931 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1932 - Q registers can be used to specify pairs of D registers
1933 - { } can be omitted from around a singleton register list
477330fc
RM
1934 FIXME: This is not implemented, as it would require backtracking in
1935 some cases, e.g.:
1936 vtbl.8 d3,d4,d5
1937 This could be done (the meaning isn't really ambiguous), but doesn't
1938 fit in well with the current parsing framework.
dcbf9037
JB
1939 - 32 D registers may be used (also true for VFPv3).
1940 FIXME: Types are ignored in these register lists, which is probably a
1941 bug. */
6057a28f 1942
c19d1205 1943static int
efd6b359
AV
1944parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype,
1945 bfd_boolean *partial_match)
6057a28f 1946{
037e8744 1947 char *str = *ccp;
c19d1205
ZW
1948 int base_reg;
1949 int new_base;
21d799b5 1950 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1951 int max_regs = 0;
c19d1205
ZW
1952 int count = 0;
1953 int warned = 0;
1954 unsigned long mask = 0;
a737bd4d 1955 int i;
efd6b359
AV
1956 bfd_boolean vpr_seen = FALSE;
1957 bfd_boolean expect_vpr =
1958 (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR);
6057a28f 1959
477330fc 1960 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1961 {
1962 inst.error = _("expecting {");
1963 return FAIL;
1964 }
6057a28f 1965
5287ad62 1966 switch (etype)
c19d1205 1967 {
5287ad62 1968 case REGLIST_VFP_S:
efd6b359 1969 case REGLIST_VFP_S_VPR:
c19d1205
ZW
1970 regtype = REG_TYPE_VFS;
1971 max_regs = 32;
5287ad62 1972 break;
5f4273c7 1973
5287ad62 1974 case REGLIST_VFP_D:
efd6b359 1975 case REGLIST_VFP_D_VPR:
5287ad62 1976 regtype = REG_TYPE_VFD;
b7fc2769 1977 break;
5f4273c7 1978
b7fc2769
JB
1979 case REGLIST_NEON_D:
1980 regtype = REG_TYPE_NDQ;
1981 break;
4b5a202f
AV
1982
1983 default:
1984 gas_assert (0);
b7fc2769
JB
1985 }
1986
efd6b359 1987 if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR)
b7fc2769 1988 {
b1cc4aeb
PB
1989 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1990 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1991 {
1992 max_regs = 32;
1993 if (thumb_mode)
1994 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1995 fpu_vfp_ext_d32);
1996 else
1997 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1998 fpu_vfp_ext_d32);
1999 }
5287ad62 2000 else
477330fc 2001 max_regs = 16;
c19d1205 2002 }
6057a28f 2003
c19d1205 2004 base_reg = max_regs;
efd6b359 2005 *partial_match = FALSE;
a737bd4d 2006
c19d1205
ZW
2007 do
2008 {
5287ad62 2009 int setmask = 1, addregs = 1;
efd6b359
AV
2010 const char vpr_str[] = "vpr";
2011 int vpr_str_len = strlen (vpr_str);
dcbf9037 2012
037e8744 2013 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 2014
efd6b359
AV
2015 if (expect_vpr)
2016 {
2017 if (new_base == FAIL
2018 && !strncasecmp (str, vpr_str, vpr_str_len)
2019 && !ISALPHA (*(str + vpr_str_len))
2020 && !vpr_seen)
2021 {
2022 vpr_seen = TRUE;
2023 str += vpr_str_len;
2024 if (count == 0)
2025 base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */
2026 }
2027 else if (vpr_seen)
2028 {
2029 first_error (_("VPR expected last"));
2030 return FAIL;
2031 }
2032 else if (new_base == FAIL)
2033 {
2034 if (regtype == REG_TYPE_VFS)
2035 first_error (_("VFP single precision register or VPR "
2036 "expected"));
2037 else /* regtype == REG_TYPE_VFD. */
2038 first_error (_("VFP/Neon double precision register or VPR "
2039 "expected"));
2040 return FAIL;
2041 }
2042 }
2043 else if (new_base == FAIL)
a737bd4d 2044 {
dcbf9037 2045 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
2046 return FAIL;
2047 }
5f4273c7 2048
efd6b359
AV
2049 *partial_match = TRUE;
2050 if (vpr_seen)
2051 continue;
2052
b7fc2769 2053 if (new_base >= max_regs)
477330fc
RM
2054 {
2055 first_error (_("register out of range in list"));
2056 return FAIL;
2057 }
5f4273c7 2058
5287ad62
JB
2059 /* Note: a value of 2 * n is returned for the register Q<n>. */
2060 if (regtype == REG_TYPE_NQ)
477330fc
RM
2061 {
2062 setmask = 3;
2063 addregs = 2;
2064 }
5287ad62 2065
c19d1205
ZW
2066 if (new_base < base_reg)
2067 base_reg = new_base;
a737bd4d 2068
5287ad62 2069 if (mask & (setmask << new_base))
c19d1205 2070 {
dcbf9037 2071 first_error (_("invalid register list"));
c19d1205 2072 return FAIL;
a737bd4d 2073 }
a737bd4d 2074
efd6b359 2075 if ((mask >> new_base) != 0 && ! warned && !vpr_seen)
c19d1205
ZW
2076 {
2077 as_tsktsk (_("register list not in ascending order"));
2078 warned = 1;
2079 }
0bbf2aa4 2080
5287ad62
JB
2081 mask |= setmask << new_base;
2082 count += addregs;
0bbf2aa4 2083
037e8744 2084 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
2085 {
2086 int high_range;
0bbf2aa4 2087
037e8744 2088 str++;
0bbf2aa4 2089
037e8744 2090 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 2091 == FAIL)
c19d1205
ZW
2092 {
2093 inst.error = gettext (reg_expected_msgs[regtype]);
2094 return FAIL;
2095 }
0bbf2aa4 2096
477330fc
RM
2097 if (high_range >= max_regs)
2098 {
2099 first_error (_("register out of range in list"));
2100 return FAIL;
2101 }
b7fc2769 2102
477330fc
RM
2103 if (regtype == REG_TYPE_NQ)
2104 high_range = high_range + 1;
5287ad62 2105
c19d1205
ZW
2106 if (high_range <= new_base)
2107 {
2108 inst.error = _("register range not in ascending order");
2109 return FAIL;
2110 }
0bbf2aa4 2111
5287ad62 2112 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 2113 {
5287ad62 2114 if (mask & (setmask << new_base))
0bbf2aa4 2115 {
c19d1205
ZW
2116 inst.error = _("invalid register list");
2117 return FAIL;
0bbf2aa4 2118 }
c19d1205 2119
5287ad62
JB
2120 mask |= setmask << new_base;
2121 count += addregs;
0bbf2aa4 2122 }
0bbf2aa4 2123 }
0bbf2aa4 2124 }
037e8744 2125 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 2126
037e8744 2127 str++;
0bbf2aa4 2128
c19d1205 2129 /* Sanity check -- should have raised a parse error above. */
efd6b359 2130 if ((!vpr_seen && count == 0) || count > max_regs)
c19d1205
ZW
2131 abort ();
2132
2133 *pbase = base_reg;
2134
efd6b359
AV
2135 if (expect_vpr && !vpr_seen)
2136 {
2137 first_error (_("VPR expected last"));
2138 return FAIL;
2139 }
2140
c19d1205
ZW
2141 /* Final test -- the registers must be consecutive. */
2142 mask >>= base_reg;
2143 for (i = 0; i < count; i++)
2144 {
2145 if ((mask & (1u << i)) == 0)
2146 {
2147 inst.error = _("non-contiguous register range");
2148 return FAIL;
2149 }
2150 }
2151
037e8744
JB
2152 *ccp = str;
2153
c19d1205 2154 return count;
b99bd4ef
NC
2155}
2156
dcbf9037
JB
2157/* True if two alias types are the same. */
2158
c921be7d 2159static bfd_boolean
dcbf9037
JB
2160neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2161{
2162 if (!a && !b)
c921be7d 2163 return TRUE;
5f4273c7 2164
dcbf9037 2165 if (!a || !b)
c921be7d 2166 return FALSE;
dcbf9037
JB
2167
2168 if (a->defined != b->defined)
c921be7d 2169 return FALSE;
5f4273c7 2170
dcbf9037
JB
2171 if ((a->defined & NTA_HASTYPE) != 0
2172 && (a->eltype.type != b->eltype.type
477330fc 2173 || a->eltype.size != b->eltype.size))
c921be7d 2174 return FALSE;
dcbf9037
JB
2175
2176 if ((a->defined & NTA_HASINDEX) != 0
2177 && (a->index != b->index))
c921be7d 2178 return FALSE;
5f4273c7 2179
c921be7d 2180 return TRUE;
dcbf9037
JB
2181}
2182
5287ad62
JB
2183/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2184 The base register is put in *PBASE.
dcbf9037 2185 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
2186 the return value.
2187 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2188 Bits [6:5] encode the list length (minus one).
2189 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2190
5287ad62 2191#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2192#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2193#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2194
2195static int
dcbf9037 2196parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 2197 struct neon_type_el *eltype)
5287ad62
JB
2198{
2199 char *ptr = *str;
2200 int base_reg = -1;
2201 int reg_incr = -1;
2202 int count = 0;
2203 int lane = -1;
2204 int leading_brace = 0;
2205 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
2206 const char *const incr_error = _("register stride must be 1 or 2");
2207 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2208 struct neon_typed_alias firsttype;
f85d59c3
KT
2209 firsttype.defined = 0;
2210 firsttype.eltype.type = NT_invtype;
2211 firsttype.eltype.size = -1;
2212 firsttype.index = -1;
5f4273c7 2213
5287ad62
JB
2214 if (skip_past_char (&ptr, '{') == SUCCESS)
2215 leading_brace = 1;
5f4273c7 2216
5287ad62
JB
2217 do
2218 {
dcbf9037
JB
2219 struct neon_typed_alias atype;
2220 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2221
5287ad62 2222 if (getreg == FAIL)
477330fc
RM
2223 {
2224 first_error (_(reg_expected_msgs[rtype]));
2225 return FAIL;
2226 }
5f4273c7 2227
5287ad62 2228 if (base_reg == -1)
477330fc
RM
2229 {
2230 base_reg = getreg;
2231 if (rtype == REG_TYPE_NQ)
2232 {
2233 reg_incr = 1;
2234 }
2235 firsttype = atype;
2236 }
5287ad62 2237 else if (reg_incr == -1)
477330fc
RM
2238 {
2239 reg_incr = getreg - base_reg;
2240 if (reg_incr < 1 || reg_incr > 2)
2241 {
2242 first_error (_(incr_error));
2243 return FAIL;
2244 }
2245 }
5287ad62 2246 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2247 {
2248 first_error (_(incr_error));
2249 return FAIL;
2250 }
dcbf9037 2251
c921be7d 2252 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2253 {
2254 first_error (_(type_error));
2255 return FAIL;
2256 }
5f4273c7 2257
5287ad62 2258 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2259 modes. */
5287ad62 2260 if (ptr[0] == '-')
477330fc
RM
2261 {
2262 struct neon_typed_alias htype;
2263 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2264 if (lane == -1)
2265 lane = NEON_INTERLEAVE_LANES;
2266 else if (lane != NEON_INTERLEAVE_LANES)
2267 {
2268 first_error (_(type_error));
2269 return FAIL;
2270 }
2271 if (reg_incr == -1)
2272 reg_incr = 1;
2273 else if (reg_incr != 1)
2274 {
2275 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2276 return FAIL;
2277 }
2278 ptr++;
2279 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2280 if (hireg == FAIL)
2281 {
2282 first_error (_(reg_expected_msgs[rtype]));
2283 return FAIL;
2284 }
2285 if (! neon_alias_types_same (&htype, &firsttype))
2286 {
2287 first_error (_(type_error));
2288 return FAIL;
2289 }
2290 count += hireg + dregs - getreg;
2291 continue;
2292 }
5f4273c7 2293
5287ad62
JB
2294 /* If we're using Q registers, we can't use [] or [n] syntax. */
2295 if (rtype == REG_TYPE_NQ)
477330fc
RM
2296 {
2297 count += 2;
2298 continue;
2299 }
5f4273c7 2300
dcbf9037 2301 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2302 {
2303 if (lane == -1)
2304 lane = atype.index;
2305 else if (lane != atype.index)
2306 {
2307 first_error (_(type_error));
2308 return FAIL;
2309 }
2310 }
5287ad62 2311 else if (lane == -1)
477330fc 2312 lane = NEON_INTERLEAVE_LANES;
5287ad62 2313 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2314 {
2315 first_error (_(type_error));
2316 return FAIL;
2317 }
5287ad62
JB
2318 count++;
2319 }
2320 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2321
5287ad62
JB
2322 /* No lane set by [x]. We must be interleaving structures. */
2323 if (lane == -1)
2324 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2325
5287ad62
JB
2326 /* Sanity check. */
2327 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2328 || (count > 1 && reg_incr == -1))
2329 {
dcbf9037 2330 first_error (_("error parsing element/structure list"));
5287ad62
JB
2331 return FAIL;
2332 }
2333
2334 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2335 {
dcbf9037 2336 first_error (_("expected }"));
5287ad62
JB
2337 return FAIL;
2338 }
5f4273c7 2339
5287ad62
JB
2340 if (reg_incr == -1)
2341 reg_incr = 1;
2342
dcbf9037
JB
2343 if (eltype)
2344 *eltype = firsttype.eltype;
2345
5287ad62
JB
2346 *pbase = base_reg;
2347 *str = ptr;
5f4273c7 2348
5287ad62
JB
2349 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2350}
2351
c19d1205
ZW
2352/* Parse an explicit relocation suffix on an expression. This is
2353 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2354 arm_reloc_hsh contains no entries, so this function can only
2355 succeed if there is no () after the word. Returns -1 on error,
2356 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2357
c19d1205
ZW
2358static int
2359parse_reloc (char **str)
b99bd4ef 2360{
c19d1205
ZW
2361 struct reloc_entry *r;
2362 char *p, *q;
b99bd4ef 2363
c19d1205
ZW
2364 if (**str != '(')
2365 return BFD_RELOC_UNUSED;
b99bd4ef 2366
c19d1205
ZW
2367 p = *str + 1;
2368 q = p;
2369
2370 while (*q && *q != ')' && *q != ',')
2371 q++;
2372 if (*q != ')')
2373 return -1;
2374
21d799b5
NC
2375 if ((r = (struct reloc_entry *)
2376 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2377 return -1;
2378
2379 *str = q + 1;
2380 return r->reloc;
b99bd4ef
NC
2381}
2382
c19d1205
ZW
2383/* Directives: register aliases. */
2384
dcbf9037 2385static struct reg_entry *
90ec0d68 2386insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2387{
d3ce72d0 2388 struct reg_entry *new_reg;
c19d1205 2389 const char *name;
b99bd4ef 2390
d3ce72d0 2391 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2392 {
d3ce72d0 2393 if (new_reg->builtin)
c19d1205 2394 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2395
c19d1205
ZW
2396 /* Only warn about a redefinition if it's not defined as the
2397 same register. */
d3ce72d0 2398 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2399 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2400
d929913e 2401 return NULL;
c19d1205 2402 }
b99bd4ef 2403
c19d1205 2404 name = xstrdup (str);
325801bd 2405 new_reg = XNEW (struct reg_entry);
b99bd4ef 2406
d3ce72d0
NC
2407 new_reg->name = name;
2408 new_reg->number = number;
2409 new_reg->type = type;
2410 new_reg->builtin = FALSE;
2411 new_reg->neon = NULL;
b99bd4ef 2412
d3ce72d0 2413 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2414 abort ();
5f4273c7 2415
d3ce72d0 2416 return new_reg;
dcbf9037
JB
2417}
2418
2419static void
2420insert_neon_reg_alias (char *str, int number, int type,
477330fc 2421 struct neon_typed_alias *atype)
dcbf9037
JB
2422{
2423 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2424
dcbf9037
JB
2425 if (!reg)
2426 {
2427 first_error (_("attempt to redefine typed alias"));
2428 return;
2429 }
5f4273c7 2430
dcbf9037
JB
2431 if (atype)
2432 {
325801bd 2433 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2434 *reg->neon = *atype;
2435 }
c19d1205 2436}
b99bd4ef 2437
c19d1205 2438/* Look for the .req directive. This is of the form:
b99bd4ef 2439
c19d1205 2440 new_register_name .req existing_register_name
b99bd4ef 2441
c19d1205 2442 If we find one, or if it looks sufficiently like one that we want to
d929913e 2443 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2444
d929913e 2445static bfd_boolean
c19d1205
ZW
2446create_register_alias (char * newname, char *p)
2447{
2448 struct reg_entry *old;
2449 char *oldname, *nbuf;
2450 size_t nlen;
b99bd4ef 2451
c19d1205
ZW
2452 /* The input scrubber ensures that whitespace after the mnemonic is
2453 collapsed to single spaces. */
2454 oldname = p;
2455 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2456 return FALSE;
b99bd4ef 2457
c19d1205
ZW
2458 oldname += 6;
2459 if (*oldname == '\0')
d929913e 2460 return FALSE;
b99bd4ef 2461
21d799b5 2462 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2463 if (!old)
b99bd4ef 2464 {
c19d1205 2465 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2466 return TRUE;
b99bd4ef
NC
2467 }
2468
c19d1205
ZW
2469 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2470 the desired alias name, and p points to its end. If not, then
2471 the desired alias name is in the global original_case_string. */
2472#ifdef TC_CASE_SENSITIVE
2473 nlen = p - newname;
2474#else
2475 newname = original_case_string;
2476 nlen = strlen (newname);
2477#endif
b99bd4ef 2478
29a2809e 2479 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2480
c19d1205
ZW
2481 /* Create aliases under the new name as stated; an all-lowercase
2482 version of the new name; and an all-uppercase version of the new
2483 name. */
d929913e
NC
2484 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2485 {
2486 for (p = nbuf; *p; p++)
2487 *p = TOUPPER (*p);
c19d1205 2488
d929913e
NC
2489 if (strncmp (nbuf, newname, nlen))
2490 {
2491 /* If this attempt to create an additional alias fails, do not bother
2492 trying to create the all-lower case alias. We will fail and issue
2493 a second, duplicate error message. This situation arises when the
2494 programmer does something like:
2495 foo .req r0
2496 Foo .req r1
2497 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2498 the artificial FOO alias because it has already been created by the
d929913e
NC
2499 first .req. */
2500 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2501 {
2502 free (nbuf);
2503 return TRUE;
2504 }
d929913e 2505 }
c19d1205 2506
d929913e
NC
2507 for (p = nbuf; *p; p++)
2508 *p = TOLOWER (*p);
c19d1205 2509
d929913e
NC
2510 if (strncmp (nbuf, newname, nlen))
2511 insert_reg_alias (nbuf, old->number, old->type);
2512 }
c19d1205 2513
e1fa0163 2514 free (nbuf);
d929913e 2515 return TRUE;
b99bd4ef
NC
2516}
2517
dcbf9037
JB
2518/* Create a Neon typed/indexed register alias using directives, e.g.:
2519 X .dn d5.s32[1]
2520 Y .qn 6.s16
2521 Z .dn d7
2522 T .dn Z[0]
2523 These typed registers can be used instead of the types specified after the
2524 Neon mnemonic, so long as all operands given have types. Types can also be
2525 specified directly, e.g.:
5f4273c7 2526 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2527
c921be7d 2528static bfd_boolean
dcbf9037
JB
2529create_neon_reg_alias (char *newname, char *p)
2530{
2531 enum arm_reg_type basetype;
2532 struct reg_entry *basereg;
2533 struct reg_entry mybasereg;
2534 struct neon_type ntype;
2535 struct neon_typed_alias typeinfo;
12d6b0b7 2536 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2537 int namelen;
5f4273c7 2538
dcbf9037
JB
2539 typeinfo.defined = 0;
2540 typeinfo.eltype.type = NT_invtype;
2541 typeinfo.eltype.size = -1;
2542 typeinfo.index = -1;
5f4273c7 2543
dcbf9037 2544 nameend = p;
5f4273c7 2545
dcbf9037
JB
2546 if (strncmp (p, " .dn ", 5) == 0)
2547 basetype = REG_TYPE_VFD;
2548 else if (strncmp (p, " .qn ", 5) == 0)
2549 basetype = REG_TYPE_NQ;
2550 else
c921be7d 2551 return FALSE;
5f4273c7 2552
dcbf9037 2553 p += 5;
5f4273c7 2554
dcbf9037 2555 if (*p == '\0')
c921be7d 2556 return FALSE;
5f4273c7 2557
dcbf9037
JB
2558 basereg = arm_reg_parse_multi (&p);
2559
2560 if (basereg && basereg->type != basetype)
2561 {
2562 as_bad (_("bad type for register"));
c921be7d 2563 return FALSE;
dcbf9037
JB
2564 }
2565
2566 if (basereg == NULL)
2567 {
2568 expressionS exp;
2569 /* Try parsing as an integer. */
2570 my_get_expression (&exp, &p, GE_NO_PREFIX);
2571 if (exp.X_op != O_constant)
477330fc
RM
2572 {
2573 as_bad (_("expression must be constant"));
2574 return FALSE;
2575 }
dcbf9037
JB
2576 basereg = &mybasereg;
2577 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2578 : exp.X_add_number;
dcbf9037
JB
2579 basereg->neon = 0;
2580 }
2581
2582 if (basereg->neon)
2583 typeinfo = *basereg->neon;
2584
2585 if (parse_neon_type (&ntype, &p) == SUCCESS)
2586 {
2587 /* We got a type. */
2588 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2589 {
2590 as_bad (_("can't redefine the type of a register alias"));
2591 return FALSE;
2592 }
5f4273c7 2593
dcbf9037
JB
2594 typeinfo.defined |= NTA_HASTYPE;
2595 if (ntype.elems != 1)
477330fc
RM
2596 {
2597 as_bad (_("you must specify a single type only"));
2598 return FALSE;
2599 }
dcbf9037
JB
2600 typeinfo.eltype = ntype.el[0];
2601 }
5f4273c7 2602
dcbf9037
JB
2603 if (skip_past_char (&p, '[') == SUCCESS)
2604 {
2605 expressionS exp;
2606 /* We got a scalar index. */
5f4273c7 2607
dcbf9037 2608 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2609 {
2610 as_bad (_("can't redefine the index of a scalar alias"));
2611 return FALSE;
2612 }
5f4273c7 2613
dcbf9037 2614 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2615
dcbf9037 2616 if (exp.X_op != O_constant)
477330fc
RM
2617 {
2618 as_bad (_("scalar index must be constant"));
2619 return FALSE;
2620 }
5f4273c7 2621
dcbf9037
JB
2622 typeinfo.defined |= NTA_HASINDEX;
2623 typeinfo.index = exp.X_add_number;
5f4273c7 2624
dcbf9037 2625 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2626 {
2627 as_bad (_("expecting ]"));
2628 return FALSE;
2629 }
dcbf9037
JB
2630 }
2631
15735687
NS
2632 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2633 the desired alias name, and p points to its end. If not, then
2634 the desired alias name is in the global original_case_string. */
2635#ifdef TC_CASE_SENSITIVE
dcbf9037 2636 namelen = nameend - newname;
15735687
NS
2637#else
2638 newname = original_case_string;
2639 namelen = strlen (newname);
2640#endif
2641
29a2809e 2642 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2643
dcbf9037 2644 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2645 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2646
dcbf9037
JB
2647 /* Insert name in all uppercase. */
2648 for (p = namebuf; *p; p++)
2649 *p = TOUPPER (*p);
5f4273c7 2650
dcbf9037
JB
2651 if (strncmp (namebuf, newname, namelen))
2652 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2653 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2654
dcbf9037
JB
2655 /* Insert name in all lowercase. */
2656 for (p = namebuf; *p; p++)
2657 *p = TOLOWER (*p);
5f4273c7 2658
dcbf9037
JB
2659 if (strncmp (namebuf, newname, namelen))
2660 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2661 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2662
e1fa0163 2663 free (namebuf);
c921be7d 2664 return TRUE;
dcbf9037
JB
2665}
2666
c19d1205
ZW
2667/* Should never be called, as .req goes between the alias and the
2668 register name, not at the beginning of the line. */
c921be7d 2669
b99bd4ef 2670static void
c19d1205 2671s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2672{
c19d1205
ZW
2673 as_bad (_("invalid syntax for .req directive"));
2674}
b99bd4ef 2675
dcbf9037
JB
2676static void
2677s_dn (int a ATTRIBUTE_UNUSED)
2678{
2679 as_bad (_("invalid syntax for .dn directive"));
2680}
2681
2682static void
2683s_qn (int a ATTRIBUTE_UNUSED)
2684{
2685 as_bad (_("invalid syntax for .qn directive"));
2686}
2687
c19d1205
ZW
2688/* The .unreq directive deletes an alias which was previously defined
2689 by .req. For example:
b99bd4ef 2690
c19d1205
ZW
2691 my_alias .req r11
2692 .unreq my_alias */
b99bd4ef
NC
2693
2694static void
c19d1205 2695s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2696{
c19d1205
ZW
2697 char * name;
2698 char saved_char;
b99bd4ef 2699
c19d1205
ZW
2700 name = input_line_pointer;
2701
2702 while (*input_line_pointer != 0
2703 && *input_line_pointer != ' '
2704 && *input_line_pointer != '\n')
2705 ++input_line_pointer;
2706
2707 saved_char = *input_line_pointer;
2708 *input_line_pointer = 0;
2709
2710 if (!*name)
2711 as_bad (_("invalid syntax for .unreq directive"));
2712 else
2713 {
21d799b5 2714 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2715 name);
c19d1205
ZW
2716
2717 if (!reg)
2718 as_bad (_("unknown register alias '%s'"), name);
2719 else if (reg->builtin)
a1727c1a 2720 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2721 name);
2722 else
2723 {
d929913e
NC
2724 char * p;
2725 char * nbuf;
2726
db0bc284 2727 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2728 free ((char *) reg->name);
477330fc
RM
2729 if (reg->neon)
2730 free (reg->neon);
c19d1205 2731 free (reg);
d929913e
NC
2732
2733 /* Also locate the all upper case and all lower case versions.
2734 Do not complain if we cannot find one or the other as it
2735 was probably deleted above. */
5f4273c7 2736
d929913e
NC
2737 nbuf = strdup (name);
2738 for (p = nbuf; *p; p++)
2739 *p = TOUPPER (*p);
21d799b5 2740 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2741 if (reg)
2742 {
db0bc284 2743 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2744 free ((char *) reg->name);
2745 if (reg->neon)
2746 free (reg->neon);
2747 free (reg);
2748 }
2749
2750 for (p = nbuf; *p; p++)
2751 *p = TOLOWER (*p);
21d799b5 2752 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2753 if (reg)
2754 {
db0bc284 2755 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2756 free ((char *) reg->name);
2757 if (reg->neon)
2758 free (reg->neon);
2759 free (reg);
2760 }
2761
2762 free (nbuf);
c19d1205
ZW
2763 }
2764 }
b99bd4ef 2765
c19d1205 2766 *input_line_pointer = saved_char;
b99bd4ef
NC
2767 demand_empty_rest_of_line ();
2768}
2769
c19d1205
ZW
2770/* Directives: Instruction set selection. */
2771
2772#ifdef OBJ_ELF
2773/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2774 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2775 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2776 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2777
cd000bff
DJ
2778/* Create a new mapping symbol for the transition to STATE. */
2779
2780static void
2781make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2782{
a737bd4d 2783 symbolS * symbolP;
c19d1205
ZW
2784 const char * symname;
2785 int type;
b99bd4ef 2786
c19d1205 2787 switch (state)
b99bd4ef 2788 {
c19d1205
ZW
2789 case MAP_DATA:
2790 symname = "$d";
2791 type = BSF_NO_FLAGS;
2792 break;
2793 case MAP_ARM:
2794 symname = "$a";
2795 type = BSF_NO_FLAGS;
2796 break;
2797 case MAP_THUMB:
2798 symname = "$t";
2799 type = BSF_NO_FLAGS;
2800 break;
c19d1205
ZW
2801 default:
2802 abort ();
2803 }
2804
cd000bff 2805 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2806 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2807
2808 switch (state)
2809 {
2810 case MAP_ARM:
2811 THUMB_SET_FUNC (symbolP, 0);
2812 ARM_SET_THUMB (symbolP, 0);
2813 ARM_SET_INTERWORK (symbolP, support_interwork);
2814 break;
2815
2816 case MAP_THUMB:
2817 THUMB_SET_FUNC (symbolP, 1);
2818 ARM_SET_THUMB (symbolP, 1);
2819 ARM_SET_INTERWORK (symbolP, support_interwork);
2820 break;
2821
2822 case MAP_DATA:
2823 default:
cd000bff
DJ
2824 break;
2825 }
2826
2827 /* Save the mapping symbols for future reference. Also check that
2828 we do not place two mapping symbols at the same offset within a
2829 frag. We'll handle overlap between frags in
2de7820f
JZ
2830 check_mapping_symbols.
2831
2832 If .fill or other data filling directive generates zero sized data,
2833 the mapping symbol for the following code will have the same value
2834 as the one generated for the data filling directive. In this case,
2835 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2836 if (value == 0)
2837 {
2de7820f
JZ
2838 if (frag->tc_frag_data.first_map != NULL)
2839 {
2840 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2841 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2842 }
cd000bff
DJ
2843 frag->tc_frag_data.first_map = symbolP;
2844 }
2845 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2846 {
2847 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2848 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2849 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2850 }
cd000bff
DJ
2851 frag->tc_frag_data.last_map = symbolP;
2852}
2853
2854/* We must sometimes convert a region marked as code to data during
2855 code alignment, if an odd number of bytes have to be padded. The
2856 code mapping symbol is pushed to an aligned address. */
2857
2858static void
2859insert_data_mapping_symbol (enum mstate state,
2860 valueT value, fragS *frag, offsetT bytes)
2861{
2862 /* If there was already a mapping symbol, remove it. */
2863 if (frag->tc_frag_data.last_map != NULL
2864 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2865 {
2866 symbolS *symp = frag->tc_frag_data.last_map;
2867
2868 if (value == 0)
2869 {
2870 know (frag->tc_frag_data.first_map == symp);
2871 frag->tc_frag_data.first_map = NULL;
2872 }
2873 frag->tc_frag_data.last_map = NULL;
2874 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2875 }
cd000bff
DJ
2876
2877 make_mapping_symbol (MAP_DATA, value, frag);
2878 make_mapping_symbol (state, value + bytes, frag);
2879}
2880
2881static void mapping_state_2 (enum mstate state, int max_chars);
2882
2883/* Set the mapping state to STATE. Only call this when about to
2884 emit some STATE bytes to the file. */
2885
4e9aaefb 2886#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2887void
2888mapping_state (enum mstate state)
2889{
940b5ce0
DJ
2890 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2891
cd000bff
DJ
2892 if (mapstate == state)
2893 /* The mapping symbol has already been emitted.
2894 There is nothing else to do. */
2895 return;
49c62a33
NC
2896
2897 if (state == MAP_ARM || state == MAP_THUMB)
2898 /* PR gas/12931
2899 All ARM instructions require 4-byte alignment.
2900 (Almost) all Thumb instructions require 2-byte alignment.
2901
2902 When emitting instructions into any section, mark the section
2903 appropriately.
2904
2905 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2906 but themselves require 2-byte alignment; this applies to some
33eaf5de 2907 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
2908 literal pool generation or an explicit .align >=2, both of
2909 which will cause the section to me marked with sufficient
2910 alignment. Thus, we don't handle those cases here. */
2911 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2912
2913 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2914 /* This case will be evaluated later. */
cd000bff 2915 return;
cd000bff
DJ
2916
2917 mapping_state_2 (state, 0);
cd000bff
DJ
2918}
2919
2920/* Same as mapping_state, but MAX_CHARS bytes have already been
2921 allocated. Put the mapping symbol that far back. */
2922
2923static void
2924mapping_state_2 (enum mstate state, int max_chars)
2925{
940b5ce0
DJ
2926 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2927
2928 if (!SEG_NORMAL (now_seg))
2929 return;
2930
cd000bff
DJ
2931 if (mapstate == state)
2932 /* The mapping symbol has already been emitted.
2933 There is nothing else to do. */
2934 return;
2935
4e9aaefb
SA
2936 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2937 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2938 {
2939 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2940 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2941
2942 if (add_symbol)
2943 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2944 }
2945
cd000bff
DJ
2946 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2947 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2948}
4e9aaefb 2949#undef TRANSITION
c19d1205 2950#else
d3106081
NS
2951#define mapping_state(x) ((void)0)
2952#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2953#endif
2954
2955/* Find the real, Thumb encoded start of a Thumb function. */
2956
4343666d 2957#ifdef OBJ_COFF
c19d1205
ZW
2958static symbolS *
2959find_real_start (symbolS * symbolP)
2960{
2961 char * real_start;
2962 const char * name = S_GET_NAME (symbolP);
2963 symbolS * new_target;
2964
2965 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2966#define STUB_NAME ".real_start_of"
2967
2968 if (name == NULL)
2969 abort ();
2970
37f6032b
ZW
2971 /* The compiler may generate BL instructions to local labels because
2972 it needs to perform a branch to a far away location. These labels
2973 do not have a corresponding ".real_start_of" label. We check
2974 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2975 the ".real_start_of" convention for nonlocal branches. */
2976 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2977 return symbolP;
2978
e1fa0163 2979 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2980 new_target = symbol_find (real_start);
e1fa0163 2981 free (real_start);
c19d1205
ZW
2982
2983 if (new_target == NULL)
2984 {
bd3ba5d1 2985 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2986 new_target = symbolP;
2987 }
2988
c19d1205
ZW
2989 return new_target;
2990}
4343666d 2991#endif
c19d1205
ZW
2992
2993static void
2994opcode_select (int width)
2995{
2996 switch (width)
2997 {
2998 case 16:
2999 if (! thumb_mode)
3000 {
e74cfd16 3001 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
3002 as_bad (_("selected processor does not support THUMB opcodes"));
3003
3004 thumb_mode = 1;
3005 /* No need to force the alignment, since we will have been
3006 coming from ARM mode, which is word-aligned. */
3007 record_alignment (now_seg, 1);
3008 }
c19d1205
ZW
3009 break;
3010
3011 case 32:
3012 if (thumb_mode)
3013 {
e74cfd16 3014 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
3015 as_bad (_("selected processor does not support ARM opcodes"));
3016
3017 thumb_mode = 0;
3018
3019 if (!need_pass_2)
3020 frag_align (2, 0, 0);
3021
3022 record_alignment (now_seg, 1);
3023 }
c19d1205
ZW
3024 break;
3025
3026 default:
3027 as_bad (_("invalid instruction size selected (%d)"), width);
3028 }
3029}
3030
3031static void
3032s_arm (int ignore ATTRIBUTE_UNUSED)
3033{
3034 opcode_select (32);
3035 demand_empty_rest_of_line ();
3036}
3037
3038static void
3039s_thumb (int ignore ATTRIBUTE_UNUSED)
3040{
3041 opcode_select (16);
3042 demand_empty_rest_of_line ();
3043}
3044
3045static void
3046s_code (int unused ATTRIBUTE_UNUSED)
3047{
3048 int temp;
3049
3050 temp = get_absolute_expression ();
3051 switch (temp)
3052 {
3053 case 16:
3054 case 32:
3055 opcode_select (temp);
3056 break;
3057
3058 default:
3059 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
3060 }
3061}
3062
3063static void
3064s_force_thumb (int ignore ATTRIBUTE_UNUSED)
3065{
3066 /* If we are not already in thumb mode go into it, EVEN if
3067 the target processor does not support thumb instructions.
3068 This is used by gcc/config/arm/lib1funcs.asm for example
3069 to compile interworking support functions even if the
3070 target processor should not support interworking. */
3071 if (! thumb_mode)
3072 {
3073 thumb_mode = 2;
3074 record_alignment (now_seg, 1);
3075 }
3076
3077 demand_empty_rest_of_line ();
3078}
3079
3080static void
3081s_thumb_func (int ignore ATTRIBUTE_UNUSED)
3082{
3083 s_thumb (0);
3084
3085 /* The following label is the name/address of the start of a Thumb function.
3086 We need to know this for the interworking support. */
3087 label_is_thumb_function_name = TRUE;
3088}
3089
3090/* Perform a .set directive, but also mark the alias as
3091 being a thumb function. */
3092
3093static void
3094s_thumb_set (int equiv)
3095{
3096 /* XXX the following is a duplicate of the code for s_set() in read.c
3097 We cannot just call that code as we need to get at the symbol that
3098 is created. */
3099 char * name;
3100 char delim;
3101 char * end_name;
3102 symbolS * symbolP;
3103
3104 /* Especial apologies for the random logic:
3105 This just grew, and could be parsed much more simply!
3106 Dean - in haste. */
d02603dc 3107 delim = get_symbol_name (& name);
c19d1205 3108 end_name = input_line_pointer;
d02603dc 3109 (void) restore_line_pointer (delim);
c19d1205
ZW
3110
3111 if (*input_line_pointer != ',')
3112 {
3113 *end_name = 0;
3114 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
3115 *end_name = delim;
3116 ignore_rest_of_line ();
3117 return;
3118 }
3119
3120 input_line_pointer++;
3121 *end_name = 0;
3122
3123 if (name[0] == '.' && name[1] == '\0')
3124 {
3125 /* XXX - this should not happen to .thumb_set. */
3126 abort ();
3127 }
3128
3129 if ((symbolP = symbol_find (name)) == NULL
3130 && (symbolP = md_undefined_symbol (name)) == NULL)
3131 {
3132#ifndef NO_LISTING
3133 /* When doing symbol listings, play games with dummy fragments living
3134 outside the normal fragment chain to record the file and line info
c19d1205 3135 for this symbol. */
b99bd4ef
NC
3136 if (listing & LISTING_SYMBOLS)
3137 {
3138 extern struct list_info_struct * listing_tail;
21d799b5 3139 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
3140
3141 memset (dummy_frag, 0, sizeof (fragS));
3142 dummy_frag->fr_type = rs_fill;
3143 dummy_frag->line = listing_tail;
3144 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
3145 dummy_frag->fr_symbol = symbolP;
3146 }
3147 else
3148#endif
3149 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
3150
3151#ifdef OBJ_COFF
3152 /* "set" symbols are local unless otherwise specified. */
3153 SF_SET_LOCAL (symbolP);
3154#endif /* OBJ_COFF */
3155 } /* Make a new symbol. */
3156
3157 symbol_table_insert (symbolP);
3158
3159 * end_name = delim;
3160
3161 if (equiv
3162 && S_IS_DEFINED (symbolP)
3163 && S_GET_SEGMENT (symbolP) != reg_section)
3164 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3165
3166 pseudo_set (symbolP);
3167
3168 demand_empty_rest_of_line ();
3169
c19d1205 3170 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
3171
3172 THUMB_SET_FUNC (symbolP, 1);
3173 ARM_SET_THUMB (symbolP, 1);
3174#if defined OBJ_ELF || defined OBJ_COFF
3175 ARM_SET_INTERWORK (symbolP, support_interwork);
3176#endif
3177}
3178
c19d1205 3179/* Directives: Mode selection. */
b99bd4ef 3180
c19d1205
ZW
3181/* .syntax [unified|divided] - choose the new unified syntax
3182 (same for Arm and Thumb encoding, modulo slight differences in what
3183 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 3184static void
c19d1205 3185s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 3186{
c19d1205
ZW
3187 char *name, delim;
3188
d02603dc 3189 delim = get_symbol_name (& name);
c19d1205
ZW
3190
3191 if (!strcasecmp (name, "unified"))
3192 unified_syntax = TRUE;
3193 else if (!strcasecmp (name, "divided"))
3194 unified_syntax = FALSE;
3195 else
3196 {
3197 as_bad (_("unrecognized syntax mode \"%s\""), name);
3198 return;
3199 }
d02603dc 3200 (void) restore_line_pointer (delim);
b99bd4ef
NC
3201 demand_empty_rest_of_line ();
3202}
3203
c19d1205
ZW
3204/* Directives: sectioning and alignment. */
3205
c19d1205
ZW
3206static void
3207s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3208{
c19d1205
ZW
3209 /* We don't support putting frags in the BSS segment, we fake it by
3210 marking in_bss, then looking at s_skip for clues. */
3211 subseg_set (bss_section, 0);
3212 demand_empty_rest_of_line ();
cd000bff
DJ
3213
3214#ifdef md_elf_section_change_hook
3215 md_elf_section_change_hook ();
3216#endif
c19d1205 3217}
b99bd4ef 3218
c19d1205
ZW
3219static void
3220s_even (int ignore ATTRIBUTE_UNUSED)
3221{
3222 /* Never make frag if expect extra pass. */
3223 if (!need_pass_2)
3224 frag_align (1, 0, 0);
b99bd4ef 3225
c19d1205 3226 record_alignment (now_seg, 1);
b99bd4ef 3227
c19d1205 3228 demand_empty_rest_of_line ();
b99bd4ef
NC
3229}
3230
2e6976a8
DG
3231/* Directives: CodeComposer Studio. */
3232
3233/* .ref (for CodeComposer Studio syntax only). */
3234static void
3235s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3236{
3237 if (codecomposer_syntax)
3238 ignore_rest_of_line ();
3239 else
3240 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3241}
3242
3243/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3244 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3245static void
3246asmfunc_debug (const char * name)
3247{
3248 static const char * last_name = NULL;
3249
3250 if (name != NULL)
3251 {
3252 gas_assert (last_name == NULL);
3253 last_name = name;
3254
3255 if (debug_type == DEBUG_STABS)
3256 stabs_generate_asm_func (name, name);
3257 }
3258 else
3259 {
3260 gas_assert (last_name != NULL);
3261
3262 if (debug_type == DEBUG_STABS)
3263 stabs_generate_asm_endfunc (last_name, last_name);
3264
3265 last_name = NULL;
3266 }
3267}
3268
3269static void
3270s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3271{
3272 if (codecomposer_syntax)
3273 {
3274 switch (asmfunc_state)
3275 {
3276 case OUTSIDE_ASMFUNC:
3277 asmfunc_state = WAITING_ASMFUNC_NAME;
3278 break;
3279
3280 case WAITING_ASMFUNC_NAME:
3281 as_bad (_(".asmfunc repeated."));
3282 break;
3283
3284 case WAITING_ENDASMFUNC:
3285 as_bad (_(".asmfunc without function."));
3286 break;
3287 }
3288 demand_empty_rest_of_line ();
3289 }
3290 else
3291 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3292}
3293
3294static void
3295s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3296{
3297 if (codecomposer_syntax)
3298 {
3299 switch (asmfunc_state)
3300 {
3301 case OUTSIDE_ASMFUNC:
3302 as_bad (_(".endasmfunc without a .asmfunc."));
3303 break;
3304
3305 case WAITING_ASMFUNC_NAME:
3306 as_bad (_(".endasmfunc without function."));
3307 break;
3308
3309 case WAITING_ENDASMFUNC:
3310 asmfunc_state = OUTSIDE_ASMFUNC;
3311 asmfunc_debug (NULL);
3312 break;
3313 }
3314 demand_empty_rest_of_line ();
3315 }
3316 else
3317 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3318}
3319
3320static void
3321s_ccs_def (int name)
3322{
3323 if (codecomposer_syntax)
3324 s_globl (name);
3325 else
3326 as_bad (_(".def pseudo-op only available with -mccs flag."));
3327}
3328
c19d1205 3329/* Directives: Literal pools. */
a737bd4d 3330
c19d1205
ZW
3331static literal_pool *
3332find_literal_pool (void)
a737bd4d 3333{
c19d1205 3334 literal_pool * pool;
a737bd4d 3335
c19d1205 3336 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3337 {
c19d1205
ZW
3338 if (pool->section == now_seg
3339 && pool->sub_section == now_subseg)
3340 break;
a737bd4d
NC
3341 }
3342
c19d1205 3343 return pool;
a737bd4d
NC
3344}
3345
c19d1205
ZW
3346static literal_pool *
3347find_or_make_literal_pool (void)
a737bd4d 3348{
c19d1205
ZW
3349 /* Next literal pool ID number. */
3350 static unsigned int latest_pool_num = 1;
3351 literal_pool * pool;
a737bd4d 3352
c19d1205 3353 pool = find_literal_pool ();
a737bd4d 3354
c19d1205 3355 if (pool == NULL)
a737bd4d 3356 {
c19d1205 3357 /* Create a new pool. */
325801bd 3358 pool = XNEW (literal_pool);
c19d1205
ZW
3359 if (! pool)
3360 return NULL;
a737bd4d 3361
c19d1205
ZW
3362 pool->next_free_entry = 0;
3363 pool->section = now_seg;
3364 pool->sub_section = now_subseg;
3365 pool->next = list_of_pools;
3366 pool->symbol = NULL;
8335d6aa 3367 pool->alignment = 2;
c19d1205
ZW
3368
3369 /* Add it to the list. */
3370 list_of_pools = pool;
a737bd4d 3371 }
a737bd4d 3372
c19d1205
ZW
3373 /* New pools, and emptied pools, will have a NULL symbol. */
3374 if (pool->symbol == NULL)
a737bd4d 3375 {
c19d1205
ZW
3376 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3377 (valueT) 0, &zero_address_frag);
3378 pool->id = latest_pool_num ++;
a737bd4d
NC
3379 }
3380
c19d1205
ZW
3381 /* Done. */
3382 return pool;
a737bd4d
NC
3383}
3384
c19d1205 3385/* Add the literal in the global 'inst'
5f4273c7 3386 structure to the relevant literal pool. */
b99bd4ef
NC
3387
3388static int
8335d6aa 3389add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3390{
8335d6aa
JW
3391#define PADDING_SLOT 0x1
3392#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3393 literal_pool * pool;
8335d6aa
JW
3394 unsigned int entry, pool_size = 0;
3395 bfd_boolean padding_slot_p = FALSE;
e56c722b 3396 unsigned imm1 = 0;
8335d6aa
JW
3397 unsigned imm2 = 0;
3398
3399 if (nbytes == 8)
3400 {
3401 imm1 = inst.operands[1].imm;
3402 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
e2b0ab59 3403 : inst.relocs[0].exp.X_unsigned ? 0
2569ceb0 3404 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3405 if (target_big_endian)
3406 {
3407 imm1 = imm2;
3408 imm2 = inst.operands[1].imm;
3409 }
3410 }
b99bd4ef 3411
c19d1205
ZW
3412 pool = find_or_make_literal_pool ();
3413
3414 /* Check if this literal value is already in the pool. */
3415 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3416 {
8335d6aa
JW
3417 if (nbytes == 4)
3418 {
e2b0ab59
AV
3419 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3420 && (inst.relocs[0].exp.X_op == O_constant)
8335d6aa 3421 && (pool->literals[entry].X_add_number
e2b0ab59 3422 == inst.relocs[0].exp.X_add_number)
8335d6aa
JW
3423 && (pool->literals[entry].X_md == nbytes)
3424 && (pool->literals[entry].X_unsigned
e2b0ab59 3425 == inst.relocs[0].exp.X_unsigned))
8335d6aa
JW
3426 break;
3427
e2b0ab59
AV
3428 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3429 && (inst.relocs[0].exp.X_op == O_symbol)
8335d6aa 3430 && (pool->literals[entry].X_add_number
e2b0ab59 3431 == inst.relocs[0].exp.X_add_number)
8335d6aa 3432 && (pool->literals[entry].X_add_symbol
e2b0ab59 3433 == inst.relocs[0].exp.X_add_symbol)
8335d6aa 3434 && (pool->literals[entry].X_op_symbol
e2b0ab59 3435 == inst.relocs[0].exp.X_op_symbol)
8335d6aa
JW
3436 && (pool->literals[entry].X_md == nbytes))
3437 break;
3438 }
3439 else if ((nbytes == 8)
3440 && !(pool_size & 0x7)
3441 && ((entry + 1) != pool->next_free_entry)
3442 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3443 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa 3444 && (pool->literals[entry].X_unsigned
e2b0ab59 3445 == inst.relocs[0].exp.X_unsigned)
8335d6aa 3446 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3447 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa 3448 && (pool->literals[entry + 1].X_unsigned
e2b0ab59 3449 == inst.relocs[0].exp.X_unsigned))
c19d1205
ZW
3450 break;
3451
8335d6aa
JW
3452 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3453 if (padding_slot_p && (nbytes == 4))
c19d1205 3454 break;
8335d6aa
JW
3455
3456 pool_size += 4;
b99bd4ef
NC
3457 }
3458
c19d1205
ZW
3459 /* Do we need to create a new entry? */
3460 if (entry == pool->next_free_entry)
3461 {
3462 if (entry >= MAX_LITERAL_POOL_SIZE)
3463 {
3464 inst.error = _("literal pool overflow");
3465 return FAIL;
3466 }
3467
8335d6aa
JW
3468 if (nbytes == 8)
3469 {
3470 /* For 8-byte entries, we align to an 8-byte boundary,
3471 and split it into two 4-byte entries, because on 32-bit
3472 host, 8-byte constants are treated as big num, thus
3473 saved in "generic_bignum" which will be overwritten
3474 by later assignments.
3475
3476 We also need to make sure there is enough space for
3477 the split.
3478
3479 We also check to make sure the literal operand is a
3480 constant number. */
e2b0ab59
AV
3481 if (!(inst.relocs[0].exp.X_op == O_constant
3482 || inst.relocs[0].exp.X_op == O_big))
8335d6aa
JW
3483 {
3484 inst.error = _("invalid type for literal pool");
3485 return FAIL;
3486 }
3487 else if (pool_size & 0x7)
3488 {
3489 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3490 {
3491 inst.error = _("literal pool overflow");
3492 return FAIL;
3493 }
3494
e2b0ab59 3495 pool->literals[entry] = inst.relocs[0].exp;
a6684f0d 3496 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3497 pool->literals[entry].X_add_number = 0;
3498 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3499 pool->next_free_entry += 1;
3500 pool_size += 4;
3501 }
3502 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3503 {
3504 inst.error = _("literal pool overflow");
3505 return FAIL;
3506 }
3507
e2b0ab59 3508 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3509 pool->literals[entry].X_op = O_constant;
3510 pool->literals[entry].X_add_number = imm1;
e2b0ab59 3511 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa 3512 pool->literals[entry++].X_md = 4;
e2b0ab59 3513 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3514 pool->literals[entry].X_op = O_constant;
3515 pool->literals[entry].X_add_number = imm2;
e2b0ab59 3516 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa
JW
3517 pool->literals[entry].X_md = 4;
3518 pool->alignment = 3;
3519 pool->next_free_entry += 1;
3520 }
3521 else
3522 {
e2b0ab59 3523 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3524 pool->literals[entry].X_md = 4;
3525 }
3526
a8040cf2
NC
3527#ifdef OBJ_ELF
3528 /* PR ld/12974: Record the location of the first source line to reference
3529 this entry in the literal pool. If it turns out during linking that the
3530 symbol does not exist we will be able to give an accurate line number for
3531 the (first use of the) missing reference. */
3532 if (debug_type == DEBUG_DWARF2)
3533 dwarf2_where (pool->locs + entry);
3534#endif
c19d1205
ZW
3535 pool->next_free_entry += 1;
3536 }
8335d6aa
JW
3537 else if (padding_slot_p)
3538 {
e2b0ab59 3539 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3540 pool->literals[entry].X_md = nbytes;
3541 }
b99bd4ef 3542
e2b0ab59
AV
3543 inst.relocs[0].exp.X_op = O_symbol;
3544 inst.relocs[0].exp.X_add_number = pool_size;
3545 inst.relocs[0].exp.X_add_symbol = pool->symbol;
b99bd4ef 3546
c19d1205 3547 return SUCCESS;
b99bd4ef
NC
3548}
3549
2e6976a8 3550bfd_boolean
2e57ce7b 3551tc_start_label_without_colon (void)
2e6976a8
DG
3552{
3553 bfd_boolean ret = TRUE;
3554
3555 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3556 {
2e57ce7b 3557 const char *label = input_line_pointer;
2e6976a8
DG
3558
3559 while (!is_end_of_line[(int) label[-1]])
3560 --label;
3561
3562 if (*label == '.')
3563 {
3564 as_bad (_("Invalid label '%s'"), label);
3565 ret = FALSE;
3566 }
3567
3568 asmfunc_debug (label);
3569
3570 asmfunc_state = WAITING_ENDASMFUNC;
3571 }
3572
3573 return ret;
3574}
3575
c19d1205 3576/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3577 a later date assign it a value. That's what these functions do. */
e16bb312 3578
c19d1205
ZW
3579static void
3580symbol_locate (symbolS * symbolP,
3581 const char * name, /* It is copied, the caller can modify. */
3582 segT segment, /* Segment identifier (SEG_<something>). */
3583 valueT valu, /* Symbol value. */
3584 fragS * frag) /* Associated fragment. */
3585{
e57e6ddc 3586 size_t name_length;
c19d1205 3587 char * preserved_copy_of_name;
e16bb312 3588
c19d1205
ZW
3589 name_length = strlen (name) + 1; /* +1 for \0. */
3590 obstack_grow (&notes, name, name_length);
21d799b5 3591 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3592
c19d1205
ZW
3593#ifdef tc_canonicalize_symbol_name
3594 preserved_copy_of_name =
3595 tc_canonicalize_symbol_name (preserved_copy_of_name);
3596#endif
b99bd4ef 3597
c19d1205 3598 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3599
c19d1205
ZW
3600 S_SET_SEGMENT (symbolP, segment);
3601 S_SET_VALUE (symbolP, valu);
3602 symbol_clear_list_pointers (symbolP);
b99bd4ef 3603
c19d1205 3604 symbol_set_frag (symbolP, frag);
b99bd4ef 3605
c19d1205
ZW
3606 /* Link to end of symbol chain. */
3607 {
3608 extern int symbol_table_frozen;
b99bd4ef 3609
c19d1205
ZW
3610 if (symbol_table_frozen)
3611 abort ();
3612 }
b99bd4ef 3613
c19d1205 3614 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3615
c19d1205 3616 obj_symbol_new_hook (symbolP);
b99bd4ef 3617
c19d1205
ZW
3618#ifdef tc_symbol_new_hook
3619 tc_symbol_new_hook (symbolP);
3620#endif
3621
3622#ifdef DEBUG_SYMS
3623 verify_symbol_chain (symbol_rootP, symbol_lastP);
3624#endif /* DEBUG_SYMS */
b99bd4ef
NC
3625}
3626
c19d1205
ZW
3627static void
3628s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3629{
c19d1205
ZW
3630 unsigned int entry;
3631 literal_pool * pool;
3632 char sym_name[20];
b99bd4ef 3633
c19d1205
ZW
3634 pool = find_literal_pool ();
3635 if (pool == NULL
3636 || pool->symbol == NULL
3637 || pool->next_free_entry == 0)
3638 return;
b99bd4ef 3639
c19d1205
ZW
3640 /* Align pool as you have word accesses.
3641 Only make a frag if we have to. */
3642 if (!need_pass_2)
8335d6aa 3643 frag_align (pool->alignment, 0, 0);
b99bd4ef 3644
c19d1205 3645 record_alignment (now_seg, 2);
b99bd4ef 3646
aaca88ef 3647#ifdef OBJ_ELF
47fc6e36
WN
3648 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3649 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3650#endif
c19d1205 3651 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3652
c19d1205
ZW
3653 symbol_locate (pool->symbol, sym_name, now_seg,
3654 (valueT) frag_now_fix (), frag_now);
3655 symbol_table_insert (pool->symbol);
b99bd4ef 3656
c19d1205 3657 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3658
c19d1205
ZW
3659#if defined OBJ_COFF || defined OBJ_ELF
3660 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3661#endif
6c43fab6 3662
c19d1205 3663 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3664 {
3665#ifdef OBJ_ELF
3666 if (debug_type == DEBUG_DWARF2)
3667 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3668#endif
3669 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3670 emit_expr (&(pool->literals[entry]),
3671 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3672 }
b99bd4ef 3673
c19d1205
ZW
3674 /* Mark the pool as empty. */
3675 pool->next_free_entry = 0;
3676 pool->symbol = NULL;
b99bd4ef
NC
3677}
3678
c19d1205
ZW
3679#ifdef OBJ_ELF
3680/* Forward declarations for functions below, in the MD interface
3681 section. */
3682static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3683static valueT create_unwind_entry (int);
3684static void start_unwind_section (const segT, int);
3685static void add_unwind_opcode (valueT, int);
3686static void flush_pending_unwind (void);
b99bd4ef 3687
c19d1205 3688/* Directives: Data. */
b99bd4ef 3689
c19d1205
ZW
3690static void
3691s_arm_elf_cons (int nbytes)
3692{
3693 expressionS exp;
b99bd4ef 3694
c19d1205
ZW
3695#ifdef md_flush_pending_output
3696 md_flush_pending_output ();
3697#endif
b99bd4ef 3698
c19d1205 3699 if (is_it_end_of_statement ())
b99bd4ef 3700 {
c19d1205
ZW
3701 demand_empty_rest_of_line ();
3702 return;
b99bd4ef
NC
3703 }
3704
c19d1205
ZW
3705#ifdef md_cons_align
3706 md_cons_align (nbytes);
3707#endif
b99bd4ef 3708
c19d1205
ZW
3709 mapping_state (MAP_DATA);
3710 do
b99bd4ef 3711 {
c19d1205
ZW
3712 int reloc;
3713 char *base = input_line_pointer;
b99bd4ef 3714
c19d1205 3715 expression (& exp);
b99bd4ef 3716
c19d1205
ZW
3717 if (exp.X_op != O_symbol)
3718 emit_expr (&exp, (unsigned int) nbytes);
3719 else
3720 {
3721 char *before_reloc = input_line_pointer;
3722 reloc = parse_reloc (&input_line_pointer);
3723 if (reloc == -1)
3724 {
3725 as_bad (_("unrecognized relocation suffix"));
3726 ignore_rest_of_line ();
3727 return;
3728 }
3729 else if (reloc == BFD_RELOC_UNUSED)
3730 emit_expr (&exp, (unsigned int) nbytes);
3731 else
3732 {
21d799b5 3733 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3734 bfd_reloc_type_lookup (stdoutput,
3735 (bfd_reloc_code_real_type) reloc);
c19d1205 3736 int size = bfd_get_reloc_size (howto);
b99bd4ef 3737
2fc8bdac
ZW
3738 if (reloc == BFD_RELOC_ARM_PLT32)
3739 {
3740 as_bad (_("(plt) is only valid on branch targets"));
3741 reloc = BFD_RELOC_UNUSED;
3742 size = 0;
3743 }
3744
c19d1205 3745 if (size > nbytes)
992a06ee
AM
3746 as_bad (ngettext ("%s relocations do not fit in %d byte",
3747 "%s relocations do not fit in %d bytes",
3748 nbytes),
c19d1205
ZW
3749 howto->name, nbytes);
3750 else
3751 {
3752 /* We've parsed an expression stopping at O_symbol.
3753 But there may be more expression left now that we
3754 have parsed the relocation marker. Parse it again.
3755 XXX Surely there is a cleaner way to do this. */
3756 char *p = input_line_pointer;
3757 int offset;
325801bd 3758 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3759
c19d1205
ZW
3760 memcpy (save_buf, base, input_line_pointer - base);
3761 memmove (base + (input_line_pointer - before_reloc),
3762 base, before_reloc - base);
3763
3764 input_line_pointer = base + (input_line_pointer-before_reloc);
3765 expression (&exp);
3766 memcpy (base, save_buf, p - base);
3767
3768 offset = nbytes - size;
4b1a927e
AM
3769 p = frag_more (nbytes);
3770 memset (p, 0, nbytes);
c19d1205 3771 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3772 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3773 free (save_buf);
c19d1205
ZW
3774 }
3775 }
3776 }
b99bd4ef 3777 }
c19d1205 3778 while (*input_line_pointer++ == ',');
b99bd4ef 3779
c19d1205
ZW
3780 /* Put terminator back into stream. */
3781 input_line_pointer --;
3782 demand_empty_rest_of_line ();
b99bd4ef
NC
3783}
3784
c921be7d
NC
3785/* Emit an expression containing a 32-bit thumb instruction.
3786 Implementation based on put_thumb32_insn. */
3787
3788static void
3789emit_thumb32_expr (expressionS * exp)
3790{
3791 expressionS exp_high = *exp;
3792
3793 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3794 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3795 exp->X_add_number &= 0xffff;
3796 emit_expr (exp, (unsigned int) THUMB_SIZE);
3797}
3798
3799/* Guess the instruction size based on the opcode. */
3800
3801static int
3802thumb_insn_size (int opcode)
3803{
3804 if ((unsigned int) opcode < 0xe800u)
3805 return 2;
3806 else if ((unsigned int) opcode >= 0xe8000000u)
3807 return 4;
3808 else
3809 return 0;
3810}
3811
3812static bfd_boolean
3813emit_insn (expressionS *exp, int nbytes)
3814{
3815 int size = 0;
3816
3817 if (exp->X_op == O_constant)
3818 {
3819 size = nbytes;
3820
3821 if (size == 0)
3822 size = thumb_insn_size (exp->X_add_number);
3823
3824 if (size != 0)
3825 {
3826 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3827 {
3828 as_bad (_(".inst.n operand too big. "\
3829 "Use .inst.w instead"));
3830 size = 0;
3831 }
3832 else
3833 {
5ee91343
AV
3834 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
3835 set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0);
c921be7d 3836 else
5ee91343 3837 set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
c921be7d
NC
3838
3839 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3840 emit_thumb32_expr (exp);
3841 else
3842 emit_expr (exp, (unsigned int) size);
3843
3844 it_fsm_post_encode ();
3845 }
3846 }
3847 else
3848 as_bad (_("cannot determine Thumb instruction size. " \
3849 "Use .inst.n/.inst.w instead"));
3850 }
3851 else
3852 as_bad (_("constant expression required"));
3853
3854 return (size != 0);
3855}
3856
3857/* Like s_arm_elf_cons but do not use md_cons_align and
3858 set the mapping state to MAP_ARM/MAP_THUMB. */
3859
3860static void
3861s_arm_elf_inst (int nbytes)
3862{
3863 if (is_it_end_of_statement ())
3864 {
3865 demand_empty_rest_of_line ();
3866 return;
3867 }
3868
3869 /* Calling mapping_state () here will not change ARM/THUMB,
3870 but will ensure not to be in DATA state. */
3871
3872 if (thumb_mode)
3873 mapping_state (MAP_THUMB);
3874 else
3875 {
3876 if (nbytes != 0)
3877 {
3878 as_bad (_("width suffixes are invalid in ARM mode"));
3879 ignore_rest_of_line ();
3880 return;
3881 }
3882
3883 nbytes = 4;
3884
3885 mapping_state (MAP_ARM);
3886 }
3887
3888 do
3889 {
3890 expressionS exp;
3891
3892 expression (& exp);
3893
3894 if (! emit_insn (& exp, nbytes))
3895 {
3896 ignore_rest_of_line ();
3897 return;
3898 }
3899 }
3900 while (*input_line_pointer++ == ',');
3901
3902 /* Put terminator back into stream. */
3903 input_line_pointer --;
3904 demand_empty_rest_of_line ();
3905}
b99bd4ef 3906
c19d1205 3907/* Parse a .rel31 directive. */
b99bd4ef 3908
c19d1205
ZW
3909static void
3910s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3911{
3912 expressionS exp;
3913 char *p;
3914 valueT highbit;
b99bd4ef 3915
c19d1205
ZW
3916 highbit = 0;
3917 if (*input_line_pointer == '1')
3918 highbit = 0x80000000;
3919 else if (*input_line_pointer != '0')
3920 as_bad (_("expected 0 or 1"));
b99bd4ef 3921
c19d1205
ZW
3922 input_line_pointer++;
3923 if (*input_line_pointer != ',')
3924 as_bad (_("missing comma"));
3925 input_line_pointer++;
b99bd4ef 3926
c19d1205
ZW
3927#ifdef md_flush_pending_output
3928 md_flush_pending_output ();
3929#endif
b99bd4ef 3930
c19d1205
ZW
3931#ifdef md_cons_align
3932 md_cons_align (4);
3933#endif
b99bd4ef 3934
c19d1205 3935 mapping_state (MAP_DATA);
b99bd4ef 3936
c19d1205 3937 expression (&exp);
b99bd4ef 3938
c19d1205
ZW
3939 p = frag_more (4);
3940 md_number_to_chars (p, highbit, 4);
3941 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3942 BFD_RELOC_ARM_PREL31);
b99bd4ef 3943
c19d1205 3944 demand_empty_rest_of_line ();
b99bd4ef
NC
3945}
3946
c19d1205 3947/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3948
c19d1205 3949/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3950
c19d1205
ZW
3951static void
3952s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3953{
3954 demand_empty_rest_of_line ();
921e5f0a
PB
3955 if (unwind.proc_start)
3956 {
c921be7d 3957 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3958 return;
3959 }
3960
c19d1205
ZW
3961 /* Mark the start of the function. */
3962 unwind.proc_start = expr_build_dot ();
b99bd4ef 3963
c19d1205
ZW
3964 /* Reset the rest of the unwind info. */
3965 unwind.opcode_count = 0;
3966 unwind.table_entry = NULL;
3967 unwind.personality_routine = NULL;
3968 unwind.personality_index = -1;
3969 unwind.frame_size = 0;
3970 unwind.fp_offset = 0;
fdfde340 3971 unwind.fp_reg = REG_SP;
c19d1205
ZW
3972 unwind.fp_used = 0;
3973 unwind.sp_restored = 0;
3974}
b99bd4ef 3975
b99bd4ef 3976
c19d1205
ZW
3977/* Parse a handlerdata directive. Creates the exception handling table entry
3978 for the function. */
b99bd4ef 3979
c19d1205
ZW
3980static void
3981s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3982{
3983 demand_empty_rest_of_line ();
921e5f0a 3984 if (!unwind.proc_start)
c921be7d 3985 as_bad (MISSING_FNSTART);
921e5f0a 3986
c19d1205 3987 if (unwind.table_entry)
6decc662 3988 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3989
c19d1205
ZW
3990 create_unwind_entry (1);
3991}
a737bd4d 3992
c19d1205 3993/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3994
c19d1205
ZW
3995static void
3996s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3997{
3998 long where;
3999 char *ptr;
4000 valueT val;
940b5ce0 4001 unsigned int marked_pr_dependency;
f02232aa 4002
c19d1205 4003 demand_empty_rest_of_line ();
f02232aa 4004
921e5f0a
PB
4005 if (!unwind.proc_start)
4006 {
c921be7d 4007 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
4008 return;
4009 }
4010
c19d1205
ZW
4011 /* Add eh table entry. */
4012 if (unwind.table_entry == NULL)
4013 val = create_unwind_entry (0);
4014 else
4015 val = 0;
f02232aa 4016
c19d1205
ZW
4017 /* Add index table entry. This is two words. */
4018 start_unwind_section (unwind.saved_seg, 1);
4019 frag_align (2, 0, 0);
4020 record_alignment (now_seg, 2);
b99bd4ef 4021
c19d1205 4022 ptr = frag_more (8);
5011093d 4023 memset (ptr, 0, 8);
c19d1205 4024 where = frag_now_fix () - 8;
f02232aa 4025
c19d1205
ZW
4026 /* Self relative offset of the function start. */
4027 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
4028 BFD_RELOC_ARM_PREL31);
f02232aa 4029
c19d1205
ZW
4030 /* Indicate dependency on EHABI-defined personality routines to the
4031 linker, if it hasn't been done already. */
940b5ce0
DJ
4032 marked_pr_dependency
4033 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
4034 if (unwind.personality_index >= 0 && unwind.personality_index < 3
4035 && !(marked_pr_dependency & (1 << unwind.personality_index)))
4036 {
5f4273c7
NC
4037 static const char *const name[] =
4038 {
4039 "__aeabi_unwind_cpp_pr0",
4040 "__aeabi_unwind_cpp_pr1",
4041 "__aeabi_unwind_cpp_pr2"
4042 };
c19d1205
ZW
4043 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
4044 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 4045 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 4046 |= 1 << unwind.personality_index;
c19d1205 4047 }
f02232aa 4048
c19d1205
ZW
4049 if (val)
4050 /* Inline exception table entry. */
4051 md_number_to_chars (ptr + 4, val, 4);
4052 else
4053 /* Self relative offset of the table entry. */
4054 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
4055 BFD_RELOC_ARM_PREL31);
f02232aa 4056
c19d1205
ZW
4057 /* Restore the original section. */
4058 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
4059
4060 unwind.proc_start = NULL;
c19d1205 4061}
f02232aa 4062
f02232aa 4063
c19d1205 4064/* Parse an unwind_cantunwind directive. */
b99bd4ef 4065
c19d1205
ZW
4066static void
4067s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
4068{
4069 demand_empty_rest_of_line ();
921e5f0a 4070 if (!unwind.proc_start)
c921be7d 4071 as_bad (MISSING_FNSTART);
921e5f0a 4072
c19d1205
ZW
4073 if (unwind.personality_routine || unwind.personality_index != -1)
4074 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 4075
c19d1205
ZW
4076 unwind.personality_index = -2;
4077}
b99bd4ef 4078
b99bd4ef 4079
c19d1205 4080/* Parse a personalityindex directive. */
b99bd4ef 4081
c19d1205
ZW
4082static void
4083s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
4084{
4085 expressionS exp;
b99bd4ef 4086
921e5f0a 4087 if (!unwind.proc_start)
c921be7d 4088 as_bad (MISSING_FNSTART);
921e5f0a 4089
c19d1205
ZW
4090 if (unwind.personality_routine || unwind.personality_index != -1)
4091 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 4092
c19d1205 4093 expression (&exp);
b99bd4ef 4094
c19d1205
ZW
4095 if (exp.X_op != O_constant
4096 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 4097 {
c19d1205
ZW
4098 as_bad (_("bad personality routine number"));
4099 ignore_rest_of_line ();
4100 return;
b99bd4ef
NC
4101 }
4102
c19d1205 4103 unwind.personality_index = exp.X_add_number;
b99bd4ef 4104
c19d1205
ZW
4105 demand_empty_rest_of_line ();
4106}
e16bb312 4107
e16bb312 4108
c19d1205 4109/* Parse a personality directive. */
e16bb312 4110
c19d1205
ZW
4111static void
4112s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
4113{
4114 char *name, *p, c;
a737bd4d 4115
921e5f0a 4116 if (!unwind.proc_start)
c921be7d 4117 as_bad (MISSING_FNSTART);
921e5f0a 4118
c19d1205
ZW
4119 if (unwind.personality_routine || unwind.personality_index != -1)
4120 as_bad (_("duplicate .personality directive"));
a737bd4d 4121
d02603dc 4122 c = get_symbol_name (& name);
c19d1205 4123 p = input_line_pointer;
d02603dc
NC
4124 if (c == '"')
4125 ++ input_line_pointer;
c19d1205
ZW
4126 unwind.personality_routine = symbol_find_or_make (name);
4127 *p = c;
4128 demand_empty_rest_of_line ();
4129}
e16bb312 4130
e16bb312 4131
c19d1205 4132/* Parse a directive saving core registers. */
e16bb312 4133
c19d1205
ZW
4134static void
4135s_arm_unwind_save_core (void)
e16bb312 4136{
c19d1205
ZW
4137 valueT op;
4138 long range;
4139 int n;
e16bb312 4140
4b5a202f 4141 range = parse_reg_list (&input_line_pointer, REGLIST_RN);
c19d1205 4142 if (range == FAIL)
e16bb312 4143 {
c19d1205
ZW
4144 as_bad (_("expected register list"));
4145 ignore_rest_of_line ();
4146 return;
4147 }
e16bb312 4148
c19d1205 4149 demand_empty_rest_of_line ();
e16bb312 4150
c19d1205
ZW
4151 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4152 into .unwind_save {..., sp...}. We aren't bothered about the value of
4153 ip because it is clobbered by calls. */
4154 if (unwind.sp_restored && unwind.fp_reg == 12
4155 && (range & 0x3000) == 0x1000)
4156 {
4157 unwind.opcode_count--;
4158 unwind.sp_restored = 0;
4159 range = (range | 0x2000) & ~0x1000;
4160 unwind.pending_offset = 0;
4161 }
e16bb312 4162
01ae4198
DJ
4163 /* Pop r4-r15. */
4164 if (range & 0xfff0)
c19d1205 4165 {
01ae4198
DJ
4166 /* See if we can use the short opcodes. These pop a block of up to 8
4167 registers starting with r4, plus maybe r14. */
4168 for (n = 0; n < 8; n++)
4169 {
4170 /* Break at the first non-saved register. */
4171 if ((range & (1 << (n + 4))) == 0)
4172 break;
4173 }
4174 /* See if there are any other bits set. */
4175 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4176 {
4177 /* Use the long form. */
4178 op = 0x8000 | ((range >> 4) & 0xfff);
4179 add_unwind_opcode (op, 2);
4180 }
0dd132b6 4181 else
01ae4198
DJ
4182 {
4183 /* Use the short form. */
4184 if (range & 0x4000)
4185 op = 0xa8; /* Pop r14. */
4186 else
4187 op = 0xa0; /* Do not pop r14. */
4188 op |= (n - 1);
4189 add_unwind_opcode (op, 1);
4190 }
c19d1205 4191 }
0dd132b6 4192
c19d1205
ZW
4193 /* Pop r0-r3. */
4194 if (range & 0xf)
4195 {
4196 op = 0xb100 | (range & 0xf);
4197 add_unwind_opcode (op, 2);
0dd132b6
NC
4198 }
4199
c19d1205
ZW
4200 /* Record the number of bytes pushed. */
4201 for (n = 0; n < 16; n++)
4202 {
4203 if (range & (1 << n))
4204 unwind.frame_size += 4;
4205 }
0dd132b6
NC
4206}
4207
c19d1205
ZW
4208
4209/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4210
4211static void
c19d1205 4212s_arm_unwind_save_fpa (int reg)
b99bd4ef 4213{
c19d1205
ZW
4214 expressionS exp;
4215 int num_regs;
4216 valueT op;
b99bd4ef 4217
c19d1205
ZW
4218 /* Get Number of registers to transfer. */
4219 if (skip_past_comma (&input_line_pointer) != FAIL)
4220 expression (&exp);
4221 else
4222 exp.X_op = O_illegal;
b99bd4ef 4223
c19d1205 4224 if (exp.X_op != O_constant)
b99bd4ef 4225 {
c19d1205
ZW
4226 as_bad (_("expected , <constant>"));
4227 ignore_rest_of_line ();
b99bd4ef
NC
4228 return;
4229 }
4230
c19d1205
ZW
4231 num_regs = exp.X_add_number;
4232
4233 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4234 {
c19d1205
ZW
4235 as_bad (_("number of registers must be in the range [1:4]"));
4236 ignore_rest_of_line ();
b99bd4ef
NC
4237 return;
4238 }
4239
c19d1205 4240 demand_empty_rest_of_line ();
b99bd4ef 4241
c19d1205
ZW
4242 if (reg == 4)
4243 {
4244 /* Short form. */
4245 op = 0xb4 | (num_regs - 1);
4246 add_unwind_opcode (op, 1);
4247 }
b99bd4ef
NC
4248 else
4249 {
c19d1205
ZW
4250 /* Long form. */
4251 op = 0xc800 | (reg << 4) | (num_regs - 1);
4252 add_unwind_opcode (op, 2);
b99bd4ef 4253 }
c19d1205 4254 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4255}
4256
c19d1205 4257
fa073d69
MS
4258/* Parse a directive saving VFP registers for ARMv6 and above. */
4259
4260static void
4261s_arm_unwind_save_vfp_armv6 (void)
4262{
4263 int count;
4264 unsigned int start;
4265 valueT op;
4266 int num_vfpv3_regs = 0;
4267 int num_regs_below_16;
efd6b359 4268 bfd_boolean partial_match;
fa073d69 4269
efd6b359
AV
4270 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D,
4271 &partial_match);
fa073d69
MS
4272 if (count == FAIL)
4273 {
4274 as_bad (_("expected register list"));
4275 ignore_rest_of_line ();
4276 return;
4277 }
4278
4279 demand_empty_rest_of_line ();
4280
4281 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4282 than FSTMX/FLDMX-style ones). */
4283
4284 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4285 if (start >= 16)
4286 num_vfpv3_regs = count;
4287 else if (start + count > 16)
4288 num_vfpv3_regs = start + count - 16;
4289
4290 if (num_vfpv3_regs > 0)
4291 {
4292 int start_offset = start > 16 ? start - 16 : 0;
4293 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4294 add_unwind_opcode (op, 2);
4295 }
4296
4297 /* Generate opcode for registers numbered in the range 0 .. 15. */
4298 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4299 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4300 if (num_regs_below_16 > 0)
4301 {
4302 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4303 add_unwind_opcode (op, 2);
4304 }
4305
4306 unwind.frame_size += count * 8;
4307}
4308
4309
4310/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4311
4312static void
c19d1205 4313s_arm_unwind_save_vfp (void)
b99bd4ef 4314{
c19d1205 4315 int count;
ca3f61f7 4316 unsigned int reg;
c19d1205 4317 valueT op;
efd6b359 4318 bfd_boolean partial_match;
b99bd4ef 4319
efd6b359
AV
4320 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D,
4321 &partial_match);
c19d1205 4322 if (count == FAIL)
b99bd4ef 4323 {
c19d1205
ZW
4324 as_bad (_("expected register list"));
4325 ignore_rest_of_line ();
b99bd4ef
NC
4326 return;
4327 }
4328
c19d1205 4329 demand_empty_rest_of_line ();
b99bd4ef 4330
c19d1205 4331 if (reg == 8)
b99bd4ef 4332 {
c19d1205
ZW
4333 /* Short form. */
4334 op = 0xb8 | (count - 1);
4335 add_unwind_opcode (op, 1);
b99bd4ef 4336 }
c19d1205 4337 else
b99bd4ef 4338 {
c19d1205
ZW
4339 /* Long form. */
4340 op = 0xb300 | (reg << 4) | (count - 1);
4341 add_unwind_opcode (op, 2);
b99bd4ef 4342 }
c19d1205
ZW
4343 unwind.frame_size += count * 8 + 4;
4344}
b99bd4ef 4345
b99bd4ef 4346
c19d1205
ZW
4347/* Parse a directive saving iWMMXt data registers. */
4348
4349static void
4350s_arm_unwind_save_mmxwr (void)
4351{
4352 int reg;
4353 int hi_reg;
4354 int i;
4355 unsigned mask = 0;
4356 valueT op;
b99bd4ef 4357
c19d1205
ZW
4358 if (*input_line_pointer == '{')
4359 input_line_pointer++;
b99bd4ef 4360
c19d1205 4361 do
b99bd4ef 4362 {
dcbf9037 4363 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4364
c19d1205 4365 if (reg == FAIL)
b99bd4ef 4366 {
9b7132d3 4367 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4368 goto error;
b99bd4ef
NC
4369 }
4370
c19d1205
ZW
4371 if (mask >> reg)
4372 as_tsktsk (_("register list not in ascending order"));
4373 mask |= 1 << reg;
b99bd4ef 4374
c19d1205
ZW
4375 if (*input_line_pointer == '-')
4376 {
4377 input_line_pointer++;
dcbf9037 4378 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4379 if (hi_reg == FAIL)
4380 {
9b7132d3 4381 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4382 goto error;
4383 }
4384 else if (reg >= hi_reg)
4385 {
4386 as_bad (_("bad register range"));
4387 goto error;
4388 }
4389 for (; reg < hi_reg; reg++)
4390 mask |= 1 << reg;
4391 }
4392 }
4393 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4394
d996d970 4395 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4396
c19d1205 4397 demand_empty_rest_of_line ();
b99bd4ef 4398
708587a4 4399 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4400 the list. */
4401 flush_pending_unwind ();
b99bd4ef 4402
c19d1205 4403 for (i = 0; i < 16; i++)
b99bd4ef 4404 {
c19d1205
ZW
4405 if (mask & (1 << i))
4406 unwind.frame_size += 8;
b99bd4ef
NC
4407 }
4408
c19d1205
ZW
4409 /* Attempt to combine with a previous opcode. We do this because gcc
4410 likes to output separate unwind directives for a single block of
4411 registers. */
4412 if (unwind.opcode_count > 0)
b99bd4ef 4413 {
c19d1205
ZW
4414 i = unwind.opcodes[unwind.opcode_count - 1];
4415 if ((i & 0xf8) == 0xc0)
4416 {
4417 i &= 7;
4418 /* Only merge if the blocks are contiguous. */
4419 if (i < 6)
4420 {
4421 if ((mask & 0xfe00) == (1 << 9))
4422 {
4423 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4424 unwind.opcode_count--;
4425 }
4426 }
4427 else if (i == 6 && unwind.opcode_count >= 2)
4428 {
4429 i = unwind.opcodes[unwind.opcode_count - 2];
4430 reg = i >> 4;
4431 i &= 0xf;
b99bd4ef 4432
c19d1205
ZW
4433 op = 0xffff << (reg - 1);
4434 if (reg > 0
87a1fd79 4435 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4436 {
4437 op = (1 << (reg + i + 1)) - 1;
4438 op &= ~((1 << reg) - 1);
4439 mask |= op;
4440 unwind.opcode_count -= 2;
4441 }
4442 }
4443 }
b99bd4ef
NC
4444 }
4445
c19d1205
ZW
4446 hi_reg = 15;
4447 /* We want to generate opcodes in the order the registers have been
4448 saved, ie. descending order. */
4449 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4450 {
c19d1205
ZW
4451 /* Save registers in blocks. */
4452 if (reg < 0
4453 || !(mask & (1 << reg)))
4454 {
4455 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4456 preceding block. */
c19d1205
ZW
4457 if (reg != hi_reg)
4458 {
4459 if (reg == 9)
4460 {
4461 /* Short form. */
4462 op = 0xc0 | (hi_reg - 10);
4463 add_unwind_opcode (op, 1);
4464 }
4465 else
4466 {
4467 /* Long form. */
4468 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4469 add_unwind_opcode (op, 2);
4470 }
4471 }
4472 hi_reg = reg - 1;
4473 }
b99bd4ef
NC
4474 }
4475
c19d1205
ZW
4476 return;
4477error:
4478 ignore_rest_of_line ();
b99bd4ef
NC
4479}
4480
4481static void
c19d1205 4482s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4483{
c19d1205
ZW
4484 int reg;
4485 int hi_reg;
4486 unsigned mask = 0;
4487 valueT op;
b99bd4ef 4488
c19d1205
ZW
4489 if (*input_line_pointer == '{')
4490 input_line_pointer++;
b99bd4ef 4491
477330fc
RM
4492 skip_whitespace (input_line_pointer);
4493
c19d1205 4494 do
b99bd4ef 4495 {
dcbf9037 4496 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4497
c19d1205
ZW
4498 if (reg == FAIL)
4499 {
9b7132d3 4500 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4501 goto error;
4502 }
b99bd4ef 4503
c19d1205
ZW
4504 reg -= 8;
4505 if (mask >> reg)
4506 as_tsktsk (_("register list not in ascending order"));
4507 mask |= 1 << reg;
b99bd4ef 4508
c19d1205
ZW
4509 if (*input_line_pointer == '-')
4510 {
4511 input_line_pointer++;
dcbf9037 4512 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4513 if (hi_reg == FAIL)
4514 {
9b7132d3 4515 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4516 goto error;
4517 }
4518 else if (reg >= hi_reg)
4519 {
4520 as_bad (_("bad register range"));
4521 goto error;
4522 }
4523 for (; reg < hi_reg; reg++)
4524 mask |= 1 << reg;
4525 }
b99bd4ef 4526 }
c19d1205 4527 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4528
d996d970 4529 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4530
c19d1205
ZW
4531 demand_empty_rest_of_line ();
4532
708587a4 4533 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4534 the list. */
4535 flush_pending_unwind ();
b99bd4ef 4536
c19d1205 4537 for (reg = 0; reg < 16; reg++)
b99bd4ef 4538 {
c19d1205
ZW
4539 if (mask & (1 << reg))
4540 unwind.frame_size += 4;
b99bd4ef 4541 }
c19d1205
ZW
4542 op = 0xc700 | mask;
4543 add_unwind_opcode (op, 2);
4544 return;
4545error:
4546 ignore_rest_of_line ();
b99bd4ef
NC
4547}
4548
c19d1205 4549
fa073d69
MS
4550/* Parse an unwind_save directive.
4551 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4552
b99bd4ef 4553static void
fa073d69 4554s_arm_unwind_save (int arch_v6)
b99bd4ef 4555{
c19d1205
ZW
4556 char *peek;
4557 struct reg_entry *reg;
4558 bfd_boolean had_brace = FALSE;
b99bd4ef 4559
921e5f0a 4560 if (!unwind.proc_start)
c921be7d 4561 as_bad (MISSING_FNSTART);
921e5f0a 4562
c19d1205
ZW
4563 /* Figure out what sort of save we have. */
4564 peek = input_line_pointer;
b99bd4ef 4565
c19d1205 4566 if (*peek == '{')
b99bd4ef 4567 {
c19d1205
ZW
4568 had_brace = TRUE;
4569 peek++;
b99bd4ef
NC
4570 }
4571
c19d1205 4572 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4573
c19d1205 4574 if (!reg)
b99bd4ef 4575 {
c19d1205
ZW
4576 as_bad (_("register expected"));
4577 ignore_rest_of_line ();
b99bd4ef
NC
4578 return;
4579 }
4580
c19d1205 4581 switch (reg->type)
b99bd4ef 4582 {
c19d1205
ZW
4583 case REG_TYPE_FN:
4584 if (had_brace)
4585 {
4586 as_bad (_("FPA .unwind_save does not take a register list"));
4587 ignore_rest_of_line ();
4588 return;
4589 }
93ac2687 4590 input_line_pointer = peek;
c19d1205 4591 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4592 return;
c19d1205 4593
1f5afe1c
NC
4594 case REG_TYPE_RN:
4595 s_arm_unwind_save_core ();
4596 return;
4597
fa073d69
MS
4598 case REG_TYPE_VFD:
4599 if (arch_v6)
477330fc 4600 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4601 else
477330fc 4602 s_arm_unwind_save_vfp ();
fa073d69 4603 return;
1f5afe1c
NC
4604
4605 case REG_TYPE_MMXWR:
4606 s_arm_unwind_save_mmxwr ();
4607 return;
4608
4609 case REG_TYPE_MMXWCG:
4610 s_arm_unwind_save_mmxwcg ();
4611 return;
c19d1205
ZW
4612
4613 default:
4614 as_bad (_(".unwind_save does not support this kind of register"));
4615 ignore_rest_of_line ();
b99bd4ef 4616 }
c19d1205 4617}
b99bd4ef 4618
b99bd4ef 4619
c19d1205
ZW
4620/* Parse an unwind_movsp directive. */
4621
4622static void
4623s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4624{
4625 int reg;
4626 valueT op;
4fa3602b 4627 int offset;
c19d1205 4628
921e5f0a 4629 if (!unwind.proc_start)
c921be7d 4630 as_bad (MISSING_FNSTART);
921e5f0a 4631
dcbf9037 4632 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4633 if (reg == FAIL)
b99bd4ef 4634 {
9b7132d3 4635 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4636 ignore_rest_of_line ();
b99bd4ef
NC
4637 return;
4638 }
4fa3602b
PB
4639
4640 /* Optional constant. */
4641 if (skip_past_comma (&input_line_pointer) != FAIL)
4642 {
4643 if (immediate_for_directive (&offset) == FAIL)
4644 return;
4645 }
4646 else
4647 offset = 0;
4648
c19d1205 4649 demand_empty_rest_of_line ();
b99bd4ef 4650
c19d1205 4651 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4652 {
c19d1205 4653 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4654 return;
4655 }
4656
c19d1205
ZW
4657 if (unwind.fp_reg != REG_SP)
4658 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4659
c19d1205
ZW
4660 /* Generate opcode to restore the value. */
4661 op = 0x90 | reg;
4662 add_unwind_opcode (op, 1);
4663
4664 /* Record the information for later. */
4665 unwind.fp_reg = reg;
4fa3602b 4666 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4667 unwind.sp_restored = 1;
b05fe5cf
ZW
4668}
4669
c19d1205
ZW
4670/* Parse an unwind_pad directive. */
4671
b05fe5cf 4672static void
c19d1205 4673s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4674{
c19d1205 4675 int offset;
b05fe5cf 4676
921e5f0a 4677 if (!unwind.proc_start)
c921be7d 4678 as_bad (MISSING_FNSTART);
921e5f0a 4679
c19d1205
ZW
4680 if (immediate_for_directive (&offset) == FAIL)
4681 return;
b99bd4ef 4682
c19d1205
ZW
4683 if (offset & 3)
4684 {
4685 as_bad (_("stack increment must be multiple of 4"));
4686 ignore_rest_of_line ();
4687 return;
4688 }
b99bd4ef 4689
c19d1205
ZW
4690 /* Don't generate any opcodes, just record the details for later. */
4691 unwind.frame_size += offset;
4692 unwind.pending_offset += offset;
4693
4694 demand_empty_rest_of_line ();
4695}
4696
4697/* Parse an unwind_setfp directive. */
4698
4699static void
4700s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4701{
c19d1205
ZW
4702 int sp_reg;
4703 int fp_reg;
4704 int offset;
4705
921e5f0a 4706 if (!unwind.proc_start)
c921be7d 4707 as_bad (MISSING_FNSTART);
921e5f0a 4708
dcbf9037 4709 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4710 if (skip_past_comma (&input_line_pointer) == FAIL)
4711 sp_reg = FAIL;
4712 else
dcbf9037 4713 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4714
c19d1205
ZW
4715 if (fp_reg == FAIL || sp_reg == FAIL)
4716 {
4717 as_bad (_("expected <reg>, <reg>"));
4718 ignore_rest_of_line ();
4719 return;
4720 }
b99bd4ef 4721
c19d1205
ZW
4722 /* Optional constant. */
4723 if (skip_past_comma (&input_line_pointer) != FAIL)
4724 {
4725 if (immediate_for_directive (&offset) == FAIL)
4726 return;
4727 }
4728 else
4729 offset = 0;
a737bd4d 4730
c19d1205 4731 demand_empty_rest_of_line ();
a737bd4d 4732
fdfde340 4733 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4734 {
c19d1205
ZW
4735 as_bad (_("register must be either sp or set by a previous"
4736 "unwind_movsp directive"));
4737 return;
a737bd4d
NC
4738 }
4739
c19d1205
ZW
4740 /* Don't generate any opcodes, just record the information for later. */
4741 unwind.fp_reg = fp_reg;
4742 unwind.fp_used = 1;
fdfde340 4743 if (sp_reg == REG_SP)
c19d1205
ZW
4744 unwind.fp_offset = unwind.frame_size - offset;
4745 else
4746 unwind.fp_offset -= offset;
a737bd4d
NC
4747}
4748
c19d1205
ZW
4749/* Parse an unwind_raw directive. */
4750
4751static void
4752s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4753{
c19d1205 4754 expressionS exp;
708587a4 4755 /* This is an arbitrary limit. */
c19d1205
ZW
4756 unsigned char op[16];
4757 int count;
a737bd4d 4758
921e5f0a 4759 if (!unwind.proc_start)
c921be7d 4760 as_bad (MISSING_FNSTART);
921e5f0a 4761
c19d1205
ZW
4762 expression (&exp);
4763 if (exp.X_op == O_constant
4764 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4765 {
c19d1205
ZW
4766 unwind.frame_size += exp.X_add_number;
4767 expression (&exp);
4768 }
4769 else
4770 exp.X_op = O_illegal;
a737bd4d 4771
c19d1205
ZW
4772 if (exp.X_op != O_constant)
4773 {
4774 as_bad (_("expected <offset>, <opcode>"));
4775 ignore_rest_of_line ();
4776 return;
4777 }
a737bd4d 4778
c19d1205 4779 count = 0;
a737bd4d 4780
c19d1205
ZW
4781 /* Parse the opcode. */
4782 for (;;)
4783 {
4784 if (count >= 16)
4785 {
4786 as_bad (_("unwind opcode too long"));
4787 ignore_rest_of_line ();
a737bd4d 4788 }
c19d1205 4789 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4790 {
c19d1205
ZW
4791 as_bad (_("invalid unwind opcode"));
4792 ignore_rest_of_line ();
4793 return;
a737bd4d 4794 }
c19d1205 4795 op[count++] = exp.X_add_number;
a737bd4d 4796
c19d1205
ZW
4797 /* Parse the next byte. */
4798 if (skip_past_comma (&input_line_pointer) == FAIL)
4799 break;
a737bd4d 4800
c19d1205
ZW
4801 expression (&exp);
4802 }
b99bd4ef 4803
c19d1205
ZW
4804 /* Add the opcode bytes in reverse order. */
4805 while (count--)
4806 add_unwind_opcode (op[count], 1);
b99bd4ef 4807
c19d1205 4808 demand_empty_rest_of_line ();
b99bd4ef 4809}
ee065d83
PB
4810
4811
4812/* Parse a .eabi_attribute directive. */
4813
4814static void
4815s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4816{
0420f52b 4817 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378 4818
3076e594 4819 if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES)
ee3c0378 4820 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4821}
4822
0855e32b
NS
4823/* Emit a tls fix for the symbol. */
4824
4825static void
4826s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4827{
4828 char *p;
4829 expressionS exp;
4830#ifdef md_flush_pending_output
4831 md_flush_pending_output ();
4832#endif
4833
4834#ifdef md_cons_align
4835 md_cons_align (4);
4836#endif
4837
4838 /* Since we're just labelling the code, there's no need to define a
4839 mapping symbol. */
4840 expression (&exp);
4841 p = obstack_next_free (&frchain_now->frch_obstack);
4842 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4843 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4844 : BFD_RELOC_ARM_TLS_DESCSEQ);
4845}
cdf9ccec 4846#endif /* OBJ_ELF */
0855e32b 4847
ee065d83 4848static void s_arm_arch (int);
7a1d4c38 4849static void s_arm_object_arch (int);
ee065d83
PB
4850static void s_arm_cpu (int);
4851static void s_arm_fpu (int);
69133863 4852static void s_arm_arch_extension (int);
b99bd4ef 4853
f0927246
NC
4854#ifdef TE_PE
4855
4856static void
5f4273c7 4857pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4858{
4859 expressionS exp;
4860
4861 do
4862 {
4863 expression (&exp);
4864 if (exp.X_op == O_symbol)
4865 exp.X_op = O_secrel;
4866
4867 emit_expr (&exp, 4);
4868 }
4869 while (*input_line_pointer++ == ',');
4870
4871 input_line_pointer--;
4872 demand_empty_rest_of_line ();
4873}
4874#endif /* TE_PE */
4875
c19d1205
ZW
4876/* This table describes all the machine specific pseudo-ops the assembler
4877 has to support. The fields are:
4878 pseudo-op name without dot
4879 function to call to execute this pseudo-op
4880 Integer arg to pass to the function. */
b99bd4ef 4881
c19d1205 4882const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4883{
c19d1205
ZW
4884 /* Never called because '.req' does not start a line. */
4885 { "req", s_req, 0 },
dcbf9037
JB
4886 /* Following two are likewise never called. */
4887 { "dn", s_dn, 0 },
4888 { "qn", s_qn, 0 },
c19d1205
ZW
4889 { "unreq", s_unreq, 0 },
4890 { "bss", s_bss, 0 },
db2ed2e0 4891 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4892 { "arm", s_arm, 0 },
4893 { "thumb", s_thumb, 0 },
4894 { "code", s_code, 0 },
4895 { "force_thumb", s_force_thumb, 0 },
4896 { "thumb_func", s_thumb_func, 0 },
4897 { "thumb_set", s_thumb_set, 0 },
4898 { "even", s_even, 0 },
4899 { "ltorg", s_ltorg, 0 },
4900 { "pool", s_ltorg, 0 },
4901 { "syntax", s_syntax, 0 },
8463be01
PB
4902 { "cpu", s_arm_cpu, 0 },
4903 { "arch", s_arm_arch, 0 },
7a1d4c38 4904 { "object_arch", s_arm_object_arch, 0 },
8463be01 4905 { "fpu", s_arm_fpu, 0 },
69133863 4906 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4907#ifdef OBJ_ELF
c921be7d
NC
4908 { "word", s_arm_elf_cons, 4 },
4909 { "long", s_arm_elf_cons, 4 },
4910 { "inst.n", s_arm_elf_inst, 2 },
4911 { "inst.w", s_arm_elf_inst, 4 },
4912 { "inst", s_arm_elf_inst, 0 },
4913 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4914 { "fnstart", s_arm_unwind_fnstart, 0 },
4915 { "fnend", s_arm_unwind_fnend, 0 },
4916 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4917 { "personality", s_arm_unwind_personality, 0 },
4918 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4919 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4920 { "save", s_arm_unwind_save, 0 },
fa073d69 4921 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4922 { "movsp", s_arm_unwind_movsp, 0 },
4923 { "pad", s_arm_unwind_pad, 0 },
4924 { "setfp", s_arm_unwind_setfp, 0 },
4925 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4926 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4927 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4928#else
4929 { "word", cons, 4},
f0927246
NC
4930
4931 /* These are used for dwarf. */
4932 {"2byte", cons, 2},
4933 {"4byte", cons, 4},
4934 {"8byte", cons, 8},
4935 /* These are used for dwarf2. */
68d20676 4936 { "file", dwarf2_directive_file, 0 },
f0927246
NC
4937 { "loc", dwarf2_directive_loc, 0 },
4938 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4939#endif
4940 { "extend", float_cons, 'x' },
4941 { "ldouble", float_cons, 'x' },
4942 { "packed", float_cons, 'p' },
f0927246
NC
4943#ifdef TE_PE
4944 {"secrel32", pe_directive_secrel, 0},
4945#endif
2e6976a8
DG
4946
4947 /* These are for compatibility with CodeComposer Studio. */
4948 {"ref", s_ccs_ref, 0},
4949 {"def", s_ccs_def, 0},
4950 {"asmfunc", s_ccs_asmfunc, 0},
4951 {"endasmfunc", s_ccs_endasmfunc, 0},
4952
c19d1205
ZW
4953 { 0, 0, 0 }
4954};
4955\f
4956/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4957
c19d1205
ZW
4958/* Generic immediate-value read function for use in insn parsing.
4959 STR points to the beginning of the immediate (the leading #);
4960 VAL receives the value; if the value is outside [MIN, MAX]
4961 issue an error. PREFIX_OPT is true if the immediate prefix is
4962 optional. */
b99bd4ef 4963
c19d1205
ZW
4964static int
4965parse_immediate (char **str, int *val, int min, int max,
4966 bfd_boolean prefix_opt)
4967{
4968 expressionS exp;
0198d5e6 4969
c19d1205
ZW
4970 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4971 if (exp.X_op != O_constant)
b99bd4ef 4972 {
c19d1205
ZW
4973 inst.error = _("constant expression required");
4974 return FAIL;
4975 }
b99bd4ef 4976
c19d1205
ZW
4977 if (exp.X_add_number < min || exp.X_add_number > max)
4978 {
4979 inst.error = _("immediate value out of range");
4980 return FAIL;
4981 }
b99bd4ef 4982
c19d1205
ZW
4983 *val = exp.X_add_number;
4984 return SUCCESS;
4985}
b99bd4ef 4986
5287ad62 4987/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4988 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4989 instructions. Puts the result directly in inst.operands[i]. */
4990
4991static int
8335d6aa
JW
4992parse_big_immediate (char **str, int i, expressionS *in_exp,
4993 bfd_boolean allow_symbol_p)
5287ad62
JB
4994{
4995 expressionS exp;
8335d6aa 4996 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4997 char *ptr = *str;
4998
8335d6aa 4999 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 5000
8335d6aa 5001 if (exp_p->X_op == O_constant)
036dc3f7 5002 {
8335d6aa 5003 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
5004 /* If we're on a 64-bit host, then a 64-bit number can be returned using
5005 O_constant. We have to be careful not to break compilation for
5006 32-bit X_add_number, though. */
8335d6aa 5007 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 5008 {
8335d6aa
JW
5009 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
5010 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
5011 & 0xffffffff);
036dc3f7
PB
5012 inst.operands[i].regisimm = 1;
5013 }
5014 }
8335d6aa
JW
5015 else if (exp_p->X_op == O_big
5016 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
5017 {
5018 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 5019
5287ad62 5020 /* Bignums have their least significant bits in
477330fc
RM
5021 generic_bignum[0]. Make sure we put 32 bits in imm and
5022 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 5023 gas_assert (parts != 0);
95b75c01
NC
5024
5025 /* Make sure that the number is not too big.
5026 PR 11972: Bignums can now be sign-extended to the
5027 size of a .octa so check that the out of range bits
5028 are all zero or all one. */
8335d6aa 5029 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
5030 {
5031 LITTLENUM_TYPE m = -1;
5032
5033 if (generic_bignum[parts * 2] != 0
5034 && generic_bignum[parts * 2] != m)
5035 return FAIL;
5036
8335d6aa 5037 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
5038 if (generic_bignum[j] != generic_bignum[j-1])
5039 return FAIL;
5040 }
5041
5287ad62
JB
5042 inst.operands[i].imm = 0;
5043 for (j = 0; j < parts; j++, idx++)
477330fc
RM
5044 inst.operands[i].imm |= generic_bignum[idx]
5045 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
5046 inst.operands[i].reg = 0;
5047 for (j = 0; j < parts; j++, idx++)
477330fc
RM
5048 inst.operands[i].reg |= generic_bignum[idx]
5049 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
5050 inst.operands[i].regisimm = 1;
5051 }
8335d6aa 5052 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 5053 return FAIL;
5f4273c7 5054
5287ad62
JB
5055 *str = ptr;
5056
5057 return SUCCESS;
5058}
5059
c19d1205
ZW
5060/* Returns the pseudo-register number of an FPA immediate constant,
5061 or FAIL if there isn't a valid constant here. */
b99bd4ef 5062
c19d1205
ZW
5063static int
5064parse_fpa_immediate (char ** str)
5065{
5066 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5067 char * save_in;
5068 expressionS exp;
5069 int i;
5070 int j;
b99bd4ef 5071
c19d1205
ZW
5072 /* First try and match exact strings, this is to guarantee
5073 that some formats will work even for cross assembly. */
b99bd4ef 5074
c19d1205
ZW
5075 for (i = 0; fp_const[i]; i++)
5076 {
5077 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 5078 {
c19d1205 5079 char *start = *str;
b99bd4ef 5080
c19d1205
ZW
5081 *str += strlen (fp_const[i]);
5082 if (is_end_of_line[(unsigned char) **str])
5083 return i + 8;
5084 *str = start;
5085 }
5086 }
b99bd4ef 5087
c19d1205
ZW
5088 /* Just because we didn't get a match doesn't mean that the constant
5089 isn't valid, just that it is in a format that we don't
5090 automatically recognize. Try parsing it with the standard
5091 expression routines. */
b99bd4ef 5092
c19d1205 5093 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 5094
c19d1205
ZW
5095 /* Look for a raw floating point number. */
5096 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
5097 && is_end_of_line[(unsigned char) *save_in])
5098 {
5099 for (i = 0; i < NUM_FLOAT_VALS; i++)
5100 {
5101 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 5102 {
c19d1205
ZW
5103 if (words[j] != fp_values[i][j])
5104 break;
b99bd4ef
NC
5105 }
5106
c19d1205 5107 if (j == MAX_LITTLENUMS)
b99bd4ef 5108 {
c19d1205
ZW
5109 *str = save_in;
5110 return i + 8;
b99bd4ef
NC
5111 }
5112 }
5113 }
b99bd4ef 5114
c19d1205
ZW
5115 /* Try and parse a more complex expression, this will probably fail
5116 unless the code uses a floating point prefix (eg "0f"). */
5117 save_in = input_line_pointer;
5118 input_line_pointer = *str;
5119 if (expression (&exp) == absolute_section
5120 && exp.X_op == O_big
5121 && exp.X_add_number < 0)
5122 {
5123 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
5124 Ditto for 15. */
ba592044
AM
5125#define X_PRECISION 5
5126#define E_PRECISION 15L
5127 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
5128 {
5129 for (i = 0; i < NUM_FLOAT_VALS; i++)
5130 {
5131 for (j = 0; j < MAX_LITTLENUMS; j++)
5132 {
5133 if (words[j] != fp_values[i][j])
5134 break;
5135 }
b99bd4ef 5136
c19d1205
ZW
5137 if (j == MAX_LITTLENUMS)
5138 {
5139 *str = input_line_pointer;
5140 input_line_pointer = save_in;
5141 return i + 8;
5142 }
5143 }
5144 }
b99bd4ef
NC
5145 }
5146
c19d1205
ZW
5147 *str = input_line_pointer;
5148 input_line_pointer = save_in;
5149 inst.error = _("invalid FPA immediate expression");
5150 return FAIL;
b99bd4ef
NC
5151}
5152
136da414
JB
5153/* Returns 1 if a number has "quarter-precision" float format
5154 0baBbbbbbc defgh000 00000000 00000000. */
5155
5156static int
5157is_quarter_float (unsigned imm)
5158{
5159 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5160 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5161}
5162
aacf0b33
KT
5163
5164/* Detect the presence of a floating point or integer zero constant,
5165 i.e. #0.0 or #0. */
5166
5167static bfd_boolean
5168parse_ifimm_zero (char **in)
5169{
5170 int error_code;
5171
5172 if (!is_immediate_prefix (**in))
3c6452ae
TP
5173 {
5174 /* In unified syntax, all prefixes are optional. */
5175 if (!unified_syntax)
5176 return FALSE;
5177 }
5178 else
5179 ++*in;
0900a05b
JW
5180
5181 /* Accept #0x0 as a synonym for #0. */
5182 if (strncmp (*in, "0x", 2) == 0)
5183 {
5184 int val;
5185 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5186 return FALSE;
5187 return TRUE;
5188 }
5189
aacf0b33
KT
5190 error_code = atof_generic (in, ".", EXP_CHARS,
5191 &generic_floating_point_number);
5192
5193 if (!error_code
5194 && generic_floating_point_number.sign == '+'
5195 && (generic_floating_point_number.low
5196 > generic_floating_point_number.leader))
5197 return TRUE;
5198
5199 return FALSE;
5200}
5201
136da414
JB
5202/* Parse an 8-bit "quarter-precision" floating point number of the form:
5203 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5204 The zero and minus-zero cases need special handling, since they can't be
5205 encoded in the "quarter-precision" float format, but can nonetheless be
5206 loaded as integer constants. */
136da414
JB
5207
5208static unsigned
5209parse_qfloat_immediate (char **ccp, int *immed)
5210{
5211 char *str = *ccp;
c96612cc 5212 char *fpnum;
136da414 5213 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5214 int found_fpchar = 0;
5f4273c7 5215
136da414 5216 skip_past_char (&str, '#');
5f4273c7 5217
c96612cc
JB
5218 /* We must not accidentally parse an integer as a floating-point number. Make
5219 sure that the value we parse is not an integer by checking for special
5220 characters '.' or 'e'.
5221 FIXME: This is a horrible hack, but doing better is tricky because type
5222 information isn't in a very usable state at parse time. */
5223 fpnum = str;
5224 skip_whitespace (fpnum);
5225
5226 if (strncmp (fpnum, "0x", 2) == 0)
5227 return FAIL;
5228 else
5229 {
5230 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5231 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5232 {
5233 found_fpchar = 1;
5234 break;
5235 }
c96612cc
JB
5236
5237 if (!found_fpchar)
477330fc 5238 return FAIL;
c96612cc 5239 }
5f4273c7 5240
136da414
JB
5241 if ((str = atof_ieee (str, 's', words)) != NULL)
5242 {
5243 unsigned fpword = 0;
5244 int i;
5f4273c7 5245
136da414
JB
5246 /* Our FP word must be 32 bits (single-precision FP). */
5247 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5248 {
5249 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5250 fpword |= words[i];
5251 }
5f4273c7 5252
c96612cc 5253 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5254 *immed = fpword;
136da414 5255 else
477330fc 5256 return FAIL;
136da414
JB
5257
5258 *ccp = str;
5f4273c7 5259
136da414
JB
5260 return SUCCESS;
5261 }
5f4273c7 5262
136da414
JB
5263 return FAIL;
5264}
5265
c19d1205
ZW
5266/* Shift operands. */
5267enum shift_kind
b99bd4ef 5268{
c19d1205
ZW
5269 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5270};
b99bd4ef 5271
c19d1205
ZW
5272struct asm_shift_name
5273{
5274 const char *name;
5275 enum shift_kind kind;
5276};
b99bd4ef 5277
c19d1205
ZW
5278/* Third argument to parse_shift. */
5279enum parse_shift_mode
5280{
5281 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5282 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5283 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5284 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5285 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5286};
b99bd4ef 5287
c19d1205
ZW
5288/* Parse a <shift> specifier on an ARM data processing instruction.
5289 This has three forms:
b99bd4ef 5290
c19d1205
ZW
5291 (LSL|LSR|ASL|ASR|ROR) Rs
5292 (LSL|LSR|ASL|ASR|ROR) #imm
5293 RRX
b99bd4ef 5294
c19d1205
ZW
5295 Note that ASL is assimilated to LSL in the instruction encoding, and
5296 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5297
c19d1205
ZW
5298static int
5299parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5300{
c19d1205
ZW
5301 const struct asm_shift_name *shift_name;
5302 enum shift_kind shift;
5303 char *s = *str;
5304 char *p = s;
5305 int reg;
b99bd4ef 5306
c19d1205
ZW
5307 for (p = *str; ISALPHA (*p); p++)
5308 ;
b99bd4ef 5309
c19d1205 5310 if (p == *str)
b99bd4ef 5311 {
c19d1205
ZW
5312 inst.error = _("shift expression expected");
5313 return FAIL;
b99bd4ef
NC
5314 }
5315
21d799b5 5316 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5317 p - *str);
c19d1205
ZW
5318
5319 if (shift_name == NULL)
b99bd4ef 5320 {
c19d1205
ZW
5321 inst.error = _("shift expression expected");
5322 return FAIL;
b99bd4ef
NC
5323 }
5324
c19d1205 5325 shift = shift_name->kind;
b99bd4ef 5326
c19d1205
ZW
5327 switch (mode)
5328 {
5329 case NO_SHIFT_RESTRICT:
5330 case SHIFT_IMMEDIATE: break;
b99bd4ef 5331
c19d1205
ZW
5332 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5333 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5334 {
5335 inst.error = _("'LSL' or 'ASR' required");
5336 return FAIL;
5337 }
5338 break;
b99bd4ef 5339
c19d1205
ZW
5340 case SHIFT_LSL_IMMEDIATE:
5341 if (shift != SHIFT_LSL)
5342 {
5343 inst.error = _("'LSL' required");
5344 return FAIL;
5345 }
5346 break;
b99bd4ef 5347
c19d1205
ZW
5348 case SHIFT_ASR_IMMEDIATE:
5349 if (shift != SHIFT_ASR)
5350 {
5351 inst.error = _("'ASR' required");
5352 return FAIL;
5353 }
5354 break;
b99bd4ef 5355
c19d1205
ZW
5356 default: abort ();
5357 }
b99bd4ef 5358
c19d1205
ZW
5359 if (shift != SHIFT_RRX)
5360 {
5361 /* Whitespace can appear here if the next thing is a bare digit. */
5362 skip_whitespace (p);
b99bd4ef 5363
c19d1205 5364 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5365 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5366 {
5367 inst.operands[i].imm = reg;
5368 inst.operands[i].immisreg = 1;
5369 }
e2b0ab59 5370 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
c19d1205
ZW
5371 return FAIL;
5372 }
5373 inst.operands[i].shift_kind = shift;
5374 inst.operands[i].shifted = 1;
5375 *str = p;
5376 return SUCCESS;
b99bd4ef
NC
5377}
5378
c19d1205 5379/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5380
c19d1205
ZW
5381 #<immediate>
5382 #<immediate>, <rotate>
5383 <Rm>
5384 <Rm>, <shift>
b99bd4ef 5385
c19d1205
ZW
5386 where <shift> is defined by parse_shift above, and <rotate> is a
5387 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5388 is deferred to md_apply_fix. */
b99bd4ef 5389
c19d1205
ZW
5390static int
5391parse_shifter_operand (char **str, int i)
5392{
5393 int value;
91d6fa6a 5394 expressionS exp;
b99bd4ef 5395
dcbf9037 5396 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5397 {
5398 inst.operands[i].reg = value;
5399 inst.operands[i].isreg = 1;
b99bd4ef 5400
c19d1205 5401 /* parse_shift will override this if appropriate */
e2b0ab59
AV
5402 inst.relocs[0].exp.X_op = O_constant;
5403 inst.relocs[0].exp.X_add_number = 0;
b99bd4ef 5404
c19d1205
ZW
5405 if (skip_past_comma (str) == FAIL)
5406 return SUCCESS;
b99bd4ef 5407
c19d1205
ZW
5408 /* Shift operation on register. */
5409 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5410 }
5411
e2b0ab59 5412 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
c19d1205 5413 return FAIL;
b99bd4ef 5414
c19d1205 5415 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5416 {
c19d1205 5417 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5418 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5419 return FAIL;
b99bd4ef 5420
e2b0ab59 5421 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
c19d1205
ZW
5422 {
5423 inst.error = _("constant expression expected");
5424 return FAIL;
5425 }
b99bd4ef 5426
91d6fa6a 5427 value = exp.X_add_number;
c19d1205
ZW
5428 if (value < 0 || value > 30 || value % 2 != 0)
5429 {
5430 inst.error = _("invalid rotation");
5431 return FAIL;
5432 }
e2b0ab59
AV
5433 if (inst.relocs[0].exp.X_add_number < 0
5434 || inst.relocs[0].exp.X_add_number > 255)
c19d1205
ZW
5435 {
5436 inst.error = _("invalid constant");
5437 return FAIL;
5438 }
09d92015 5439
a415b1cd 5440 /* Encode as specified. */
e2b0ab59 5441 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
a415b1cd 5442 return SUCCESS;
09d92015
MM
5443 }
5444
e2b0ab59
AV
5445 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5446 inst.relocs[0].pc_rel = 0;
c19d1205 5447 return SUCCESS;
09d92015
MM
5448}
5449
4962c51a
MS
5450/* Group relocation information. Each entry in the table contains the
5451 textual name of the relocation as may appear in assembler source
5452 and must end with a colon.
5453 Along with this textual name are the relocation codes to be used if
5454 the corresponding instruction is an ALU instruction (ADD or SUB only),
5455 an LDR, an LDRS, or an LDC. */
5456
5457struct group_reloc_table_entry
5458{
5459 const char *name;
5460 int alu_code;
5461 int ldr_code;
5462 int ldrs_code;
5463 int ldc_code;
5464};
5465
5466typedef enum
5467{
5468 /* Varieties of non-ALU group relocation. */
5469
5470 GROUP_LDR,
5471 GROUP_LDRS,
5472 GROUP_LDC
5473} group_reloc_type;
5474
5475static struct group_reloc_table_entry group_reloc_table[] =
5476 { /* Program counter relative: */
5477 { "pc_g0_nc",
5478 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5479 0, /* LDR */
5480 0, /* LDRS */
5481 0 }, /* LDC */
5482 { "pc_g0",
5483 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5484 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5485 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5486 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5487 { "pc_g1_nc",
5488 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5489 0, /* LDR */
5490 0, /* LDRS */
5491 0 }, /* LDC */
5492 { "pc_g1",
5493 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5494 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5495 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5496 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5497 { "pc_g2",
5498 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5499 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5500 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5501 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5502 /* Section base relative */
5503 { "sb_g0_nc",
5504 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5505 0, /* LDR */
5506 0, /* LDRS */
5507 0 }, /* LDC */
5508 { "sb_g0",
5509 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5510 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5511 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5512 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5513 { "sb_g1_nc",
5514 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5515 0, /* LDR */
5516 0, /* LDRS */
5517 0 }, /* LDC */
5518 { "sb_g1",
5519 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5520 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5521 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5522 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5523 { "sb_g2",
5524 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5525 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5526 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5527 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5528 /* Absolute thumb alu relocations. */
5529 { "lower0_7",
5530 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5531 0, /* LDR. */
5532 0, /* LDRS. */
5533 0 }, /* LDC. */
5534 { "lower8_15",
5535 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5536 0, /* LDR. */
5537 0, /* LDRS. */
5538 0 }, /* LDC. */
5539 { "upper0_7",
5540 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5541 0, /* LDR. */
5542 0, /* LDRS. */
5543 0 }, /* LDC. */
5544 { "upper8_15",
5545 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5546 0, /* LDR. */
5547 0, /* LDRS. */
5548 0 } }; /* LDC. */
4962c51a
MS
5549
5550/* Given the address of a pointer pointing to the textual name of a group
5551 relocation as may appear in assembler source, attempt to find its details
5552 in group_reloc_table. The pointer will be updated to the character after
5553 the trailing colon. On failure, FAIL will be returned; SUCCESS
5554 otherwise. On success, *entry will be updated to point at the relevant
5555 group_reloc_table entry. */
5556
5557static int
5558find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5559{
5560 unsigned int i;
5561 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5562 {
5563 int length = strlen (group_reloc_table[i].name);
5564
5f4273c7
NC
5565 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5566 && (*str)[length] == ':')
477330fc
RM
5567 {
5568 *out = &group_reloc_table[i];
5569 *str += (length + 1);
5570 return SUCCESS;
5571 }
4962c51a
MS
5572 }
5573
5574 return FAIL;
5575}
5576
5577/* Parse a <shifter_operand> for an ARM data processing instruction
5578 (as for parse_shifter_operand) where group relocations are allowed:
5579
5580 #<immediate>
5581 #<immediate>, <rotate>
5582 #:<group_reloc>:<expression>
5583 <Rm>
5584 <Rm>, <shift>
5585
5586 where <group_reloc> is one of the strings defined in group_reloc_table.
5587 The hashes are optional.
5588
5589 Everything else is as for parse_shifter_operand. */
5590
5591static parse_operand_result
5592parse_shifter_operand_group_reloc (char **str, int i)
5593{
5594 /* Determine if we have the sequence of characters #: or just :
5595 coming next. If we do, then we check for a group relocation.
5596 If we don't, punt the whole lot to parse_shifter_operand. */
5597
5598 if (((*str)[0] == '#' && (*str)[1] == ':')
5599 || (*str)[0] == ':')
5600 {
5601 struct group_reloc_table_entry *entry;
5602
5603 if ((*str)[0] == '#')
477330fc 5604 (*str) += 2;
4962c51a 5605 else
477330fc 5606 (*str)++;
4962c51a
MS
5607
5608 /* Try to parse a group relocation. Anything else is an error. */
5609 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5610 {
5611 inst.error = _("unknown group relocation");
5612 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5613 }
4962c51a
MS
5614
5615 /* We now have the group relocation table entry corresponding to
477330fc 5616 the name in the assembler source. Next, we parse the expression. */
e2b0ab59 5617 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
477330fc 5618 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5619
5620 /* Record the relocation type (always the ALU variant here). */
e2b0ab59
AV
5621 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5622 gas_assert (inst.relocs[0].type != 0);
4962c51a
MS
5623
5624 return PARSE_OPERAND_SUCCESS;
5625 }
5626 else
5627 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5628 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5629
5630 /* Never reached. */
5631}
5632
8e560766
MGD
5633/* Parse a Neon alignment expression. Information is written to
5634 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5635
8e560766
MGD
5636 align .imm = align << 8, .immisalign=1, .preind=0 */
5637static parse_operand_result
5638parse_neon_alignment (char **str, int i)
5639{
5640 char *p = *str;
5641 expressionS exp;
5642
5643 my_get_expression (&exp, &p, GE_NO_PREFIX);
5644
5645 if (exp.X_op != O_constant)
5646 {
5647 inst.error = _("alignment must be constant");
5648 return PARSE_OPERAND_FAIL;
5649 }
5650
5651 inst.operands[i].imm = exp.X_add_number << 8;
5652 inst.operands[i].immisalign = 1;
5653 /* Alignments are not pre-indexes. */
5654 inst.operands[i].preind = 0;
5655
5656 *str = p;
5657 return PARSE_OPERAND_SUCCESS;
5658}
5659
c19d1205 5660/* Parse all forms of an ARM address expression. Information is written
e2b0ab59 5661 to inst.operands[i] and/or inst.relocs[0].
09d92015 5662
c19d1205 5663 Preindexed addressing (.preind=1):
09d92015 5664
e2b0ab59 5665 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5666 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5667 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5668 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5669
c19d1205 5670 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5671
c19d1205 5672 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5673
e2b0ab59 5674 [Rn], #offset .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5675 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5676 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5677 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5678
c19d1205 5679 Unindexed addressing (.preind=0, .postind=0):
09d92015 5680
c19d1205 5681 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5682
c19d1205 5683 Other:
09d92015 5684
c19d1205 5685 [Rn]{!} shorthand for [Rn,#0]{!}
e2b0ab59
AV
5686 =immediate .isreg=0 .relocs[0].exp=immediate
5687 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
09d92015 5688
c19d1205 5689 It is the caller's responsibility to check for addressing modes not
e2b0ab59 5690 supported by the instruction, and to set inst.relocs[0].type. */
c19d1205 5691
4962c51a
MS
5692static parse_operand_result
5693parse_address_main (char **str, int i, int group_relocations,
477330fc 5694 group_reloc_type group_type)
09d92015 5695{
c19d1205
ZW
5696 char *p = *str;
5697 int reg;
09d92015 5698
c19d1205 5699 if (skip_past_char (&p, '[') == FAIL)
09d92015 5700 {
c19d1205
ZW
5701 if (skip_past_char (&p, '=') == FAIL)
5702 {
974da60d 5703 /* Bare address - translate to PC-relative offset. */
e2b0ab59 5704 inst.relocs[0].pc_rel = 1;
c19d1205
ZW
5705 inst.operands[i].reg = REG_PC;
5706 inst.operands[i].isreg = 1;
5707 inst.operands[i].preind = 1;
09d92015 5708
e2b0ab59 5709 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
8335d6aa
JW
5710 return PARSE_OPERAND_FAIL;
5711 }
e2b0ab59 5712 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
8335d6aa 5713 /*allow_symbol_p=*/TRUE))
4962c51a 5714 return PARSE_OPERAND_FAIL;
09d92015 5715
c19d1205 5716 *str = p;
4962c51a 5717 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5718 }
5719
8ab8155f
NC
5720 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5721 skip_whitespace (p);
5722
dcbf9037 5723 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5724 {
c19d1205 5725 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5726 return PARSE_OPERAND_FAIL;
09d92015 5727 }
c19d1205
ZW
5728 inst.operands[i].reg = reg;
5729 inst.operands[i].isreg = 1;
09d92015 5730
c19d1205 5731 if (skip_past_comma (&p) == SUCCESS)
09d92015 5732 {
c19d1205 5733 inst.operands[i].preind = 1;
09d92015 5734
c19d1205
ZW
5735 if (*p == '+') p++;
5736 else if (*p == '-') p++, inst.operands[i].negative = 1;
5737
dcbf9037 5738 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5739 {
c19d1205
ZW
5740 inst.operands[i].imm = reg;
5741 inst.operands[i].immisreg = 1;
5742
5743 if (skip_past_comma (&p) == SUCCESS)
5744 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5745 return PARSE_OPERAND_FAIL;
c19d1205 5746 }
5287ad62 5747 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5748 {
5749 /* FIXME: '@' should be used here, but it's filtered out by generic
5750 code before we get to see it here. This may be subject to
5751 change. */
5752 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5753
8e560766
MGD
5754 if (result != PARSE_OPERAND_SUCCESS)
5755 return result;
5756 }
c19d1205
ZW
5757 else
5758 {
5759 if (inst.operands[i].negative)
5760 {
5761 inst.operands[i].negative = 0;
5762 p--;
5763 }
4962c51a 5764
5f4273c7
NC
5765 if (group_relocations
5766 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5767 {
5768 struct group_reloc_table_entry *entry;
5769
477330fc
RM
5770 /* Skip over the #: or : sequence. */
5771 if (*p == '#')
5772 p += 2;
5773 else
5774 p++;
4962c51a
MS
5775
5776 /* Try to parse a group relocation. Anything else is an
477330fc 5777 error. */
4962c51a
MS
5778 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5779 {
5780 inst.error = _("unknown group relocation");
5781 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5782 }
5783
5784 /* We now have the group relocation table entry corresponding to
5785 the name in the assembler source. Next, we parse the
477330fc 5786 expression. */
e2b0ab59 5787 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
4962c51a
MS
5788 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5789
5790 /* Record the relocation type. */
477330fc
RM
5791 switch (group_type)
5792 {
5793 case GROUP_LDR:
e2b0ab59
AV
5794 inst.relocs[0].type
5795 = (bfd_reloc_code_real_type) entry->ldr_code;
477330fc 5796 break;
4962c51a 5797
477330fc 5798 case GROUP_LDRS:
e2b0ab59
AV
5799 inst.relocs[0].type
5800 = (bfd_reloc_code_real_type) entry->ldrs_code;
477330fc 5801 break;
4962c51a 5802
477330fc 5803 case GROUP_LDC:
e2b0ab59
AV
5804 inst.relocs[0].type
5805 = (bfd_reloc_code_real_type) entry->ldc_code;
477330fc 5806 break;
4962c51a 5807
477330fc
RM
5808 default:
5809 gas_assert (0);
5810 }
4962c51a 5811
e2b0ab59 5812 if (inst.relocs[0].type == 0)
4962c51a
MS
5813 {
5814 inst.error = _("this group relocation is not allowed on this instruction");
5815 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5816 }
477330fc
RM
5817 }
5818 else
26d97720
NS
5819 {
5820 char *q = p;
0198d5e6 5821
e2b0ab59 5822 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
26d97720
NS
5823 return PARSE_OPERAND_FAIL;
5824 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
5825 if (inst.relocs[0].exp.X_op == O_constant
5826 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
5827 {
5828 skip_whitespace (q);
5829 if (*q == '#')
5830 {
5831 q++;
5832 skip_whitespace (q);
5833 }
5834 if (*q == '-')
5835 inst.operands[i].negative = 1;
5836 }
5837 }
09d92015
MM
5838 }
5839 }
8e560766
MGD
5840 else if (skip_past_char (&p, ':') == SUCCESS)
5841 {
5842 /* FIXME: '@' should be used here, but it's filtered out by generic code
5843 before we get to see it here. This may be subject to change. */
5844 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5845
8e560766
MGD
5846 if (result != PARSE_OPERAND_SUCCESS)
5847 return result;
5848 }
09d92015 5849
c19d1205 5850 if (skip_past_char (&p, ']') == FAIL)
09d92015 5851 {
c19d1205 5852 inst.error = _("']' expected");
4962c51a 5853 return PARSE_OPERAND_FAIL;
09d92015
MM
5854 }
5855
c19d1205
ZW
5856 if (skip_past_char (&p, '!') == SUCCESS)
5857 inst.operands[i].writeback = 1;
09d92015 5858
c19d1205 5859 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5860 {
c19d1205
ZW
5861 if (skip_past_char (&p, '{') == SUCCESS)
5862 {
5863 /* [Rn], {expr} - unindexed, with option */
5864 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5865 0, 255, TRUE) == FAIL)
4962c51a 5866 return PARSE_OPERAND_FAIL;
09d92015 5867
c19d1205
ZW
5868 if (skip_past_char (&p, '}') == FAIL)
5869 {
5870 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5871 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5872 }
5873 if (inst.operands[i].preind)
5874 {
5875 inst.error = _("cannot combine index with option");
4962c51a 5876 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5877 }
5878 *str = p;
4962c51a 5879 return PARSE_OPERAND_SUCCESS;
09d92015 5880 }
c19d1205
ZW
5881 else
5882 {
5883 inst.operands[i].postind = 1;
5884 inst.operands[i].writeback = 1;
09d92015 5885
c19d1205
ZW
5886 if (inst.operands[i].preind)
5887 {
5888 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5889 return PARSE_OPERAND_FAIL;
c19d1205 5890 }
09d92015 5891
c19d1205
ZW
5892 if (*p == '+') p++;
5893 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5894
dcbf9037 5895 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5896 {
477330fc
RM
5897 /* We might be using the immediate for alignment already. If we
5898 are, OR the register number into the low-order bits. */
5899 if (inst.operands[i].immisalign)
5900 inst.operands[i].imm |= reg;
5901 else
5902 inst.operands[i].imm = reg;
c19d1205 5903 inst.operands[i].immisreg = 1;
a737bd4d 5904
c19d1205
ZW
5905 if (skip_past_comma (&p) == SUCCESS)
5906 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5907 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5908 }
5909 else
5910 {
26d97720 5911 char *q = p;
0198d5e6 5912
c19d1205
ZW
5913 if (inst.operands[i].negative)
5914 {
5915 inst.operands[i].negative = 0;
5916 p--;
5917 }
e2b0ab59 5918 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
4962c51a 5919 return PARSE_OPERAND_FAIL;
26d97720 5920 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
5921 if (inst.relocs[0].exp.X_op == O_constant
5922 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
5923 {
5924 skip_whitespace (q);
5925 if (*q == '#')
5926 {
5927 q++;
5928 skip_whitespace (q);
5929 }
5930 if (*q == '-')
5931 inst.operands[i].negative = 1;
5932 }
c19d1205
ZW
5933 }
5934 }
a737bd4d
NC
5935 }
5936
c19d1205
ZW
5937 /* If at this point neither .preind nor .postind is set, we have a
5938 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5939 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5940 {
5941 inst.operands[i].preind = 1;
e2b0ab59
AV
5942 inst.relocs[0].exp.X_op = O_constant;
5943 inst.relocs[0].exp.X_add_number = 0;
c19d1205
ZW
5944 }
5945 *str = p;
4962c51a
MS
5946 return PARSE_OPERAND_SUCCESS;
5947}
5948
5949static int
5950parse_address (char **str, int i)
5951{
21d799b5 5952 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5953 ? SUCCESS : FAIL;
4962c51a
MS
5954}
5955
5956static parse_operand_result
5957parse_address_group_reloc (char **str, int i, group_reloc_type type)
5958{
5959 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5960}
5961
b6895b4f
PB
5962/* Parse an operand for a MOVW or MOVT instruction. */
5963static int
5964parse_half (char **str)
5965{
5966 char * p;
5f4273c7 5967
b6895b4f
PB
5968 p = *str;
5969 skip_past_char (&p, '#');
5f4273c7 5970 if (strncasecmp (p, ":lower16:", 9) == 0)
e2b0ab59 5971 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
b6895b4f 5972 else if (strncasecmp (p, ":upper16:", 9) == 0)
e2b0ab59 5973 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
b6895b4f 5974
e2b0ab59 5975 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
b6895b4f
PB
5976 {
5977 p += 9;
5f4273c7 5978 skip_whitespace (p);
b6895b4f
PB
5979 }
5980
e2b0ab59 5981 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
b6895b4f
PB
5982 return FAIL;
5983
e2b0ab59 5984 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 5985 {
e2b0ab59 5986 if (inst.relocs[0].exp.X_op != O_constant)
b6895b4f
PB
5987 {
5988 inst.error = _("constant expression expected");
5989 return FAIL;
5990 }
e2b0ab59
AV
5991 if (inst.relocs[0].exp.X_add_number < 0
5992 || inst.relocs[0].exp.X_add_number > 0xffff)
b6895b4f
PB
5993 {
5994 inst.error = _("immediate value out of range");
5995 return FAIL;
5996 }
5997 }
5998 *str = p;
5999 return SUCCESS;
6000}
6001
c19d1205 6002/* Miscellaneous. */
a737bd4d 6003
c19d1205
ZW
6004/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
6005 or a bitmask suitable to be or-ed into the ARM msr instruction. */
6006static int
d2cd1205 6007parse_psr (char **str, bfd_boolean lhs)
09d92015 6008{
c19d1205
ZW
6009 char *p;
6010 unsigned long psr_field;
62b3e311
PB
6011 const struct asm_psr *psr;
6012 char *start;
d2cd1205 6013 bfd_boolean is_apsr = FALSE;
ac7f631b 6014 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 6015
a4482bb6
NC
6016 /* PR gas/12698: If the user has specified -march=all then m_profile will
6017 be TRUE, but we want to ignore it in this case as we are building for any
6018 CPU type, including non-m variants. */
823d2571 6019 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
6020 m_profile = FALSE;
6021
c19d1205
ZW
6022 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
6023 feature for ease of use and backwards compatibility. */
6024 p = *str;
62b3e311 6025 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
6026 {
6027 if (m_profile)
6028 goto unsupported_psr;
fa94de6b 6029
d2cd1205
JB
6030 psr_field = SPSR_BIT;
6031 }
6032 else if (strncasecmp (p, "CPSR", 4) == 0)
6033 {
6034 if (m_profile)
6035 goto unsupported_psr;
6036
6037 psr_field = 0;
6038 }
6039 else if (strncasecmp (p, "APSR", 4) == 0)
6040 {
6041 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
6042 and ARMv7-R architecture CPUs. */
6043 is_apsr = TRUE;
6044 psr_field = 0;
6045 }
6046 else if (m_profile)
62b3e311
PB
6047 {
6048 start = p;
6049 do
6050 p++;
6051 while (ISALNUM (*p) || *p == '_');
6052
d2cd1205
JB
6053 if (strncasecmp (start, "iapsr", 5) == 0
6054 || strncasecmp (start, "eapsr", 5) == 0
6055 || strncasecmp (start, "xpsr", 4) == 0
6056 || strncasecmp (start, "psr", 3) == 0)
6057 p = start + strcspn (start, "rR") + 1;
6058
21d799b5 6059 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 6060 p - start);
d2cd1205 6061
62b3e311
PB
6062 if (!psr)
6063 return FAIL;
09d92015 6064
d2cd1205
JB
6065 /* If APSR is being written, a bitfield may be specified. Note that
6066 APSR itself is handled above. */
6067 if (psr->field <= 3)
6068 {
6069 psr_field = psr->field;
6070 is_apsr = TRUE;
6071 goto check_suffix;
6072 }
6073
62b3e311 6074 *str = p;
d2cd1205
JB
6075 /* M-profile MSR instructions have the mask field set to "10", except
6076 *PSR variants which modify APSR, which may use a different mask (and
6077 have been handled already). Do that by setting the PSR_f field
6078 here. */
6079 return psr->field | (lhs ? PSR_f : 0);
62b3e311 6080 }
d2cd1205
JB
6081 else
6082 goto unsupported_psr;
09d92015 6083
62b3e311 6084 p += 4;
d2cd1205 6085check_suffix:
c19d1205
ZW
6086 if (*p == '_')
6087 {
6088 /* A suffix follows. */
c19d1205
ZW
6089 p++;
6090 start = p;
a737bd4d 6091
c19d1205
ZW
6092 do
6093 p++;
6094 while (ISALNUM (*p) || *p == '_');
a737bd4d 6095
d2cd1205
JB
6096 if (is_apsr)
6097 {
6098 /* APSR uses a notation for bits, rather than fields. */
6099 unsigned int nzcvq_bits = 0;
6100 unsigned int g_bit = 0;
6101 char *bit;
fa94de6b 6102
d2cd1205
JB
6103 for (bit = start; bit != p; bit++)
6104 {
6105 switch (TOLOWER (*bit))
477330fc 6106 {
d2cd1205
JB
6107 case 'n':
6108 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
6109 break;
6110
6111 case 'z':
6112 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
6113 break;
6114
6115 case 'c':
6116 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
6117 break;
6118
6119 case 'v':
6120 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
6121 break;
fa94de6b 6122
d2cd1205
JB
6123 case 'q':
6124 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
6125 break;
fa94de6b 6126
d2cd1205
JB
6127 case 'g':
6128 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
6129 break;
fa94de6b 6130
d2cd1205
JB
6131 default:
6132 inst.error = _("unexpected bit specified after APSR");
6133 return FAIL;
6134 }
6135 }
fa94de6b 6136
d2cd1205
JB
6137 if (nzcvq_bits == 0x1f)
6138 psr_field |= PSR_f;
fa94de6b 6139
d2cd1205
JB
6140 if (g_bit == 0x1)
6141 {
6142 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 6143 {
d2cd1205
JB
6144 inst.error = _("selected processor does not "
6145 "support DSP extension");
6146 return FAIL;
6147 }
6148
6149 psr_field |= PSR_s;
6150 }
fa94de6b 6151
d2cd1205
JB
6152 if ((nzcvq_bits & 0x20) != 0
6153 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6154 || (g_bit & 0x2) != 0)
6155 {
6156 inst.error = _("bad bitmask specified after APSR");
6157 return FAIL;
6158 }
6159 }
6160 else
477330fc 6161 {
d2cd1205 6162 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 6163 p - start);
d2cd1205 6164 if (!psr)
477330fc 6165 goto error;
a737bd4d 6166
d2cd1205
JB
6167 psr_field |= psr->field;
6168 }
a737bd4d 6169 }
c19d1205 6170 else
a737bd4d 6171 {
c19d1205
ZW
6172 if (ISALNUM (*p))
6173 goto error; /* Garbage after "[CS]PSR". */
6174
d2cd1205 6175 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 6176 is deprecated, but allow it anyway. */
d2cd1205
JB
6177 if (is_apsr && lhs)
6178 {
6179 psr_field |= PSR_f;
6180 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6181 "deprecated"));
6182 }
6183 else if (!m_profile)
6184 /* These bits are never right for M-profile devices: don't set them
6185 (only code paths which read/write APSR reach here). */
6186 psr_field |= (PSR_c | PSR_f);
a737bd4d 6187 }
c19d1205
ZW
6188 *str = p;
6189 return psr_field;
a737bd4d 6190
d2cd1205
JB
6191 unsupported_psr:
6192 inst.error = _("selected processor does not support requested special "
6193 "purpose register");
6194 return FAIL;
6195
c19d1205
ZW
6196 error:
6197 inst.error = _("flag for {c}psr instruction expected");
6198 return FAIL;
a737bd4d
NC
6199}
6200
32c36c3c
AV
6201static int
6202parse_sys_vldr_vstr (char **str)
6203{
6204 unsigned i;
6205 int val = FAIL;
6206 struct {
6207 const char *name;
6208 int regl;
6209 int regh;
6210 } sysregs[] = {
6211 {"FPSCR", 0x1, 0x0},
6212 {"FPSCR_nzcvqc", 0x2, 0x0},
6213 {"VPR", 0x4, 0x1},
6214 {"P0", 0x5, 0x1},
6215 {"FPCXTNS", 0x6, 0x1},
6216 {"FPCXTS", 0x7, 0x1}
6217 };
6218 char *op_end = strchr (*str, ',');
6219 size_t op_strlen = op_end - *str;
6220
6221 for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++)
6222 {
6223 if (!strncmp (*str, sysregs[i].name, op_strlen))
6224 {
6225 val = sysregs[i].regl | (sysregs[i].regh << 3);
6226 *str = op_end;
6227 break;
6228 }
6229 }
6230
6231 return val;
6232}
6233
c19d1205
ZW
6234/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6235 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6236
c19d1205
ZW
6237static int
6238parse_cps_flags (char **str)
a737bd4d 6239{
c19d1205
ZW
6240 int val = 0;
6241 int saw_a_flag = 0;
6242 char *s = *str;
a737bd4d 6243
c19d1205
ZW
6244 for (;;)
6245 switch (*s++)
6246 {
6247 case '\0': case ',':
6248 goto done;
a737bd4d 6249
c19d1205
ZW
6250 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6251 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6252 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6253
c19d1205
ZW
6254 default:
6255 inst.error = _("unrecognized CPS flag");
6256 return FAIL;
6257 }
a737bd4d 6258
c19d1205
ZW
6259 done:
6260 if (saw_a_flag == 0)
a737bd4d 6261 {
c19d1205
ZW
6262 inst.error = _("missing CPS flags");
6263 return FAIL;
a737bd4d 6264 }
a737bd4d 6265
c19d1205
ZW
6266 *str = s - 1;
6267 return val;
a737bd4d
NC
6268}
6269
c19d1205
ZW
6270/* Parse an endian specifier ("BE" or "LE", case insensitive);
6271 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6272
6273static int
c19d1205 6274parse_endian_specifier (char **str)
a737bd4d 6275{
c19d1205
ZW
6276 int little_endian;
6277 char *s = *str;
a737bd4d 6278
c19d1205
ZW
6279 if (strncasecmp (s, "BE", 2))
6280 little_endian = 0;
6281 else if (strncasecmp (s, "LE", 2))
6282 little_endian = 1;
6283 else
a737bd4d 6284 {
c19d1205 6285 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6286 return FAIL;
6287 }
6288
c19d1205 6289 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6290 {
c19d1205 6291 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6292 return FAIL;
6293 }
6294
c19d1205
ZW
6295 *str = s + 2;
6296 return little_endian;
6297}
a737bd4d 6298
c19d1205
ZW
6299/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6300 value suitable for poking into the rotate field of an sxt or sxta
6301 instruction, or FAIL on error. */
6302
6303static int
6304parse_ror (char **str)
6305{
6306 int rot;
6307 char *s = *str;
6308
6309 if (strncasecmp (s, "ROR", 3) == 0)
6310 s += 3;
6311 else
a737bd4d 6312 {
c19d1205 6313 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6314 return FAIL;
6315 }
c19d1205
ZW
6316
6317 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6318 return FAIL;
6319
6320 switch (rot)
a737bd4d 6321 {
c19d1205
ZW
6322 case 0: *str = s; return 0x0;
6323 case 8: *str = s; return 0x1;
6324 case 16: *str = s; return 0x2;
6325 case 24: *str = s; return 0x3;
6326
6327 default:
6328 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6329 return FAIL;
6330 }
c19d1205 6331}
a737bd4d 6332
c19d1205
ZW
6333/* Parse a conditional code (from conds[] below). The value returned is in the
6334 range 0 .. 14, or FAIL. */
6335static int
6336parse_cond (char **str)
6337{
c462b453 6338 char *q;
c19d1205 6339 const struct asm_cond *c;
c462b453
PB
6340 int n;
6341 /* Condition codes are always 2 characters, so matching up to
6342 3 characters is sufficient. */
6343 char cond[3];
a737bd4d 6344
c462b453
PB
6345 q = *str;
6346 n = 0;
6347 while (ISALPHA (*q) && n < 3)
6348 {
e07e6e58 6349 cond[n] = TOLOWER (*q);
c462b453
PB
6350 q++;
6351 n++;
6352 }
a737bd4d 6353
21d799b5 6354 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6355 if (!c)
a737bd4d 6356 {
c19d1205 6357 inst.error = _("condition required");
a737bd4d
NC
6358 return FAIL;
6359 }
6360
c19d1205
ZW
6361 *str = q;
6362 return c->value;
6363}
6364
62b3e311
PB
6365/* Parse an option for a barrier instruction. Returns the encoding for the
6366 option, or FAIL. */
6367static int
6368parse_barrier (char **str)
6369{
6370 char *p, *q;
6371 const struct asm_barrier_opt *o;
6372
6373 p = q = *str;
6374 while (ISALPHA (*q))
6375 q++;
6376
21d799b5 6377 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6378 q - p);
62b3e311
PB
6379 if (!o)
6380 return FAIL;
6381
e797f7e0
MGD
6382 if (!mark_feature_used (&o->arch))
6383 return FAIL;
6384
62b3e311
PB
6385 *str = q;
6386 return o->value;
6387}
6388
92e90b6e
PB
6389/* Parse the operands of a table branch instruction. Similar to a memory
6390 operand. */
6391static int
6392parse_tb (char **str)
6393{
6394 char * p = *str;
6395 int reg;
6396
6397 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6398 {
6399 inst.error = _("'[' expected");
6400 return FAIL;
6401 }
92e90b6e 6402
dcbf9037 6403 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6404 {
6405 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6406 return FAIL;
6407 }
6408 inst.operands[0].reg = reg;
6409
6410 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6411 {
6412 inst.error = _("',' expected");
6413 return FAIL;
6414 }
5f4273c7 6415
dcbf9037 6416 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6417 {
6418 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6419 return FAIL;
6420 }
6421 inst.operands[0].imm = reg;
6422
6423 if (skip_past_comma (&p) == SUCCESS)
6424 {
6425 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6426 return FAIL;
e2b0ab59 6427 if (inst.relocs[0].exp.X_add_number != 1)
92e90b6e
PB
6428 {
6429 inst.error = _("invalid shift");
6430 return FAIL;
6431 }
6432 inst.operands[0].shifted = 1;
6433 }
6434
6435 if (skip_past_char (&p, ']') == FAIL)
6436 {
6437 inst.error = _("']' expected");
6438 return FAIL;
6439 }
6440 *str = p;
6441 return SUCCESS;
6442}
6443
5287ad62
JB
6444/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6445 information on the types the operands can take and how they are encoded.
037e8744
JB
6446 Up to four operands may be read; this function handles setting the
6447 ".present" field for each read operand itself.
5287ad62
JB
6448 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6449 else returns FAIL. */
6450
6451static int
6452parse_neon_mov (char **str, int *which_operand)
6453{
6454 int i = *which_operand, val;
6455 enum arm_reg_type rtype;
6456 char *ptr = *str;
dcbf9037 6457 struct neon_type_el optype;
5f4273c7 6458
dcbf9037 6459 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6460 {
6461 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6462 inst.operands[i].reg = val;
6463 inst.operands[i].isscalar = 1;
dcbf9037 6464 inst.operands[i].vectype = optype;
5287ad62
JB
6465 inst.operands[i++].present = 1;
6466
6467 if (skip_past_comma (&ptr) == FAIL)
477330fc 6468 goto wanted_comma;
5f4273c7 6469
dcbf9037 6470 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6471 goto wanted_arm;
5f4273c7 6472
5287ad62
JB
6473 inst.operands[i].reg = val;
6474 inst.operands[i].isreg = 1;
6475 inst.operands[i].present = 1;
6476 }
037e8744 6477 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6478 != FAIL)
5287ad62
JB
6479 {
6480 /* Cases 0, 1, 2, 3, 5 (D only). */
6481 if (skip_past_comma (&ptr) == FAIL)
477330fc 6482 goto wanted_comma;
5f4273c7 6483
5287ad62
JB
6484 inst.operands[i].reg = val;
6485 inst.operands[i].isreg = 1;
6486 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6487 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6488 inst.operands[i].isvec = 1;
dcbf9037 6489 inst.operands[i].vectype = optype;
5287ad62
JB
6490 inst.operands[i++].present = 1;
6491
dcbf9037 6492 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6493 {
6494 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6495 Case 13: VMOV <Sd>, <Rm> */
6496 inst.operands[i].reg = val;
6497 inst.operands[i].isreg = 1;
6498 inst.operands[i].present = 1;
6499
6500 if (rtype == REG_TYPE_NQ)
6501 {
6502 first_error (_("can't use Neon quad register here"));
6503 return FAIL;
6504 }
6505 else if (rtype != REG_TYPE_VFS)
6506 {
6507 i++;
6508 if (skip_past_comma (&ptr) == FAIL)
6509 goto wanted_comma;
6510 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6511 goto wanted_arm;
6512 inst.operands[i].reg = val;
6513 inst.operands[i].isreg = 1;
6514 inst.operands[i].present = 1;
6515 }
6516 }
037e8744 6517 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6518 &optype)) != FAIL)
6519 {
6520 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6521 Case 1: VMOV<c><q> <Dd>, <Dm>
6522 Case 8: VMOV.F32 <Sd>, <Sm>
6523 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6524
6525 inst.operands[i].reg = val;
6526 inst.operands[i].isreg = 1;
6527 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6528 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6529 inst.operands[i].isvec = 1;
6530 inst.operands[i].vectype = optype;
6531 inst.operands[i].present = 1;
6532
6533 if (skip_past_comma (&ptr) == SUCCESS)
6534 {
6535 /* Case 15. */
6536 i++;
6537
6538 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6539 goto wanted_arm;
6540
6541 inst.operands[i].reg = val;
6542 inst.operands[i].isreg = 1;
6543 inst.operands[i++].present = 1;
6544
6545 if (skip_past_comma (&ptr) == FAIL)
6546 goto wanted_comma;
6547
6548 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6549 goto wanted_arm;
6550
6551 inst.operands[i].reg = val;
6552 inst.operands[i].isreg = 1;
6553 inst.operands[i].present = 1;
6554 }
6555 }
4641781c 6556 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6557 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6558 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6559 Case 10: VMOV.F32 <Sd>, #<imm>
6560 Case 11: VMOV.F64 <Dd>, #<imm> */
6561 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6562 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6563 == SUCCESS)
477330fc
RM
6564 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6565 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6566 ;
5287ad62 6567 else
477330fc
RM
6568 {
6569 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6570 return FAIL;
6571 }
5287ad62 6572 }
dcbf9037 6573 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6574 {
6575 /* Cases 6, 7. */
6576 inst.operands[i].reg = val;
6577 inst.operands[i].isreg = 1;
6578 inst.operands[i++].present = 1;
5f4273c7 6579
5287ad62 6580 if (skip_past_comma (&ptr) == FAIL)
477330fc 6581 goto wanted_comma;
5f4273c7 6582
dcbf9037 6583 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6584 {
6585 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6586 inst.operands[i].reg = val;
6587 inst.operands[i].isscalar = 1;
6588 inst.operands[i].present = 1;
6589 inst.operands[i].vectype = optype;
6590 }
dcbf9037 6591 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6592 {
6593 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6594 inst.operands[i].reg = val;
6595 inst.operands[i].isreg = 1;
6596 inst.operands[i++].present = 1;
6597
6598 if (skip_past_comma (&ptr) == FAIL)
6599 goto wanted_comma;
6600
6601 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6602 == FAIL)
6603 {
6604 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6605 return FAIL;
6606 }
6607
6608 inst.operands[i].reg = val;
6609 inst.operands[i].isreg = 1;
6610 inst.operands[i].isvec = 1;
6611 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6612 inst.operands[i].vectype = optype;
6613 inst.operands[i].present = 1;
6614
6615 if (rtype == REG_TYPE_VFS)
6616 {
6617 /* Case 14. */
6618 i++;
6619 if (skip_past_comma (&ptr) == FAIL)
6620 goto wanted_comma;
6621 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6622 &optype)) == FAIL)
6623 {
6624 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6625 return FAIL;
6626 }
6627 inst.operands[i].reg = val;
6628 inst.operands[i].isreg = 1;
6629 inst.operands[i].isvec = 1;
6630 inst.operands[i].issingle = 1;
6631 inst.operands[i].vectype = optype;
6632 inst.operands[i].present = 1;
6633 }
6634 }
037e8744 6635 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6636 != FAIL)
6637 {
6638 /* Case 13. */
6639 inst.operands[i].reg = val;
6640 inst.operands[i].isreg = 1;
6641 inst.operands[i].isvec = 1;
6642 inst.operands[i].issingle = 1;
6643 inst.operands[i].vectype = optype;
6644 inst.operands[i].present = 1;
6645 }
5287ad62
JB
6646 }
6647 else
6648 {
dcbf9037 6649 first_error (_("parse error"));
5287ad62
JB
6650 return FAIL;
6651 }
6652
6653 /* Successfully parsed the operands. Update args. */
6654 *which_operand = i;
6655 *str = ptr;
6656 return SUCCESS;
6657
5f4273c7 6658 wanted_comma:
dcbf9037 6659 first_error (_("expected comma"));
5287ad62 6660 return FAIL;
5f4273c7
NC
6661
6662 wanted_arm:
dcbf9037 6663 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6664 return FAIL;
5287ad62
JB
6665}
6666
5be8be5d
DG
6667/* Use this macro when the operand constraints are different
6668 for ARM and THUMB (e.g. ldrd). */
6669#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6670 ((arm_operand) | ((thumb_operand) << 16))
6671
c19d1205
ZW
6672/* Matcher codes for parse_operands. */
6673enum operand_parse_code
6674{
6675 OP_stop, /* end of line */
6676
6677 OP_RR, /* ARM register */
6678 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6679 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6680 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6681 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6682 optional trailing ! */
c19d1205
ZW
6683 OP_RRw, /* ARM register, not r15, optional trailing ! */
6684 OP_RCP, /* Coprocessor number */
6685 OP_RCN, /* Coprocessor register */
6686 OP_RF, /* FPA register */
6687 OP_RVS, /* VFP single precision register */
5287ad62
JB
6688 OP_RVD, /* VFP double precision register (0..15) */
6689 OP_RND, /* Neon double precision register (0..31) */
5ee91343
AV
6690 OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */
6691 OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register.
6692 */
5287ad62 6693 OP_RNQ, /* Neon quad precision register */
5ee91343 6694 OP_RNQMQ, /* Neon quad or MVE vector register. */
037e8744 6695 OP_RVSD, /* VFP single or double precision register */
dec41383 6696 OP_RNSD, /* Neon single or double precision register */
5287ad62 6697 OP_RNDQ, /* Neon double or quad precision register */
5ee91343 6698 OP_RNDQMQ, /* Neon double, quad or MVE vector register. */
037e8744 6699 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6700 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6701 OP_RVC, /* VFP control register */
6702 OP_RMF, /* Maverick F register */
6703 OP_RMD, /* Maverick D register */
6704 OP_RMFX, /* Maverick FX register */
6705 OP_RMDX, /* Maverick DX register */
6706 OP_RMAX, /* Maverick AX register */
6707 OP_RMDS, /* Maverick DSPSC register */
6708 OP_RIWR, /* iWMMXt wR register */
6709 OP_RIWC, /* iWMMXt wC register */
6710 OP_RIWG, /* iWMMXt wCG register */
6711 OP_RXA, /* XScale accumulator register */
6712
5ee91343
AV
6713 OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register
6714 */
6715 OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or
6716 GPR (no SP/SP) */
60f993ce
AV
6717 /* New operands for Armv8.1-M Mainline. */
6718 OP_LR, /* ARM LR register */
6719 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
6720
c19d1205 6721 OP_REGLST, /* ARM register list */
4b5a202f 6722 OP_CLRMLST, /* CLRM register list */
c19d1205
ZW
6723 OP_VRSLST, /* VFP single-precision register list */
6724 OP_VRDLST, /* VFP double-precision register list */
037e8744 6725 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6726 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6727 OP_NSTRLST, /* Neon element/structure list */
efd6b359 6728 OP_VRSDVLST, /* VFP single or double-precision register list and VPR */
5287ad62 6729
5287ad62 6730 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6731 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6732 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6733 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 6734 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 6735 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6736 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6737 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6738 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6739 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6740 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6741 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
32c36c3c 6742 OP_VLDR, /* VLDR operand. */
5287ad62
JB
6743
6744 OP_I0, /* immediate zero */
c19d1205
ZW
6745 OP_I7, /* immediate value 0 .. 7 */
6746 OP_I15, /* 0 .. 15 */
6747 OP_I16, /* 1 .. 16 */
5287ad62 6748 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6749 OP_I31, /* 0 .. 31 */
6750 OP_I31w, /* 0 .. 31, optional trailing ! */
6751 OP_I32, /* 1 .. 32 */
5287ad62
JB
6752 OP_I32z, /* 0 .. 32 */
6753 OP_I63, /* 0 .. 63 */
c19d1205 6754 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6755 OP_I64, /* 1 .. 64 */
6756 OP_I64z, /* 0 .. 64 */
c19d1205 6757 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6758
6759 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6760 OP_I7b, /* 0 .. 7 */
6761 OP_I15b, /* 0 .. 15 */
6762 OP_I31b, /* 0 .. 31 */
6763
6764 OP_SH, /* shifter operand */
4962c51a 6765 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6766 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6767 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6768 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6769 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6770 OP_EXP, /* arbitrary expression */
6771 OP_EXPi, /* same, with optional immediate prefix */
6772 OP_EXPr, /* same, with optional relocation suffix */
e2b0ab59 6773 OP_EXPs, /* same, with optional non-first operand relocation suffix */
b6895b4f 6774 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
6775 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6776 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
6777
6778 OP_CPSF, /* CPS flags */
6779 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6780 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6781 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6782 OP_COND, /* conditional code */
92e90b6e 6783 OP_TB, /* Table branch. */
c19d1205 6784
037e8744
JB
6785 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6786
c19d1205 6787 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 6788 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
6789 OP_RR_EXi, /* ARM register or expression with imm prefix */
6790 OP_RF_IF, /* FPA register or immediate */
6791 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6792 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6793
6794 /* Optional operands. */
6795 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6796 OP_oI31b, /* 0 .. 31 */
5287ad62 6797 OP_oI32b, /* 1 .. 32 */
5f1af56b 6798 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6799 OP_oIffffb, /* 0 .. 65535 */
6800 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6801
6802 OP_oRR, /* ARM register */
60f993ce 6803 OP_oLR, /* ARM LR register */
c19d1205 6804 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6805 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6806 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6807 OP_oRND, /* Optional Neon double precision register */
6808 OP_oRNQ, /* Optional Neon quad precision register */
5ee91343 6809 OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */
5287ad62 6810 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6811 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5ee91343
AV
6812 OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector
6813 register. */
c19d1205
ZW
6814 OP_oSHll, /* LSL immediate */
6815 OP_oSHar, /* ASR immediate */
6816 OP_oSHllar, /* LSL or ASR immediate */
6817 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6818 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6819
5be8be5d
DG
6820 /* Some pre-defined mixed (ARM/THUMB) operands. */
6821 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6822 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6823 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6824
c19d1205
ZW
6825 OP_FIRST_OPTIONAL = OP_oI7b
6826};
a737bd4d 6827
c19d1205
ZW
6828/* Generic instruction operand parser. This does no encoding and no
6829 semantic validation; it merely squirrels values away in the inst
6830 structure. Returns SUCCESS or FAIL depending on whether the
6831 specified grammar matched. */
6832static int
5be8be5d 6833parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6834{
5be8be5d 6835 unsigned const int *upat = pattern;
c19d1205
ZW
6836 char *backtrack_pos = 0;
6837 const char *backtrack_error = 0;
99aad254 6838 int i, val = 0, backtrack_index = 0;
5287ad62 6839 enum arm_reg_type rtype;
4962c51a 6840 parse_operand_result result;
5be8be5d 6841 unsigned int op_parse_code;
efd6b359 6842 bfd_boolean partial_match;
c19d1205 6843
e07e6e58
NC
6844#define po_char_or_fail(chr) \
6845 do \
6846 { \
6847 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6848 goto bad_args; \
e07e6e58
NC
6849 } \
6850 while (0)
c19d1205 6851
e07e6e58
NC
6852#define po_reg_or_fail(regtype) \
6853 do \
dcbf9037 6854 { \
e07e6e58 6855 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6856 & inst.operands[i].vectype); \
e07e6e58 6857 if (val == FAIL) \
477330fc
RM
6858 { \
6859 first_error (_(reg_expected_msgs[regtype])); \
6860 goto failure; \
6861 } \
e07e6e58
NC
6862 inst.operands[i].reg = val; \
6863 inst.operands[i].isreg = 1; \
6864 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6865 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6866 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6867 || rtype == REG_TYPE_VFD \
6868 || rtype == REG_TYPE_NQ); \
dcbf9037 6869 } \
e07e6e58
NC
6870 while (0)
6871
6872#define po_reg_or_goto(regtype, label) \
6873 do \
6874 { \
6875 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6876 & inst.operands[i].vectype); \
6877 if (val == FAIL) \
6878 goto label; \
dcbf9037 6879 \
e07e6e58
NC
6880 inst.operands[i].reg = val; \
6881 inst.operands[i].isreg = 1; \
6882 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6883 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6884 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6885 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6886 || rtype == REG_TYPE_NQ); \
6887 } \
6888 while (0)
6889
6890#define po_imm_or_fail(min, max, popt) \
6891 do \
6892 { \
6893 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6894 goto failure; \
6895 inst.operands[i].imm = val; \
6896 } \
6897 while (0)
6898
6899#define po_scalar_or_goto(elsz, label) \
6900 do \
6901 { \
6902 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6903 if (val == FAIL) \
6904 goto label; \
6905 inst.operands[i].reg = val; \
6906 inst.operands[i].isscalar = 1; \
6907 } \
6908 while (0)
6909
6910#define po_misc_or_fail(expr) \
6911 do \
6912 { \
6913 if (expr) \
6914 goto failure; \
6915 } \
6916 while (0)
6917
6918#define po_misc_or_fail_no_backtrack(expr) \
6919 do \
6920 { \
6921 result = expr; \
6922 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6923 backtrack_pos = 0; \
6924 if (result != PARSE_OPERAND_SUCCESS) \
6925 goto failure; \
6926 } \
6927 while (0)
4962c51a 6928
52e7f43d
RE
6929#define po_barrier_or_imm(str) \
6930 do \
6931 { \
6932 val = parse_barrier (&str); \
ccb84d65
JB
6933 if (val == FAIL && ! ISALPHA (*str)) \
6934 goto immediate; \
6935 if (val == FAIL \
6936 /* ISB can only take SY as an option. */ \
6937 || ((inst.instruction & 0xf0) == 0x60 \
6938 && val != 0xf)) \
52e7f43d 6939 { \
ccb84d65
JB
6940 inst.error = _("invalid barrier type"); \
6941 backtrack_pos = 0; \
6942 goto failure; \
52e7f43d
RE
6943 } \
6944 } \
6945 while (0)
6946
c19d1205
ZW
6947 skip_whitespace (str);
6948
6949 for (i = 0; upat[i] != OP_stop; i++)
6950 {
5be8be5d
DG
6951 op_parse_code = upat[i];
6952 if (op_parse_code >= 1<<16)
6953 op_parse_code = thumb ? (op_parse_code >> 16)
6954 : (op_parse_code & ((1<<16)-1));
6955
6956 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6957 {
6958 /* Remember where we are in case we need to backtrack. */
9c2799c2 6959 gas_assert (!backtrack_pos);
c19d1205
ZW
6960 backtrack_pos = str;
6961 backtrack_error = inst.error;
6962 backtrack_index = i;
6963 }
6964
b6702015 6965 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6966 po_char_or_fail (',');
6967
5be8be5d 6968 switch (op_parse_code)
c19d1205
ZW
6969 {
6970 /* Registers */
6971 case OP_oRRnpc:
5be8be5d 6972 case OP_oRRnpcsp:
c19d1205 6973 case OP_RRnpc:
5be8be5d 6974 case OP_RRnpcsp:
c19d1205 6975 case OP_oRR:
60f993ce
AV
6976 case OP_LR:
6977 case OP_oLR:
c19d1205
ZW
6978 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6979 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6980 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6981 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6982 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6983 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6984 case OP_oRND:
5ee91343
AV
6985 case OP_RNDMQR:
6986 po_reg_or_goto (REG_TYPE_RN, try_rndmq);
6987 break;
6988 try_rndmq:
6989 case OP_RNDMQ:
6990 po_reg_or_goto (REG_TYPE_MQ, try_rnd);
6991 break;
6992 try_rnd:
5287ad62 6993 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6994 case OP_RVC:
6995 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6996 break;
6997 /* Also accept generic coprocessor regs for unknown registers. */
6998 coproc_reg:
6999 po_reg_or_fail (REG_TYPE_CN);
7000 break;
c19d1205
ZW
7001 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
7002 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
7003 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
7004 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
7005 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
7006 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
7007 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
7008 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
7009 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
7010 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 7011 case OP_oRNQ:
5ee91343
AV
7012 case OP_RNQMQ:
7013 po_reg_or_goto (REG_TYPE_MQ, try_nq);
7014 break;
7015 try_nq:
5287ad62 7016 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 7017 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
5ee91343
AV
7018 case OP_oRNDQMQ:
7019 case OP_RNDQMQ:
7020 po_reg_or_goto (REG_TYPE_MQ, try_rndq);
7021 break;
7022 try_rndq:
477330fc 7023 case OP_oRNDQ:
5287ad62 7024 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
7025 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
7026 case OP_oRNSDQ:
7027 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5ee91343
AV
7028 case OP_RNSDQMQR:
7029 po_reg_or_goto (REG_TYPE_RN, try_mq);
7030 break;
7031 try_mq:
7032 case OP_oRNSDQMQ:
7033 case OP_RNSDQMQ:
7034 po_reg_or_goto (REG_TYPE_MQ, try_nsdq2);
7035 break;
7036 try_nsdq2:
7037 po_reg_or_fail (REG_TYPE_NSDQ);
7038 inst.error = 0;
7039 break;
477330fc
RM
7040 /* Neon scalar. Using an element size of 8 means that some invalid
7041 scalars are accepted here, so deal with those in later code. */
7042 case OP_RNSC: po_scalar_or_goto (8, failure); break;
7043
7044 case OP_RNDQ_I0:
7045 {
7046 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
7047 break;
7048 try_imm0:
7049 po_imm_or_fail (0, 0, TRUE);
7050 }
7051 break;
7052
7053 case OP_RVSD_I0:
7054 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
7055 break;
7056
aacf0b33
KT
7057 case OP_RSVD_FI0:
7058 {
7059 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
7060 break;
7061 try_ifimm0:
7062 if (parse_ifimm_zero (&str))
7063 inst.operands[i].imm = 0;
7064 else
7065 {
7066 inst.error
7067 = _("only floating point zero is allowed as immediate value");
7068 goto failure;
7069 }
7070 }
7071 break;
7072
477330fc
RM
7073 case OP_RR_RNSC:
7074 {
7075 po_scalar_or_goto (8, try_rr);
7076 break;
7077 try_rr:
7078 po_reg_or_fail (REG_TYPE_RN);
7079 }
7080 break;
7081
7082 case OP_RNSDQ_RNSC:
7083 {
7084 po_scalar_or_goto (8, try_nsdq);
7085 break;
7086 try_nsdq:
7087 po_reg_or_fail (REG_TYPE_NSDQ);
7088 }
7089 break;
7090
dec41383
JW
7091 case OP_RNSD_RNSC:
7092 {
7093 po_scalar_or_goto (8, try_s_scalar);
7094 break;
7095 try_s_scalar:
7096 po_scalar_or_goto (4, try_nsd);
7097 break;
7098 try_nsd:
7099 po_reg_or_fail (REG_TYPE_NSD);
7100 }
7101 break;
7102
477330fc
RM
7103 case OP_RNDQ_RNSC:
7104 {
7105 po_scalar_or_goto (8, try_ndq);
7106 break;
7107 try_ndq:
7108 po_reg_or_fail (REG_TYPE_NDQ);
7109 }
7110 break;
7111
7112 case OP_RND_RNSC:
7113 {
7114 po_scalar_or_goto (8, try_vfd);
7115 break;
7116 try_vfd:
7117 po_reg_or_fail (REG_TYPE_VFD);
7118 }
7119 break;
7120
7121 case OP_VMOV:
7122 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
7123 not careful then bad things might happen. */
7124 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
7125 break;
7126
7127 case OP_RNDQ_Ibig:
7128 {
7129 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
7130 break;
7131 try_immbig:
7132 /* There's a possibility of getting a 64-bit immediate here, so
7133 we need special handling. */
8335d6aa
JW
7134 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
7135 == FAIL)
477330fc
RM
7136 {
7137 inst.error = _("immediate value is out of range");
7138 goto failure;
7139 }
7140 }
7141 break;
7142
7143 case OP_RNDQ_I63b:
7144 {
7145 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
7146 break;
7147 try_shimm:
7148 po_imm_or_fail (0, 63, TRUE);
7149 }
7150 break;
c19d1205
ZW
7151
7152 case OP_RRnpcb:
7153 po_char_or_fail ('[');
7154 po_reg_or_fail (REG_TYPE_RN);
7155 po_char_or_fail (']');
7156 break;
a737bd4d 7157
55881a11 7158 case OP_RRnpctw:
c19d1205 7159 case OP_RRw:
b6702015 7160 case OP_oRRw:
c19d1205
ZW
7161 po_reg_or_fail (REG_TYPE_RN);
7162 if (skip_past_char (&str, '!') == SUCCESS)
7163 inst.operands[i].writeback = 1;
7164 break;
7165
7166 /* Immediates */
7167 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
7168 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
7169 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 7170 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
7171 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
7172 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 7173 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 7174 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
7175 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
7176 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
7177 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 7178 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
7179
7180 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
7181 case OP_oI7b:
7182 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
7183 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
7184 case OP_oI31b:
7185 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
7186 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
7187 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
7188 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
7189
7190 /* Immediate variants */
7191 case OP_oI255c:
7192 po_char_or_fail ('{');
7193 po_imm_or_fail (0, 255, TRUE);
7194 po_char_or_fail ('}');
7195 break;
7196
7197 case OP_I31w:
7198 /* The expression parser chokes on a trailing !, so we have
7199 to find it first and zap it. */
7200 {
7201 char *s = str;
7202 while (*s && *s != ',')
7203 s++;
7204 if (s[-1] == '!')
7205 {
7206 s[-1] = '\0';
7207 inst.operands[i].writeback = 1;
7208 }
7209 po_imm_or_fail (0, 31, TRUE);
7210 if (str == s - 1)
7211 str = s;
7212 }
7213 break;
7214
7215 /* Expressions */
7216 case OP_EXPi: EXPi:
e2b0ab59 7217 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7218 GE_OPT_PREFIX));
7219 break;
7220
7221 case OP_EXP:
e2b0ab59 7222 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7223 GE_NO_PREFIX));
7224 break;
7225
7226 case OP_EXPr: EXPr:
e2b0ab59 7227 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205 7228 GE_NO_PREFIX));
e2b0ab59 7229 if (inst.relocs[0].exp.X_op == O_symbol)
a737bd4d 7230 {
c19d1205
ZW
7231 val = parse_reloc (&str);
7232 if (val == -1)
7233 {
7234 inst.error = _("unrecognized relocation suffix");
7235 goto failure;
7236 }
7237 else if (val != BFD_RELOC_UNUSED)
7238 {
7239 inst.operands[i].imm = val;
7240 inst.operands[i].hasreloc = 1;
7241 }
a737bd4d 7242 }
c19d1205 7243 break;
a737bd4d 7244
e2b0ab59
AV
7245 case OP_EXPs:
7246 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7247 GE_NO_PREFIX));
7248 if (inst.relocs[i].exp.X_op == O_symbol)
7249 {
7250 inst.operands[i].hasreloc = 1;
7251 }
7252 else if (inst.relocs[i].exp.X_op == O_constant)
7253 {
7254 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7255 inst.operands[i].hasreloc = 0;
7256 }
7257 break;
7258
b6895b4f
PB
7259 /* Operand for MOVW or MOVT. */
7260 case OP_HALF:
7261 po_misc_or_fail (parse_half (&str));
7262 break;
7263
e07e6e58 7264 /* Register or expression. */
c19d1205
ZW
7265 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7266 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7267
e07e6e58 7268 /* Register or immediate. */
c19d1205
ZW
7269 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7270 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7271
c19d1205
ZW
7272 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7273 IF:
7274 if (!is_immediate_prefix (*str))
7275 goto bad_args;
7276 str++;
7277 val = parse_fpa_immediate (&str);
7278 if (val == FAIL)
7279 goto failure;
7280 /* FPA immediates are encoded as registers 8-15.
7281 parse_fpa_immediate has already applied the offset. */
7282 inst.operands[i].reg = val;
7283 inst.operands[i].isreg = 1;
7284 break;
09d92015 7285
2d447fca
JM
7286 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7287 I32z: po_imm_or_fail (0, 32, FALSE); break;
7288
e07e6e58 7289 /* Two kinds of register. */
c19d1205
ZW
7290 case OP_RIWR_RIWC:
7291 {
7292 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7293 if (!rege
7294 || (rege->type != REG_TYPE_MMXWR
7295 && rege->type != REG_TYPE_MMXWC
7296 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7297 {
7298 inst.error = _("iWMMXt data or control register expected");
7299 goto failure;
7300 }
7301 inst.operands[i].reg = rege->number;
7302 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7303 }
7304 break;
09d92015 7305
41adaa5c
JM
7306 case OP_RIWC_RIWG:
7307 {
7308 struct reg_entry *rege = arm_reg_parse_multi (&str);
7309 if (!rege
7310 || (rege->type != REG_TYPE_MMXWC
7311 && rege->type != REG_TYPE_MMXWCG))
7312 {
7313 inst.error = _("iWMMXt control register expected");
7314 goto failure;
7315 }
7316 inst.operands[i].reg = rege->number;
7317 inst.operands[i].isreg = 1;
7318 }
7319 break;
7320
c19d1205
ZW
7321 /* Misc */
7322 case OP_CPSF: val = parse_cps_flags (&str); break;
7323 case OP_ENDI: val = parse_endian_specifier (&str); break;
7324 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7325 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7326 case OP_oBARRIER_I15:
7327 po_barrier_or_imm (str); break;
7328 immediate:
7329 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7330 goto failure;
52e7f43d 7331 break;
c19d1205 7332
fa94de6b 7333 case OP_wPSR:
d2cd1205 7334 case OP_rPSR:
90ec0d68
MGD
7335 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7336 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7337 {
7338 inst.error = _("Banked registers are not available with this "
7339 "architecture.");
7340 goto failure;
7341 }
7342 break;
d2cd1205
JB
7343 try_psr:
7344 val = parse_psr (&str, op_parse_code == OP_wPSR);
7345 break;
037e8744 7346
32c36c3c
AV
7347 case OP_VLDR:
7348 po_reg_or_goto (REG_TYPE_VFSD, try_sysreg);
7349 break;
7350 try_sysreg:
7351 val = parse_sys_vldr_vstr (&str);
7352 break;
7353
477330fc
RM
7354 case OP_APSR_RR:
7355 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7356 break;
7357 try_apsr:
7358 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7359 instruction). */
7360 if (strncasecmp (str, "APSR_", 5) == 0)
7361 {
7362 unsigned found = 0;
7363 str += 5;
7364 while (found < 15)
7365 switch (*str++)
7366 {
7367 case 'c': found = (found & 1) ? 16 : found | 1; break;
7368 case 'n': found = (found & 2) ? 16 : found | 2; break;
7369 case 'z': found = (found & 4) ? 16 : found | 4; break;
7370 case 'v': found = (found & 8) ? 16 : found | 8; break;
7371 default: found = 16;
7372 }
7373 if (found != 15)
7374 goto failure;
7375 inst.operands[i].isvec = 1;
f7c21dc7
NC
7376 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7377 inst.operands[i].reg = REG_PC;
477330fc
RM
7378 }
7379 else
7380 goto failure;
7381 break;
037e8744 7382
92e90b6e
PB
7383 case OP_TB:
7384 po_misc_or_fail (parse_tb (&str));
7385 break;
7386
e07e6e58 7387 /* Register lists. */
c19d1205 7388 case OP_REGLST:
4b5a202f 7389 val = parse_reg_list (&str, REGLIST_RN);
c19d1205
ZW
7390 if (*str == '^')
7391 {
5e0d7f77 7392 inst.operands[i].writeback = 1;
c19d1205
ZW
7393 str++;
7394 }
7395 break;
09d92015 7396
4b5a202f
AV
7397 case OP_CLRMLST:
7398 val = parse_reg_list (&str, REGLIST_CLRM);
7399 break;
7400
c19d1205 7401 case OP_VRSLST:
efd6b359
AV
7402 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S,
7403 &partial_match);
c19d1205 7404 break;
09d92015 7405
c19d1205 7406 case OP_VRDLST:
efd6b359
AV
7407 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D,
7408 &partial_match);
c19d1205 7409 break;
a737bd4d 7410
477330fc
RM
7411 case OP_VRSDLST:
7412 /* Allow Q registers too. */
7413 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7414 REGLIST_NEON_D, &partial_match);
477330fc
RM
7415 if (val == FAIL)
7416 {
7417 inst.error = NULL;
7418 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359
AV
7419 REGLIST_VFP_S, &partial_match);
7420 inst.operands[i].issingle = 1;
7421 }
7422 break;
7423
7424 case OP_VRSDVLST:
7425 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7426 REGLIST_VFP_D_VPR, &partial_match);
7427 if (val == FAIL && !partial_match)
7428 {
7429 inst.error = NULL;
7430 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7431 REGLIST_VFP_S_VPR, &partial_match);
477330fc
RM
7432 inst.operands[i].issingle = 1;
7433 }
7434 break;
7435
7436 case OP_NRDLST:
7437 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7438 REGLIST_NEON_D, &partial_match);
477330fc 7439 break;
5287ad62
JB
7440
7441 case OP_NSTRLST:
477330fc
RM
7442 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7443 &inst.operands[i].vectype);
7444 break;
5287ad62 7445
c19d1205
ZW
7446 /* Addressing modes */
7447 case OP_ADDR:
7448 po_misc_or_fail (parse_address (&str, i));
7449 break;
09d92015 7450
4962c51a
MS
7451 case OP_ADDRGLDR:
7452 po_misc_or_fail_no_backtrack (
477330fc 7453 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7454 break;
7455
7456 case OP_ADDRGLDRS:
7457 po_misc_or_fail_no_backtrack (
477330fc 7458 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7459 break;
7460
7461 case OP_ADDRGLDC:
7462 po_misc_or_fail_no_backtrack (
477330fc 7463 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7464 break;
7465
c19d1205
ZW
7466 case OP_SH:
7467 po_misc_or_fail (parse_shifter_operand (&str, i));
7468 break;
09d92015 7469
4962c51a
MS
7470 case OP_SHG:
7471 po_misc_or_fail_no_backtrack (
477330fc 7472 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7473 break;
7474
c19d1205
ZW
7475 case OP_oSHll:
7476 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7477 break;
09d92015 7478
c19d1205
ZW
7479 case OP_oSHar:
7480 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7481 break;
09d92015 7482
c19d1205
ZW
7483 case OP_oSHllar:
7484 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7485 break;
09d92015 7486
c19d1205 7487 default:
5be8be5d 7488 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7489 }
09d92015 7490
c19d1205
ZW
7491 /* Various value-based sanity checks and shared operations. We
7492 do not signal immediate failures for the register constraints;
7493 this allows a syntax error to take precedence. */
5be8be5d 7494 switch (op_parse_code)
c19d1205
ZW
7495 {
7496 case OP_oRRnpc:
7497 case OP_RRnpc:
7498 case OP_RRnpcb:
7499 case OP_RRw:
b6702015 7500 case OP_oRRw:
c19d1205
ZW
7501 case OP_RRnpc_I0:
7502 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7503 inst.error = BAD_PC;
7504 break;
09d92015 7505
5be8be5d
DG
7506 case OP_oRRnpcsp:
7507 case OP_RRnpcsp:
7508 if (inst.operands[i].isreg)
7509 {
7510 if (inst.operands[i].reg == REG_PC)
7511 inst.error = BAD_PC;
5c8ed6a4
JW
7512 else if (inst.operands[i].reg == REG_SP
7513 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7514 relaxed since ARMv8-A. */
7515 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7516 {
7517 gas_assert (thumb);
7518 inst.error = BAD_SP;
7519 }
5be8be5d
DG
7520 }
7521 break;
7522
55881a11 7523 case OP_RRnpctw:
fa94de6b
RM
7524 if (inst.operands[i].isreg
7525 && inst.operands[i].reg == REG_PC
55881a11
MGD
7526 && (inst.operands[i].writeback || thumb))
7527 inst.error = BAD_PC;
7528 break;
7529
32c36c3c
AV
7530 case OP_VLDR:
7531 if (inst.operands[i].isreg)
7532 break;
7533 /* fall through. */
c19d1205
ZW
7534 case OP_CPSF:
7535 case OP_ENDI:
7536 case OP_oROR:
d2cd1205
JB
7537 case OP_wPSR:
7538 case OP_rPSR:
c19d1205 7539 case OP_COND:
52e7f43d 7540 case OP_oBARRIER_I15:
c19d1205 7541 case OP_REGLST:
4b5a202f 7542 case OP_CLRMLST:
c19d1205
ZW
7543 case OP_VRSLST:
7544 case OP_VRDLST:
477330fc 7545 case OP_VRSDLST:
efd6b359 7546 case OP_VRSDVLST:
477330fc
RM
7547 case OP_NRDLST:
7548 case OP_NSTRLST:
c19d1205
ZW
7549 if (val == FAIL)
7550 goto failure;
7551 inst.operands[i].imm = val;
7552 break;
a737bd4d 7553
60f993ce
AV
7554 case OP_LR:
7555 case OP_oLR:
7556 if (inst.operands[i].reg != REG_LR)
7557 inst.error = _("operand must be LR register");
7558 break;
7559
c19d1205
ZW
7560 default:
7561 break;
7562 }
09d92015 7563
c19d1205
ZW
7564 /* If we get here, this operand was successfully parsed. */
7565 inst.operands[i].present = 1;
7566 continue;
09d92015 7567
c19d1205 7568 bad_args:
09d92015 7569 inst.error = BAD_ARGS;
c19d1205
ZW
7570
7571 failure:
7572 if (!backtrack_pos)
d252fdde
PB
7573 {
7574 /* The parse routine should already have set inst.error, but set a
5f4273c7 7575 default here just in case. */
d252fdde 7576 if (!inst.error)
5ee91343 7577 inst.error = BAD_SYNTAX;
d252fdde
PB
7578 return FAIL;
7579 }
c19d1205
ZW
7580
7581 /* Do not backtrack over a trailing optional argument that
7582 absorbed some text. We will only fail again, with the
7583 'garbage following instruction' error message, which is
7584 probably less helpful than the current one. */
7585 if (backtrack_index == i && backtrack_pos != str
7586 && upat[i+1] == OP_stop)
d252fdde
PB
7587 {
7588 if (!inst.error)
5ee91343 7589 inst.error = BAD_SYNTAX;
d252fdde
PB
7590 return FAIL;
7591 }
c19d1205
ZW
7592
7593 /* Try again, skipping the optional argument at backtrack_pos. */
7594 str = backtrack_pos;
7595 inst.error = backtrack_error;
7596 inst.operands[backtrack_index].present = 0;
7597 i = backtrack_index;
7598 backtrack_pos = 0;
09d92015 7599 }
09d92015 7600
c19d1205
ZW
7601 /* Check that we have parsed all the arguments. */
7602 if (*str != '\0' && !inst.error)
7603 inst.error = _("garbage following instruction");
09d92015 7604
c19d1205 7605 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7606}
7607
c19d1205
ZW
7608#undef po_char_or_fail
7609#undef po_reg_or_fail
7610#undef po_reg_or_goto
7611#undef po_imm_or_fail
5287ad62 7612#undef po_scalar_or_fail
52e7f43d 7613#undef po_barrier_or_imm
e07e6e58 7614
c19d1205 7615/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7616#define constraint(expr, err) \
7617 do \
c19d1205 7618 { \
e07e6e58
NC
7619 if (expr) \
7620 { \
7621 inst.error = err; \
7622 return; \
7623 } \
c19d1205 7624 } \
e07e6e58 7625 while (0)
c19d1205 7626
fdfde340
JM
7627/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7628 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
7629 is the BadReg predicate in ARM's Thumb-2 documentation.
7630
7631 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7632 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7633#define reject_bad_reg(reg) \
7634 do \
7635 if (reg == REG_PC) \
7636 { \
7637 inst.error = BAD_PC; \
7638 return; \
7639 } \
7640 else if (reg == REG_SP \
7641 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7642 { \
7643 inst.error = BAD_SP; \
7644 return; \
7645 } \
fdfde340
JM
7646 while (0)
7647
94206790
MM
7648/* If REG is R13 (the stack pointer), warn that its use is
7649 deprecated. */
7650#define warn_deprecated_sp(reg) \
7651 do \
7652 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7653 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7654 while (0)
7655
c19d1205
ZW
7656/* Functions for operand encoding. ARM, then Thumb. */
7657
d840c081 7658#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7659
9db2f6b4
RL
7660/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7661
7662 The only binary encoding difference is the Coprocessor number. Coprocessor
7663 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 7664 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
7665 exists for Single-Precision operation. */
7666
7667static void
7668do_scalar_fp16_v82_encode (void)
7669{
5ee91343 7670 if (inst.cond < COND_ALWAYS)
9db2f6b4
RL
7671 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7672 " the behaviour is UNPREDICTABLE"));
7673 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7674 _(BAD_FP16));
7675
7676 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7677 mark_feature_used (&arm_ext_fp16);
7678}
7679
c19d1205
ZW
7680/* If VAL can be encoded in the immediate field of an ARM instruction,
7681 return the encoded form. Otherwise, return FAIL. */
7682
7683static unsigned int
7684encode_arm_immediate (unsigned int val)
09d92015 7685{
c19d1205
ZW
7686 unsigned int a, i;
7687
4f1d6205
L
7688 if (val <= 0xff)
7689 return val;
7690
7691 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7692 if ((a = rotate_left (val, i)) <= 0xff)
7693 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7694
7695 return FAIL;
09d92015
MM
7696}
7697
c19d1205
ZW
7698/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7699 return the encoded form. Otherwise, return FAIL. */
7700static unsigned int
7701encode_thumb32_immediate (unsigned int val)
09d92015 7702{
c19d1205 7703 unsigned int a, i;
09d92015 7704
9c3c69f2 7705 if (val <= 0xff)
c19d1205 7706 return val;
a737bd4d 7707
9c3c69f2 7708 for (i = 1; i <= 24; i++)
09d92015 7709 {
9c3c69f2
PB
7710 a = val >> i;
7711 if ((val & ~(0xff << i)) == 0)
7712 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7713 }
a737bd4d 7714
c19d1205
ZW
7715 a = val & 0xff;
7716 if (val == ((a << 16) | a))
7717 return 0x100 | a;
7718 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7719 return 0x300 | a;
09d92015 7720
c19d1205
ZW
7721 a = val & 0xff00;
7722 if (val == ((a << 16) | a))
7723 return 0x200 | (a >> 8);
a737bd4d 7724
c19d1205 7725 return FAIL;
09d92015 7726}
5287ad62 7727/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7728
7729static void
5287ad62
JB
7730encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7731{
7732 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7733 && reg > 15)
7734 {
b1cc4aeb 7735 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7736 {
7737 if (thumb_mode)
7738 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7739 fpu_vfp_ext_d32);
7740 else
7741 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7742 fpu_vfp_ext_d32);
7743 }
5287ad62 7744 else
477330fc
RM
7745 {
7746 first_error (_("D register out of range for selected VFP version"));
7747 return;
7748 }
5287ad62
JB
7749 }
7750
c19d1205 7751 switch (pos)
09d92015 7752 {
c19d1205
ZW
7753 case VFP_REG_Sd:
7754 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7755 break;
7756
7757 case VFP_REG_Sn:
7758 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7759 break;
7760
7761 case VFP_REG_Sm:
7762 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7763 break;
7764
5287ad62
JB
7765 case VFP_REG_Dd:
7766 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7767 break;
5f4273c7 7768
5287ad62
JB
7769 case VFP_REG_Dn:
7770 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7771 break;
5f4273c7 7772
5287ad62
JB
7773 case VFP_REG_Dm:
7774 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7775 break;
7776
c19d1205
ZW
7777 default:
7778 abort ();
09d92015 7779 }
09d92015
MM
7780}
7781
c19d1205 7782/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7783 if any, is handled by md_apply_fix. */
09d92015 7784static void
c19d1205 7785encode_arm_shift (int i)
09d92015 7786{
008a97ef
RL
7787 /* register-shifted register. */
7788 if (inst.operands[i].immisreg)
7789 {
bf355b69
MR
7790 int op_index;
7791 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 7792 {
5689c942
RL
7793 /* Check the operand only when it's presented. In pre-UAL syntax,
7794 if the destination register is the same as the first operand, two
7795 register form of the instruction can be used. */
bf355b69
MR
7796 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7797 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
7798 as_warn (UNPRED_REG ("r15"));
7799 }
7800
7801 if (inst.operands[i].imm == REG_PC)
7802 as_warn (UNPRED_REG ("r15"));
7803 }
7804
c19d1205
ZW
7805 if (inst.operands[i].shift_kind == SHIFT_RRX)
7806 inst.instruction |= SHIFT_ROR << 5;
7807 else
09d92015 7808 {
c19d1205
ZW
7809 inst.instruction |= inst.operands[i].shift_kind << 5;
7810 if (inst.operands[i].immisreg)
7811 {
7812 inst.instruction |= SHIFT_BY_REG;
7813 inst.instruction |= inst.operands[i].imm << 8;
7814 }
7815 else
e2b0ab59 7816 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7817 }
c19d1205 7818}
09d92015 7819
c19d1205
ZW
7820static void
7821encode_arm_shifter_operand (int i)
7822{
7823 if (inst.operands[i].isreg)
09d92015 7824 {
c19d1205
ZW
7825 inst.instruction |= inst.operands[i].reg;
7826 encode_arm_shift (i);
09d92015 7827 }
c19d1205 7828 else
a415b1cd
JB
7829 {
7830 inst.instruction |= INST_IMMEDIATE;
e2b0ab59 7831 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
a415b1cd
JB
7832 inst.instruction |= inst.operands[i].imm;
7833 }
09d92015
MM
7834}
7835
c19d1205 7836/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7837static void
c19d1205 7838encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7839{
2b2f5df9
NC
7840 /* PR 14260:
7841 Generate an error if the operand is not a register. */
7842 constraint (!inst.operands[i].isreg,
7843 _("Instruction does not support =N addresses"));
7844
c19d1205 7845 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7846
c19d1205 7847 if (inst.operands[i].preind)
09d92015 7848 {
c19d1205
ZW
7849 if (is_t)
7850 {
7851 inst.error = _("instruction does not accept preindexed addressing");
7852 return;
7853 }
7854 inst.instruction |= PRE_INDEX;
7855 if (inst.operands[i].writeback)
7856 inst.instruction |= WRITE_BACK;
09d92015 7857
c19d1205
ZW
7858 }
7859 else if (inst.operands[i].postind)
7860 {
9c2799c2 7861 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7862 if (is_t)
7863 inst.instruction |= WRITE_BACK;
7864 }
7865 else /* unindexed - only for coprocessor */
09d92015 7866 {
c19d1205 7867 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7868 return;
7869 }
7870
c19d1205
ZW
7871 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7872 && (((inst.instruction & 0x000f0000) >> 16)
7873 == ((inst.instruction & 0x0000f000) >> 12)))
7874 as_warn ((inst.instruction & LOAD_BIT)
7875 ? _("destination register same as write-back base")
7876 : _("source register same as write-back base"));
09d92015
MM
7877}
7878
c19d1205
ZW
7879/* inst.operands[i] was set up by parse_address. Encode it into an
7880 ARM-format mode 2 load or store instruction. If is_t is true,
7881 reject forms that cannot be used with a T instruction (i.e. not
7882 post-indexed). */
a737bd4d 7883static void
c19d1205 7884encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7885{
5be8be5d
DG
7886 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7887
c19d1205 7888 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7889
c19d1205 7890 if (inst.operands[i].immisreg)
09d92015 7891 {
5be8be5d
DG
7892 constraint ((inst.operands[i].imm == REG_PC
7893 || (is_pc && inst.operands[i].writeback)),
7894 BAD_PC_ADDRESSING);
c19d1205
ZW
7895 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7896 inst.instruction |= inst.operands[i].imm;
7897 if (!inst.operands[i].negative)
7898 inst.instruction |= INDEX_UP;
7899 if (inst.operands[i].shifted)
7900 {
7901 if (inst.operands[i].shift_kind == SHIFT_RRX)
7902 inst.instruction |= SHIFT_ROR << 5;
7903 else
7904 {
7905 inst.instruction |= inst.operands[i].shift_kind << 5;
e2b0ab59 7906 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
c19d1205
ZW
7907 }
7908 }
09d92015 7909 }
e2b0ab59 7910 else /* immediate offset in inst.relocs[0] */
09d92015 7911 {
e2b0ab59 7912 if (is_pc && !inst.relocs[0].pc_rel)
5be8be5d
DG
7913 {
7914 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7915
7916 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7917 cannot use PC in addressing.
7918 PC cannot be used in writeback addressing, either. */
7919 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7920 BAD_PC_ADDRESSING);
23a10334 7921
dc5ec521 7922 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7923 if (warn_on_deprecated
7924 && !is_load
7925 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7926 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7927 }
7928
e2b0ab59 7929 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
7930 {
7931 /* Prefer + for zero encoded value. */
7932 if (!inst.operands[i].negative)
7933 inst.instruction |= INDEX_UP;
e2b0ab59 7934 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
26d97720 7935 }
09d92015 7936 }
09d92015
MM
7937}
7938
c19d1205
ZW
7939/* inst.operands[i] was set up by parse_address. Encode it into an
7940 ARM-format mode 3 load or store instruction. Reject forms that
7941 cannot be used with such instructions. If is_t is true, reject
7942 forms that cannot be used with a T instruction (i.e. not
7943 post-indexed). */
7944static void
7945encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7946{
c19d1205 7947 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7948 {
c19d1205
ZW
7949 inst.error = _("instruction does not accept scaled register index");
7950 return;
09d92015 7951 }
a737bd4d 7952
c19d1205 7953 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7954
c19d1205
ZW
7955 if (inst.operands[i].immisreg)
7956 {
5be8be5d 7957 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7958 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7959 BAD_PC_ADDRESSING);
eb9f3f00
JB
7960 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7961 BAD_PC_WRITEBACK);
c19d1205
ZW
7962 inst.instruction |= inst.operands[i].imm;
7963 if (!inst.operands[i].negative)
7964 inst.instruction |= INDEX_UP;
7965 }
e2b0ab59 7966 else /* immediate offset in inst.relocs[0] */
c19d1205 7967 {
e2b0ab59 7968 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
5be8be5d
DG
7969 && inst.operands[i].writeback),
7970 BAD_PC_WRITEBACK);
c19d1205 7971 inst.instruction |= HWOFFSET_IMM;
e2b0ab59 7972 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
7973 {
7974 /* Prefer + for zero encoded value. */
7975 if (!inst.operands[i].negative)
7976 inst.instruction |= INDEX_UP;
7977
e2b0ab59 7978 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
26d97720 7979 }
c19d1205 7980 }
a737bd4d
NC
7981}
7982
8335d6aa
JW
7983/* Write immediate bits [7:0] to the following locations:
7984
7985 |28/24|23 19|18 16|15 4|3 0|
7986 | 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|
7987
7988 This function is used by VMOV/VMVN/VORR/VBIC. */
7989
7990static void
7991neon_write_immbits (unsigned immbits)
7992{
7993 inst.instruction |= immbits & 0xf;
7994 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7995 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7996}
7997
7998/* Invert low-order SIZE bits of XHI:XLO. */
7999
8000static void
8001neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
8002{
8003 unsigned immlo = xlo ? *xlo : 0;
8004 unsigned immhi = xhi ? *xhi : 0;
8005
8006 switch (size)
8007 {
8008 case 8:
8009 immlo = (~immlo) & 0xff;
8010 break;
8011
8012 case 16:
8013 immlo = (~immlo) & 0xffff;
8014 break;
8015
8016 case 64:
8017 immhi = (~immhi) & 0xffffffff;
8018 /* fall through. */
8019
8020 case 32:
8021 immlo = (~immlo) & 0xffffffff;
8022 break;
8023
8024 default:
8025 abort ();
8026 }
8027
8028 if (xlo)
8029 *xlo = immlo;
8030
8031 if (xhi)
8032 *xhi = immhi;
8033}
8034
8035/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
8036 A, B, C, D. */
09d92015 8037
c19d1205 8038static int
8335d6aa 8039neon_bits_same_in_bytes (unsigned imm)
09d92015 8040{
8335d6aa
JW
8041 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
8042 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
8043 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
8044 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
8045}
a737bd4d 8046
8335d6aa 8047/* For immediate of above form, return 0bABCD. */
09d92015 8048
8335d6aa
JW
8049static unsigned
8050neon_squash_bits (unsigned imm)
8051{
8052 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
8053 | ((imm & 0x01000000) >> 21);
8054}
8055
8056/* Compress quarter-float representation to 0b...000 abcdefgh. */
8057
8058static unsigned
8059neon_qfloat_bits (unsigned imm)
8060{
8061 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
8062}
8063
8064/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
8065 the instruction. *OP is passed as the initial value of the op field, and
8066 may be set to a different value depending on the constant (i.e.
8067 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
8068 MVN). If the immediate looks like a repeated pattern then also
8069 try smaller element sizes. */
8070
8071static int
8072neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
8073 unsigned *immbits, int *op, int size,
8074 enum neon_el_type type)
8075{
8076 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
8077 float. */
8078 if (type == NT_float && !float_p)
8079 return FAIL;
8080
8081 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 8082 {
8335d6aa
JW
8083 if (size != 32 || *op == 1)
8084 return FAIL;
8085 *immbits = neon_qfloat_bits (immlo);
8086 return 0xf;
8087 }
8088
8089 if (size == 64)
8090 {
8091 if (neon_bits_same_in_bytes (immhi)
8092 && neon_bits_same_in_bytes (immlo))
c19d1205 8093 {
8335d6aa
JW
8094 if (*op == 1)
8095 return FAIL;
8096 *immbits = (neon_squash_bits (immhi) << 4)
8097 | neon_squash_bits (immlo);
8098 *op = 1;
8099 return 0xe;
c19d1205 8100 }
a737bd4d 8101
8335d6aa
JW
8102 if (immhi != immlo)
8103 return FAIL;
8104 }
a737bd4d 8105
8335d6aa 8106 if (size >= 32)
09d92015 8107 {
8335d6aa 8108 if (immlo == (immlo & 0x000000ff))
c19d1205 8109 {
8335d6aa
JW
8110 *immbits = immlo;
8111 return 0x0;
c19d1205 8112 }
8335d6aa 8113 else if (immlo == (immlo & 0x0000ff00))
c19d1205 8114 {
8335d6aa
JW
8115 *immbits = immlo >> 8;
8116 return 0x2;
c19d1205 8117 }
8335d6aa
JW
8118 else if (immlo == (immlo & 0x00ff0000))
8119 {
8120 *immbits = immlo >> 16;
8121 return 0x4;
8122 }
8123 else if (immlo == (immlo & 0xff000000))
8124 {
8125 *immbits = immlo >> 24;
8126 return 0x6;
8127 }
8128 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
8129 {
8130 *immbits = (immlo >> 8) & 0xff;
8131 return 0xc;
8132 }
8133 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
8134 {
8135 *immbits = (immlo >> 16) & 0xff;
8136 return 0xd;
8137 }
8138
8139 if ((immlo & 0xffff) != (immlo >> 16))
8140 return FAIL;
8141 immlo &= 0xffff;
09d92015 8142 }
a737bd4d 8143
8335d6aa 8144 if (size >= 16)
4962c51a 8145 {
8335d6aa
JW
8146 if (immlo == (immlo & 0x000000ff))
8147 {
8148 *immbits = immlo;
8149 return 0x8;
8150 }
8151 else if (immlo == (immlo & 0x0000ff00))
8152 {
8153 *immbits = immlo >> 8;
8154 return 0xa;
8155 }
8156
8157 if ((immlo & 0xff) != (immlo >> 8))
8158 return FAIL;
8159 immlo &= 0xff;
4962c51a
MS
8160 }
8161
8335d6aa
JW
8162 if (immlo == (immlo & 0x000000ff))
8163 {
8164 /* Don't allow MVN with 8-bit immediate. */
8165 if (*op == 1)
8166 return FAIL;
8167 *immbits = immlo;
8168 return 0xe;
8169 }
26d97720 8170
8335d6aa 8171 return FAIL;
c19d1205 8172}
a737bd4d 8173
5fc177c8 8174#if defined BFD_HOST_64_BIT
ba592044
AM
8175/* Returns TRUE if double precision value V may be cast
8176 to single precision without loss of accuracy. */
8177
8178static bfd_boolean
5fc177c8 8179is_double_a_single (bfd_int64_t v)
ba592044 8180{
5fc177c8 8181 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 8182 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
8183
8184 return (exp == 0 || exp == 0x7FF
8185 || (exp >= 1023 - 126 && exp <= 1023 + 127))
8186 && (mantissa & 0x1FFFFFFFl) == 0;
8187}
8188
3739860c 8189/* Returns a double precision value casted to single precision
ba592044
AM
8190 (ignoring the least significant bits in exponent and mantissa). */
8191
8192static int
5fc177c8 8193double_to_single (bfd_int64_t v)
ba592044
AM
8194{
8195 int sign = (int) ((v >> 63) & 1l);
5fc177c8 8196 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 8197 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
8198
8199 if (exp == 0x7FF)
8200 exp = 0xFF;
8201 else
8202 {
8203 exp = exp - 1023 + 127;
8204 if (exp >= 0xFF)
8205 {
8206 /* Infinity. */
8207 exp = 0x7F;
8208 mantissa = 0;
8209 }
8210 else if (exp < 0)
8211 {
8212 /* No denormalized numbers. */
8213 exp = 0;
8214 mantissa = 0;
8215 }
8216 }
8217 mantissa >>= 29;
8218 return (sign << 31) | (exp << 23) | mantissa;
8219}
5fc177c8 8220#endif /* BFD_HOST_64_BIT */
ba592044 8221
8335d6aa
JW
8222enum lit_type
8223{
8224 CONST_THUMB,
8225 CONST_ARM,
8226 CONST_VEC
8227};
8228
ba592044
AM
8229static void do_vfp_nsyn_opcode (const char *);
8230
e2b0ab59 8231/* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
c19d1205
ZW
8232 Determine whether it can be performed with a move instruction; if
8233 it can, convert inst.instruction to that move instruction and
c921be7d
NC
8234 return TRUE; if it can't, convert inst.instruction to a literal-pool
8235 load and return FALSE. If this is not a valid thing to do in the
8236 current context, set inst.error and return TRUE.
a737bd4d 8237
c19d1205
ZW
8238 inst.operands[i] describes the destination register. */
8239
c921be7d 8240static bfd_boolean
8335d6aa 8241move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 8242{
53365c0d 8243 unsigned long tbit;
8335d6aa
JW
8244 bfd_boolean thumb_p = (t == CONST_THUMB);
8245 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
8246
8247 if (thumb_p)
8248 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8249 else
8250 tbit = LOAD_BIT;
8251
8252 if ((inst.instruction & tbit) == 0)
09d92015 8253 {
c19d1205 8254 inst.error = _("invalid pseudo operation");
c921be7d 8255 return TRUE;
09d92015 8256 }
ba592044 8257
e2b0ab59
AV
8258 if (inst.relocs[0].exp.X_op != O_constant
8259 && inst.relocs[0].exp.X_op != O_symbol
8260 && inst.relocs[0].exp.X_op != O_big)
09d92015
MM
8261 {
8262 inst.error = _("constant expression expected");
c921be7d 8263 return TRUE;
09d92015 8264 }
ba592044 8265
e2b0ab59
AV
8266 if (inst.relocs[0].exp.X_op == O_constant
8267 || inst.relocs[0].exp.X_op == O_big)
8335d6aa 8268 {
5fc177c8
NC
8269#if defined BFD_HOST_64_BIT
8270 bfd_int64_t v;
8271#else
ba592044 8272 offsetT v;
5fc177c8 8273#endif
e2b0ab59 8274 if (inst.relocs[0].exp.X_op == O_big)
8335d6aa 8275 {
ba592044
AM
8276 LITTLENUM_TYPE w[X_PRECISION];
8277 LITTLENUM_TYPE * l;
8278
e2b0ab59 8279 if (inst.relocs[0].exp.X_add_number == -1)
8335d6aa 8280 {
ba592044
AM
8281 gen_to_words (w, X_PRECISION, E_PRECISION);
8282 l = w;
8283 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 8284 }
ba592044
AM
8285 else
8286 l = generic_bignum;
3739860c 8287
5fc177c8
NC
8288#if defined BFD_HOST_64_BIT
8289 v =
8290 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8291 << LITTLENUM_NUMBER_OF_BITS)
8292 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8293 << LITTLENUM_NUMBER_OF_BITS)
8294 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8295 << LITTLENUM_NUMBER_OF_BITS)
8296 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8297#else
ba592044
AM
8298 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8299 | (l[0] & LITTLENUM_MASK);
5fc177c8 8300#endif
8335d6aa 8301 }
ba592044 8302 else
e2b0ab59 8303 v = inst.relocs[0].exp.X_add_number;
ba592044
AM
8304
8305 if (!inst.operands[i].issingle)
8335d6aa 8306 {
12569877 8307 if (thumb_p)
8335d6aa 8308 {
53445554
TP
8309 /* LDR should not use lead in a flag-setting instruction being
8310 chosen so we do not check whether movs can be used. */
12569877 8311
53445554 8312 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8313 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8314 && inst.operands[i].reg != 13
8315 && inst.operands[i].reg != 15)
12569877 8316 {
fc289b0a
TP
8317 /* Check if on thumb2 it can be done with a mov.w, mvn or
8318 movw instruction. */
12569877
AM
8319 unsigned int newimm;
8320 bfd_boolean isNegated;
8321
8322 newimm = encode_thumb32_immediate (v);
8323 if (newimm != (unsigned int) FAIL)
8324 isNegated = FALSE;
8325 else
8326 {
582cfe03 8327 newimm = encode_thumb32_immediate (~v);
12569877
AM
8328 if (newimm != (unsigned int) FAIL)
8329 isNegated = TRUE;
8330 }
8331
fc289b0a
TP
8332 /* The number can be loaded with a mov.w or mvn
8333 instruction. */
ff8646ee
TP
8334 if (newimm != (unsigned int) FAIL
8335 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8336 {
fc289b0a 8337 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8338 | (inst.operands[i].reg << 8));
fc289b0a 8339 /* Change to MOVN. */
582cfe03 8340 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8341 inst.instruction |= (newimm & 0x800) << 15;
8342 inst.instruction |= (newimm & 0x700) << 4;
8343 inst.instruction |= (newimm & 0x0ff);
8344 return TRUE;
8345 }
fc289b0a 8346 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8347 else if ((v & ~0xFFFF) == 0
8348 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8349 {
582cfe03 8350 int imm = v & 0xFFFF;
12569877 8351
582cfe03 8352 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8353 inst.instruction |= (inst.operands[i].reg << 8);
8354 inst.instruction |= (imm & 0xf000) << 4;
8355 inst.instruction |= (imm & 0x0800) << 15;
8356 inst.instruction |= (imm & 0x0700) << 4;
8357 inst.instruction |= (imm & 0x00ff);
8358 return TRUE;
8359 }
8360 }
8335d6aa 8361 }
12569877 8362 else if (arm_p)
ba592044
AM
8363 {
8364 int value = encode_arm_immediate (v);
12569877 8365
ba592044
AM
8366 if (value != FAIL)
8367 {
8368 /* This can be done with a mov instruction. */
8369 inst.instruction &= LITERAL_MASK;
8370 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8371 inst.instruction |= value & 0xfff;
8372 return TRUE;
8373 }
8335d6aa 8374
ba592044
AM
8375 value = encode_arm_immediate (~ v);
8376 if (value != FAIL)
8377 {
8378 /* This can be done with a mvn instruction. */
8379 inst.instruction &= LITERAL_MASK;
8380 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8381 inst.instruction |= value & 0xfff;
8382 return TRUE;
8383 }
8384 }
934c2632 8385 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8386 {
ba592044
AM
8387 int op = 0;
8388 unsigned immbits = 0;
8389 unsigned immlo = inst.operands[1].imm;
8390 unsigned immhi = inst.operands[1].regisimm
8391 ? inst.operands[1].reg
e2b0ab59 8392 : inst.relocs[0].exp.X_unsigned
ba592044
AM
8393 ? 0
8394 : ((bfd_int64_t)((int) immlo)) >> 32;
8395 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8396 &op, 64, NT_invtype);
8397
8398 if (cmode == FAIL)
8399 {
8400 neon_invert_size (&immlo, &immhi, 64);
8401 op = !op;
8402 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8403 &op, 64, NT_invtype);
8404 }
8405
8406 if (cmode != FAIL)
8407 {
8408 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8409 | (1 << 23)
8410 | (cmode << 8)
8411 | (op << 5)
8412 | (1 << 4);
8413
8414 /* Fill other bits in vmov encoding for both thumb and arm. */
8415 if (thumb_mode)
eff0bc54 8416 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8417 else
eff0bc54 8418 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8419 neon_write_immbits (immbits);
8420 return TRUE;
8421 }
8335d6aa
JW
8422 }
8423 }
8335d6aa 8424
ba592044
AM
8425 if (t == CONST_VEC)
8426 {
8427 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8428 if (inst.operands[i].issingle
8429 && is_quarter_float (inst.operands[1].imm)
8430 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8431 {
ba592044
AM
8432 inst.operands[1].imm =
8433 neon_qfloat_bits (v);
8434 do_vfp_nsyn_opcode ("fconsts");
8435 return TRUE;
8335d6aa 8436 }
5fc177c8
NC
8437
8438 /* If our host does not support a 64-bit type then we cannot perform
8439 the following optimization. This mean that there will be a
8440 discrepancy between the output produced by an assembler built for
8441 a 32-bit-only host and the output produced from a 64-bit host, but
8442 this cannot be helped. */
8443#if defined BFD_HOST_64_BIT
ba592044
AM
8444 else if (!inst.operands[1].issingle
8445 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8446 {
ba592044
AM
8447 if (is_double_a_single (v)
8448 && is_quarter_float (double_to_single (v)))
8449 {
8450 inst.operands[1].imm =
8451 neon_qfloat_bits (double_to_single (v));
8452 do_vfp_nsyn_opcode ("fconstd");
8453 return TRUE;
8454 }
8335d6aa 8455 }
5fc177c8 8456#endif
8335d6aa
JW
8457 }
8458 }
8459
8460 if (add_to_lit_pool ((!inst.operands[i].isvec
8461 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8462 return TRUE;
8463
8464 inst.operands[1].reg = REG_PC;
8465 inst.operands[1].isreg = 1;
8466 inst.operands[1].preind = 1;
e2b0ab59
AV
8467 inst.relocs[0].pc_rel = 1;
8468 inst.relocs[0].type = (thumb_p
8335d6aa
JW
8469 ? BFD_RELOC_ARM_THUMB_OFFSET
8470 : (mode_3
8471 ? BFD_RELOC_ARM_HWLITERAL
8472 : BFD_RELOC_ARM_LITERAL));
8473 return FALSE;
8474}
8475
8476/* inst.operands[i] was set up by parse_address. Encode it into an
8477 ARM-format instruction. Reject all forms which cannot be encoded
8478 into a coprocessor load/store instruction. If wb_ok is false,
8479 reject use of writeback; if unind_ok is false, reject use of
8480 unindexed addressing. If reloc_override is not 0, use it instead
8481 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8482 (in which case it is preserved). */
8483
8484static int
8485encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8486{
8487 if (!inst.operands[i].isreg)
8488 {
99b2a2dd
NC
8489 /* PR 18256 */
8490 if (! inst.operands[0].isvec)
8491 {
8492 inst.error = _("invalid co-processor operand");
8493 return FAIL;
8494 }
8335d6aa
JW
8495 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8496 return SUCCESS;
8497 }
8498
8499 inst.instruction |= inst.operands[i].reg << 16;
8500
8501 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8502
8503 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8504 {
8505 gas_assert (!inst.operands[i].writeback);
8506 if (!unind_ok)
8507 {
8508 inst.error = _("instruction does not support unindexed addressing");
8509 return FAIL;
8510 }
8511 inst.instruction |= inst.operands[i].imm;
8512 inst.instruction |= INDEX_UP;
8513 return SUCCESS;
8514 }
8515
8516 if (inst.operands[i].preind)
8517 inst.instruction |= PRE_INDEX;
8518
8519 if (inst.operands[i].writeback)
09d92015 8520 {
8335d6aa 8521 if (inst.operands[i].reg == REG_PC)
c19d1205 8522 {
8335d6aa
JW
8523 inst.error = _("pc may not be used with write-back");
8524 return FAIL;
c19d1205 8525 }
8335d6aa 8526 if (!wb_ok)
c19d1205 8527 {
8335d6aa
JW
8528 inst.error = _("instruction does not support writeback");
8529 return FAIL;
c19d1205 8530 }
8335d6aa 8531 inst.instruction |= WRITE_BACK;
09d92015
MM
8532 }
8533
8335d6aa 8534 if (reloc_override)
e2b0ab59
AV
8535 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
8536 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
8537 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
8538 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8539 {
8335d6aa 8540 if (thumb_mode)
e2b0ab59 8541 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8335d6aa 8542 else
e2b0ab59 8543 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8544 }
8335d6aa
JW
8545
8546 /* Prefer + for zero encoded value. */
8547 if (!inst.operands[i].negative)
8548 inst.instruction |= INDEX_UP;
8549
8550 return SUCCESS;
09d92015
MM
8551}
8552
5f4273c7 8553/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8554 First some generics; their names are taken from the conventional
8555 bit positions for register arguments in ARM format instructions. */
09d92015 8556
a737bd4d 8557static void
c19d1205 8558do_noargs (void)
09d92015 8559{
c19d1205 8560}
a737bd4d 8561
c19d1205
ZW
8562static void
8563do_rd (void)
8564{
8565 inst.instruction |= inst.operands[0].reg << 12;
8566}
a737bd4d 8567
16a1fa25
TP
8568static void
8569do_rn (void)
8570{
8571 inst.instruction |= inst.operands[0].reg << 16;
8572}
8573
c19d1205
ZW
8574static void
8575do_rd_rm (void)
8576{
8577 inst.instruction |= inst.operands[0].reg << 12;
8578 inst.instruction |= inst.operands[1].reg;
8579}
09d92015 8580
9eb6c0f1
MGD
8581static void
8582do_rm_rn (void)
8583{
8584 inst.instruction |= inst.operands[0].reg;
8585 inst.instruction |= inst.operands[1].reg << 16;
8586}
8587
c19d1205
ZW
8588static void
8589do_rd_rn (void)
8590{
8591 inst.instruction |= inst.operands[0].reg << 12;
8592 inst.instruction |= inst.operands[1].reg << 16;
8593}
a737bd4d 8594
c19d1205
ZW
8595static void
8596do_rn_rd (void)
8597{
8598 inst.instruction |= inst.operands[0].reg << 16;
8599 inst.instruction |= inst.operands[1].reg << 12;
8600}
09d92015 8601
4ed7ed8d
TP
8602static void
8603do_tt (void)
8604{
8605 inst.instruction |= inst.operands[0].reg << 8;
8606 inst.instruction |= inst.operands[1].reg << 16;
8607}
8608
59d09be6
MGD
8609static bfd_boolean
8610check_obsolete (const arm_feature_set *feature, const char *msg)
8611{
8612 if (ARM_CPU_IS_ANY (cpu_variant))
8613 {
5c3696f8 8614 as_tsktsk ("%s", msg);
59d09be6
MGD
8615 return TRUE;
8616 }
8617 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8618 {
8619 as_bad ("%s", msg);
8620 return TRUE;
8621 }
8622
8623 return FALSE;
8624}
8625
c19d1205
ZW
8626static void
8627do_rd_rm_rn (void)
8628{
9a64e435 8629 unsigned Rn = inst.operands[2].reg;
708587a4 8630 /* Enforce restrictions on SWP instruction. */
9a64e435 8631 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8632 {
8633 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8634 _("Rn must not overlap other operands"));
8635
59d09be6
MGD
8636 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8637 */
8638 if (!check_obsolete (&arm_ext_v8,
8639 _("swp{b} use is obsoleted for ARMv8 and later"))
8640 && warn_on_deprecated
8641 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8642 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8643 }
59d09be6 8644
c19d1205
ZW
8645 inst.instruction |= inst.operands[0].reg << 12;
8646 inst.instruction |= inst.operands[1].reg;
9a64e435 8647 inst.instruction |= Rn << 16;
c19d1205 8648}
09d92015 8649
c19d1205
ZW
8650static void
8651do_rd_rn_rm (void)
8652{
8653 inst.instruction |= inst.operands[0].reg << 12;
8654 inst.instruction |= inst.operands[1].reg << 16;
8655 inst.instruction |= inst.operands[2].reg;
8656}
a737bd4d 8657
c19d1205
ZW
8658static void
8659do_rm_rd_rn (void)
8660{
5be8be5d 8661 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
e2b0ab59
AV
8662 constraint (((inst.relocs[0].exp.X_op != O_constant
8663 && inst.relocs[0].exp.X_op != O_illegal)
8664 || inst.relocs[0].exp.X_add_number != 0),
5be8be5d 8665 BAD_ADDR_MODE);
c19d1205
ZW
8666 inst.instruction |= inst.operands[0].reg;
8667 inst.instruction |= inst.operands[1].reg << 12;
8668 inst.instruction |= inst.operands[2].reg << 16;
8669}
09d92015 8670
c19d1205
ZW
8671static void
8672do_imm0 (void)
8673{
8674 inst.instruction |= inst.operands[0].imm;
8675}
09d92015 8676
c19d1205
ZW
8677static void
8678do_rd_cpaddr (void)
8679{
8680 inst.instruction |= inst.operands[0].reg << 12;
8681 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8682}
a737bd4d 8683
c19d1205
ZW
8684/* ARM instructions, in alphabetical order by function name (except
8685 that wrapper functions appear immediately after the function they
8686 wrap). */
09d92015 8687
c19d1205
ZW
8688/* This is a pseudo-op of the form "adr rd, label" to be converted
8689 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8690
8691static void
c19d1205 8692do_adr (void)
09d92015 8693{
c19d1205 8694 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8695
c19d1205
ZW
8696 /* Frag hacking will turn this into a sub instruction if the offset turns
8697 out to be negative. */
e2b0ab59
AV
8698 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
8699 inst.relocs[0].pc_rel = 1;
8700 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 8701
fc6141f0 8702 if (support_interwork
e2b0ab59
AV
8703 && inst.relocs[0].exp.X_op == O_symbol
8704 && inst.relocs[0].exp.X_add_symbol != NULL
8705 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
8706 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
8707 inst.relocs[0].exp.X_add_number |= 1;
c19d1205 8708}
b99bd4ef 8709
c19d1205
ZW
8710/* This is a pseudo-op of the form "adrl rd, label" to be converted
8711 into a relative address of the form:
8712 add rd, pc, #low(label-.-8)"
8713 add rd, rd, #high(label-.-8)" */
b99bd4ef 8714
c19d1205
ZW
8715static void
8716do_adrl (void)
8717{
8718 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8719
c19d1205
ZW
8720 /* Frag hacking will turn this into a sub instruction if the offset turns
8721 out to be negative. */
e2b0ab59
AV
8722 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
8723 inst.relocs[0].pc_rel = 1;
c19d1205 8724 inst.size = INSN_SIZE * 2;
e2b0ab59 8725 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 8726
fc6141f0 8727 if (support_interwork
e2b0ab59
AV
8728 && inst.relocs[0].exp.X_op == O_symbol
8729 && inst.relocs[0].exp.X_add_symbol != NULL
8730 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
8731 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
8732 inst.relocs[0].exp.X_add_number |= 1;
b99bd4ef
NC
8733}
8734
b99bd4ef 8735static void
c19d1205 8736do_arit (void)
b99bd4ef 8737{
e2b0ab59
AV
8738 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8739 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 8740 THUMB1_RELOC_ONLY);
c19d1205
ZW
8741 if (!inst.operands[1].present)
8742 inst.operands[1].reg = inst.operands[0].reg;
8743 inst.instruction |= inst.operands[0].reg << 12;
8744 inst.instruction |= inst.operands[1].reg << 16;
8745 encode_arm_shifter_operand (2);
8746}
b99bd4ef 8747
62b3e311
PB
8748static void
8749do_barrier (void)
8750{
8751 if (inst.operands[0].present)
ccb84d65 8752 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8753 else
8754 inst.instruction |= 0xf;
8755}
8756
c19d1205
ZW
8757static void
8758do_bfc (void)
8759{
8760 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8761 constraint (msb > 32, _("bit-field extends past end of register"));
8762 /* The instruction encoding stores the LSB and MSB,
8763 not the LSB and width. */
8764 inst.instruction |= inst.operands[0].reg << 12;
8765 inst.instruction |= inst.operands[1].imm << 7;
8766 inst.instruction |= (msb - 1) << 16;
8767}
b99bd4ef 8768
c19d1205
ZW
8769static void
8770do_bfi (void)
8771{
8772 unsigned int msb;
b99bd4ef 8773
c19d1205
ZW
8774 /* #0 in second position is alternative syntax for bfc, which is
8775 the same instruction but with REG_PC in the Rm field. */
8776 if (!inst.operands[1].isreg)
8777 inst.operands[1].reg = REG_PC;
b99bd4ef 8778
c19d1205
ZW
8779 msb = inst.operands[2].imm + inst.operands[3].imm;
8780 constraint (msb > 32, _("bit-field extends past end of register"));
8781 /* The instruction encoding stores the LSB and MSB,
8782 not the LSB and width. */
8783 inst.instruction |= inst.operands[0].reg << 12;
8784 inst.instruction |= inst.operands[1].reg;
8785 inst.instruction |= inst.operands[2].imm << 7;
8786 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8787}
8788
b99bd4ef 8789static void
c19d1205 8790do_bfx (void)
b99bd4ef 8791{
c19d1205
ZW
8792 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8793 _("bit-field extends past end of register"));
8794 inst.instruction |= inst.operands[0].reg << 12;
8795 inst.instruction |= inst.operands[1].reg;
8796 inst.instruction |= inst.operands[2].imm << 7;
8797 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8798}
09d92015 8799
c19d1205
ZW
8800/* ARM V5 breakpoint instruction (argument parse)
8801 BKPT <16 bit unsigned immediate>
8802 Instruction is not conditional.
8803 The bit pattern given in insns[] has the COND_ALWAYS condition,
8804 and it is an error if the caller tried to override that. */
b99bd4ef 8805
c19d1205
ZW
8806static void
8807do_bkpt (void)
8808{
8809 /* Top 12 of 16 bits to bits 19:8. */
8810 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8811
c19d1205
ZW
8812 /* Bottom 4 of 16 bits to bits 3:0. */
8813 inst.instruction |= inst.operands[0].imm & 0xf;
8814}
09d92015 8815
c19d1205
ZW
8816static void
8817encode_branch (int default_reloc)
8818{
8819 if (inst.operands[0].hasreloc)
8820 {
0855e32b
NS
8821 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8822 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8823 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
e2b0ab59 8824 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
0855e32b
NS
8825 ? BFD_RELOC_ARM_PLT32
8826 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8827 }
b99bd4ef 8828 else
e2b0ab59
AV
8829 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
8830 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
8831}
8832
b99bd4ef 8833static void
c19d1205 8834do_branch (void)
b99bd4ef 8835{
39b41c9c
PB
8836#ifdef OBJ_ELF
8837 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8838 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8839 else
8840#endif
8841 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8842}
8843
8844static void
8845do_bl (void)
8846{
8847#ifdef OBJ_ELF
8848 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8849 {
8850 if (inst.cond == COND_ALWAYS)
8851 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8852 else
8853 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8854 }
8855 else
8856#endif
8857 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8858}
b99bd4ef 8859
c19d1205
ZW
8860/* ARM V5 branch-link-exchange instruction (argument parse)
8861 BLX <target_addr> ie BLX(1)
8862 BLX{<condition>} <Rm> ie BLX(2)
8863 Unfortunately, there are two different opcodes for this mnemonic.
8864 So, the insns[].value is not used, and the code here zaps values
8865 into inst.instruction.
8866 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8867
c19d1205
ZW
8868static void
8869do_blx (void)
8870{
8871 if (inst.operands[0].isreg)
b99bd4ef 8872 {
c19d1205
ZW
8873 /* Arg is a register; the opcode provided by insns[] is correct.
8874 It is not illegal to do "blx pc", just useless. */
8875 if (inst.operands[0].reg == REG_PC)
8876 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8877
c19d1205
ZW
8878 inst.instruction |= inst.operands[0].reg;
8879 }
8880 else
b99bd4ef 8881 {
c19d1205 8882 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8883 conditionally, and the opcode must be adjusted.
8884 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8885 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8886 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8887 inst.instruction = 0xfa000000;
267bf995 8888 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8889 }
c19d1205
ZW
8890}
8891
8892static void
8893do_bx (void)
8894{
845b51d6
PB
8895 bfd_boolean want_reloc;
8896
c19d1205
ZW
8897 if (inst.operands[0].reg == REG_PC)
8898 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8899
c19d1205 8900 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8901 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8902 it is for ARMv4t or earlier. */
8903 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
4d354d8b
TP
8904 if (!ARM_FEATURE_ZERO (selected_object_arch)
8905 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
845b51d6
PB
8906 want_reloc = TRUE;
8907
5ad34203 8908#ifdef OBJ_ELF
845b51d6 8909 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8910#endif
584206db 8911 want_reloc = FALSE;
845b51d6
PB
8912
8913 if (want_reloc)
e2b0ab59 8914 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8915}
8916
c19d1205
ZW
8917
8918/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8919
8920static void
c19d1205 8921do_bxj (void)
a737bd4d 8922{
c19d1205
ZW
8923 if (inst.operands[0].reg == REG_PC)
8924 as_tsktsk (_("use of r15 in bxj is not really useful"));
8925
8926 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8927}
8928
c19d1205
ZW
8929/* Co-processor data operation:
8930 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8931 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8932static void
8933do_cdp (void)
8934{
8935 inst.instruction |= inst.operands[0].reg << 8;
8936 inst.instruction |= inst.operands[1].imm << 20;
8937 inst.instruction |= inst.operands[2].reg << 12;
8938 inst.instruction |= inst.operands[3].reg << 16;
8939 inst.instruction |= inst.operands[4].reg;
8940 inst.instruction |= inst.operands[5].imm << 5;
8941}
a737bd4d
NC
8942
8943static void
c19d1205 8944do_cmp (void)
a737bd4d 8945{
c19d1205
ZW
8946 inst.instruction |= inst.operands[0].reg << 16;
8947 encode_arm_shifter_operand (1);
a737bd4d
NC
8948}
8949
c19d1205
ZW
8950/* Transfer between coprocessor and ARM registers.
8951 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8952 MRC2
8953 MCR{cond}
8954 MCR2
8955
8956 No special properties. */
09d92015 8957
dcbd0d71
MGD
8958struct deprecated_coproc_regs_s
8959{
8960 unsigned cp;
8961 int opc1;
8962 unsigned crn;
8963 unsigned crm;
8964 int opc2;
8965 arm_feature_set deprecated;
8966 arm_feature_set obsoleted;
8967 const char *dep_msg;
8968 const char *obs_msg;
8969};
8970
8971#define DEPR_ACCESS_V8 \
8972 N_("This coprocessor register access is deprecated in ARMv8")
8973
8974/* Table of all deprecated coprocessor registers. */
8975static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8976{
8977 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8978 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8979 DEPR_ACCESS_V8, NULL},
8980 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8981 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8982 DEPR_ACCESS_V8, NULL},
8983 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8984 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8985 DEPR_ACCESS_V8, NULL},
8986 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8987 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8988 DEPR_ACCESS_V8, NULL},
8989 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8990 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8991 DEPR_ACCESS_V8, NULL},
8992};
8993
8994#undef DEPR_ACCESS_V8
8995
8996static const size_t deprecated_coproc_reg_count =
8997 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8998
09d92015 8999static void
c19d1205 9000do_co_reg (void)
09d92015 9001{
fdfde340 9002 unsigned Rd;
dcbd0d71 9003 size_t i;
fdfde340
JM
9004
9005 Rd = inst.operands[2].reg;
9006 if (thumb_mode)
9007 {
9008 if (inst.instruction == 0xee000010
9009 || inst.instruction == 0xfe000010)
9010 /* MCR, MCR2 */
9011 reject_bad_reg (Rd);
5c8ed6a4 9012 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
9013 /* MRC, MRC2 */
9014 constraint (Rd == REG_SP, BAD_SP);
9015 }
9016 else
9017 {
9018 /* MCR */
9019 if (inst.instruction == 0xe000010)
9020 constraint (Rd == REG_PC, BAD_PC);
9021 }
9022
dcbd0d71
MGD
9023 for (i = 0; i < deprecated_coproc_reg_count; ++i)
9024 {
9025 const struct deprecated_coproc_regs_s *r =
9026 deprecated_coproc_regs + i;
9027
9028 if (inst.operands[0].reg == r->cp
9029 && inst.operands[1].imm == r->opc1
9030 && inst.operands[3].reg == r->crn
9031 && inst.operands[4].reg == r->crm
9032 && inst.operands[5].imm == r->opc2)
9033 {
b10bf8c5 9034 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 9035 && warn_on_deprecated
dcbd0d71 9036 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 9037 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
9038 }
9039 }
fdfde340 9040
c19d1205
ZW
9041 inst.instruction |= inst.operands[0].reg << 8;
9042 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 9043 inst.instruction |= Rd << 12;
c19d1205
ZW
9044 inst.instruction |= inst.operands[3].reg << 16;
9045 inst.instruction |= inst.operands[4].reg;
9046 inst.instruction |= inst.operands[5].imm << 5;
9047}
09d92015 9048
c19d1205
ZW
9049/* Transfer between coprocessor register and pair of ARM registers.
9050 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
9051 MCRR2
9052 MRRC{cond}
9053 MRRC2
b99bd4ef 9054
c19d1205 9055 Two XScale instructions are special cases of these:
09d92015 9056
c19d1205
ZW
9057 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
9058 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 9059
5f4273c7 9060 Result unpredictable if Rd or Rn is R15. */
a737bd4d 9061
c19d1205
ZW
9062static void
9063do_co_reg2c (void)
9064{
fdfde340
JM
9065 unsigned Rd, Rn;
9066
9067 Rd = inst.operands[2].reg;
9068 Rn = inst.operands[3].reg;
9069
9070 if (thumb_mode)
9071 {
9072 reject_bad_reg (Rd);
9073 reject_bad_reg (Rn);
9074 }
9075 else
9076 {
9077 constraint (Rd == REG_PC, BAD_PC);
9078 constraint (Rn == REG_PC, BAD_PC);
9079 }
9080
873f10f0
TC
9081 /* Only check the MRRC{2} variants. */
9082 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
9083 {
9084 /* If Rd == Rn, error that the operation is
9085 unpredictable (example MRRC p3,#1,r1,r1,c4). */
9086 constraint (Rd == Rn, BAD_OVERLAP);
9087 }
9088
c19d1205
ZW
9089 inst.instruction |= inst.operands[0].reg << 8;
9090 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
9091 inst.instruction |= Rd << 12;
9092 inst.instruction |= Rn << 16;
c19d1205 9093 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
9094}
9095
c19d1205
ZW
9096static void
9097do_cpsi (void)
9098{
9099 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
9100 if (inst.operands[1].present)
9101 {
9102 inst.instruction |= CPSI_MMOD;
9103 inst.instruction |= inst.operands[1].imm;
9104 }
c19d1205 9105}
b99bd4ef 9106
62b3e311
PB
9107static void
9108do_dbg (void)
9109{
9110 inst.instruction |= inst.operands[0].imm;
9111}
9112
eea54501
MGD
9113static void
9114do_div (void)
9115{
9116 unsigned Rd, Rn, Rm;
9117
9118 Rd = inst.operands[0].reg;
9119 Rn = (inst.operands[1].present
9120 ? inst.operands[1].reg : Rd);
9121 Rm = inst.operands[2].reg;
9122
9123 constraint ((Rd == REG_PC), BAD_PC);
9124 constraint ((Rn == REG_PC), BAD_PC);
9125 constraint ((Rm == REG_PC), BAD_PC);
9126
9127 inst.instruction |= Rd << 16;
9128 inst.instruction |= Rn << 0;
9129 inst.instruction |= Rm << 8;
9130}
9131
b99bd4ef 9132static void
c19d1205 9133do_it (void)
b99bd4ef 9134{
c19d1205 9135 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
9136 process it to do the validation as if in
9137 thumb mode, just in case the code gets
9138 assembled for thumb using the unified syntax. */
9139
c19d1205 9140 inst.size = 0;
e07e6e58
NC
9141 if (unified_syntax)
9142 {
5ee91343
AV
9143 set_pred_insn_type (IT_INSN);
9144 now_pred.mask = (inst.instruction & 0xf) | 0x10;
9145 now_pred.cc = inst.operands[0].imm;
e07e6e58 9146 }
09d92015 9147}
b99bd4ef 9148
6530b175
NC
9149/* If there is only one register in the register list,
9150 then return its register number. Otherwise return -1. */
9151static int
9152only_one_reg_in_list (int range)
9153{
9154 int i = ffs (range) - 1;
9155 return (i > 15 || range != (1 << i)) ? -1 : i;
9156}
9157
09d92015 9158static void
6530b175 9159encode_ldmstm(int from_push_pop_mnem)
ea6ef066 9160{
c19d1205
ZW
9161 int base_reg = inst.operands[0].reg;
9162 int range = inst.operands[1].imm;
6530b175 9163 int one_reg;
ea6ef066 9164
c19d1205
ZW
9165 inst.instruction |= base_reg << 16;
9166 inst.instruction |= range;
ea6ef066 9167
c19d1205
ZW
9168 if (inst.operands[1].writeback)
9169 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 9170
c19d1205 9171 if (inst.operands[0].writeback)
ea6ef066 9172 {
c19d1205
ZW
9173 inst.instruction |= WRITE_BACK;
9174 /* Check for unpredictable uses of writeback. */
9175 if (inst.instruction & LOAD_BIT)
09d92015 9176 {
c19d1205
ZW
9177 /* Not allowed in LDM type 2. */
9178 if ((inst.instruction & LDM_TYPE_2_OR_3)
9179 && ((range & (1 << REG_PC)) == 0))
9180 as_warn (_("writeback of base register is UNPREDICTABLE"));
9181 /* Only allowed if base reg not in list for other types. */
9182 else if (range & (1 << base_reg))
9183 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
9184 }
9185 else /* STM. */
9186 {
9187 /* Not allowed for type 2. */
9188 if (inst.instruction & LDM_TYPE_2_OR_3)
9189 as_warn (_("writeback of base register is UNPREDICTABLE"));
9190 /* Only allowed if base reg not in list, or first in list. */
9191 else if ((range & (1 << base_reg))
9192 && (range & ((1 << base_reg) - 1)))
9193 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 9194 }
ea6ef066 9195 }
6530b175
NC
9196
9197 /* If PUSH/POP has only one register, then use the A2 encoding. */
9198 one_reg = only_one_reg_in_list (range);
9199 if (from_push_pop_mnem && one_reg >= 0)
9200 {
9201 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
9202
4f588891
NC
9203 if (is_push && one_reg == 13 /* SP */)
9204 /* PR 22483: The A2 encoding cannot be used when
9205 pushing the stack pointer as this is UNPREDICTABLE. */
9206 return;
9207
6530b175
NC
9208 inst.instruction &= A_COND_MASK;
9209 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
9210 inst.instruction |= one_reg << 12;
9211 }
9212}
9213
9214static void
9215do_ldmstm (void)
9216{
9217 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
9218}
9219
c19d1205
ZW
9220/* ARMv5TE load-consecutive (argument parse)
9221 Mode is like LDRH.
9222
9223 LDRccD R, mode
9224 STRccD R, mode. */
9225
a737bd4d 9226static void
c19d1205 9227do_ldrd (void)
a737bd4d 9228{
c19d1205 9229 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 9230 _("first transfer register must be even"));
c19d1205
ZW
9231 constraint (inst.operands[1].present
9232 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 9233 _("can only transfer two consecutive registers"));
c19d1205
ZW
9234 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9235 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 9236
c19d1205
ZW
9237 if (!inst.operands[1].present)
9238 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 9239
c56791bb
RE
9240 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9241 register and the first register written; we have to diagnose
9242 overlap between the base and the second register written here. */
ea6ef066 9243
c56791bb
RE
9244 if (inst.operands[2].reg == inst.operands[1].reg
9245 && (inst.operands[2].writeback || inst.operands[2].postind))
9246 as_warn (_("base register written back, and overlaps "
9247 "second transfer register"));
b05fe5cf 9248
c56791bb
RE
9249 if (!(inst.instruction & V4_STR_BIT))
9250 {
c19d1205 9251 /* For an index-register load, the index register must not overlap the
c56791bb
RE
9252 destination (even if not write-back). */
9253 if (inst.operands[2].immisreg
9254 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9255 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9256 as_warn (_("index register overlaps transfer register"));
b05fe5cf 9257 }
c19d1205
ZW
9258 inst.instruction |= inst.operands[0].reg << 12;
9259 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
9260}
9261
9262static void
c19d1205 9263do_ldrex (void)
b05fe5cf 9264{
c19d1205
ZW
9265 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9266 || inst.operands[1].postind || inst.operands[1].writeback
9267 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
9268 || inst.operands[1].negative
9269 /* This can arise if the programmer has written
9270 strex rN, rM, foo
9271 or if they have mistakenly used a register name as the last
9272 operand, eg:
9273 strex rN, rM, rX
9274 It is very difficult to distinguish between these two cases
9275 because "rX" might actually be a label. ie the register
9276 name has been occluded by a symbol of the same name. So we
9277 just generate a general 'bad addressing mode' type error
9278 message and leave it up to the programmer to discover the
9279 true cause and fix their mistake. */
9280 || (inst.operands[1].reg == REG_PC),
9281 BAD_ADDR_MODE);
b05fe5cf 9282
e2b0ab59
AV
9283 constraint (inst.relocs[0].exp.X_op != O_constant
9284 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9285 _("offset must be zero in ARM encoding"));
b05fe5cf 9286
5be8be5d
DG
9287 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9288
c19d1205
ZW
9289 inst.instruction |= inst.operands[0].reg << 12;
9290 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 9291 inst.relocs[0].type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
9292}
9293
9294static void
c19d1205 9295do_ldrexd (void)
b05fe5cf 9296{
c19d1205
ZW
9297 constraint (inst.operands[0].reg % 2 != 0,
9298 _("even register required"));
9299 constraint (inst.operands[1].present
9300 && inst.operands[1].reg != inst.operands[0].reg + 1,
9301 _("can only load two consecutive registers"));
9302 /* If op 1 were present and equal to PC, this function wouldn't
9303 have been called in the first place. */
9304 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9305
c19d1205
ZW
9306 inst.instruction |= inst.operands[0].reg << 12;
9307 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9308}
9309
1be5fd2e
NC
9310/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9311 which is not a multiple of four is UNPREDICTABLE. */
9312static void
9313check_ldr_r15_aligned (void)
9314{
9315 constraint (!(inst.operands[1].immisreg)
9316 && (inst.operands[0].reg == REG_PC
9317 && inst.operands[1].reg == REG_PC
e2b0ab59 9318 && (inst.relocs[0].exp.X_add_number & 0x3)),
de194d85 9319 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9320}
9321
b05fe5cf 9322static void
c19d1205 9323do_ldst (void)
b05fe5cf 9324{
c19d1205
ZW
9325 inst.instruction |= inst.operands[0].reg << 12;
9326 if (!inst.operands[1].isreg)
8335d6aa 9327 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9328 return;
c19d1205 9329 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9330 check_ldr_r15_aligned ();
b05fe5cf
ZW
9331}
9332
9333static void
c19d1205 9334do_ldstt (void)
b05fe5cf 9335{
c19d1205
ZW
9336 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9337 reject [Rn,...]. */
9338 if (inst.operands[1].preind)
b05fe5cf 9339 {
e2b0ab59
AV
9340 constraint (inst.relocs[0].exp.X_op != O_constant
9341 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9342 _("this instruction requires a post-indexed address"));
b05fe5cf 9343
c19d1205
ZW
9344 inst.operands[1].preind = 0;
9345 inst.operands[1].postind = 1;
9346 inst.operands[1].writeback = 1;
b05fe5cf 9347 }
c19d1205
ZW
9348 inst.instruction |= inst.operands[0].reg << 12;
9349 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9350}
b05fe5cf 9351
c19d1205 9352/* Halfword and signed-byte load/store operations. */
b05fe5cf 9353
c19d1205
ZW
9354static void
9355do_ldstv4 (void)
9356{
ff4a8d2b 9357 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9358 inst.instruction |= inst.operands[0].reg << 12;
9359 if (!inst.operands[1].isreg)
8335d6aa 9360 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9361 return;
c19d1205 9362 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9363}
9364
9365static void
c19d1205 9366do_ldsttv4 (void)
b05fe5cf 9367{
c19d1205
ZW
9368 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9369 reject [Rn,...]. */
9370 if (inst.operands[1].preind)
b05fe5cf 9371 {
e2b0ab59
AV
9372 constraint (inst.relocs[0].exp.X_op != O_constant
9373 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9374 _("this instruction requires a post-indexed address"));
b05fe5cf 9375
c19d1205
ZW
9376 inst.operands[1].preind = 0;
9377 inst.operands[1].postind = 1;
9378 inst.operands[1].writeback = 1;
b05fe5cf 9379 }
c19d1205
ZW
9380 inst.instruction |= inst.operands[0].reg << 12;
9381 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9382}
b05fe5cf 9383
c19d1205
ZW
9384/* Co-processor register load/store.
9385 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9386static void
9387do_lstc (void)
9388{
9389 inst.instruction |= inst.operands[0].reg << 8;
9390 inst.instruction |= inst.operands[1].reg << 12;
9391 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9392}
9393
b05fe5cf 9394static void
c19d1205 9395do_mlas (void)
b05fe5cf 9396{
8fb9d7b9 9397 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9398 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9399 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9400 && !(inst.instruction & 0x00400000))
8fb9d7b9 9401 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9402
c19d1205
ZW
9403 inst.instruction |= inst.operands[0].reg << 16;
9404 inst.instruction |= inst.operands[1].reg;
9405 inst.instruction |= inst.operands[2].reg << 8;
9406 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9407}
b05fe5cf 9408
c19d1205
ZW
9409static void
9410do_mov (void)
9411{
e2b0ab59
AV
9412 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9413 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9414 THUMB1_RELOC_ONLY);
c19d1205
ZW
9415 inst.instruction |= inst.operands[0].reg << 12;
9416 encode_arm_shifter_operand (1);
9417}
b05fe5cf 9418
c19d1205
ZW
9419/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9420static void
9421do_mov16 (void)
9422{
b6895b4f
PB
9423 bfd_vma imm;
9424 bfd_boolean top;
9425
9426 top = (inst.instruction & 0x00400000) != 0;
e2b0ab59 9427 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
33eaf5de 9428 _(":lower16: not allowed in this instruction"));
e2b0ab59 9429 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
33eaf5de 9430 _(":upper16: not allowed in this instruction"));
c19d1205 9431 inst.instruction |= inst.operands[0].reg << 12;
e2b0ab59 9432 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 9433 {
e2b0ab59 9434 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
9435 /* The value is in two pieces: 0:11, 16:19. */
9436 inst.instruction |= (imm & 0x00000fff);
9437 inst.instruction |= (imm & 0x0000f000) << 4;
9438 }
b05fe5cf 9439}
b99bd4ef 9440
037e8744
JB
9441static int
9442do_vfp_nsyn_mrs (void)
9443{
9444 if (inst.operands[0].isvec)
9445 {
9446 if (inst.operands[1].reg != 1)
477330fc 9447 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9448 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9449 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9450 do_vfp_nsyn_opcode ("fmstat");
9451 }
9452 else if (inst.operands[1].isvec)
9453 do_vfp_nsyn_opcode ("fmrx");
9454 else
9455 return FAIL;
5f4273c7 9456
037e8744
JB
9457 return SUCCESS;
9458}
9459
9460static int
9461do_vfp_nsyn_msr (void)
9462{
9463 if (inst.operands[0].isvec)
9464 do_vfp_nsyn_opcode ("fmxr");
9465 else
9466 return FAIL;
9467
9468 return SUCCESS;
9469}
9470
f7c21dc7
NC
9471static void
9472do_vmrs (void)
9473{
9474 unsigned Rt = inst.operands[0].reg;
fa94de6b 9475
16d02dc9 9476 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9477 {
9478 inst.error = BAD_SP;
9479 return;
9480 }
9481
40c7d507
RR
9482 /* MVFR2 is only valid at ARMv8-A. */
9483 if (inst.operands[1].reg == 5)
9484 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9485 _(BAD_FPU));
9486
f7c21dc7 9487 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9488 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9489 {
9490 inst.error = BAD_PC;
9491 return;
9492 }
9493
16d02dc9
JB
9494 /* If we get through parsing the register name, we just insert the number
9495 generated into the instruction without further validation. */
9496 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9497 inst.instruction |= (Rt << 12);
9498}
9499
9500static void
9501do_vmsr (void)
9502{
9503 unsigned Rt = inst.operands[1].reg;
fa94de6b 9504
f7c21dc7
NC
9505 if (thumb_mode)
9506 reject_bad_reg (Rt);
9507 else if (Rt == REG_PC)
9508 {
9509 inst.error = BAD_PC;
9510 return;
9511 }
9512
40c7d507
RR
9513 /* MVFR2 is only valid for ARMv8-A. */
9514 if (inst.operands[0].reg == 5)
9515 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9516 _(BAD_FPU));
9517
16d02dc9
JB
9518 /* If we get through parsing the register name, we just insert the number
9519 generated into the instruction without further validation. */
9520 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9521 inst.instruction |= (Rt << 12);
9522}
9523
b99bd4ef 9524static void
c19d1205 9525do_mrs (void)
b99bd4ef 9526{
90ec0d68
MGD
9527 unsigned br;
9528
037e8744
JB
9529 if (do_vfp_nsyn_mrs () == SUCCESS)
9530 return;
9531
ff4a8d2b 9532 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9533 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9534
9535 if (inst.operands[1].isreg)
9536 {
9537 br = inst.operands[1].reg;
806ab1c0 9538 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
90ec0d68
MGD
9539 as_bad (_("bad register for mrs"));
9540 }
9541 else
9542 {
9543 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9544 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9545 != (PSR_c|PSR_f),
d2cd1205 9546 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9547 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9548 }
9549
9550 inst.instruction |= br;
c19d1205 9551}
b99bd4ef 9552
c19d1205
ZW
9553/* Two possible forms:
9554 "{C|S}PSR_<field>, Rm",
9555 "{C|S}PSR_f, #expression". */
b99bd4ef 9556
c19d1205
ZW
9557static void
9558do_msr (void)
9559{
037e8744
JB
9560 if (do_vfp_nsyn_msr () == SUCCESS)
9561 return;
9562
c19d1205
ZW
9563 inst.instruction |= inst.operands[0].imm;
9564 if (inst.operands[1].isreg)
9565 inst.instruction |= inst.operands[1].reg;
9566 else
b99bd4ef 9567 {
c19d1205 9568 inst.instruction |= INST_IMMEDIATE;
e2b0ab59
AV
9569 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9570 inst.relocs[0].pc_rel = 0;
b99bd4ef 9571 }
b99bd4ef
NC
9572}
9573
c19d1205
ZW
9574static void
9575do_mul (void)
a737bd4d 9576{
ff4a8d2b
NC
9577 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9578
c19d1205
ZW
9579 if (!inst.operands[2].present)
9580 inst.operands[2].reg = inst.operands[0].reg;
9581 inst.instruction |= inst.operands[0].reg << 16;
9582 inst.instruction |= inst.operands[1].reg;
9583 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9584
8fb9d7b9
MS
9585 if (inst.operands[0].reg == inst.operands[1].reg
9586 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9587 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9588}
9589
c19d1205
ZW
9590/* Long Multiply Parser
9591 UMULL RdLo, RdHi, Rm, Rs
9592 SMULL RdLo, RdHi, Rm, Rs
9593 UMLAL RdLo, RdHi, Rm, Rs
9594 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9595
9596static void
c19d1205 9597do_mull (void)
b99bd4ef 9598{
c19d1205
ZW
9599 inst.instruction |= inst.operands[0].reg << 12;
9600 inst.instruction |= inst.operands[1].reg << 16;
9601 inst.instruction |= inst.operands[2].reg;
9602 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9603
682b27ad
PB
9604 /* rdhi and rdlo must be different. */
9605 if (inst.operands[0].reg == inst.operands[1].reg)
9606 as_tsktsk (_("rdhi and rdlo must be different"));
9607
9608 /* rdhi, rdlo and rm must all be different before armv6. */
9609 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9610 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9611 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9612 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9613}
b99bd4ef 9614
c19d1205
ZW
9615static void
9616do_nop (void)
9617{
e7495e45
NS
9618 if (inst.operands[0].present
9619 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9620 {
9621 /* Architectural NOP hints are CPSR sets with no bits selected. */
9622 inst.instruction &= 0xf0000000;
e7495e45
NS
9623 inst.instruction |= 0x0320f000;
9624 if (inst.operands[0].present)
9625 inst.instruction |= inst.operands[0].imm;
c19d1205 9626 }
b99bd4ef
NC
9627}
9628
c19d1205
ZW
9629/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9630 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9631 Condition defaults to COND_ALWAYS.
9632 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9633
9634static void
c19d1205 9635do_pkhbt (void)
b99bd4ef 9636{
c19d1205
ZW
9637 inst.instruction |= inst.operands[0].reg << 12;
9638 inst.instruction |= inst.operands[1].reg << 16;
9639 inst.instruction |= inst.operands[2].reg;
9640 if (inst.operands[3].present)
9641 encode_arm_shift (3);
9642}
b99bd4ef 9643
c19d1205 9644/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9645
c19d1205
ZW
9646static void
9647do_pkhtb (void)
9648{
9649 if (!inst.operands[3].present)
b99bd4ef 9650 {
c19d1205
ZW
9651 /* If the shift specifier is omitted, turn the instruction
9652 into pkhbt rd, rm, rn. */
9653 inst.instruction &= 0xfff00010;
9654 inst.instruction |= inst.operands[0].reg << 12;
9655 inst.instruction |= inst.operands[1].reg;
9656 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9657 }
9658 else
9659 {
c19d1205
ZW
9660 inst.instruction |= inst.operands[0].reg << 12;
9661 inst.instruction |= inst.operands[1].reg << 16;
9662 inst.instruction |= inst.operands[2].reg;
9663 encode_arm_shift (3);
b99bd4ef
NC
9664 }
9665}
9666
c19d1205 9667/* ARMv5TE: Preload-Cache
60e5ef9f 9668 MP Extensions: Preload for write
c19d1205 9669
60e5ef9f 9670 PLD(W) <addr_mode>
c19d1205
ZW
9671
9672 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9673
9674static void
c19d1205 9675do_pld (void)
b99bd4ef 9676{
c19d1205
ZW
9677 constraint (!inst.operands[0].isreg,
9678 _("'[' expected after PLD mnemonic"));
9679 constraint (inst.operands[0].postind,
9680 _("post-indexed expression used in preload instruction"));
9681 constraint (inst.operands[0].writeback,
9682 _("writeback used in preload instruction"));
9683 constraint (!inst.operands[0].preind,
9684 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9685 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9686}
b99bd4ef 9687
62b3e311
PB
9688/* ARMv7: PLI <addr_mode> */
9689static void
9690do_pli (void)
9691{
9692 constraint (!inst.operands[0].isreg,
9693 _("'[' expected after PLI mnemonic"));
9694 constraint (inst.operands[0].postind,
9695 _("post-indexed expression used in preload instruction"));
9696 constraint (inst.operands[0].writeback,
9697 _("writeback used in preload instruction"));
9698 constraint (!inst.operands[0].preind,
9699 _("unindexed addressing used in preload instruction"));
9700 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9701 inst.instruction &= ~PRE_INDEX;
9702}
9703
c19d1205
ZW
9704static void
9705do_push_pop (void)
9706{
5e0d7f77
MP
9707 constraint (inst.operands[0].writeback,
9708 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9709 inst.operands[1] = inst.operands[0];
9710 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9711 inst.operands[0].isreg = 1;
9712 inst.operands[0].writeback = 1;
9713 inst.operands[0].reg = REG_SP;
6530b175 9714 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9715}
b99bd4ef 9716
c19d1205
ZW
9717/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9718 word at the specified address and the following word
9719 respectively.
9720 Unconditionally executed.
9721 Error if Rn is R15. */
b99bd4ef 9722
c19d1205
ZW
9723static void
9724do_rfe (void)
9725{
9726 inst.instruction |= inst.operands[0].reg << 16;
9727 if (inst.operands[0].writeback)
9728 inst.instruction |= WRITE_BACK;
9729}
b99bd4ef 9730
c19d1205 9731/* ARM V6 ssat (argument parse). */
b99bd4ef 9732
c19d1205
ZW
9733static void
9734do_ssat (void)
9735{
9736 inst.instruction |= inst.operands[0].reg << 12;
9737 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9738 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9739
c19d1205
ZW
9740 if (inst.operands[3].present)
9741 encode_arm_shift (3);
b99bd4ef
NC
9742}
9743
c19d1205 9744/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9745
9746static void
c19d1205 9747do_usat (void)
b99bd4ef 9748{
c19d1205
ZW
9749 inst.instruction |= inst.operands[0].reg << 12;
9750 inst.instruction |= inst.operands[1].imm << 16;
9751 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9752
c19d1205
ZW
9753 if (inst.operands[3].present)
9754 encode_arm_shift (3);
b99bd4ef
NC
9755}
9756
c19d1205 9757/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9758
9759static void
c19d1205 9760do_ssat16 (void)
09d92015 9761{
c19d1205
ZW
9762 inst.instruction |= inst.operands[0].reg << 12;
9763 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9764 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9765}
9766
c19d1205
ZW
9767static void
9768do_usat16 (void)
a737bd4d 9769{
c19d1205
ZW
9770 inst.instruction |= inst.operands[0].reg << 12;
9771 inst.instruction |= inst.operands[1].imm << 16;
9772 inst.instruction |= inst.operands[2].reg;
9773}
a737bd4d 9774
c19d1205
ZW
9775/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9776 preserving the other bits.
a737bd4d 9777
c19d1205
ZW
9778 setend <endian_specifier>, where <endian_specifier> is either
9779 BE or LE. */
a737bd4d 9780
c19d1205
ZW
9781static void
9782do_setend (void)
9783{
12e37cbc
MGD
9784 if (warn_on_deprecated
9785 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9786 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9787
c19d1205
ZW
9788 if (inst.operands[0].imm)
9789 inst.instruction |= 0x200;
a737bd4d
NC
9790}
9791
9792static void
c19d1205 9793do_shift (void)
a737bd4d 9794{
c19d1205
ZW
9795 unsigned int Rm = (inst.operands[1].present
9796 ? inst.operands[1].reg
9797 : inst.operands[0].reg);
a737bd4d 9798
c19d1205
ZW
9799 inst.instruction |= inst.operands[0].reg << 12;
9800 inst.instruction |= Rm;
9801 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9802 {
c19d1205
ZW
9803 inst.instruction |= inst.operands[2].reg << 8;
9804 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9805 /* PR 12854: Error on extraneous shifts. */
9806 constraint (inst.operands[2].shifted,
9807 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9808 }
9809 else
e2b0ab59 9810 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9811}
9812
09d92015 9813static void
3eb17e6b 9814do_smc (void)
09d92015 9815{
e2b0ab59
AV
9816 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
9817 inst.relocs[0].pc_rel = 0;
09d92015
MM
9818}
9819
90ec0d68
MGD
9820static void
9821do_hvc (void)
9822{
e2b0ab59
AV
9823 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
9824 inst.relocs[0].pc_rel = 0;
90ec0d68
MGD
9825}
9826
09d92015 9827static void
c19d1205 9828do_swi (void)
09d92015 9829{
e2b0ab59
AV
9830 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
9831 inst.relocs[0].pc_rel = 0;
09d92015
MM
9832}
9833
ddfded2f
MW
9834static void
9835do_setpan (void)
9836{
9837 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9838 _("selected processor does not support SETPAN instruction"));
9839
9840 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9841}
9842
9843static void
9844do_t_setpan (void)
9845{
9846 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9847 _("selected processor does not support SETPAN instruction"));
9848
9849 inst.instruction |= (inst.operands[0].imm << 3);
9850}
9851
c19d1205
ZW
9852/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9853 SMLAxy{cond} Rd,Rm,Rs,Rn
9854 SMLAWy{cond} Rd,Rm,Rs,Rn
9855 Error if any register is R15. */
e16bb312 9856
c19d1205
ZW
9857static void
9858do_smla (void)
e16bb312 9859{
c19d1205
ZW
9860 inst.instruction |= inst.operands[0].reg << 16;
9861 inst.instruction |= inst.operands[1].reg;
9862 inst.instruction |= inst.operands[2].reg << 8;
9863 inst.instruction |= inst.operands[3].reg << 12;
9864}
a737bd4d 9865
c19d1205
ZW
9866/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9867 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9868 Error if any register is R15.
9869 Warning if Rdlo == Rdhi. */
a737bd4d 9870
c19d1205
ZW
9871static void
9872do_smlal (void)
9873{
9874 inst.instruction |= inst.operands[0].reg << 12;
9875 inst.instruction |= inst.operands[1].reg << 16;
9876 inst.instruction |= inst.operands[2].reg;
9877 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9878
c19d1205
ZW
9879 if (inst.operands[0].reg == inst.operands[1].reg)
9880 as_tsktsk (_("rdhi and rdlo must be different"));
9881}
a737bd4d 9882
c19d1205
ZW
9883/* ARM V5E (El Segundo) signed-multiply (argument parse)
9884 SMULxy{cond} Rd,Rm,Rs
9885 Error if any register is R15. */
a737bd4d 9886
c19d1205
ZW
9887static void
9888do_smul (void)
9889{
9890 inst.instruction |= inst.operands[0].reg << 16;
9891 inst.instruction |= inst.operands[1].reg;
9892 inst.instruction |= inst.operands[2].reg << 8;
9893}
a737bd4d 9894
b6702015
PB
9895/* ARM V6 srs (argument parse). The variable fields in the encoding are
9896 the same for both ARM and Thumb-2. */
a737bd4d 9897
c19d1205
ZW
9898static void
9899do_srs (void)
9900{
b6702015
PB
9901 int reg;
9902
9903 if (inst.operands[0].present)
9904 {
9905 reg = inst.operands[0].reg;
fdfde340 9906 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9907 }
9908 else
fdfde340 9909 reg = REG_SP;
b6702015
PB
9910
9911 inst.instruction |= reg << 16;
9912 inst.instruction |= inst.operands[1].imm;
9913 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9914 inst.instruction |= WRITE_BACK;
9915}
a737bd4d 9916
c19d1205 9917/* ARM V6 strex (argument parse). */
a737bd4d 9918
c19d1205
ZW
9919static void
9920do_strex (void)
9921{
9922 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9923 || inst.operands[2].postind || inst.operands[2].writeback
9924 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9925 || inst.operands[2].negative
9926 /* See comment in do_ldrex(). */
9927 || (inst.operands[2].reg == REG_PC),
9928 BAD_ADDR_MODE);
a737bd4d 9929
c19d1205
ZW
9930 constraint (inst.operands[0].reg == inst.operands[1].reg
9931 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9932
e2b0ab59
AV
9933 constraint (inst.relocs[0].exp.X_op != O_constant
9934 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9935 _("offset must be zero in ARM encoding"));
a737bd4d 9936
c19d1205
ZW
9937 inst.instruction |= inst.operands[0].reg << 12;
9938 inst.instruction |= inst.operands[1].reg;
9939 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 9940 inst.relocs[0].type = BFD_RELOC_UNUSED;
e16bb312
NC
9941}
9942
877807f8
NC
9943static void
9944do_t_strexbh (void)
9945{
9946 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9947 || inst.operands[2].postind || inst.operands[2].writeback
9948 || inst.operands[2].immisreg || inst.operands[2].shifted
9949 || inst.operands[2].negative,
9950 BAD_ADDR_MODE);
9951
9952 constraint (inst.operands[0].reg == inst.operands[1].reg
9953 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9954
9955 do_rm_rd_rn ();
9956}
9957
e16bb312 9958static void
c19d1205 9959do_strexd (void)
e16bb312 9960{
c19d1205
ZW
9961 constraint (inst.operands[1].reg % 2 != 0,
9962 _("even register required"));
9963 constraint (inst.operands[2].present
9964 && inst.operands[2].reg != inst.operands[1].reg + 1,
9965 _("can only store two consecutive registers"));
9966 /* If op 2 were present and equal to PC, this function wouldn't
9967 have been called in the first place. */
9968 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9969
c19d1205
ZW
9970 constraint (inst.operands[0].reg == inst.operands[1].reg
9971 || inst.operands[0].reg == inst.operands[1].reg + 1
9972 || inst.operands[0].reg == inst.operands[3].reg,
9973 BAD_OVERLAP);
e16bb312 9974
c19d1205
ZW
9975 inst.instruction |= inst.operands[0].reg << 12;
9976 inst.instruction |= inst.operands[1].reg;
9977 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9978}
9979
9eb6c0f1
MGD
9980/* ARM V8 STRL. */
9981static void
4b8c8c02 9982do_stlex (void)
9eb6c0f1
MGD
9983{
9984 constraint (inst.operands[0].reg == inst.operands[1].reg
9985 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9986
9987 do_rd_rm_rn ();
9988}
9989
9990static void
4b8c8c02 9991do_t_stlex (void)
9eb6c0f1
MGD
9992{
9993 constraint (inst.operands[0].reg == inst.operands[1].reg
9994 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9995
9996 do_rm_rd_rn ();
9997}
9998
c19d1205
ZW
9999/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
10000 extends it to 32-bits, and adds the result to a value in another
10001 register. You can specify a rotation by 0, 8, 16, or 24 bits
10002 before extracting the 16-bit value.
10003 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
10004 Condition defaults to COND_ALWAYS.
10005 Error if any register uses R15. */
10006
e16bb312 10007static void
c19d1205 10008do_sxtah (void)
e16bb312 10009{
c19d1205
ZW
10010 inst.instruction |= inst.operands[0].reg << 12;
10011 inst.instruction |= inst.operands[1].reg << 16;
10012 inst.instruction |= inst.operands[2].reg;
10013 inst.instruction |= inst.operands[3].imm << 10;
10014}
e16bb312 10015
c19d1205 10016/* ARM V6 SXTH.
e16bb312 10017
c19d1205
ZW
10018 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
10019 Condition defaults to COND_ALWAYS.
10020 Error if any register uses R15. */
e16bb312
NC
10021
10022static void
c19d1205 10023do_sxth (void)
e16bb312 10024{
c19d1205
ZW
10025 inst.instruction |= inst.operands[0].reg << 12;
10026 inst.instruction |= inst.operands[1].reg;
10027 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 10028}
c19d1205
ZW
10029\f
10030/* VFP instructions. In a logical order: SP variant first, monad
10031 before dyad, arithmetic then move then load/store. */
e16bb312
NC
10032
10033static void
c19d1205 10034do_vfp_sp_monadic (void)
e16bb312 10035{
5287ad62
JB
10036 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10037 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10038}
10039
10040static void
c19d1205 10041do_vfp_sp_dyadic (void)
e16bb312 10042{
5287ad62
JB
10043 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10044 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10045 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10046}
10047
10048static void
c19d1205 10049do_vfp_sp_compare_z (void)
e16bb312 10050{
5287ad62 10051 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
10052}
10053
10054static void
c19d1205 10055do_vfp_dp_sp_cvt (void)
e16bb312 10056{
5287ad62
JB
10057 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10058 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10059}
10060
10061static void
c19d1205 10062do_vfp_sp_dp_cvt (void)
e16bb312 10063{
5287ad62
JB
10064 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10065 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
10066}
10067
10068static void
c19d1205 10069do_vfp_reg_from_sp (void)
e16bb312 10070{
c19d1205 10071 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 10072 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
10073}
10074
10075static void
c19d1205 10076do_vfp_reg2_from_sp2 (void)
e16bb312 10077{
c19d1205
ZW
10078 constraint (inst.operands[2].imm != 2,
10079 _("only two consecutive VFP SP registers allowed here"));
10080 inst.instruction |= inst.operands[0].reg << 12;
10081 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 10082 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10083}
10084
10085static void
c19d1205 10086do_vfp_sp_from_reg (void)
e16bb312 10087{
5287ad62 10088 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 10089 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
10090}
10091
10092static void
c19d1205 10093do_vfp_sp2_from_reg2 (void)
e16bb312 10094{
c19d1205
ZW
10095 constraint (inst.operands[0].imm != 2,
10096 _("only two consecutive VFP SP registers allowed here"));
5287ad62 10097 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
10098 inst.instruction |= inst.operands[1].reg << 12;
10099 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
10100}
10101
10102static void
c19d1205 10103do_vfp_sp_ldst (void)
e16bb312 10104{
5287ad62 10105 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 10106 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10107}
10108
10109static void
c19d1205 10110do_vfp_dp_ldst (void)
e16bb312 10111{
5287ad62 10112 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 10113 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10114}
10115
c19d1205 10116
e16bb312 10117static void
c19d1205 10118vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10119{
c19d1205
ZW
10120 if (inst.operands[0].writeback)
10121 inst.instruction |= WRITE_BACK;
10122 else
10123 constraint (ldstm_type != VFP_LDSTMIA,
10124 _("this addressing mode requires base-register writeback"));
10125 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10126 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 10127 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
10128}
10129
10130static void
c19d1205 10131vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10132{
c19d1205 10133 int count;
e16bb312 10134
c19d1205
ZW
10135 if (inst.operands[0].writeback)
10136 inst.instruction |= WRITE_BACK;
10137 else
10138 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
10139 _("this addressing mode requires base-register writeback"));
e16bb312 10140
c19d1205 10141 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10142 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 10143
c19d1205
ZW
10144 count = inst.operands[1].imm << 1;
10145 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
10146 count += 1;
e16bb312 10147
c19d1205 10148 inst.instruction |= count;
e16bb312
NC
10149}
10150
10151static void
c19d1205 10152do_vfp_sp_ldstmia (void)
e16bb312 10153{
c19d1205 10154 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10155}
10156
10157static void
c19d1205 10158do_vfp_sp_ldstmdb (void)
e16bb312 10159{
c19d1205 10160 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10161}
10162
10163static void
c19d1205 10164do_vfp_dp_ldstmia (void)
e16bb312 10165{
c19d1205 10166 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10167}
10168
10169static void
c19d1205 10170do_vfp_dp_ldstmdb (void)
e16bb312 10171{
c19d1205 10172 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10173}
10174
10175static void
c19d1205 10176do_vfp_xp_ldstmia (void)
e16bb312 10177{
c19d1205
ZW
10178 vfp_dp_ldstm (VFP_LDSTMIAX);
10179}
e16bb312 10180
c19d1205
ZW
10181static void
10182do_vfp_xp_ldstmdb (void)
10183{
10184 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 10185}
5287ad62
JB
10186
10187static void
10188do_vfp_dp_rd_rm (void)
10189{
10190 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10191 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10192}
10193
10194static void
10195do_vfp_dp_rn_rd (void)
10196{
10197 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
10198 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10199}
10200
10201static void
10202do_vfp_dp_rd_rn (void)
10203{
10204 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10205 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10206}
10207
10208static void
10209do_vfp_dp_rd_rn_rm (void)
10210{
10211 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10212 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10213 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
10214}
10215
10216static void
10217do_vfp_dp_rd (void)
10218{
10219 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10220}
10221
10222static void
10223do_vfp_dp_rm_rd_rn (void)
10224{
10225 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
10226 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10227 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
10228}
10229
10230/* VFPv3 instructions. */
10231static void
10232do_vfp_sp_const (void)
10233{
10234 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
10235 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10236 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10237}
10238
10239static void
10240do_vfp_dp_const (void)
10241{
10242 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
10243 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10244 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10245}
10246
10247static void
10248vfp_conv (int srcsize)
10249{
5f1af56b
MGD
10250 int immbits = srcsize - inst.operands[1].imm;
10251
fa94de6b
RM
10252 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10253 {
5f1af56b 10254 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 10255 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
10256 inst.error = _("immediate value out of range, expected range [0, 16]");
10257 return;
10258 }
fa94de6b 10259 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
10260 {
10261 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 10262 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
10263 inst.error = _("immediate value out of range, expected range [1, 32]");
10264 return;
10265 }
10266
5287ad62
JB
10267 inst.instruction |= (immbits & 1) << 5;
10268 inst.instruction |= (immbits >> 1);
10269}
10270
10271static void
10272do_vfp_sp_conv_16 (void)
10273{
10274 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10275 vfp_conv (16);
10276}
10277
10278static void
10279do_vfp_dp_conv_16 (void)
10280{
10281 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10282 vfp_conv (16);
10283}
10284
10285static void
10286do_vfp_sp_conv_32 (void)
10287{
10288 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10289 vfp_conv (32);
10290}
10291
10292static void
10293do_vfp_dp_conv_32 (void)
10294{
10295 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10296 vfp_conv (32);
10297}
c19d1205
ZW
10298\f
10299/* FPA instructions. Also in a logical order. */
e16bb312 10300
c19d1205
ZW
10301static void
10302do_fpa_cmp (void)
10303{
10304 inst.instruction |= inst.operands[0].reg << 16;
10305 inst.instruction |= inst.operands[1].reg;
10306}
b99bd4ef
NC
10307
10308static void
c19d1205 10309do_fpa_ldmstm (void)
b99bd4ef 10310{
c19d1205
ZW
10311 inst.instruction |= inst.operands[0].reg << 12;
10312 switch (inst.operands[1].imm)
10313 {
10314 case 1: inst.instruction |= CP_T_X; break;
10315 case 2: inst.instruction |= CP_T_Y; break;
10316 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10317 case 4: break;
10318 default: abort ();
10319 }
b99bd4ef 10320
c19d1205
ZW
10321 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10322 {
10323 /* The instruction specified "ea" or "fd", so we can only accept
10324 [Rn]{!}. The instruction does not really support stacking or
10325 unstacking, so we have to emulate these by setting appropriate
10326 bits and offsets. */
e2b0ab59
AV
10327 constraint (inst.relocs[0].exp.X_op != O_constant
10328 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 10329 _("this instruction does not support indexing"));
b99bd4ef 10330
c19d1205 10331 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
e2b0ab59 10332 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 10333
c19d1205 10334 if (!(inst.instruction & INDEX_UP))
e2b0ab59 10335 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
b99bd4ef 10336
c19d1205
ZW
10337 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10338 {
10339 inst.operands[2].preind = 0;
10340 inst.operands[2].postind = 1;
10341 }
10342 }
b99bd4ef 10343
c19d1205 10344 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 10345}
c19d1205
ZW
10346\f
10347/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 10348
c19d1205
ZW
10349static void
10350do_iwmmxt_tandorc (void)
10351{
10352 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10353}
b99bd4ef 10354
c19d1205
ZW
10355static void
10356do_iwmmxt_textrc (void)
10357{
10358 inst.instruction |= inst.operands[0].reg << 12;
10359 inst.instruction |= inst.operands[1].imm;
10360}
b99bd4ef
NC
10361
10362static void
c19d1205 10363do_iwmmxt_textrm (void)
b99bd4ef 10364{
c19d1205
ZW
10365 inst.instruction |= inst.operands[0].reg << 12;
10366 inst.instruction |= inst.operands[1].reg << 16;
10367 inst.instruction |= inst.operands[2].imm;
10368}
b99bd4ef 10369
c19d1205
ZW
10370static void
10371do_iwmmxt_tinsr (void)
10372{
10373 inst.instruction |= inst.operands[0].reg << 16;
10374 inst.instruction |= inst.operands[1].reg << 12;
10375 inst.instruction |= inst.operands[2].imm;
10376}
b99bd4ef 10377
c19d1205
ZW
10378static void
10379do_iwmmxt_tmia (void)
10380{
10381 inst.instruction |= inst.operands[0].reg << 5;
10382 inst.instruction |= inst.operands[1].reg;
10383 inst.instruction |= inst.operands[2].reg << 12;
10384}
b99bd4ef 10385
c19d1205
ZW
10386static void
10387do_iwmmxt_waligni (void)
10388{
10389 inst.instruction |= inst.operands[0].reg << 12;
10390 inst.instruction |= inst.operands[1].reg << 16;
10391 inst.instruction |= inst.operands[2].reg;
10392 inst.instruction |= inst.operands[3].imm << 20;
10393}
b99bd4ef 10394
2d447fca
JM
10395static void
10396do_iwmmxt_wmerge (void)
10397{
10398 inst.instruction |= inst.operands[0].reg << 12;
10399 inst.instruction |= inst.operands[1].reg << 16;
10400 inst.instruction |= inst.operands[2].reg;
10401 inst.instruction |= inst.operands[3].imm << 21;
10402}
10403
c19d1205
ZW
10404static void
10405do_iwmmxt_wmov (void)
10406{
10407 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10408 inst.instruction |= inst.operands[0].reg << 12;
10409 inst.instruction |= inst.operands[1].reg << 16;
10410 inst.instruction |= inst.operands[1].reg;
10411}
b99bd4ef 10412
c19d1205
ZW
10413static void
10414do_iwmmxt_wldstbh (void)
10415{
8f06b2d8 10416 int reloc;
c19d1205 10417 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10418 if (thumb_mode)
10419 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10420 else
10421 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10422 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10423}
10424
c19d1205
ZW
10425static void
10426do_iwmmxt_wldstw (void)
10427{
10428 /* RIWR_RIWC clears .isreg for a control register. */
10429 if (!inst.operands[0].isreg)
10430 {
10431 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10432 inst.instruction |= 0xf0000000;
10433 }
b99bd4ef 10434
c19d1205
ZW
10435 inst.instruction |= inst.operands[0].reg << 12;
10436 encode_arm_cp_address (1, TRUE, TRUE, 0);
10437}
b99bd4ef
NC
10438
10439static void
c19d1205 10440do_iwmmxt_wldstd (void)
b99bd4ef 10441{
c19d1205 10442 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10443 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10444 && inst.operands[1].immisreg)
10445 {
10446 inst.instruction &= ~0x1a000ff;
eff0bc54 10447 inst.instruction |= (0xfU << 28);
2d447fca
JM
10448 if (inst.operands[1].preind)
10449 inst.instruction |= PRE_INDEX;
10450 if (!inst.operands[1].negative)
10451 inst.instruction |= INDEX_UP;
10452 if (inst.operands[1].writeback)
10453 inst.instruction |= WRITE_BACK;
10454 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 10455 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
2d447fca
JM
10456 inst.instruction |= inst.operands[1].imm;
10457 }
10458 else
10459 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10460}
b99bd4ef 10461
c19d1205
ZW
10462static void
10463do_iwmmxt_wshufh (void)
10464{
10465 inst.instruction |= inst.operands[0].reg << 12;
10466 inst.instruction |= inst.operands[1].reg << 16;
10467 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10468 inst.instruction |= (inst.operands[2].imm & 0x0f);
10469}
b99bd4ef 10470
c19d1205
ZW
10471static void
10472do_iwmmxt_wzero (void)
10473{
10474 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10475 inst.instruction |= inst.operands[0].reg;
10476 inst.instruction |= inst.operands[0].reg << 12;
10477 inst.instruction |= inst.operands[0].reg << 16;
10478}
2d447fca
JM
10479
10480static void
10481do_iwmmxt_wrwrwr_or_imm5 (void)
10482{
10483 if (inst.operands[2].isreg)
10484 do_rd_rn_rm ();
10485 else {
10486 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10487 _("immediate operand requires iWMMXt2"));
10488 do_rd_rn ();
10489 if (inst.operands[2].imm == 0)
10490 {
10491 switch ((inst.instruction >> 20) & 0xf)
10492 {
10493 case 4:
10494 case 5:
10495 case 6:
5f4273c7 10496 case 7:
2d447fca
JM
10497 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10498 inst.operands[2].imm = 16;
10499 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10500 break;
10501 case 8:
10502 case 9:
10503 case 10:
10504 case 11:
10505 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10506 inst.operands[2].imm = 32;
10507 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10508 break;
10509 case 12:
10510 case 13:
10511 case 14:
10512 case 15:
10513 {
10514 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10515 unsigned long wrn;
10516 wrn = (inst.instruction >> 16) & 0xf;
10517 inst.instruction &= 0xff0fff0f;
10518 inst.instruction |= wrn;
10519 /* Bail out here; the instruction is now assembled. */
10520 return;
10521 }
10522 }
10523 }
10524 /* Map 32 -> 0, etc. */
10525 inst.operands[2].imm &= 0x1f;
eff0bc54 10526 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10527 }
10528}
c19d1205
ZW
10529\f
10530/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10531 operations first, then control, shift, and load/store. */
b99bd4ef 10532
c19d1205 10533/* Insns like "foo X,Y,Z". */
b99bd4ef 10534
c19d1205
ZW
10535static void
10536do_mav_triple (void)
10537{
10538 inst.instruction |= inst.operands[0].reg << 16;
10539 inst.instruction |= inst.operands[1].reg;
10540 inst.instruction |= inst.operands[2].reg << 12;
10541}
b99bd4ef 10542
c19d1205
ZW
10543/* Insns like "foo W,X,Y,Z".
10544 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10545
c19d1205
ZW
10546static void
10547do_mav_quad (void)
10548{
10549 inst.instruction |= inst.operands[0].reg << 5;
10550 inst.instruction |= inst.operands[1].reg << 12;
10551 inst.instruction |= inst.operands[2].reg << 16;
10552 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10553}
10554
c19d1205
ZW
10555/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10556static void
10557do_mav_dspsc (void)
a737bd4d 10558{
c19d1205
ZW
10559 inst.instruction |= inst.operands[1].reg << 12;
10560}
a737bd4d 10561
c19d1205
ZW
10562/* Maverick shift immediate instructions.
10563 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10564 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10565
c19d1205
ZW
10566static void
10567do_mav_shift (void)
10568{
10569 int imm = inst.operands[2].imm;
a737bd4d 10570
c19d1205
ZW
10571 inst.instruction |= inst.operands[0].reg << 12;
10572 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10573
c19d1205
ZW
10574 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10575 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10576 Bit 4 should be 0. */
10577 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10578
c19d1205
ZW
10579 inst.instruction |= imm;
10580}
10581\f
10582/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10583
c19d1205
ZW
10584/* Xscale multiply-accumulate (argument parse)
10585 MIAcc acc0,Rm,Rs
10586 MIAPHcc acc0,Rm,Rs
10587 MIAxycc acc0,Rm,Rs. */
a737bd4d 10588
c19d1205
ZW
10589static void
10590do_xsc_mia (void)
10591{
10592 inst.instruction |= inst.operands[1].reg;
10593 inst.instruction |= inst.operands[2].reg << 12;
10594}
a737bd4d 10595
c19d1205 10596/* Xscale move-accumulator-register (argument parse)
a737bd4d 10597
c19d1205 10598 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10599
c19d1205
ZW
10600static void
10601do_xsc_mar (void)
10602{
10603 inst.instruction |= inst.operands[1].reg << 12;
10604 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10605}
10606
c19d1205 10607/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10608
c19d1205 10609 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10610
10611static void
c19d1205 10612do_xsc_mra (void)
b99bd4ef 10613{
c19d1205
ZW
10614 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10615 inst.instruction |= inst.operands[0].reg << 12;
10616 inst.instruction |= inst.operands[1].reg << 16;
10617}
10618\f
10619/* Encoding functions relevant only to Thumb. */
b99bd4ef 10620
c19d1205
ZW
10621/* inst.operands[i] is a shifted-register operand; encode
10622 it into inst.instruction in the format used by Thumb32. */
10623
10624static void
10625encode_thumb32_shifted_operand (int i)
10626{
e2b0ab59 10627 unsigned int value = inst.relocs[0].exp.X_add_number;
c19d1205 10628 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10629
9c3c69f2
PB
10630 constraint (inst.operands[i].immisreg,
10631 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10632 inst.instruction |= inst.operands[i].reg;
10633 if (shift == SHIFT_RRX)
10634 inst.instruction |= SHIFT_ROR << 4;
10635 else
b99bd4ef 10636 {
e2b0ab59 10637 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
10638 _("expression too complex"));
10639
10640 constraint (value > 32
10641 || (value == 32 && (shift == SHIFT_LSL
10642 || shift == SHIFT_ROR)),
10643 _("shift expression is too large"));
10644
10645 if (value == 0)
10646 shift = SHIFT_LSL;
10647 else if (value == 32)
10648 value = 0;
10649
10650 inst.instruction |= shift << 4;
10651 inst.instruction |= (value & 0x1c) << 10;
10652 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10653 }
c19d1205 10654}
b99bd4ef 10655
b99bd4ef 10656
c19d1205
ZW
10657/* inst.operands[i] was set up by parse_address. Encode it into a
10658 Thumb32 format load or store instruction. Reject forms that cannot
10659 be used with such instructions. If is_t is true, reject forms that
10660 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10661 that cannot be used with a D instruction. If it is a store insn,
10662 reject PC in Rn. */
b99bd4ef 10663
c19d1205
ZW
10664static void
10665encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10666{
5be8be5d 10667 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10668
10669 constraint (!inst.operands[i].isreg,
53365c0d 10670 _("Instruction does not support =N addresses"));
b99bd4ef 10671
c19d1205
ZW
10672 inst.instruction |= inst.operands[i].reg << 16;
10673 if (inst.operands[i].immisreg)
b99bd4ef 10674 {
5be8be5d 10675 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10676 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10677 constraint (inst.operands[i].negative,
10678 _("Thumb does not support negative register indexing"));
10679 constraint (inst.operands[i].postind,
10680 _("Thumb does not support register post-indexing"));
10681 constraint (inst.operands[i].writeback,
10682 _("Thumb does not support register indexing with writeback"));
10683 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10684 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10685
f40d1643 10686 inst.instruction |= inst.operands[i].imm;
c19d1205 10687 if (inst.operands[i].shifted)
b99bd4ef 10688 {
e2b0ab59 10689 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 10690 _("expression too complex"));
e2b0ab59
AV
10691 constraint (inst.relocs[0].exp.X_add_number < 0
10692 || inst.relocs[0].exp.X_add_number > 3,
c19d1205 10693 _("shift out of range"));
e2b0ab59 10694 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
c19d1205 10695 }
e2b0ab59 10696 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205
ZW
10697 }
10698 else if (inst.operands[i].preind)
10699 {
5be8be5d 10700 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10701 constraint (is_t && inst.operands[i].writeback,
c19d1205 10702 _("cannot use writeback with this instruction"));
4755303e
WN
10703 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10704 BAD_PC_ADDRESSING);
c19d1205
ZW
10705
10706 if (is_d)
10707 {
10708 inst.instruction |= 0x01000000;
10709 if (inst.operands[i].writeback)
10710 inst.instruction |= 0x00200000;
b99bd4ef 10711 }
c19d1205 10712 else
b99bd4ef 10713 {
c19d1205
ZW
10714 inst.instruction |= 0x00000c00;
10715 if (inst.operands[i].writeback)
10716 inst.instruction |= 0x00000100;
b99bd4ef 10717 }
e2b0ab59 10718 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10719 }
c19d1205 10720 else if (inst.operands[i].postind)
b99bd4ef 10721 {
9c2799c2 10722 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10723 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10724 constraint (is_t, _("cannot use post-indexing with this instruction"));
10725
10726 if (is_d)
10727 inst.instruction |= 0x00200000;
10728 else
10729 inst.instruction |= 0x00000900;
e2b0ab59 10730 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
c19d1205
ZW
10731 }
10732 else /* unindexed - only for coprocessor */
10733 inst.error = _("instruction does not accept unindexed addressing");
10734}
10735
10736/* Table of Thumb instructions which exist in both 16- and 32-bit
10737 encodings (the latter only in post-V6T2 cores). The index is the
10738 value used in the insns table below. When there is more than one
10739 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10740 holds variant (1).
10741 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10742#define T16_32_TAB \
21d799b5
NC
10743 X(_adc, 4140, eb400000), \
10744 X(_adcs, 4140, eb500000), \
10745 X(_add, 1c00, eb000000), \
10746 X(_adds, 1c00, eb100000), \
10747 X(_addi, 0000, f1000000), \
10748 X(_addis, 0000, f1100000), \
10749 X(_add_pc,000f, f20f0000), \
10750 X(_add_sp,000d, f10d0000), \
10751 X(_adr, 000f, f20f0000), \
10752 X(_and, 4000, ea000000), \
10753 X(_ands, 4000, ea100000), \
10754 X(_asr, 1000, fa40f000), \
10755 X(_asrs, 1000, fa50f000), \
10756 X(_b, e000, f000b000), \
10757 X(_bcond, d000, f0008000), \
4389b29a 10758 X(_bf, 0000, f040e001), \
f6b2b12d 10759 X(_bfcsel,0000, f000e001), \
f1c7f421 10760 X(_bfx, 0000, f060e001), \
65d1bc05 10761 X(_bfl, 0000, f000c001), \
f1c7f421 10762 X(_bflx, 0000, f070e001), \
21d799b5
NC
10763 X(_bic, 4380, ea200000), \
10764 X(_bics, 4380, ea300000), \
10765 X(_cmn, 42c0, eb100f00), \
10766 X(_cmp, 2800, ebb00f00), \
10767 X(_cpsie, b660, f3af8400), \
10768 X(_cpsid, b670, f3af8600), \
10769 X(_cpy, 4600, ea4f0000), \
10770 X(_dec_sp,80dd, f1ad0d00), \
60f993ce 10771 X(_dls, 0000, f040e001), \
21d799b5
NC
10772 X(_eor, 4040, ea800000), \
10773 X(_eors, 4040, ea900000), \
10774 X(_inc_sp,00dd, f10d0d00), \
10775 X(_ldmia, c800, e8900000), \
10776 X(_ldr, 6800, f8500000), \
10777 X(_ldrb, 7800, f8100000), \
10778 X(_ldrh, 8800, f8300000), \
10779 X(_ldrsb, 5600, f9100000), \
10780 X(_ldrsh, 5e00, f9300000), \
10781 X(_ldr_pc,4800, f85f0000), \
10782 X(_ldr_pc2,4800, f85f0000), \
10783 X(_ldr_sp,9800, f85d0000), \
60f993ce 10784 X(_le, 0000, f00fc001), \
21d799b5
NC
10785 X(_lsl, 0000, fa00f000), \
10786 X(_lsls, 0000, fa10f000), \
10787 X(_lsr, 0800, fa20f000), \
10788 X(_lsrs, 0800, fa30f000), \
10789 X(_mov, 2000, ea4f0000), \
10790 X(_movs, 2000, ea5f0000), \
10791 X(_mul, 4340, fb00f000), \
10792 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10793 X(_mvn, 43c0, ea6f0000), \
10794 X(_mvns, 43c0, ea7f0000), \
10795 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10796 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10797 X(_orr, 4300, ea400000), \
10798 X(_orrs, 4300, ea500000), \
10799 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10800 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10801 X(_rev, ba00, fa90f080), \
10802 X(_rev16, ba40, fa90f090), \
10803 X(_revsh, bac0, fa90f0b0), \
10804 X(_ror, 41c0, fa60f000), \
10805 X(_rors, 41c0, fa70f000), \
10806 X(_sbc, 4180, eb600000), \
10807 X(_sbcs, 4180, eb700000), \
10808 X(_stmia, c000, e8800000), \
10809 X(_str, 6000, f8400000), \
10810 X(_strb, 7000, f8000000), \
10811 X(_strh, 8000, f8200000), \
10812 X(_str_sp,9000, f84d0000), \
10813 X(_sub, 1e00, eba00000), \
10814 X(_subs, 1e00, ebb00000), \
10815 X(_subi, 8000, f1a00000), \
10816 X(_subis, 8000, f1b00000), \
10817 X(_sxtb, b240, fa4ff080), \
10818 X(_sxth, b200, fa0ff080), \
10819 X(_tst, 4200, ea100f00), \
10820 X(_uxtb, b2c0, fa5ff080), \
10821 X(_uxth, b280, fa1ff080), \
10822 X(_nop, bf00, f3af8000), \
10823 X(_yield, bf10, f3af8001), \
10824 X(_wfe, bf20, f3af8002), \
10825 X(_wfi, bf30, f3af8003), \
60f993ce 10826 X(_wls, 0000, f040c001), \
53c4b28b 10827 X(_sev, bf40, f3af8004), \
74db7efb
NC
10828 X(_sevl, bf50, f3af8005), \
10829 X(_udf, de00, f7f0a000)
c19d1205
ZW
10830
10831/* To catch errors in encoding functions, the codes are all offset by
10832 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10833 as 16-bit instructions. */
21d799b5 10834#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10835enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10836#undef X
10837
10838#define X(a,b,c) 0x##b
10839static const unsigned short thumb_op16[] = { T16_32_TAB };
10840#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10841#undef X
10842
10843#define X(a,b,c) 0x##c
10844static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10845#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10846#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10847#undef X
10848#undef T16_32_TAB
10849
10850/* Thumb instruction encoders, in alphabetical order. */
10851
92e90b6e 10852/* ADDW or SUBW. */
c921be7d 10853
92e90b6e
PB
10854static void
10855do_t_add_sub_w (void)
10856{
10857 int Rd, Rn;
10858
10859 Rd = inst.operands[0].reg;
10860 Rn = inst.operands[1].reg;
10861
539d4391
NC
10862 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10863 is the SP-{plus,minus}-immediate form of the instruction. */
10864 if (Rn == REG_SP)
10865 constraint (Rd == REG_PC, BAD_PC);
10866 else
10867 reject_bad_reg (Rd);
fdfde340 10868
92e90b6e 10869 inst.instruction |= (Rn << 16) | (Rd << 8);
e2b0ab59 10870 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
92e90b6e
PB
10871}
10872
c19d1205 10873/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 10874 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
10875
10876static void
10877do_t_add_sub (void)
10878{
10879 int Rd, Rs, Rn;
10880
10881 Rd = inst.operands[0].reg;
10882 Rs = (inst.operands[1].present
10883 ? inst.operands[1].reg /* Rd, Rs, foo */
10884 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10885
e07e6e58 10886 if (Rd == REG_PC)
5ee91343 10887 set_pred_insn_type_last ();
e07e6e58 10888
c19d1205
ZW
10889 if (unified_syntax)
10890 {
0110f2b8
PB
10891 bfd_boolean flags;
10892 bfd_boolean narrow;
10893 int opcode;
10894
10895 flags = (inst.instruction == T_MNEM_adds
10896 || inst.instruction == T_MNEM_subs);
10897 if (flags)
5ee91343 10898 narrow = !in_pred_block ();
0110f2b8 10899 else
5ee91343 10900 narrow = in_pred_block ();
c19d1205 10901 if (!inst.operands[2].isreg)
b99bd4ef 10902 {
16805f35
PB
10903 int add;
10904
5c8ed6a4
JW
10905 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10906 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 10907
16805f35
PB
10908 add = (inst.instruction == T_MNEM_add
10909 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10910 opcode = 0;
10911 if (inst.size_req != 4)
10912 {
0110f2b8 10913 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10914 appropriate. */
0110f2b8
PB
10915 if (Rd == REG_SP && Rs == REG_SP && !flags)
10916 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10917 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10918 opcode = T_MNEM_add_sp;
10919 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10920 opcode = T_MNEM_add_pc;
10921 else if (Rd <= 7 && Rs <= 7 && narrow)
10922 {
10923 if (flags)
10924 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10925 else
10926 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10927 }
10928 if (opcode)
10929 {
10930 inst.instruction = THUMB_OP16(opcode);
10931 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59
AV
10932 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10933 || (inst.relocs[0].type
10934 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
a9f02af8
MG
10935 {
10936 if (inst.size_req == 2)
e2b0ab59 10937 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
a9f02af8
MG
10938 else
10939 inst.relax = opcode;
10940 }
0110f2b8
PB
10941 }
10942 else
10943 constraint (inst.size_req == 2, BAD_HIREG);
10944 }
10945 if (inst.size_req == 4
10946 || (inst.size_req != 2 && !opcode))
10947 {
e2b0ab59
AV
10948 constraint ((inst.relocs[0].type
10949 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
10950 && (inst.relocs[0].type
10951 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8 10952 THUMB1_RELOC_ONLY);
efd81785
PB
10953 if (Rd == REG_PC)
10954 {
fdfde340 10955 constraint (add, BAD_PC);
efd81785
PB
10956 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10957 _("only SUBS PC, LR, #const allowed"));
e2b0ab59 10958 constraint (inst.relocs[0].exp.X_op != O_constant,
efd81785 10959 _("expression too complex"));
e2b0ab59
AV
10960 constraint (inst.relocs[0].exp.X_add_number < 0
10961 || inst.relocs[0].exp.X_add_number > 0xff,
efd81785
PB
10962 _("immediate value out of range"));
10963 inst.instruction = T2_SUBS_PC_LR
e2b0ab59
AV
10964 | inst.relocs[0].exp.X_add_number;
10965 inst.relocs[0].type = BFD_RELOC_UNUSED;
efd81785
PB
10966 return;
10967 }
10968 else if (Rs == REG_PC)
16805f35
PB
10969 {
10970 /* Always use addw/subw. */
10971 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
e2b0ab59 10972 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
16805f35
PB
10973 }
10974 else
10975 {
10976 inst.instruction = THUMB_OP32 (inst.instruction);
10977 inst.instruction = (inst.instruction & 0xe1ffffff)
10978 | 0x10000000;
10979 if (flags)
e2b0ab59 10980 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
16805f35 10981 else
e2b0ab59 10982 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
16805f35 10983 }
dc4503c6
PB
10984 inst.instruction |= Rd << 8;
10985 inst.instruction |= Rs << 16;
0110f2b8 10986 }
b99bd4ef 10987 }
c19d1205
ZW
10988 else
10989 {
e2b0ab59 10990 unsigned int value = inst.relocs[0].exp.X_add_number;
5f4cb198
NC
10991 unsigned int shift = inst.operands[2].shift_kind;
10992
c19d1205
ZW
10993 Rn = inst.operands[2].reg;
10994 /* See if we can do this with a 16-bit instruction. */
10995 if (!inst.operands[2].shifted && inst.size_req != 4)
10996 {
e27ec89e
PB
10997 if (Rd > 7 || Rs > 7 || Rn > 7)
10998 narrow = FALSE;
10999
11000 if (narrow)
c19d1205 11001 {
e27ec89e
PB
11002 inst.instruction = ((inst.instruction == T_MNEM_adds
11003 || inst.instruction == T_MNEM_add)
c19d1205
ZW
11004 ? T_OPCODE_ADD_R3
11005 : T_OPCODE_SUB_R3);
11006 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11007 return;
11008 }
b99bd4ef 11009
7e806470 11010 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 11011 {
7e806470
PB
11012 /* Thumb-1 cores (except v6-M) require at least one high
11013 register in a narrow non flag setting add. */
11014 if (Rd > 7 || Rn > 7
11015 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
11016 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 11017 {
7e806470
PB
11018 if (Rd == Rn)
11019 {
11020 Rn = Rs;
11021 Rs = Rd;
11022 }
c19d1205
ZW
11023 inst.instruction = T_OPCODE_ADD_HI;
11024 inst.instruction |= (Rd & 8) << 4;
11025 inst.instruction |= (Rd & 7);
11026 inst.instruction |= Rn << 3;
11027 return;
11028 }
c19d1205
ZW
11029 }
11030 }
c921be7d 11031
fdfde340 11032 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
11033 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11034 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
11035 constraint (Rs == REG_PC, BAD_PC);
11036 reject_bad_reg (Rn);
11037
c19d1205
ZW
11038 /* If we get here, it can't be done in 16 bits. */
11039 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
11040 _("shift must be constant"));
11041 inst.instruction = THUMB_OP32 (inst.instruction);
11042 inst.instruction |= Rd << 8;
11043 inst.instruction |= Rs << 16;
5f4cb198
NC
11044 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
11045 _("shift value over 3 not allowed in thumb mode"));
11046 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
11047 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
11048 encode_thumb32_shifted_operand (2);
11049 }
11050 }
11051 else
11052 {
11053 constraint (inst.instruction == T_MNEM_adds
11054 || inst.instruction == T_MNEM_subs,
11055 BAD_THUMB32);
b99bd4ef 11056
c19d1205 11057 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 11058 {
c19d1205
ZW
11059 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
11060 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
11061 BAD_HIREG);
11062
11063 inst.instruction = (inst.instruction == T_MNEM_add
11064 ? 0x0000 : 0x8000);
11065 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59 11066 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
11067 return;
11068 }
11069
c19d1205
ZW
11070 Rn = inst.operands[2].reg;
11071 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 11072
c19d1205
ZW
11073 /* We now have Rd, Rs, and Rn set to registers. */
11074 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 11075 {
c19d1205
ZW
11076 /* Can't do this for SUB. */
11077 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
11078 inst.instruction = T_OPCODE_ADD_HI;
11079 inst.instruction |= (Rd & 8) << 4;
11080 inst.instruction |= (Rd & 7);
11081 if (Rs == Rd)
11082 inst.instruction |= Rn << 3;
11083 else if (Rn == Rd)
11084 inst.instruction |= Rs << 3;
11085 else
11086 constraint (1, _("dest must overlap one source register"));
11087 }
11088 else
11089 {
11090 inst.instruction = (inst.instruction == T_MNEM_add
11091 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
11092 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 11093 }
b99bd4ef 11094 }
b99bd4ef
NC
11095}
11096
c19d1205
ZW
11097static void
11098do_t_adr (void)
11099{
fdfde340
JM
11100 unsigned Rd;
11101
11102 Rd = inst.operands[0].reg;
11103 reject_bad_reg (Rd);
11104
11105 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
11106 {
11107 /* Defer to section relaxation. */
11108 inst.relax = inst.instruction;
11109 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11110 inst.instruction |= Rd << 4;
0110f2b8
PB
11111 }
11112 else if (unified_syntax && inst.size_req != 2)
e9f89963 11113 {
0110f2b8 11114 /* Generate a 32-bit opcode. */
e9f89963 11115 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11116 inst.instruction |= Rd << 8;
e2b0ab59
AV
11117 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
11118 inst.relocs[0].pc_rel = 1;
e9f89963
PB
11119 }
11120 else
11121 {
0110f2b8 11122 /* Generate a 16-bit opcode. */
e9f89963 11123 inst.instruction = THUMB_OP16 (inst.instruction);
e2b0ab59
AV
11124 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11125 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
11126 inst.relocs[0].pc_rel = 1;
fdfde340 11127 inst.instruction |= Rd << 4;
e9f89963 11128 }
52a86f84 11129
e2b0ab59
AV
11130 if (inst.relocs[0].exp.X_op == O_symbol
11131 && inst.relocs[0].exp.X_add_symbol != NULL
11132 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11133 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11134 inst.relocs[0].exp.X_add_number += 1;
c19d1205 11135}
b99bd4ef 11136
c19d1205
ZW
11137/* Arithmetic instructions for which there is just one 16-bit
11138 instruction encoding, and it allows only two low registers.
11139 For maximal compatibility with ARM syntax, we allow three register
11140 operands even when Thumb-32 instructions are not available, as long
11141 as the first two are identical. For instance, both "sbc r0,r1" and
11142 "sbc r0,r0,r1" are allowed. */
b99bd4ef 11143static void
c19d1205 11144do_t_arit3 (void)
b99bd4ef 11145{
c19d1205 11146 int Rd, Rs, Rn;
b99bd4ef 11147
c19d1205
ZW
11148 Rd = inst.operands[0].reg;
11149 Rs = (inst.operands[1].present
11150 ? inst.operands[1].reg /* Rd, Rs, foo */
11151 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11152 Rn = inst.operands[2].reg;
b99bd4ef 11153
fdfde340
JM
11154 reject_bad_reg (Rd);
11155 reject_bad_reg (Rs);
11156 if (inst.operands[2].isreg)
11157 reject_bad_reg (Rn);
11158
c19d1205 11159 if (unified_syntax)
b99bd4ef 11160 {
c19d1205
ZW
11161 if (!inst.operands[2].isreg)
11162 {
11163 /* For an immediate, we always generate a 32-bit opcode;
11164 section relaxation will shrink it later if possible. */
11165 inst.instruction = THUMB_OP32 (inst.instruction);
11166 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11167 inst.instruction |= Rd << 8;
11168 inst.instruction |= Rs << 16;
e2b0ab59 11169 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
c19d1205
ZW
11170 }
11171 else
11172 {
e27ec89e
PB
11173 bfd_boolean narrow;
11174
c19d1205 11175 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11176 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11177 narrow = !in_pred_block ();
e27ec89e 11178 else
5ee91343 11179 narrow = in_pred_block ();
e27ec89e
PB
11180
11181 if (Rd > 7 || Rn > 7 || Rs > 7)
11182 narrow = FALSE;
11183 if (inst.operands[2].shifted)
11184 narrow = FALSE;
11185 if (inst.size_req == 4)
11186 narrow = FALSE;
11187
11188 if (narrow
c19d1205
ZW
11189 && Rd == Rs)
11190 {
11191 inst.instruction = THUMB_OP16 (inst.instruction);
11192 inst.instruction |= Rd;
11193 inst.instruction |= Rn << 3;
11194 return;
11195 }
b99bd4ef 11196
c19d1205
ZW
11197 /* If we get here, it can't be done in 16 bits. */
11198 constraint (inst.operands[2].shifted
11199 && inst.operands[2].immisreg,
11200 _("shift must be constant"));
11201 inst.instruction = THUMB_OP32 (inst.instruction);
11202 inst.instruction |= Rd << 8;
11203 inst.instruction |= Rs << 16;
11204 encode_thumb32_shifted_operand (2);
11205 }
a737bd4d 11206 }
c19d1205 11207 else
b99bd4ef 11208 {
c19d1205
ZW
11209 /* On its face this is a lie - the instruction does set the
11210 flags. However, the only supported mnemonic in this mode
11211 says it doesn't. */
11212 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11213
c19d1205
ZW
11214 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11215 _("unshifted register required"));
11216 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11217 constraint (Rd != Rs,
11218 _("dest and source1 must be the same register"));
a737bd4d 11219
c19d1205
ZW
11220 inst.instruction = THUMB_OP16 (inst.instruction);
11221 inst.instruction |= Rd;
11222 inst.instruction |= Rn << 3;
b99bd4ef 11223 }
a737bd4d 11224}
b99bd4ef 11225
c19d1205
ZW
11226/* Similarly, but for instructions where the arithmetic operation is
11227 commutative, so we can allow either of them to be different from
11228 the destination operand in a 16-bit instruction. For instance, all
11229 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
11230 accepted. */
11231static void
11232do_t_arit3c (void)
a737bd4d 11233{
c19d1205 11234 int Rd, Rs, Rn;
b99bd4ef 11235
c19d1205
ZW
11236 Rd = inst.operands[0].reg;
11237 Rs = (inst.operands[1].present
11238 ? inst.operands[1].reg /* Rd, Rs, foo */
11239 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11240 Rn = inst.operands[2].reg;
c921be7d 11241
fdfde340
JM
11242 reject_bad_reg (Rd);
11243 reject_bad_reg (Rs);
11244 if (inst.operands[2].isreg)
11245 reject_bad_reg (Rn);
a737bd4d 11246
c19d1205 11247 if (unified_syntax)
a737bd4d 11248 {
c19d1205 11249 if (!inst.operands[2].isreg)
b99bd4ef 11250 {
c19d1205
ZW
11251 /* For an immediate, we always generate a 32-bit opcode;
11252 section relaxation will shrink it later if possible. */
11253 inst.instruction = THUMB_OP32 (inst.instruction);
11254 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11255 inst.instruction |= Rd << 8;
11256 inst.instruction |= Rs << 16;
e2b0ab59 11257 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11258 }
c19d1205 11259 else
a737bd4d 11260 {
e27ec89e
PB
11261 bfd_boolean narrow;
11262
c19d1205 11263 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11264 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11265 narrow = !in_pred_block ();
e27ec89e 11266 else
5ee91343 11267 narrow = in_pred_block ();
e27ec89e
PB
11268
11269 if (Rd > 7 || Rn > 7 || Rs > 7)
11270 narrow = FALSE;
11271 if (inst.operands[2].shifted)
11272 narrow = FALSE;
11273 if (inst.size_req == 4)
11274 narrow = FALSE;
11275
11276 if (narrow)
a737bd4d 11277 {
c19d1205 11278 if (Rd == Rs)
a737bd4d 11279 {
c19d1205
ZW
11280 inst.instruction = THUMB_OP16 (inst.instruction);
11281 inst.instruction |= Rd;
11282 inst.instruction |= Rn << 3;
11283 return;
a737bd4d 11284 }
c19d1205 11285 if (Rd == Rn)
a737bd4d 11286 {
c19d1205
ZW
11287 inst.instruction = THUMB_OP16 (inst.instruction);
11288 inst.instruction |= Rd;
11289 inst.instruction |= Rs << 3;
11290 return;
a737bd4d
NC
11291 }
11292 }
c19d1205
ZW
11293
11294 /* If we get here, it can't be done in 16 bits. */
11295 constraint (inst.operands[2].shifted
11296 && inst.operands[2].immisreg,
11297 _("shift must be constant"));
11298 inst.instruction = THUMB_OP32 (inst.instruction);
11299 inst.instruction |= Rd << 8;
11300 inst.instruction |= Rs << 16;
11301 encode_thumb32_shifted_operand (2);
a737bd4d 11302 }
b99bd4ef 11303 }
c19d1205
ZW
11304 else
11305 {
11306 /* On its face this is a lie - the instruction does set the
11307 flags. However, the only supported mnemonic in this mode
11308 says it doesn't. */
11309 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11310
c19d1205
ZW
11311 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11312 _("unshifted register required"));
11313 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11314
11315 inst.instruction = THUMB_OP16 (inst.instruction);
11316 inst.instruction |= Rd;
11317
11318 if (Rd == Rs)
11319 inst.instruction |= Rn << 3;
11320 else if (Rd == Rn)
11321 inst.instruction |= Rs << 3;
11322 else
11323 constraint (1, _("dest must overlap one source register"));
11324 }
a737bd4d
NC
11325}
11326
c19d1205
ZW
11327static void
11328do_t_bfc (void)
a737bd4d 11329{
fdfde340 11330 unsigned Rd;
c19d1205
ZW
11331 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11332 constraint (msb > 32, _("bit-field extends past end of register"));
11333 /* The instruction encoding stores the LSB and MSB,
11334 not the LSB and width. */
fdfde340
JM
11335 Rd = inst.operands[0].reg;
11336 reject_bad_reg (Rd);
11337 inst.instruction |= Rd << 8;
c19d1205
ZW
11338 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11339 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11340 inst.instruction |= msb - 1;
b99bd4ef
NC
11341}
11342
c19d1205
ZW
11343static void
11344do_t_bfi (void)
b99bd4ef 11345{
fdfde340 11346 int Rd, Rn;
c19d1205 11347 unsigned int msb;
b99bd4ef 11348
fdfde340
JM
11349 Rd = inst.operands[0].reg;
11350 reject_bad_reg (Rd);
11351
c19d1205
ZW
11352 /* #0 in second position is alternative syntax for bfc, which is
11353 the same instruction but with REG_PC in the Rm field. */
11354 if (!inst.operands[1].isreg)
fdfde340
JM
11355 Rn = REG_PC;
11356 else
11357 {
11358 Rn = inst.operands[1].reg;
11359 reject_bad_reg (Rn);
11360 }
b99bd4ef 11361
c19d1205
ZW
11362 msb = inst.operands[2].imm + inst.operands[3].imm;
11363 constraint (msb > 32, _("bit-field extends past end of register"));
11364 /* The instruction encoding stores the LSB and MSB,
11365 not the LSB and width. */
fdfde340
JM
11366 inst.instruction |= Rd << 8;
11367 inst.instruction |= Rn << 16;
c19d1205
ZW
11368 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11369 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11370 inst.instruction |= msb - 1;
b99bd4ef
NC
11371}
11372
c19d1205
ZW
11373static void
11374do_t_bfx (void)
b99bd4ef 11375{
fdfde340
JM
11376 unsigned Rd, Rn;
11377
11378 Rd = inst.operands[0].reg;
11379 Rn = inst.operands[1].reg;
11380
11381 reject_bad_reg (Rd);
11382 reject_bad_reg (Rn);
11383
c19d1205
ZW
11384 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11385 _("bit-field extends past end of register"));
fdfde340
JM
11386 inst.instruction |= Rd << 8;
11387 inst.instruction |= Rn << 16;
c19d1205
ZW
11388 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11389 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11390 inst.instruction |= inst.operands[3].imm - 1;
11391}
b99bd4ef 11392
c19d1205
ZW
11393/* ARM V5 Thumb BLX (argument parse)
11394 BLX <target_addr> which is BLX(1)
11395 BLX <Rm> which is BLX(2)
11396 Unfortunately, there are two different opcodes for this mnemonic.
11397 So, the insns[].value is not used, and the code here zaps values
11398 into inst.instruction.
b99bd4ef 11399
c19d1205
ZW
11400 ??? How to take advantage of the additional two bits of displacement
11401 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11402
c19d1205
ZW
11403static void
11404do_t_blx (void)
11405{
5ee91343 11406 set_pred_insn_type_last ();
e07e6e58 11407
c19d1205 11408 if (inst.operands[0].isreg)
fdfde340
JM
11409 {
11410 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11411 /* We have a register, so this is BLX(2). */
11412 inst.instruction |= inst.operands[0].reg << 3;
11413 }
b99bd4ef
NC
11414 else
11415 {
c19d1205 11416 /* No register. This must be BLX(1). */
2fc8bdac 11417 inst.instruction = 0xf000e800;
0855e32b 11418 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11419 }
11420}
11421
c19d1205
ZW
11422static void
11423do_t_branch (void)
b99bd4ef 11424{
0110f2b8 11425 int opcode;
dfa9f0d5 11426 int cond;
2fe88214 11427 bfd_reloc_code_real_type reloc;
dfa9f0d5 11428
e07e6e58 11429 cond = inst.cond;
5ee91343 11430 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN);
e07e6e58 11431
5ee91343 11432 if (in_pred_block ())
dfa9f0d5
PB
11433 {
11434 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11435 branches. */
dfa9f0d5 11436 cond = COND_ALWAYS;
dfa9f0d5
PB
11437 }
11438 else
11439 cond = inst.cond;
11440
11441 if (cond != COND_ALWAYS)
0110f2b8
PB
11442 opcode = T_MNEM_bcond;
11443 else
11444 opcode = inst.instruction;
11445
12d6b0b7
RS
11446 if (unified_syntax
11447 && (inst.size_req == 4
10960bfb
PB
11448 || (inst.size_req != 2
11449 && (inst.operands[0].hasreloc
e2b0ab59 11450 || inst.relocs[0].exp.X_op == O_constant))))
c19d1205 11451 {
0110f2b8 11452 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11453 if (cond == COND_ALWAYS)
9ae92b05 11454 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11455 else
11456 {
ff8646ee
TP
11457 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11458 _("selected architecture does not support "
11459 "wide conditional branch instruction"));
11460
9c2799c2 11461 gas_assert (cond != 0xF);
dfa9f0d5 11462 inst.instruction |= cond << 22;
9ae92b05 11463 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11464 }
11465 }
b99bd4ef
NC
11466 else
11467 {
0110f2b8 11468 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11469 if (cond == COND_ALWAYS)
9ae92b05 11470 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11471 else
b99bd4ef 11472 {
dfa9f0d5 11473 inst.instruction |= cond << 8;
9ae92b05 11474 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11475 }
0110f2b8
PB
11476 /* Allow section relaxation. */
11477 if (unified_syntax && inst.size_req != 2)
11478 inst.relax = opcode;
b99bd4ef 11479 }
e2b0ab59
AV
11480 inst.relocs[0].type = reloc;
11481 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
11482}
11483
8884b720 11484/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11485 between the two is the maximum immediate allowed - which is passed in
8884b720 11486 RANGE. */
b99bd4ef 11487static void
8884b720 11488do_t_bkpt_hlt1 (int range)
b99bd4ef 11489{
dfa9f0d5
PB
11490 constraint (inst.cond != COND_ALWAYS,
11491 _("instruction is always unconditional"));
c19d1205 11492 if (inst.operands[0].present)
b99bd4ef 11493 {
8884b720 11494 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11495 _("immediate value out of range"));
11496 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11497 }
8884b720 11498
5ee91343 11499 set_pred_insn_type (NEUTRAL_IT_INSN);
8884b720
MGD
11500}
11501
11502static void
11503do_t_hlt (void)
11504{
11505 do_t_bkpt_hlt1 (63);
11506}
11507
11508static void
11509do_t_bkpt (void)
11510{
11511 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11512}
11513
11514static void
c19d1205 11515do_t_branch23 (void)
b99bd4ef 11516{
5ee91343 11517 set_pred_insn_type_last ();
0855e32b 11518 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11519
0855e32b
NS
11520 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11521 this file. We used to simply ignore the PLT reloc type here --
11522 the branch encoding is now needed to deal with TLSCALL relocs.
11523 So if we see a PLT reloc now, put it back to how it used to be to
11524 keep the preexisting behaviour. */
e2b0ab59
AV
11525 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
11526 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11527
4343666d 11528#if defined(OBJ_COFF)
c19d1205
ZW
11529 /* If the destination of the branch is a defined symbol which does not have
11530 the THUMB_FUNC attribute, then we must be calling a function which has
11531 the (interfacearm) attribute. We look for the Thumb entry point to that
11532 function and change the branch to refer to that function instead. */
e2b0ab59
AV
11533 if ( inst.relocs[0].exp.X_op == O_symbol
11534 && inst.relocs[0].exp.X_add_symbol != NULL
11535 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11536 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11537 inst.relocs[0].exp.X_add_symbol
11538 = find_real_start (inst.relocs[0].exp.X_add_symbol);
4343666d 11539#endif
90e4755a
RE
11540}
11541
11542static void
c19d1205 11543do_t_bx (void)
90e4755a 11544{
5ee91343 11545 set_pred_insn_type_last ();
c19d1205
ZW
11546 inst.instruction |= inst.operands[0].reg << 3;
11547 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11548 should cause the alignment to be checked once it is known. This is
11549 because BX PC only works if the instruction is word aligned. */
11550}
90e4755a 11551
c19d1205
ZW
11552static void
11553do_t_bxj (void)
11554{
fdfde340 11555 int Rm;
90e4755a 11556
5ee91343 11557 set_pred_insn_type_last ();
fdfde340
JM
11558 Rm = inst.operands[0].reg;
11559 reject_bad_reg (Rm);
11560 inst.instruction |= Rm << 16;
90e4755a
RE
11561}
11562
11563static void
c19d1205 11564do_t_clz (void)
90e4755a 11565{
fdfde340
JM
11566 unsigned Rd;
11567 unsigned Rm;
11568
11569 Rd = inst.operands[0].reg;
11570 Rm = inst.operands[1].reg;
11571
11572 reject_bad_reg (Rd);
11573 reject_bad_reg (Rm);
11574
11575 inst.instruction |= Rd << 8;
11576 inst.instruction |= Rm << 16;
11577 inst.instruction |= Rm;
c19d1205 11578}
90e4755a 11579
91d8b670
JG
11580static void
11581do_t_csdb (void)
11582{
5ee91343 11583 set_pred_insn_type (OUTSIDE_PRED_INSN);
91d8b670
JG
11584}
11585
dfa9f0d5
PB
11586static void
11587do_t_cps (void)
11588{
5ee91343 11589 set_pred_insn_type (OUTSIDE_PRED_INSN);
dfa9f0d5
PB
11590 inst.instruction |= inst.operands[0].imm;
11591}
11592
c19d1205
ZW
11593static void
11594do_t_cpsi (void)
11595{
5ee91343 11596 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205 11597 if (unified_syntax
62b3e311
PB
11598 && (inst.operands[1].present || inst.size_req == 4)
11599 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11600 {
c19d1205
ZW
11601 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11602 inst.instruction = 0xf3af8000;
11603 inst.instruction |= imod << 9;
11604 inst.instruction |= inst.operands[0].imm << 5;
11605 if (inst.operands[1].present)
11606 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11607 }
c19d1205 11608 else
90e4755a 11609 {
62b3e311
PB
11610 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11611 && (inst.operands[0].imm & 4),
11612 _("selected processor does not support 'A' form "
11613 "of this instruction"));
11614 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11615 _("Thumb does not support the 2-argument "
11616 "form of this instruction"));
11617 inst.instruction |= inst.operands[0].imm;
90e4755a 11618 }
90e4755a
RE
11619}
11620
c19d1205
ZW
11621/* THUMB CPY instruction (argument parse). */
11622
90e4755a 11623static void
c19d1205 11624do_t_cpy (void)
90e4755a 11625{
c19d1205 11626 if (inst.size_req == 4)
90e4755a 11627 {
c19d1205
ZW
11628 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11629 inst.instruction |= inst.operands[0].reg << 8;
11630 inst.instruction |= inst.operands[1].reg;
90e4755a 11631 }
c19d1205 11632 else
90e4755a 11633 {
c19d1205
ZW
11634 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11635 inst.instruction |= (inst.operands[0].reg & 0x7);
11636 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11637 }
90e4755a
RE
11638}
11639
90e4755a 11640static void
25fe350b 11641do_t_cbz (void)
90e4755a 11642{
5ee91343 11643 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
11644 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11645 inst.instruction |= inst.operands[0].reg;
e2b0ab59
AV
11646 inst.relocs[0].pc_rel = 1;
11647 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
c19d1205 11648}
90e4755a 11649
62b3e311
PB
11650static void
11651do_t_dbg (void)
11652{
11653 inst.instruction |= inst.operands[0].imm;
11654}
11655
11656static void
11657do_t_div (void)
11658{
fdfde340
JM
11659 unsigned Rd, Rn, Rm;
11660
11661 Rd = inst.operands[0].reg;
11662 Rn = (inst.operands[1].present
11663 ? inst.operands[1].reg : Rd);
11664 Rm = inst.operands[2].reg;
11665
11666 reject_bad_reg (Rd);
11667 reject_bad_reg (Rn);
11668 reject_bad_reg (Rm);
11669
11670 inst.instruction |= Rd << 8;
11671 inst.instruction |= Rn << 16;
11672 inst.instruction |= Rm;
62b3e311
PB
11673}
11674
c19d1205
ZW
11675static void
11676do_t_hint (void)
11677{
11678 if (unified_syntax && inst.size_req == 4)
11679 inst.instruction = THUMB_OP32 (inst.instruction);
11680 else
11681 inst.instruction = THUMB_OP16 (inst.instruction);
11682}
90e4755a 11683
c19d1205
ZW
11684static void
11685do_t_it (void)
11686{
11687 unsigned int cond = inst.operands[0].imm;
e27ec89e 11688
5ee91343
AV
11689 set_pred_insn_type (IT_INSN);
11690 now_pred.mask = (inst.instruction & 0xf) | 0x10;
11691 now_pred.cc = cond;
11692 now_pred.warn_deprecated = FALSE;
11693 now_pred.type = SCALAR_PRED;
e27ec89e
PB
11694
11695 /* If the condition is a negative condition, invert the mask. */
c19d1205 11696 if ((cond & 0x1) == 0x0)
90e4755a 11697 {
c19d1205 11698 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11699
c19d1205 11700 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11701 {
11702 /* No conversion needed. */
5ee91343 11703 now_pred.block_length = 1;
5a01bb1d 11704 }
c19d1205 11705 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11706 {
11707 mask ^= 0x8;
5ee91343 11708 now_pred.block_length = 2;
5a01bb1d 11709 }
e27ec89e 11710 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11711 {
11712 mask ^= 0xC;
5ee91343 11713 now_pred.block_length = 3;
5a01bb1d 11714 }
c19d1205 11715 else
5a01bb1d
MGD
11716 {
11717 mask ^= 0xE;
5ee91343 11718 now_pred.block_length = 4;
5a01bb1d 11719 }
90e4755a 11720
e27ec89e
PB
11721 inst.instruction &= 0xfff0;
11722 inst.instruction |= mask;
c19d1205 11723 }
90e4755a 11724
c19d1205
ZW
11725 inst.instruction |= cond << 4;
11726}
90e4755a 11727
5ee91343
AV
11728static void
11729do_mve_vpt (void)
11730{
11731 /* We are dealing with a vector predicated block. */
11732 set_pred_insn_type (VPT_INSN);
11733 now_pred.cc = 0;
11734 now_pred.mask = ((inst.instruction & 0x00400000) >> 19)
11735 | ((inst.instruction & 0xe000) >> 13);
11736 now_pred.warn_deprecated = FALSE;
11737 now_pred.type = VECTOR_PRED;
11738}
11739
3c707909
PB
11740/* Helper function used for both push/pop and ldm/stm. */
11741static void
4b5a202f
AV
11742encode_thumb2_multi (bfd_boolean do_io, int base, unsigned mask,
11743 bfd_boolean writeback)
3c707909 11744{
4b5a202f 11745 bfd_boolean load, store;
3c707909 11746
4b5a202f
AV
11747 gas_assert (base != -1 || !do_io);
11748 load = do_io && ((inst.instruction & (1 << 20)) != 0);
11749 store = do_io && !load;
3c707909
PB
11750
11751 if (mask & (1 << 13))
11752 inst.error = _("SP not allowed in register list");
1e5b0379 11753
4b5a202f 11754 if (do_io && (mask & (1 << base)) != 0
1e5b0379
NC
11755 && writeback)
11756 inst.error = _("having the base register in the register list when "
11757 "using write back is UNPREDICTABLE");
11758
3c707909
PB
11759 if (load)
11760 {
e07e6e58 11761 if (mask & (1 << 15))
477330fc
RM
11762 {
11763 if (mask & (1 << 14))
11764 inst.error = _("LR and PC should not both be in register list");
11765 else
5ee91343 11766 set_pred_insn_type_last ();
477330fc 11767 }
3c707909 11768 }
4b5a202f 11769 else if (store)
3c707909
PB
11770 {
11771 if (mask & (1 << 15))
11772 inst.error = _("PC not allowed in register list");
3c707909
PB
11773 }
11774
4b5a202f 11775 if (do_io && ((mask & (mask - 1)) == 0))
3c707909
PB
11776 {
11777 /* Single register transfers implemented as str/ldr. */
11778 if (writeback)
11779 {
11780 if (inst.instruction & (1 << 23))
11781 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11782 else
11783 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11784 }
11785 else
11786 {
11787 if (inst.instruction & (1 << 23))
11788 inst.instruction = 0x00800000; /* ia -> [base] */
11789 else
11790 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11791 }
11792
11793 inst.instruction |= 0xf8400000;
11794 if (load)
11795 inst.instruction |= 0x00100000;
11796
5f4273c7 11797 mask = ffs (mask) - 1;
3c707909
PB
11798 mask <<= 12;
11799 }
11800 else if (writeback)
11801 inst.instruction |= WRITE_BACK;
11802
11803 inst.instruction |= mask;
4b5a202f
AV
11804 if (do_io)
11805 inst.instruction |= base << 16;
3c707909
PB
11806}
11807
c19d1205
ZW
11808static void
11809do_t_ldmstm (void)
11810{
11811 /* This really doesn't seem worth it. */
e2b0ab59 11812 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205
ZW
11813 _("expression too complex"));
11814 constraint (inst.operands[1].writeback,
11815 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11816
c19d1205
ZW
11817 if (unified_syntax)
11818 {
3c707909
PB
11819 bfd_boolean narrow;
11820 unsigned mask;
11821
11822 narrow = FALSE;
c19d1205
ZW
11823 /* See if we can use a 16-bit instruction. */
11824 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11825 && inst.size_req != 4
3c707909 11826 && !(inst.operands[1].imm & ~0xff))
90e4755a 11827 {
3c707909 11828 mask = 1 << inst.operands[0].reg;
90e4755a 11829
eab4f823 11830 if (inst.operands[0].reg <= 7)
90e4755a 11831 {
3c707909 11832 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11833 ? inst.operands[0].writeback
11834 : (inst.operands[0].writeback
11835 == !(inst.operands[1].imm & mask)))
477330fc 11836 {
eab4f823
MGD
11837 if (inst.instruction == T_MNEM_stmia
11838 && (inst.operands[1].imm & mask)
11839 && (inst.operands[1].imm & (mask - 1)))
11840 as_warn (_("value stored for r%d is UNKNOWN"),
11841 inst.operands[0].reg);
3c707909 11842
eab4f823
MGD
11843 inst.instruction = THUMB_OP16 (inst.instruction);
11844 inst.instruction |= inst.operands[0].reg << 8;
11845 inst.instruction |= inst.operands[1].imm;
11846 narrow = TRUE;
11847 }
11848 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11849 {
11850 /* This means 1 register in reg list one of 3 situations:
11851 1. Instruction is stmia, but without writeback.
11852 2. lmdia without writeback, but with Rn not in
477330fc 11853 reglist.
eab4f823
MGD
11854 3. ldmia with writeback, but with Rn in reglist.
11855 Case 3 is UNPREDICTABLE behaviour, so we handle
11856 case 1 and 2 which can be converted into a 16-bit
11857 str or ldr. The SP cases are handled below. */
11858 unsigned long opcode;
11859 /* First, record an error for Case 3. */
11860 if (inst.operands[1].imm & mask
11861 && inst.operands[0].writeback)
fa94de6b 11862 inst.error =
eab4f823
MGD
11863 _("having the base register in the register list when "
11864 "using write back is UNPREDICTABLE");
fa94de6b
RM
11865
11866 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11867 : T_MNEM_ldr);
11868 inst.instruction = THUMB_OP16 (opcode);
11869 inst.instruction |= inst.operands[0].reg << 3;
11870 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11871 narrow = TRUE;
11872 }
90e4755a 11873 }
eab4f823 11874 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11875 {
eab4f823
MGD
11876 if (inst.operands[0].writeback)
11877 {
fa94de6b 11878 inst.instruction =
eab4f823 11879 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11880 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11881 inst.instruction |= inst.operands[1].imm;
477330fc 11882 narrow = TRUE;
eab4f823
MGD
11883 }
11884 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11885 {
fa94de6b 11886 inst.instruction =
eab4f823 11887 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11888 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11889 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11890 narrow = TRUE;
eab4f823 11891 }
90e4755a 11892 }
3c707909
PB
11893 }
11894
11895 if (!narrow)
11896 {
c19d1205
ZW
11897 if (inst.instruction < 0xffff)
11898 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11899
4b5a202f
AV
11900 encode_thumb2_multi (TRUE /* do_io */, inst.operands[0].reg,
11901 inst.operands[1].imm,
11902 inst.operands[0].writeback);
90e4755a
RE
11903 }
11904 }
c19d1205 11905 else
90e4755a 11906 {
c19d1205
ZW
11907 constraint (inst.operands[0].reg > 7
11908 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11909 constraint (inst.instruction != T_MNEM_ldmia
11910 && inst.instruction != T_MNEM_stmia,
11911 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11912 if (inst.instruction == T_MNEM_stmia)
f03698e6 11913 {
c19d1205
ZW
11914 if (!inst.operands[0].writeback)
11915 as_warn (_("this instruction will write back the base register"));
11916 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11917 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11918 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11919 inst.operands[0].reg);
f03698e6 11920 }
c19d1205 11921 else
90e4755a 11922 {
c19d1205
ZW
11923 if (!inst.operands[0].writeback
11924 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11925 as_warn (_("this instruction will write back the base register"));
11926 else if (inst.operands[0].writeback
11927 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11928 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11929 }
11930
c19d1205
ZW
11931 inst.instruction = THUMB_OP16 (inst.instruction);
11932 inst.instruction |= inst.operands[0].reg << 8;
11933 inst.instruction |= inst.operands[1].imm;
11934 }
11935}
e28cd48c 11936
c19d1205
ZW
11937static void
11938do_t_ldrex (void)
11939{
11940 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11941 || inst.operands[1].postind || inst.operands[1].writeback
11942 || inst.operands[1].immisreg || inst.operands[1].shifted
11943 || inst.operands[1].negative,
01cfc07f 11944 BAD_ADDR_MODE);
e28cd48c 11945
5be8be5d
DG
11946 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11947
c19d1205
ZW
11948 inst.instruction |= inst.operands[0].reg << 12;
11949 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 11950 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
c19d1205 11951}
e28cd48c 11952
c19d1205
ZW
11953static void
11954do_t_ldrexd (void)
11955{
11956 if (!inst.operands[1].present)
1cac9012 11957 {
c19d1205
ZW
11958 constraint (inst.operands[0].reg == REG_LR,
11959 _("r14 not allowed as first register "
11960 "when second register is omitted"));
11961 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11962 }
c19d1205
ZW
11963 constraint (inst.operands[0].reg == inst.operands[1].reg,
11964 BAD_OVERLAP);
b99bd4ef 11965
c19d1205
ZW
11966 inst.instruction |= inst.operands[0].reg << 12;
11967 inst.instruction |= inst.operands[1].reg << 8;
11968 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11969}
11970
11971static void
c19d1205 11972do_t_ldst (void)
b99bd4ef 11973{
0110f2b8
PB
11974 unsigned long opcode;
11975 int Rn;
11976
e07e6e58
NC
11977 if (inst.operands[0].isreg
11978 && !inst.operands[0].preind
11979 && inst.operands[0].reg == REG_PC)
5ee91343 11980 set_pred_insn_type_last ();
e07e6e58 11981
0110f2b8 11982 opcode = inst.instruction;
c19d1205 11983 if (unified_syntax)
b99bd4ef 11984 {
53365c0d
PB
11985 if (!inst.operands[1].isreg)
11986 {
11987 if (opcode <= 0xffff)
11988 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11989 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11990 return;
11991 }
0110f2b8
PB
11992 if (inst.operands[1].isreg
11993 && !inst.operands[1].writeback
c19d1205
ZW
11994 && !inst.operands[1].shifted && !inst.operands[1].postind
11995 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11996 && opcode <= 0xffff
11997 && inst.size_req != 4)
c19d1205 11998 {
0110f2b8
PB
11999 /* Insn may have a 16-bit form. */
12000 Rn = inst.operands[1].reg;
12001 if (inst.operands[1].immisreg)
12002 {
12003 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 12004 /* [Rn, Rik] */
0110f2b8
PB
12005 if (Rn <= 7 && inst.operands[1].imm <= 7)
12006 goto op16;
5be8be5d
DG
12007 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
12008 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
12009 }
12010 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
12011 && opcode != T_MNEM_ldrsb)
12012 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
12013 || (Rn == REG_SP && opcode == T_MNEM_str))
12014 {
12015 /* [Rn, #const] */
12016 if (Rn > 7)
12017 {
12018 if (Rn == REG_PC)
12019 {
e2b0ab59 12020 if (inst.relocs[0].pc_rel)
0110f2b8
PB
12021 opcode = T_MNEM_ldr_pc2;
12022 else
12023 opcode = T_MNEM_ldr_pc;
12024 }
12025 else
12026 {
12027 if (opcode == T_MNEM_ldr)
12028 opcode = T_MNEM_ldr_sp;
12029 else
12030 opcode = T_MNEM_str_sp;
12031 }
12032 inst.instruction = inst.operands[0].reg << 8;
12033 }
12034 else
12035 {
12036 inst.instruction = inst.operands[0].reg;
12037 inst.instruction |= inst.operands[1].reg << 3;
12038 }
12039 inst.instruction |= THUMB_OP16 (opcode);
12040 if (inst.size_req == 2)
e2b0ab59 12041 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
0110f2b8
PB
12042 else
12043 inst.relax = opcode;
12044 return;
12045 }
c19d1205 12046 }
0110f2b8 12047 /* Definitely a 32-bit variant. */
5be8be5d 12048
8d67f500
NC
12049 /* Warning for Erratum 752419. */
12050 if (opcode == T_MNEM_ldr
12051 && inst.operands[0].reg == REG_SP
12052 && inst.operands[1].writeback == 1
12053 && !inst.operands[1].immisreg)
12054 {
12055 if (no_cpu_selected ()
12056 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
12057 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
12058 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
12059 as_warn (_("This instruction may be unpredictable "
12060 "if executed on M-profile cores "
12061 "with interrupts enabled."));
12062 }
12063
5be8be5d 12064 /* Do some validations regarding addressing modes. */
1be5fd2e 12065 if (inst.operands[1].immisreg)
5be8be5d
DG
12066 reject_bad_reg (inst.operands[1].imm);
12067
1be5fd2e
NC
12068 constraint (inst.operands[1].writeback == 1
12069 && inst.operands[0].reg == inst.operands[1].reg,
12070 BAD_OVERLAP);
12071
0110f2b8 12072 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
12073 inst.instruction |= inst.operands[0].reg << 12;
12074 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 12075 check_ldr_r15_aligned ();
b99bd4ef
NC
12076 return;
12077 }
12078
c19d1205
ZW
12079 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12080
12081 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 12082 {
c19d1205
ZW
12083 /* Only [Rn,Rm] is acceptable. */
12084 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
12085 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
12086 || inst.operands[1].postind || inst.operands[1].shifted
12087 || inst.operands[1].negative,
12088 _("Thumb does not support this addressing mode"));
12089 inst.instruction = THUMB_OP16 (inst.instruction);
12090 goto op16;
b99bd4ef 12091 }
5f4273c7 12092
c19d1205
ZW
12093 inst.instruction = THUMB_OP16 (inst.instruction);
12094 if (!inst.operands[1].isreg)
8335d6aa 12095 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 12096 return;
b99bd4ef 12097
c19d1205
ZW
12098 constraint (!inst.operands[1].preind
12099 || inst.operands[1].shifted
12100 || inst.operands[1].writeback,
12101 _("Thumb does not support this addressing mode"));
12102 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 12103 {
c19d1205
ZW
12104 constraint (inst.instruction & 0x0600,
12105 _("byte or halfword not valid for base register"));
12106 constraint (inst.operands[1].reg == REG_PC
12107 && !(inst.instruction & THUMB_LOAD_BIT),
12108 _("r15 based store not allowed"));
12109 constraint (inst.operands[1].immisreg,
12110 _("invalid base register for register offset"));
b99bd4ef 12111
c19d1205
ZW
12112 if (inst.operands[1].reg == REG_PC)
12113 inst.instruction = T_OPCODE_LDR_PC;
12114 else if (inst.instruction & THUMB_LOAD_BIT)
12115 inst.instruction = T_OPCODE_LDR_SP;
12116 else
12117 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 12118
c19d1205 12119 inst.instruction |= inst.operands[0].reg << 8;
e2b0ab59 12120 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12121 return;
12122 }
90e4755a 12123
c19d1205
ZW
12124 constraint (inst.operands[1].reg > 7, BAD_HIREG);
12125 if (!inst.operands[1].immisreg)
12126 {
12127 /* Immediate offset. */
12128 inst.instruction |= inst.operands[0].reg;
12129 inst.instruction |= inst.operands[1].reg << 3;
e2b0ab59 12130 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12131 return;
12132 }
90e4755a 12133
c19d1205
ZW
12134 /* Register offset. */
12135 constraint (inst.operands[1].imm > 7, BAD_HIREG);
12136 constraint (inst.operands[1].negative,
12137 _("Thumb does not support this addressing mode"));
90e4755a 12138
c19d1205
ZW
12139 op16:
12140 switch (inst.instruction)
12141 {
12142 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
12143 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
12144 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
12145 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
12146 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
12147 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
12148 case 0x5600 /* ldrsb */:
12149 case 0x5e00 /* ldrsh */: break;
12150 default: abort ();
12151 }
90e4755a 12152
c19d1205
ZW
12153 inst.instruction |= inst.operands[0].reg;
12154 inst.instruction |= inst.operands[1].reg << 3;
12155 inst.instruction |= inst.operands[1].imm << 6;
12156}
90e4755a 12157
c19d1205
ZW
12158static void
12159do_t_ldstd (void)
12160{
12161 if (!inst.operands[1].present)
b99bd4ef 12162 {
c19d1205
ZW
12163 inst.operands[1].reg = inst.operands[0].reg + 1;
12164 constraint (inst.operands[0].reg == REG_LR,
12165 _("r14 not allowed here"));
bd340a04 12166 constraint (inst.operands[0].reg == REG_R12,
477330fc 12167 _("r12 not allowed here"));
b99bd4ef 12168 }
bd340a04
MGD
12169
12170 if (inst.operands[2].writeback
12171 && (inst.operands[0].reg == inst.operands[2].reg
12172 || inst.operands[1].reg == inst.operands[2].reg))
12173 as_warn (_("base register written back, and overlaps "
477330fc 12174 "one of transfer registers"));
bd340a04 12175
c19d1205
ZW
12176 inst.instruction |= inst.operands[0].reg << 12;
12177 inst.instruction |= inst.operands[1].reg << 8;
12178 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
12179}
12180
c19d1205
ZW
12181static void
12182do_t_ldstt (void)
12183{
12184 inst.instruction |= inst.operands[0].reg << 12;
12185 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
12186}
a737bd4d 12187
b99bd4ef 12188static void
c19d1205 12189do_t_mla (void)
b99bd4ef 12190{
fdfde340 12191 unsigned Rd, Rn, Rm, Ra;
c921be7d 12192
fdfde340
JM
12193 Rd = inst.operands[0].reg;
12194 Rn = inst.operands[1].reg;
12195 Rm = inst.operands[2].reg;
12196 Ra = inst.operands[3].reg;
12197
12198 reject_bad_reg (Rd);
12199 reject_bad_reg (Rn);
12200 reject_bad_reg (Rm);
12201 reject_bad_reg (Ra);
12202
12203 inst.instruction |= Rd << 8;
12204 inst.instruction |= Rn << 16;
12205 inst.instruction |= Rm;
12206 inst.instruction |= Ra << 12;
c19d1205 12207}
b99bd4ef 12208
c19d1205
ZW
12209static void
12210do_t_mlal (void)
12211{
fdfde340
JM
12212 unsigned RdLo, RdHi, Rn, Rm;
12213
12214 RdLo = inst.operands[0].reg;
12215 RdHi = inst.operands[1].reg;
12216 Rn = inst.operands[2].reg;
12217 Rm = inst.operands[3].reg;
12218
12219 reject_bad_reg (RdLo);
12220 reject_bad_reg (RdHi);
12221 reject_bad_reg (Rn);
12222 reject_bad_reg (Rm);
12223
12224 inst.instruction |= RdLo << 12;
12225 inst.instruction |= RdHi << 8;
12226 inst.instruction |= Rn << 16;
12227 inst.instruction |= Rm;
c19d1205 12228}
b99bd4ef 12229
c19d1205
ZW
12230static void
12231do_t_mov_cmp (void)
12232{
fdfde340
JM
12233 unsigned Rn, Rm;
12234
12235 Rn = inst.operands[0].reg;
12236 Rm = inst.operands[1].reg;
12237
e07e6e58 12238 if (Rn == REG_PC)
5ee91343 12239 set_pred_insn_type_last ();
e07e6e58 12240
c19d1205 12241 if (unified_syntax)
b99bd4ef 12242 {
c19d1205
ZW
12243 int r0off = (inst.instruction == T_MNEM_mov
12244 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 12245 unsigned long opcode;
3d388997
PB
12246 bfd_boolean narrow;
12247 bfd_boolean low_regs;
12248
fdfde340 12249 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 12250 opcode = inst.instruction;
5ee91343 12251 if (in_pred_block ())
0110f2b8 12252 narrow = opcode != T_MNEM_movs;
3d388997 12253 else
0110f2b8 12254 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
12255 if (inst.size_req == 4
12256 || inst.operands[1].shifted)
12257 narrow = FALSE;
12258
efd81785
PB
12259 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12260 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12261 && !inst.operands[1].shifted
fdfde340
JM
12262 && Rn == REG_PC
12263 && Rm == REG_LR)
efd81785
PB
12264 {
12265 inst.instruction = T2_SUBS_PC_LR;
12266 return;
12267 }
12268
fdfde340
JM
12269 if (opcode == T_MNEM_cmp)
12270 {
12271 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
12272 if (narrow)
12273 {
12274 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
12275 but valid. */
12276 warn_deprecated_sp (Rm);
12277 /* R15 was documented as a valid choice for Rm in ARMv6,
12278 but as UNPREDICTABLE in ARMv7. ARM's proprietary
12279 tools reject R15, so we do too. */
12280 constraint (Rm == REG_PC, BAD_PC);
12281 }
12282 else
12283 reject_bad_reg (Rm);
fdfde340
JM
12284 }
12285 else if (opcode == T_MNEM_mov
12286 || opcode == T_MNEM_movs)
12287 {
12288 if (inst.operands[1].isreg)
12289 {
12290 if (opcode == T_MNEM_movs)
12291 {
12292 reject_bad_reg (Rn);
12293 reject_bad_reg (Rm);
12294 }
76fa04a4
MGD
12295 else if (narrow)
12296 {
12297 /* This is mov.n. */
12298 if ((Rn == REG_SP || Rn == REG_PC)
12299 && (Rm == REG_SP || Rm == REG_PC))
12300 {
5c3696f8 12301 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
12302 "deprecated when r%u is the destination "
12303 "register."), Rm, Rn);
12304 }
12305 }
12306 else
12307 {
12308 /* This is mov.w. */
12309 constraint (Rn == REG_PC, BAD_PC);
12310 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
12311 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12312 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 12313 }
fdfde340
JM
12314 }
12315 else
12316 reject_bad_reg (Rn);
12317 }
12318
c19d1205
ZW
12319 if (!inst.operands[1].isreg)
12320 {
0110f2b8 12321 /* Immediate operand. */
5ee91343 12322 if (!in_pred_block () && opcode == T_MNEM_mov)
0110f2b8
PB
12323 narrow = 0;
12324 if (low_regs && narrow)
12325 {
12326 inst.instruction = THUMB_OP16 (opcode);
fdfde340 12327 inst.instruction |= Rn << 8;
e2b0ab59
AV
12328 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12329 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 12330 {
a9f02af8 12331 if (inst.size_req == 2)
e2b0ab59 12332 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
12333 else
12334 inst.relax = opcode;
72d98d16 12335 }
0110f2b8
PB
12336 }
12337 else
12338 {
e2b0ab59
AV
12339 constraint ((inst.relocs[0].type
12340 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
12341 && (inst.relocs[0].type
12342 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8
MG
12343 THUMB1_RELOC_ONLY);
12344
0110f2b8
PB
12345 inst.instruction = THUMB_OP32 (inst.instruction);
12346 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12347 inst.instruction |= Rn << r0off;
e2b0ab59 12348 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8 12349 }
c19d1205 12350 }
728ca7c9
PB
12351 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12352 && (inst.instruction == T_MNEM_mov
12353 || inst.instruction == T_MNEM_movs))
12354 {
12355 /* Register shifts are encoded as separate shift instructions. */
12356 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
12357
5ee91343 12358 if (in_pred_block ())
728ca7c9
PB
12359 narrow = !flags;
12360 else
12361 narrow = flags;
12362
12363 if (inst.size_req == 4)
12364 narrow = FALSE;
12365
12366 if (!low_regs || inst.operands[1].imm > 7)
12367 narrow = FALSE;
12368
fdfde340 12369 if (Rn != Rm)
728ca7c9
PB
12370 narrow = FALSE;
12371
12372 switch (inst.operands[1].shift_kind)
12373 {
12374 case SHIFT_LSL:
12375 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12376 break;
12377 case SHIFT_ASR:
12378 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12379 break;
12380 case SHIFT_LSR:
12381 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12382 break;
12383 case SHIFT_ROR:
12384 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12385 break;
12386 default:
5f4273c7 12387 abort ();
728ca7c9
PB
12388 }
12389
12390 inst.instruction = opcode;
12391 if (narrow)
12392 {
fdfde340 12393 inst.instruction |= Rn;
728ca7c9
PB
12394 inst.instruction |= inst.operands[1].imm << 3;
12395 }
12396 else
12397 {
12398 if (flags)
12399 inst.instruction |= CONDS_BIT;
12400
fdfde340
JM
12401 inst.instruction |= Rn << 8;
12402 inst.instruction |= Rm << 16;
728ca7c9
PB
12403 inst.instruction |= inst.operands[1].imm;
12404 }
12405 }
3d388997 12406 else if (!narrow)
c19d1205 12407 {
728ca7c9
PB
12408 /* Some mov with immediate shift have narrow variants.
12409 Register shifts are handled above. */
12410 if (low_regs && inst.operands[1].shifted
12411 && (inst.instruction == T_MNEM_mov
12412 || inst.instruction == T_MNEM_movs))
12413 {
5ee91343 12414 if (in_pred_block ())
728ca7c9
PB
12415 narrow = (inst.instruction == T_MNEM_mov);
12416 else
12417 narrow = (inst.instruction == T_MNEM_movs);
12418 }
12419
12420 if (narrow)
12421 {
12422 switch (inst.operands[1].shift_kind)
12423 {
12424 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12425 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12426 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12427 default: narrow = FALSE; break;
12428 }
12429 }
12430
12431 if (narrow)
12432 {
fdfde340
JM
12433 inst.instruction |= Rn;
12434 inst.instruction |= Rm << 3;
e2b0ab59 12435 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
728ca7c9
PB
12436 }
12437 else
12438 {
12439 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12440 inst.instruction |= Rn << r0off;
728ca7c9
PB
12441 encode_thumb32_shifted_operand (1);
12442 }
c19d1205
ZW
12443 }
12444 else
12445 switch (inst.instruction)
12446 {
12447 case T_MNEM_mov:
837b3435 12448 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12449 results. Don't allow this. */
12450 if (low_regs)
12451 {
12452 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12453 "MOV Rd, Rs with two low registers is not "
12454 "permitted on this architecture");
fa94de6b 12455 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12456 arm_ext_v6);
12457 }
12458
c19d1205 12459 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12460 inst.instruction |= (Rn & 0x8) << 4;
12461 inst.instruction |= (Rn & 0x7);
12462 inst.instruction |= Rm << 3;
c19d1205 12463 break;
b99bd4ef 12464
c19d1205
ZW
12465 case T_MNEM_movs:
12466 /* We know we have low registers at this point.
941a8a52
MGD
12467 Generate LSLS Rd, Rs, #0. */
12468 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12469 inst.instruction |= Rn;
12470 inst.instruction |= Rm << 3;
c19d1205
ZW
12471 break;
12472
12473 case T_MNEM_cmp:
3d388997 12474 if (low_regs)
c19d1205
ZW
12475 {
12476 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12477 inst.instruction |= Rn;
12478 inst.instruction |= Rm << 3;
c19d1205
ZW
12479 }
12480 else
12481 {
12482 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12483 inst.instruction |= (Rn & 0x8) << 4;
12484 inst.instruction |= (Rn & 0x7);
12485 inst.instruction |= Rm << 3;
c19d1205
ZW
12486 }
12487 break;
12488 }
b99bd4ef
NC
12489 return;
12490 }
12491
c19d1205 12492 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12493
12494 /* PR 10443: Do not silently ignore shifted operands. */
12495 constraint (inst.operands[1].shifted,
12496 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12497
c19d1205 12498 if (inst.operands[1].isreg)
b99bd4ef 12499 {
fdfde340 12500 if (Rn < 8 && Rm < 8)
b99bd4ef 12501 {
c19d1205
ZW
12502 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12503 since a MOV instruction produces unpredictable results. */
12504 if (inst.instruction == T_OPCODE_MOV_I8)
12505 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12506 else
c19d1205 12507 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12508
fdfde340
JM
12509 inst.instruction |= Rn;
12510 inst.instruction |= Rm << 3;
b99bd4ef
NC
12511 }
12512 else
12513 {
c19d1205
ZW
12514 if (inst.instruction == T_OPCODE_MOV_I8)
12515 inst.instruction = T_OPCODE_MOV_HR;
12516 else
12517 inst.instruction = T_OPCODE_CMP_HR;
12518 do_t_cpy ();
b99bd4ef
NC
12519 }
12520 }
c19d1205 12521 else
b99bd4ef 12522 {
fdfde340 12523 constraint (Rn > 7,
c19d1205 12524 _("only lo regs allowed with immediate"));
fdfde340 12525 inst.instruction |= Rn << 8;
e2b0ab59 12526 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
c19d1205
ZW
12527 }
12528}
b99bd4ef 12529
c19d1205
ZW
12530static void
12531do_t_mov16 (void)
12532{
fdfde340 12533 unsigned Rd;
b6895b4f
PB
12534 bfd_vma imm;
12535 bfd_boolean top;
12536
12537 top = (inst.instruction & 0x00800000) != 0;
e2b0ab59 12538 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
b6895b4f 12539 {
33eaf5de 12540 constraint (top, _(":lower16: not allowed in this instruction"));
e2b0ab59 12541 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
b6895b4f 12542 }
e2b0ab59 12543 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
b6895b4f 12544 {
33eaf5de 12545 constraint (!top, _(":upper16: not allowed in this instruction"));
e2b0ab59 12546 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
b6895b4f
PB
12547 }
12548
fdfde340
JM
12549 Rd = inst.operands[0].reg;
12550 reject_bad_reg (Rd);
12551
12552 inst.instruction |= Rd << 8;
e2b0ab59 12553 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 12554 {
e2b0ab59 12555 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
12556 inst.instruction |= (imm & 0xf000) << 4;
12557 inst.instruction |= (imm & 0x0800) << 15;
12558 inst.instruction |= (imm & 0x0700) << 4;
12559 inst.instruction |= (imm & 0x00ff);
12560 }
c19d1205 12561}
b99bd4ef 12562
c19d1205
ZW
12563static void
12564do_t_mvn_tst (void)
12565{
fdfde340 12566 unsigned Rn, Rm;
c921be7d 12567
fdfde340
JM
12568 Rn = inst.operands[0].reg;
12569 Rm = inst.operands[1].reg;
12570
12571 if (inst.instruction == T_MNEM_cmp
12572 || inst.instruction == T_MNEM_cmn)
12573 constraint (Rn == REG_PC, BAD_PC);
12574 else
12575 reject_bad_reg (Rn);
12576 reject_bad_reg (Rm);
12577
c19d1205
ZW
12578 if (unified_syntax)
12579 {
12580 int r0off = (inst.instruction == T_MNEM_mvn
12581 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12582 bfd_boolean narrow;
12583
12584 if (inst.size_req == 4
12585 || inst.instruction > 0xffff
12586 || inst.operands[1].shifted
fdfde340 12587 || Rn > 7 || Rm > 7)
3d388997 12588 narrow = FALSE;
fe8b4cc3
KT
12589 else if (inst.instruction == T_MNEM_cmn
12590 || inst.instruction == T_MNEM_tst)
3d388997
PB
12591 narrow = TRUE;
12592 else if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 12593 narrow = !in_pred_block ();
3d388997 12594 else
5ee91343 12595 narrow = in_pred_block ();
3d388997 12596
c19d1205 12597 if (!inst.operands[1].isreg)
b99bd4ef 12598 {
c19d1205
ZW
12599 /* For an immediate, we always generate a 32-bit opcode;
12600 section relaxation will shrink it later if possible. */
12601 if (inst.instruction < 0xffff)
12602 inst.instruction = THUMB_OP32 (inst.instruction);
12603 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12604 inst.instruction |= Rn << r0off;
e2b0ab59 12605 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12606 }
c19d1205 12607 else
b99bd4ef 12608 {
c19d1205 12609 /* See if we can do this with a 16-bit instruction. */
3d388997 12610 if (narrow)
b99bd4ef 12611 {
c19d1205 12612 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12613 inst.instruction |= Rn;
12614 inst.instruction |= Rm << 3;
b99bd4ef 12615 }
c19d1205 12616 else
b99bd4ef 12617 {
c19d1205
ZW
12618 constraint (inst.operands[1].shifted
12619 && inst.operands[1].immisreg,
12620 _("shift must be constant"));
12621 if (inst.instruction < 0xffff)
12622 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12623 inst.instruction |= Rn << r0off;
c19d1205 12624 encode_thumb32_shifted_operand (1);
b99bd4ef 12625 }
b99bd4ef
NC
12626 }
12627 }
12628 else
12629 {
c19d1205
ZW
12630 constraint (inst.instruction > 0xffff
12631 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12632 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12633 _("unshifted register required"));
fdfde340 12634 constraint (Rn > 7 || Rm > 7,
c19d1205 12635 BAD_HIREG);
b99bd4ef 12636
c19d1205 12637 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12638 inst.instruction |= Rn;
12639 inst.instruction |= Rm << 3;
b99bd4ef 12640 }
b99bd4ef
NC
12641}
12642
b05fe5cf 12643static void
c19d1205 12644do_t_mrs (void)
b05fe5cf 12645{
fdfde340 12646 unsigned Rd;
037e8744
JB
12647
12648 if (do_vfp_nsyn_mrs () == SUCCESS)
12649 return;
12650
90ec0d68
MGD
12651 Rd = inst.operands[0].reg;
12652 reject_bad_reg (Rd);
12653 inst.instruction |= Rd << 8;
12654
12655 if (inst.operands[1].isreg)
62b3e311 12656 {
90ec0d68
MGD
12657 unsigned br = inst.operands[1].reg;
12658 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12659 as_bad (_("bad register for mrs"));
12660
12661 inst.instruction |= br & (0xf << 16);
12662 inst.instruction |= (br & 0x300) >> 4;
12663 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12664 }
12665 else
12666 {
90ec0d68 12667 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12668
d2cd1205 12669 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12670 {
12671 /* PR gas/12698: The constraint is only applied for m_profile.
12672 If the user has specified -march=all, we want to ignore it as
12673 we are building for any CPU type, including non-m variants. */
823d2571
TG
12674 bfd_boolean m_profile =
12675 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12676 constraint ((flags != 0) && m_profile, _("selected processor does "
12677 "not support requested special purpose register"));
12678 }
90ec0d68 12679 else
d2cd1205
JB
12680 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12681 devices). */
12682 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12683 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12684
90ec0d68
MGD
12685 inst.instruction |= (flags & SPSR_BIT) >> 2;
12686 inst.instruction |= inst.operands[1].imm & 0xff;
12687 inst.instruction |= 0xf0000;
12688 }
c19d1205 12689}
b05fe5cf 12690
c19d1205
ZW
12691static void
12692do_t_msr (void)
12693{
62b3e311 12694 int flags;
fdfde340 12695 unsigned Rn;
62b3e311 12696
037e8744
JB
12697 if (do_vfp_nsyn_msr () == SUCCESS)
12698 return;
12699
c19d1205
ZW
12700 constraint (!inst.operands[1].isreg,
12701 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12702
12703 if (inst.operands[0].isreg)
12704 flags = (int)(inst.operands[0].reg);
12705 else
12706 flags = inst.operands[0].imm;
12707
d2cd1205 12708 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12709 {
d2cd1205
JB
12710 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12711
1a43faaf 12712 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12713 If the user has specified -march=all, we want to ignore it as
12714 we are building for any CPU type, including non-m variants. */
823d2571
TG
12715 bfd_boolean m_profile =
12716 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12717 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12718 && (bits & ~(PSR_s | PSR_f)) != 0)
12719 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12720 && bits != PSR_f)) && m_profile,
12721 _("selected processor does not support requested special "
12722 "purpose register"));
62b3e311
PB
12723 }
12724 else
d2cd1205
JB
12725 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12726 "requested special purpose register"));
c921be7d 12727
fdfde340
JM
12728 Rn = inst.operands[1].reg;
12729 reject_bad_reg (Rn);
12730
62b3e311 12731 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12732 inst.instruction |= (flags & 0xf0000) >> 8;
12733 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12734 inst.instruction |= (flags & 0xff);
fdfde340 12735 inst.instruction |= Rn << 16;
c19d1205 12736}
b05fe5cf 12737
c19d1205
ZW
12738static void
12739do_t_mul (void)
12740{
17828f45 12741 bfd_boolean narrow;
fdfde340 12742 unsigned Rd, Rn, Rm;
17828f45 12743
c19d1205
ZW
12744 if (!inst.operands[2].present)
12745 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12746
fdfde340
JM
12747 Rd = inst.operands[0].reg;
12748 Rn = inst.operands[1].reg;
12749 Rm = inst.operands[2].reg;
12750
17828f45 12751 if (unified_syntax)
b05fe5cf 12752 {
17828f45 12753 if (inst.size_req == 4
fdfde340
JM
12754 || (Rd != Rn
12755 && Rd != Rm)
12756 || Rn > 7
12757 || Rm > 7)
17828f45
JM
12758 narrow = FALSE;
12759 else if (inst.instruction == T_MNEM_muls)
5ee91343 12760 narrow = !in_pred_block ();
17828f45 12761 else
5ee91343 12762 narrow = in_pred_block ();
b05fe5cf 12763 }
c19d1205 12764 else
b05fe5cf 12765 {
17828f45 12766 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12767 constraint (Rn > 7 || Rm > 7,
c19d1205 12768 BAD_HIREG);
17828f45
JM
12769 narrow = TRUE;
12770 }
b05fe5cf 12771
17828f45
JM
12772 if (narrow)
12773 {
12774 /* 16-bit MULS/Conditional MUL. */
c19d1205 12775 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12776 inst.instruction |= Rd;
b05fe5cf 12777
fdfde340
JM
12778 if (Rd == Rn)
12779 inst.instruction |= Rm << 3;
12780 else if (Rd == Rm)
12781 inst.instruction |= Rn << 3;
c19d1205
ZW
12782 else
12783 constraint (1, _("dest must overlap one source register"));
12784 }
17828f45
JM
12785 else
12786 {
e07e6e58
NC
12787 constraint (inst.instruction != T_MNEM_mul,
12788 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12789 /* 32-bit MUL. */
12790 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12791 inst.instruction |= Rd << 8;
12792 inst.instruction |= Rn << 16;
12793 inst.instruction |= Rm << 0;
12794
12795 reject_bad_reg (Rd);
12796 reject_bad_reg (Rn);
12797 reject_bad_reg (Rm);
17828f45 12798 }
c19d1205 12799}
b05fe5cf 12800
c19d1205
ZW
12801static void
12802do_t_mull (void)
12803{
fdfde340 12804 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12805
fdfde340
JM
12806 RdLo = inst.operands[0].reg;
12807 RdHi = inst.operands[1].reg;
12808 Rn = inst.operands[2].reg;
12809 Rm = inst.operands[3].reg;
12810
12811 reject_bad_reg (RdLo);
12812 reject_bad_reg (RdHi);
12813 reject_bad_reg (Rn);
12814 reject_bad_reg (Rm);
12815
12816 inst.instruction |= RdLo << 12;
12817 inst.instruction |= RdHi << 8;
12818 inst.instruction |= Rn << 16;
12819 inst.instruction |= Rm;
12820
12821 if (RdLo == RdHi)
c19d1205
ZW
12822 as_tsktsk (_("rdhi and rdlo must be different"));
12823}
b05fe5cf 12824
c19d1205
ZW
12825static void
12826do_t_nop (void)
12827{
5ee91343 12828 set_pred_insn_type (NEUTRAL_IT_INSN);
e07e6e58 12829
c19d1205
ZW
12830 if (unified_syntax)
12831 {
12832 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12833 {
c19d1205
ZW
12834 inst.instruction = THUMB_OP32 (inst.instruction);
12835 inst.instruction |= inst.operands[0].imm;
12836 }
12837 else
12838 {
bc2d1808
NC
12839 /* PR9722: Check for Thumb2 availability before
12840 generating a thumb2 nop instruction. */
afa62d5e 12841 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12842 {
12843 inst.instruction = THUMB_OP16 (inst.instruction);
12844 inst.instruction |= inst.operands[0].imm << 4;
12845 }
12846 else
12847 inst.instruction = 0x46c0;
c19d1205
ZW
12848 }
12849 }
12850 else
12851 {
12852 constraint (inst.operands[0].present,
12853 _("Thumb does not support NOP with hints"));
12854 inst.instruction = 0x46c0;
12855 }
12856}
b05fe5cf 12857
c19d1205
ZW
12858static void
12859do_t_neg (void)
12860{
12861 if (unified_syntax)
12862 {
3d388997
PB
12863 bfd_boolean narrow;
12864
12865 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 12866 narrow = !in_pred_block ();
3d388997 12867 else
5ee91343 12868 narrow = in_pred_block ();
3d388997
PB
12869 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12870 narrow = FALSE;
12871 if (inst.size_req == 4)
12872 narrow = FALSE;
12873
12874 if (!narrow)
c19d1205
ZW
12875 {
12876 inst.instruction = THUMB_OP32 (inst.instruction);
12877 inst.instruction |= inst.operands[0].reg << 8;
12878 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12879 }
12880 else
12881 {
c19d1205
ZW
12882 inst.instruction = THUMB_OP16 (inst.instruction);
12883 inst.instruction |= inst.operands[0].reg;
12884 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12885 }
12886 }
12887 else
12888 {
c19d1205
ZW
12889 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12890 BAD_HIREG);
12891 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12892
12893 inst.instruction = THUMB_OP16 (inst.instruction);
12894 inst.instruction |= inst.operands[0].reg;
12895 inst.instruction |= inst.operands[1].reg << 3;
12896 }
12897}
12898
1c444d06
JM
12899static void
12900do_t_orn (void)
12901{
12902 unsigned Rd, Rn;
12903
12904 Rd = inst.operands[0].reg;
12905 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12906
fdfde340
JM
12907 reject_bad_reg (Rd);
12908 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12909 reject_bad_reg (Rn);
12910
1c444d06
JM
12911 inst.instruction |= Rd << 8;
12912 inst.instruction |= Rn << 16;
12913
12914 if (!inst.operands[2].isreg)
12915 {
12916 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 12917 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
1c444d06
JM
12918 }
12919 else
12920 {
12921 unsigned Rm;
12922
12923 Rm = inst.operands[2].reg;
fdfde340 12924 reject_bad_reg (Rm);
1c444d06
JM
12925
12926 constraint (inst.operands[2].shifted
12927 && inst.operands[2].immisreg,
12928 _("shift must be constant"));
12929 encode_thumb32_shifted_operand (2);
12930 }
12931}
12932
c19d1205
ZW
12933static void
12934do_t_pkhbt (void)
12935{
fdfde340
JM
12936 unsigned Rd, Rn, Rm;
12937
12938 Rd = inst.operands[0].reg;
12939 Rn = inst.operands[1].reg;
12940 Rm = inst.operands[2].reg;
12941
12942 reject_bad_reg (Rd);
12943 reject_bad_reg (Rn);
12944 reject_bad_reg (Rm);
12945
12946 inst.instruction |= Rd << 8;
12947 inst.instruction |= Rn << 16;
12948 inst.instruction |= Rm;
c19d1205
ZW
12949 if (inst.operands[3].present)
12950 {
e2b0ab59
AV
12951 unsigned int val = inst.relocs[0].exp.X_add_number;
12952 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
12953 _("expression too complex"));
12954 inst.instruction |= (val & 0x1c) << 10;
12955 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12956 }
c19d1205 12957}
b05fe5cf 12958
c19d1205
ZW
12959static void
12960do_t_pkhtb (void)
12961{
12962 if (!inst.operands[3].present)
1ef52f49
NC
12963 {
12964 unsigned Rtmp;
12965
12966 inst.instruction &= ~0x00000020;
12967
12968 /* PR 10168. Swap the Rm and Rn registers. */
12969 Rtmp = inst.operands[1].reg;
12970 inst.operands[1].reg = inst.operands[2].reg;
12971 inst.operands[2].reg = Rtmp;
12972 }
c19d1205 12973 do_t_pkhbt ();
b05fe5cf
ZW
12974}
12975
c19d1205
ZW
12976static void
12977do_t_pld (void)
12978{
fdfde340
JM
12979 if (inst.operands[0].immisreg)
12980 reject_bad_reg (inst.operands[0].imm);
12981
c19d1205
ZW
12982 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12983}
b05fe5cf 12984
c19d1205
ZW
12985static void
12986do_t_push_pop (void)
b99bd4ef 12987{
e9f89963 12988 unsigned mask;
5f4273c7 12989
c19d1205
ZW
12990 constraint (inst.operands[0].writeback,
12991 _("push/pop do not support {reglist}^"));
e2b0ab59 12992 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205 12993 _("expression too complex"));
b99bd4ef 12994
e9f89963 12995 mask = inst.operands[0].imm;
d3bfe16e 12996 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12997 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12998 else if (inst.size_req != 4
c6025a80 12999 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 13000 ? REG_LR : REG_PC)))
b99bd4ef 13001 {
c19d1205
ZW
13002 inst.instruction = THUMB_OP16 (inst.instruction);
13003 inst.instruction |= THUMB_PP_PC_LR;
3c707909 13004 inst.instruction |= mask & 0xff;
c19d1205
ZW
13005 }
13006 else if (unified_syntax)
13007 {
3c707909 13008 inst.instruction = THUMB_OP32 (inst.instruction);
4b5a202f
AV
13009 encode_thumb2_multi (TRUE /* do_io */, 13, mask, TRUE);
13010 }
13011 else
13012 {
13013 inst.error = _("invalid register list to push/pop instruction");
13014 return;
c19d1205 13015 }
4b5a202f
AV
13016}
13017
13018static void
13019do_t_clrm (void)
13020{
13021 if (unified_syntax)
13022 encode_thumb2_multi (FALSE /* do_io */, -1, inst.operands[0].imm, FALSE);
c19d1205
ZW
13023 else
13024 {
13025 inst.error = _("invalid register list to push/pop instruction");
13026 return;
13027 }
c19d1205 13028}
b99bd4ef 13029
efd6b359
AV
13030static void
13031do_t_vscclrm (void)
13032{
13033 if (inst.operands[0].issingle)
13034 {
13035 inst.instruction |= (inst.operands[0].reg & 0x1) << 22;
13036 inst.instruction |= (inst.operands[0].reg & 0x1e) << 11;
13037 inst.instruction |= inst.operands[0].imm;
13038 }
13039 else
13040 {
13041 inst.instruction |= (inst.operands[0].reg & 0x10) << 18;
13042 inst.instruction |= (inst.operands[0].reg & 0xf) << 12;
13043 inst.instruction |= 1 << 8;
13044 inst.instruction |= inst.operands[0].imm << 1;
13045 }
13046}
13047
c19d1205
ZW
13048static void
13049do_t_rbit (void)
13050{
fdfde340
JM
13051 unsigned Rd, Rm;
13052
13053 Rd = inst.operands[0].reg;
13054 Rm = inst.operands[1].reg;
13055
13056 reject_bad_reg (Rd);
13057 reject_bad_reg (Rm);
13058
13059 inst.instruction |= Rd << 8;
13060 inst.instruction |= Rm << 16;
13061 inst.instruction |= Rm;
c19d1205 13062}
b99bd4ef 13063
c19d1205
ZW
13064static void
13065do_t_rev (void)
13066{
fdfde340
JM
13067 unsigned Rd, Rm;
13068
13069 Rd = inst.operands[0].reg;
13070 Rm = inst.operands[1].reg;
13071
13072 reject_bad_reg (Rd);
13073 reject_bad_reg (Rm);
13074
13075 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
13076 && inst.size_req != 4)
13077 {
13078 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13079 inst.instruction |= Rd;
13080 inst.instruction |= Rm << 3;
c19d1205
ZW
13081 }
13082 else if (unified_syntax)
13083 {
13084 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13085 inst.instruction |= Rd << 8;
13086 inst.instruction |= Rm << 16;
13087 inst.instruction |= Rm;
c19d1205
ZW
13088 }
13089 else
13090 inst.error = BAD_HIREG;
13091}
b99bd4ef 13092
1c444d06
JM
13093static void
13094do_t_rrx (void)
13095{
13096 unsigned Rd, Rm;
13097
13098 Rd = inst.operands[0].reg;
13099 Rm = inst.operands[1].reg;
13100
fdfde340
JM
13101 reject_bad_reg (Rd);
13102 reject_bad_reg (Rm);
c921be7d 13103
1c444d06
JM
13104 inst.instruction |= Rd << 8;
13105 inst.instruction |= Rm;
13106}
13107
c19d1205
ZW
13108static void
13109do_t_rsb (void)
13110{
fdfde340 13111 unsigned Rd, Rs;
b99bd4ef 13112
c19d1205
ZW
13113 Rd = inst.operands[0].reg;
13114 Rs = (inst.operands[1].present
13115 ? inst.operands[1].reg /* Rd, Rs, foo */
13116 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 13117
fdfde340
JM
13118 reject_bad_reg (Rd);
13119 reject_bad_reg (Rs);
13120 if (inst.operands[2].isreg)
13121 reject_bad_reg (inst.operands[2].reg);
13122
c19d1205
ZW
13123 inst.instruction |= Rd << 8;
13124 inst.instruction |= Rs << 16;
13125 if (!inst.operands[2].isreg)
13126 {
026d3abb
PB
13127 bfd_boolean narrow;
13128
13129 if ((inst.instruction & 0x00100000) != 0)
5ee91343 13130 narrow = !in_pred_block ();
026d3abb 13131 else
5ee91343 13132 narrow = in_pred_block ();
026d3abb
PB
13133
13134 if (Rd > 7 || Rs > 7)
13135 narrow = FALSE;
13136
13137 if (inst.size_req == 4 || !unified_syntax)
13138 narrow = FALSE;
13139
e2b0ab59
AV
13140 if (inst.relocs[0].exp.X_op != O_constant
13141 || inst.relocs[0].exp.X_add_number != 0)
026d3abb
PB
13142 narrow = FALSE;
13143
13144 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 13145 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
13146 if (narrow)
13147 {
e2b0ab59 13148 inst.relocs[0].type = BFD_RELOC_UNUSED;
026d3abb
PB
13149 inst.instruction = THUMB_OP16 (T_MNEM_negs);
13150 inst.instruction |= Rs << 3;
13151 inst.instruction |= Rd;
13152 }
13153 else
13154 {
13155 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13156 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
026d3abb 13157 }
c19d1205
ZW
13158 }
13159 else
13160 encode_thumb32_shifted_operand (2);
13161}
b99bd4ef 13162
c19d1205
ZW
13163static void
13164do_t_setend (void)
13165{
12e37cbc
MGD
13166 if (warn_on_deprecated
13167 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 13168 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 13169
5ee91343 13170 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
13171 if (inst.operands[0].imm)
13172 inst.instruction |= 0x8;
13173}
b99bd4ef 13174
c19d1205
ZW
13175static void
13176do_t_shift (void)
13177{
13178 if (!inst.operands[1].present)
13179 inst.operands[1].reg = inst.operands[0].reg;
13180
13181 if (unified_syntax)
13182 {
3d388997
PB
13183 bfd_boolean narrow;
13184 int shift_kind;
13185
13186 switch (inst.instruction)
13187 {
13188 case T_MNEM_asr:
13189 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
13190 case T_MNEM_lsl:
13191 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
13192 case T_MNEM_lsr:
13193 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
13194 case T_MNEM_ror:
13195 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
13196 default: abort ();
13197 }
13198
13199 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13200 narrow = !in_pred_block ();
3d388997 13201 else
5ee91343 13202 narrow = in_pred_block ();
3d388997
PB
13203 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13204 narrow = FALSE;
13205 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
13206 narrow = FALSE;
13207 if (inst.operands[2].isreg
13208 && (inst.operands[1].reg != inst.operands[0].reg
13209 || inst.operands[2].reg > 7))
13210 narrow = FALSE;
13211 if (inst.size_req == 4)
13212 narrow = FALSE;
13213
fdfde340
JM
13214 reject_bad_reg (inst.operands[0].reg);
13215 reject_bad_reg (inst.operands[1].reg);
c921be7d 13216
3d388997 13217 if (!narrow)
c19d1205
ZW
13218 {
13219 if (inst.operands[2].isreg)
b99bd4ef 13220 {
fdfde340 13221 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
13222 inst.instruction = THUMB_OP32 (inst.instruction);
13223 inst.instruction |= inst.operands[0].reg << 8;
13224 inst.instruction |= inst.operands[1].reg << 16;
13225 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
13226
13227 /* PR 12854: Error on extraneous shifts. */
13228 constraint (inst.operands[2].shifted,
13229 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
13230 }
13231 else
13232 {
13233 inst.operands[1].shifted = 1;
3d388997 13234 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
13235 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
13236 ? T_MNEM_movs : T_MNEM_mov);
13237 inst.instruction |= inst.operands[0].reg << 8;
13238 encode_thumb32_shifted_operand (1);
13239 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
e2b0ab59 13240 inst.relocs[0].type = BFD_RELOC_UNUSED;
b99bd4ef
NC
13241 }
13242 }
13243 else
13244 {
c19d1205 13245 if (inst.operands[2].isreg)
b99bd4ef 13246 {
3d388997 13247 switch (shift_kind)
b99bd4ef 13248 {
3d388997
PB
13249 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
13250 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
13251 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
13252 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 13253 default: abort ();
b99bd4ef 13254 }
5f4273c7 13255
c19d1205
ZW
13256 inst.instruction |= inst.operands[0].reg;
13257 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
13258
13259 /* PR 12854: Error on extraneous shifts. */
13260 constraint (inst.operands[2].shifted,
13261 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
13262 }
13263 else
13264 {
3d388997 13265 switch (shift_kind)
b99bd4ef 13266 {
3d388997
PB
13267 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13268 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13269 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 13270 default: abort ();
b99bd4ef 13271 }
e2b0ab59 13272 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
13273 inst.instruction |= inst.operands[0].reg;
13274 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
13275 }
13276 }
c19d1205
ZW
13277 }
13278 else
13279 {
13280 constraint (inst.operands[0].reg > 7
13281 || inst.operands[1].reg > 7, BAD_HIREG);
13282 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 13283
c19d1205
ZW
13284 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
13285 {
13286 constraint (inst.operands[2].reg > 7, BAD_HIREG);
13287 constraint (inst.operands[0].reg != inst.operands[1].reg,
13288 _("source1 and dest must be same register"));
b99bd4ef 13289
c19d1205
ZW
13290 switch (inst.instruction)
13291 {
13292 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
13293 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
13294 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
13295 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
13296 default: abort ();
13297 }
5f4273c7 13298
c19d1205
ZW
13299 inst.instruction |= inst.operands[0].reg;
13300 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
13301
13302 /* PR 12854: Error on extraneous shifts. */
13303 constraint (inst.operands[2].shifted,
13304 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
13305 }
13306 else
b99bd4ef 13307 {
c19d1205
ZW
13308 switch (inst.instruction)
13309 {
13310 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
13311 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
13312 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
13313 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
13314 default: abort ();
13315 }
e2b0ab59 13316 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
13317 inst.instruction |= inst.operands[0].reg;
13318 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
13319 }
13320 }
b99bd4ef
NC
13321}
13322
13323static void
c19d1205 13324do_t_simd (void)
b99bd4ef 13325{
fdfde340
JM
13326 unsigned Rd, Rn, Rm;
13327
13328 Rd = inst.operands[0].reg;
13329 Rn = inst.operands[1].reg;
13330 Rm = inst.operands[2].reg;
13331
13332 reject_bad_reg (Rd);
13333 reject_bad_reg (Rn);
13334 reject_bad_reg (Rm);
13335
13336 inst.instruction |= Rd << 8;
13337 inst.instruction |= Rn << 16;
13338 inst.instruction |= Rm;
c19d1205 13339}
b99bd4ef 13340
03ee1b7f
NC
13341static void
13342do_t_simd2 (void)
13343{
13344 unsigned Rd, Rn, Rm;
13345
13346 Rd = inst.operands[0].reg;
13347 Rm = inst.operands[1].reg;
13348 Rn = inst.operands[2].reg;
13349
13350 reject_bad_reg (Rd);
13351 reject_bad_reg (Rn);
13352 reject_bad_reg (Rm);
13353
13354 inst.instruction |= Rd << 8;
13355 inst.instruction |= Rn << 16;
13356 inst.instruction |= Rm;
13357}
13358
c19d1205 13359static void
3eb17e6b 13360do_t_smc (void)
c19d1205 13361{
e2b0ab59 13362 unsigned int value = inst.relocs[0].exp.X_add_number;
f4c65163
MGD
13363 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
13364 _("SMC is not permitted on this architecture"));
e2b0ab59 13365 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 13366 _("expression too complex"));
e2b0ab59 13367 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205
ZW
13368 inst.instruction |= (value & 0xf000) >> 12;
13369 inst.instruction |= (value & 0x0ff0);
13370 inst.instruction |= (value & 0x000f) << 16;
24382199 13371 /* PR gas/15623: SMC instructions must be last in an IT block. */
5ee91343 13372 set_pred_insn_type_last ();
c19d1205 13373}
b99bd4ef 13374
90ec0d68
MGD
13375static void
13376do_t_hvc (void)
13377{
e2b0ab59 13378 unsigned int value = inst.relocs[0].exp.X_add_number;
90ec0d68 13379
e2b0ab59 13380 inst.relocs[0].type = BFD_RELOC_UNUSED;
90ec0d68
MGD
13381 inst.instruction |= (value & 0x0fff);
13382 inst.instruction |= (value & 0xf000) << 4;
13383}
13384
c19d1205 13385static void
3a21c15a 13386do_t_ssat_usat (int bias)
c19d1205 13387{
fdfde340
JM
13388 unsigned Rd, Rn;
13389
13390 Rd = inst.operands[0].reg;
13391 Rn = inst.operands[2].reg;
13392
13393 reject_bad_reg (Rd);
13394 reject_bad_reg (Rn);
13395
13396 inst.instruction |= Rd << 8;
3a21c15a 13397 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 13398 inst.instruction |= Rn << 16;
b99bd4ef 13399
c19d1205 13400 if (inst.operands[3].present)
b99bd4ef 13401 {
e2b0ab59 13402 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
3a21c15a 13403
e2b0ab59 13404 inst.relocs[0].type = BFD_RELOC_UNUSED;
3a21c15a 13405
e2b0ab59 13406 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 13407 _("expression too complex"));
b99bd4ef 13408
3a21c15a 13409 if (shift_amount != 0)
6189168b 13410 {
3a21c15a
NC
13411 constraint (shift_amount > 31,
13412 _("shift expression is too large"));
13413
c19d1205 13414 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
13415 inst.instruction |= 0x00200000; /* sh bit. */
13416
13417 inst.instruction |= (shift_amount & 0x1c) << 10;
13418 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
13419 }
13420 }
b99bd4ef 13421}
c921be7d 13422
3a21c15a
NC
13423static void
13424do_t_ssat (void)
13425{
13426 do_t_ssat_usat (1);
13427}
b99bd4ef 13428
0dd132b6 13429static void
c19d1205 13430do_t_ssat16 (void)
0dd132b6 13431{
fdfde340
JM
13432 unsigned Rd, Rn;
13433
13434 Rd = inst.operands[0].reg;
13435 Rn = inst.operands[2].reg;
13436
13437 reject_bad_reg (Rd);
13438 reject_bad_reg (Rn);
13439
13440 inst.instruction |= Rd << 8;
c19d1205 13441 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 13442 inst.instruction |= Rn << 16;
c19d1205 13443}
0dd132b6 13444
c19d1205
ZW
13445static void
13446do_t_strex (void)
13447{
13448 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13449 || inst.operands[2].postind || inst.operands[2].writeback
13450 || inst.operands[2].immisreg || inst.operands[2].shifted
13451 || inst.operands[2].negative,
01cfc07f 13452 BAD_ADDR_MODE);
0dd132b6 13453
5be8be5d
DG
13454 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13455
c19d1205
ZW
13456 inst.instruction |= inst.operands[0].reg << 8;
13457 inst.instruction |= inst.operands[1].reg << 12;
13458 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 13459 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13460}
13461
b99bd4ef 13462static void
c19d1205 13463do_t_strexd (void)
b99bd4ef 13464{
c19d1205
ZW
13465 if (!inst.operands[2].present)
13466 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13467
c19d1205
ZW
13468 constraint (inst.operands[0].reg == inst.operands[1].reg
13469 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13470 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13471 BAD_OVERLAP);
b99bd4ef 13472
c19d1205
ZW
13473 inst.instruction |= inst.operands[0].reg;
13474 inst.instruction |= inst.operands[1].reg << 12;
13475 inst.instruction |= inst.operands[2].reg << 8;
13476 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13477}
13478
13479static void
c19d1205 13480do_t_sxtah (void)
b99bd4ef 13481{
fdfde340
JM
13482 unsigned Rd, Rn, Rm;
13483
13484 Rd = inst.operands[0].reg;
13485 Rn = inst.operands[1].reg;
13486 Rm = inst.operands[2].reg;
13487
13488 reject_bad_reg (Rd);
13489 reject_bad_reg (Rn);
13490 reject_bad_reg (Rm);
13491
13492 inst.instruction |= Rd << 8;
13493 inst.instruction |= Rn << 16;
13494 inst.instruction |= Rm;
c19d1205
ZW
13495 inst.instruction |= inst.operands[3].imm << 4;
13496}
b99bd4ef 13497
c19d1205
ZW
13498static void
13499do_t_sxth (void)
13500{
fdfde340
JM
13501 unsigned Rd, Rm;
13502
13503 Rd = inst.operands[0].reg;
13504 Rm = inst.operands[1].reg;
13505
13506 reject_bad_reg (Rd);
13507 reject_bad_reg (Rm);
c921be7d
NC
13508
13509 if (inst.instruction <= 0xffff
13510 && inst.size_req != 4
fdfde340 13511 && Rd <= 7 && Rm <= 7
c19d1205 13512 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13513 {
c19d1205 13514 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13515 inst.instruction |= Rd;
13516 inst.instruction |= Rm << 3;
b99bd4ef 13517 }
c19d1205 13518 else if (unified_syntax)
b99bd4ef 13519 {
c19d1205
ZW
13520 if (inst.instruction <= 0xffff)
13521 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13522 inst.instruction |= Rd << 8;
13523 inst.instruction |= Rm;
c19d1205 13524 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13525 }
c19d1205 13526 else
b99bd4ef 13527 {
c19d1205
ZW
13528 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13529 _("Thumb encoding does not support rotation"));
13530 constraint (1, BAD_HIREG);
b99bd4ef 13531 }
c19d1205 13532}
b99bd4ef 13533
c19d1205
ZW
13534static void
13535do_t_swi (void)
13536{
e2b0ab59 13537 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
c19d1205 13538}
b99bd4ef 13539
92e90b6e
PB
13540static void
13541do_t_tb (void)
13542{
fdfde340 13543 unsigned Rn, Rm;
92e90b6e
PB
13544 int half;
13545
13546 half = (inst.instruction & 0x10) != 0;
5ee91343 13547 set_pred_insn_type_last ();
dfa9f0d5
PB
13548 constraint (inst.operands[0].immisreg,
13549 _("instruction requires register index"));
fdfde340
JM
13550
13551 Rn = inst.operands[0].reg;
13552 Rm = inst.operands[0].imm;
c921be7d 13553
5c8ed6a4
JW
13554 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13555 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
13556 reject_bad_reg (Rm);
13557
92e90b6e
PB
13558 constraint (!half && inst.operands[0].shifted,
13559 _("instruction does not allow shifted index"));
fdfde340 13560 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13561}
13562
74db7efb
NC
13563static void
13564do_t_udf (void)
13565{
13566 if (!inst.operands[0].present)
13567 inst.operands[0].imm = 0;
13568
13569 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13570 {
13571 constraint (inst.size_req == 2,
13572 _("immediate value out of range"));
13573 inst.instruction = THUMB_OP32 (inst.instruction);
13574 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13575 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13576 }
13577 else
13578 {
13579 inst.instruction = THUMB_OP16 (inst.instruction);
13580 inst.instruction |= inst.operands[0].imm;
13581 }
13582
5ee91343 13583 set_pred_insn_type (NEUTRAL_IT_INSN);
74db7efb
NC
13584}
13585
13586
c19d1205
ZW
13587static void
13588do_t_usat (void)
13589{
3a21c15a 13590 do_t_ssat_usat (0);
b99bd4ef
NC
13591}
13592
13593static void
c19d1205 13594do_t_usat16 (void)
b99bd4ef 13595{
fdfde340
JM
13596 unsigned Rd, Rn;
13597
13598 Rd = inst.operands[0].reg;
13599 Rn = inst.operands[2].reg;
13600
13601 reject_bad_reg (Rd);
13602 reject_bad_reg (Rn);
13603
13604 inst.instruction |= Rd << 8;
c19d1205 13605 inst.instruction |= inst.operands[1].imm;
fdfde340 13606 inst.instruction |= Rn << 16;
b99bd4ef 13607}
c19d1205 13608
e12437dc
AV
13609/* Checking the range of the branch offset (VAL) with NBITS bits
13610 and IS_SIGNED signedness. Also checks the LSB to be 0. */
13611static int
13612v8_1_branch_value_check (int val, int nbits, int is_signed)
13613{
13614 gas_assert (nbits > 0 && nbits <= 32);
13615 if (is_signed)
13616 {
13617 int cmp = (1 << (nbits - 1));
13618 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
13619 return FAIL;
13620 }
13621 else
13622 {
13623 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
13624 return FAIL;
13625 }
13626 return SUCCESS;
13627}
13628
4389b29a
AV
13629/* For branches in Armv8.1-M Mainline. */
13630static void
13631do_t_branch_future (void)
13632{
13633 unsigned long insn = inst.instruction;
13634
13635 inst.instruction = THUMB_OP32 (inst.instruction);
13636 if (inst.operands[0].hasreloc == 0)
13637 {
13638 if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL)
13639 as_bad (BAD_BRANCH_OFF);
13640
13641 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
13642 }
13643 else
13644 {
13645 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
13646 inst.relocs[0].pc_rel = 1;
13647 }
13648
13649 switch (insn)
13650 {
13651 case T_MNEM_bf:
13652 if (inst.operands[1].hasreloc == 0)
13653 {
13654 int val = inst.operands[1].imm;
13655 if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL)
13656 as_bad (BAD_BRANCH_OFF);
13657
13658 int immA = (val & 0x0001f000) >> 12;
13659 int immB = (val & 0x00000ffc) >> 2;
13660 int immC = (val & 0x00000002) >> 1;
13661 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
13662 }
13663 else
13664 {
13665 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
13666 inst.relocs[1].pc_rel = 1;
13667 }
13668 break;
13669
65d1bc05
AV
13670 case T_MNEM_bfl:
13671 if (inst.operands[1].hasreloc == 0)
13672 {
13673 int val = inst.operands[1].imm;
13674 if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL)
13675 as_bad (BAD_BRANCH_OFF);
13676
13677 int immA = (val & 0x0007f000) >> 12;
13678 int immB = (val & 0x00000ffc) >> 2;
13679 int immC = (val & 0x00000002) >> 1;
13680 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
13681 }
13682 else
13683 {
13684 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
13685 inst.relocs[1].pc_rel = 1;
13686 }
13687 break;
13688
f6b2b12d
AV
13689 case T_MNEM_bfcsel:
13690 /* Operand 1. */
13691 if (inst.operands[1].hasreloc == 0)
13692 {
13693 int val = inst.operands[1].imm;
13694 int immA = (val & 0x00001000) >> 12;
13695 int immB = (val & 0x00000ffc) >> 2;
13696 int immC = (val & 0x00000002) >> 1;
13697 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
13698 }
13699 else
13700 {
13701 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
13702 inst.relocs[1].pc_rel = 1;
13703 }
13704
13705 /* Operand 2. */
13706 if (inst.operands[2].hasreloc == 0)
13707 {
13708 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
13709 int val2 = inst.operands[2].imm;
13710 int val0 = inst.operands[0].imm & 0x1f;
13711 int diff = val2 - val0;
13712 if (diff == 4)
13713 inst.instruction |= 1 << 17; /* T bit. */
13714 else if (diff != 2)
13715 as_bad (_("out of range label-relative fixup value"));
13716 }
13717 else
13718 {
13719 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
13720 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
13721 inst.relocs[2].pc_rel = 1;
13722 }
13723
13724 /* Operand 3. */
13725 constraint (inst.cond != COND_ALWAYS, BAD_COND);
13726 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
13727 break;
13728
f1c7f421
AV
13729 case T_MNEM_bfx:
13730 case T_MNEM_bflx:
13731 inst.instruction |= inst.operands[1].reg << 16;
13732 break;
13733
4389b29a
AV
13734 default: abort ();
13735 }
13736}
13737
60f993ce
AV
13738/* Helper function for do_t_loloop to handle relocations. */
13739static void
13740v8_1_loop_reloc (int is_le)
13741{
13742 if (inst.relocs[0].exp.X_op == O_constant)
13743 {
13744 int value = inst.relocs[0].exp.X_add_number;
13745 value = (is_le) ? -value : value;
13746
13747 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
13748 as_bad (BAD_BRANCH_OFF);
13749
13750 int imml, immh;
13751
13752 immh = (value & 0x00000ffc) >> 2;
13753 imml = (value & 0x00000002) >> 1;
13754
13755 inst.instruction |= (imml << 11) | (immh << 1);
13756 }
13757 else
13758 {
13759 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
13760 inst.relocs[0].pc_rel = 1;
13761 }
13762}
13763
13764/* To handle the Scalar Low Overhead Loop instructions
13765 in Armv8.1-M Mainline. */
13766static void
13767do_t_loloop (void)
13768{
13769 unsigned long insn = inst.instruction;
13770
5ee91343 13771 set_pred_insn_type (OUTSIDE_PRED_INSN);
60f993ce
AV
13772 inst.instruction = THUMB_OP32 (inst.instruction);
13773
13774 switch (insn)
13775 {
13776 case T_MNEM_le:
13777 /* le <label>. */
13778 if (!inst.operands[0].present)
13779 inst.instruction |= 1 << 21;
13780
13781 v8_1_loop_reloc (TRUE);
13782 break;
13783
13784 case T_MNEM_wls:
13785 v8_1_loop_reloc (FALSE);
13786 /* Fall through. */
13787 case T_MNEM_dls:
13788 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
13789 inst.instruction |= (inst.operands[1].reg << 16);
13790 break;
13791
13792 default: abort();
13793 }
13794}
13795
5287ad62 13796/* Neon instruction encoder helpers. */
5f4273c7 13797
5287ad62 13798/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13799
5287ad62
JB
13800/* An "invalid" code for the following tables. */
13801#define N_INV -1u
13802
13803struct neon_tab_entry
b99bd4ef 13804{
5287ad62
JB
13805 unsigned integer;
13806 unsigned float_or_poly;
13807 unsigned scalar_or_imm;
13808};
5f4273c7 13809
5287ad62
JB
13810/* Map overloaded Neon opcodes to their respective encodings. */
13811#define NEON_ENC_TAB \
13812 X(vabd, 0x0000700, 0x1200d00, N_INV), \
5ee91343 13813 X(vabdl, 0x0800700, N_INV, N_INV), \
5287ad62
JB
13814 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13815 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13816 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13817 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13818 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13819 X(vadd, 0x0000800, 0x0000d00, N_INV), \
5ee91343 13820 X(vaddl, 0x0800000, N_INV, N_INV), \
5287ad62 13821 X(vsub, 0x1000800, 0x0200d00, N_INV), \
5ee91343 13822 X(vsubl, 0x0800200, N_INV, N_INV), \
5287ad62
JB
13823 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13824 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13825 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13826 /* Register variants of the following two instructions are encoded as
e07e6e58 13827 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13828 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13829 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13830 X(vfma, N_INV, 0x0000c10, N_INV), \
13831 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13832 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13833 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13834 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13835 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13836 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13837 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13838 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13839 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13840 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13841 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13842 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13843 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13844 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13845 X(vshl, 0x0000400, N_INV, 0x0800510), \
13846 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13847 X(vand, 0x0000110, N_INV, 0x0800030), \
13848 X(vbic, 0x0100110, N_INV, 0x0800030), \
13849 X(veor, 0x1000110, N_INV, N_INV), \
13850 X(vorn, 0x0300110, N_INV, 0x0800010), \
13851 X(vorr, 0x0200110, N_INV, 0x0800010), \
13852 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13853 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13854 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13855 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13856 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13857 X(vst1, 0x0000000, 0x0800000, N_INV), \
13858 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13859 X(vst2, 0x0000100, 0x0800100, N_INV), \
13860 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13861 X(vst3, 0x0000200, 0x0800200, N_INV), \
13862 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13863 X(vst4, 0x0000300, 0x0800300, N_INV), \
13864 X(vmovn, 0x1b20200, N_INV, N_INV), \
13865 X(vtrn, 0x1b20080, N_INV, N_INV), \
13866 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13867 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13868 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13869 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13870 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13871 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13872 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13873 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13874 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13875 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13876 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13877 X(vseleq, 0xe000a00, N_INV, N_INV), \
13878 X(vselvs, 0xe100a00, N_INV, N_INV), \
13879 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13880 X(vselgt, 0xe300a00, N_INV, N_INV), \
13881 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13882 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13883 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13884 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13885 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13886 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13887 X(sha3op, 0x2000c00, N_INV, N_INV), \
13888 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13889 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13890
13891enum neon_opc
13892{
13893#define X(OPC,I,F,S) N_MNEM_##OPC
13894NEON_ENC_TAB
13895#undef X
13896};
b99bd4ef 13897
5287ad62
JB
13898static const struct neon_tab_entry neon_enc_tab[] =
13899{
13900#define X(OPC,I,F,S) { (I), (F), (S) }
13901NEON_ENC_TAB
13902#undef X
13903};
b99bd4ef 13904
88714cb8
DG
13905/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13906#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13907#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13908#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13909#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13910#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13911#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13912#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13913#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13914#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13915#define NEON_ENC_SINGLE_(X) \
037e8744 13916 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13917#define NEON_ENC_DOUBLE_(X) \
037e8744 13918 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13919#define NEON_ENC_FPV8_(X) \
13920 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13921
88714cb8
DG
13922#define NEON_ENCODE(type, inst) \
13923 do \
13924 { \
13925 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13926 inst.is_neon = 1; \
13927 } \
13928 while (0)
13929
13930#define check_neon_suffixes \
13931 do \
13932 { \
13933 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13934 { \
13935 as_bad (_("invalid neon suffix for non neon instruction")); \
13936 return; \
13937 } \
13938 } \
13939 while (0)
13940
037e8744
JB
13941/* Define shapes for instruction operands. The following mnemonic characters
13942 are used in this table:
5287ad62 13943
037e8744 13944 F - VFP S<n> register
5287ad62
JB
13945 D - Neon D<n> register
13946 Q - Neon Q<n> register
13947 I - Immediate
13948 S - Scalar
13949 R - ARM register
13950 L - D<n> register list
5f4273c7 13951
037e8744
JB
13952 This table is used to generate various data:
13953 - enumerations of the form NS_DDR to be used as arguments to
13954 neon_select_shape.
13955 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13956 - a table used to drive neon_select_shape. */
b99bd4ef 13957
037e8744
JB
13958#define NEON_SHAPE_DEF \
13959 X(3, (D, D, D), DOUBLE), \
13960 X(3, (Q, Q, Q), QUAD), \
13961 X(3, (D, D, I), DOUBLE), \
13962 X(3, (Q, Q, I), QUAD), \
13963 X(3, (D, D, S), DOUBLE), \
13964 X(3, (Q, Q, S), QUAD), \
5ee91343 13965 X(3, (Q, Q, R), QUAD), \
037e8744
JB
13966 X(2, (D, D), DOUBLE), \
13967 X(2, (Q, Q), QUAD), \
13968 X(2, (D, S), DOUBLE), \
13969 X(2, (Q, S), QUAD), \
13970 X(2, (D, R), DOUBLE), \
13971 X(2, (Q, R), QUAD), \
13972 X(2, (D, I), DOUBLE), \
13973 X(2, (Q, I), QUAD), \
13974 X(3, (D, L, D), DOUBLE), \
13975 X(2, (D, Q), MIXED), \
13976 X(2, (Q, D), MIXED), \
13977 X(3, (D, Q, I), MIXED), \
13978 X(3, (Q, D, I), MIXED), \
13979 X(3, (Q, D, D), MIXED), \
13980 X(3, (D, Q, Q), MIXED), \
13981 X(3, (Q, Q, D), MIXED), \
13982 X(3, (Q, D, S), MIXED), \
13983 X(3, (D, Q, S), MIXED), \
13984 X(4, (D, D, D, I), DOUBLE), \
13985 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
13986 X(4, (D, D, S, I), DOUBLE), \
13987 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
13988 X(2, (F, F), SINGLE), \
13989 X(3, (F, F, F), SINGLE), \
13990 X(2, (F, I), SINGLE), \
13991 X(2, (F, D), MIXED), \
13992 X(2, (D, F), MIXED), \
13993 X(3, (F, F, I), MIXED), \
13994 X(4, (R, R, F, F), SINGLE), \
13995 X(4, (F, F, R, R), SINGLE), \
13996 X(3, (D, R, R), DOUBLE), \
13997 X(3, (R, R, D), DOUBLE), \
13998 X(2, (S, R), SINGLE), \
13999 X(2, (R, S), SINGLE), \
14000 X(2, (F, R), SINGLE), \
d54af2d0
RL
14001 X(2, (R, F), SINGLE), \
14002/* Half float shape supported so far. */\
14003 X (2, (H, D), MIXED), \
14004 X (2, (D, H), MIXED), \
14005 X (2, (H, F), MIXED), \
14006 X (2, (F, H), MIXED), \
14007 X (2, (H, H), HALF), \
14008 X (2, (H, R), HALF), \
14009 X (2, (R, H), HALF), \
14010 X (2, (H, I), HALF), \
14011 X (3, (H, H, H), HALF), \
14012 X (3, (H, F, I), MIXED), \
dec41383
JW
14013 X (3, (F, H, I), MIXED), \
14014 X (3, (D, H, H), MIXED), \
14015 X (3, (D, H, S), MIXED)
037e8744
JB
14016
14017#define S2(A,B) NS_##A##B
14018#define S3(A,B,C) NS_##A##B##C
14019#define S4(A,B,C,D) NS_##A##B##C##D
14020
14021#define X(N, L, C) S##N L
14022
5287ad62
JB
14023enum neon_shape
14024{
037e8744
JB
14025 NEON_SHAPE_DEF,
14026 NS_NULL
5287ad62 14027};
b99bd4ef 14028
037e8744
JB
14029#undef X
14030#undef S2
14031#undef S3
14032#undef S4
14033
14034enum neon_shape_class
14035{
d54af2d0 14036 SC_HALF,
037e8744
JB
14037 SC_SINGLE,
14038 SC_DOUBLE,
14039 SC_QUAD,
14040 SC_MIXED
14041};
14042
14043#define X(N, L, C) SC_##C
14044
14045static enum neon_shape_class neon_shape_class[] =
14046{
14047 NEON_SHAPE_DEF
14048};
14049
14050#undef X
14051
14052enum neon_shape_el
14053{
d54af2d0 14054 SE_H,
037e8744
JB
14055 SE_F,
14056 SE_D,
14057 SE_Q,
14058 SE_I,
14059 SE_S,
14060 SE_R,
14061 SE_L
14062};
14063
14064/* Register widths of above. */
14065static unsigned neon_shape_el_size[] =
14066{
d54af2d0 14067 16,
037e8744
JB
14068 32,
14069 64,
14070 128,
14071 0,
14072 32,
14073 32,
14074 0
14075};
14076
14077struct neon_shape_info
14078{
14079 unsigned els;
14080 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
14081};
14082
14083#define S2(A,B) { SE_##A, SE_##B }
14084#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
14085#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
14086
14087#define X(N, L, C) { N, S##N L }
14088
14089static struct neon_shape_info neon_shape_tab[] =
14090{
14091 NEON_SHAPE_DEF
14092};
14093
14094#undef X
14095#undef S2
14096#undef S3
14097#undef S4
14098
5287ad62
JB
14099/* Bit masks used in type checking given instructions.
14100 'N_EQK' means the type must be the same as (or based on in some way) the key
14101 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
14102 set, various other bits can be set as well in order to modify the meaning of
14103 the type constraint. */
14104
14105enum neon_type_mask
14106{
8e79c3df
CM
14107 N_S8 = 0x0000001,
14108 N_S16 = 0x0000002,
14109 N_S32 = 0x0000004,
14110 N_S64 = 0x0000008,
14111 N_U8 = 0x0000010,
14112 N_U16 = 0x0000020,
14113 N_U32 = 0x0000040,
14114 N_U64 = 0x0000080,
14115 N_I8 = 0x0000100,
14116 N_I16 = 0x0000200,
14117 N_I32 = 0x0000400,
14118 N_I64 = 0x0000800,
14119 N_8 = 0x0001000,
14120 N_16 = 0x0002000,
14121 N_32 = 0x0004000,
14122 N_64 = 0x0008000,
14123 N_P8 = 0x0010000,
14124 N_P16 = 0x0020000,
14125 N_F16 = 0x0040000,
14126 N_F32 = 0x0080000,
14127 N_F64 = 0x0100000,
4f51b4bd 14128 N_P64 = 0x0200000,
c921be7d
NC
14129 N_KEY = 0x1000000, /* Key element (main type specifier). */
14130 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 14131 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 14132 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
14133 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
14134 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
14135 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
14136 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
14137 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
14138 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
14139 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 14140 N_UTYP = 0,
4f51b4bd 14141 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
14142};
14143
dcbf9037
JB
14144#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
14145
5287ad62
JB
14146#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
14147#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
14148#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
14149#define N_S_32 (N_S8 | N_S16 | N_S32)
14150#define N_F_16_32 (N_F16 | N_F32)
14151#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 14152#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 14153#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 14154#define N_F_ALL (N_F16 | N_F32 | N_F64)
5ee91343
AV
14155#define N_I_MVE (N_I8 | N_I16 | N_I32)
14156#define N_F_MVE (N_F16 | N_F32)
14157#define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
5287ad62
JB
14158
14159/* Pass this as the first type argument to neon_check_type to ignore types
14160 altogether. */
14161#define N_IGNORE_TYPE (N_KEY | N_EQK)
14162
037e8744
JB
14163/* Select a "shape" for the current instruction (describing register types or
14164 sizes) from a list of alternatives. Return NS_NULL if the current instruction
14165 doesn't fit. For non-polymorphic shapes, checking is usually done as a
14166 function of operand parsing, so this function doesn't need to be called.
14167 Shapes should be listed in order of decreasing length. */
5287ad62
JB
14168
14169static enum neon_shape
037e8744 14170neon_select_shape (enum neon_shape shape, ...)
5287ad62 14171{
037e8744
JB
14172 va_list ap;
14173 enum neon_shape first_shape = shape;
5287ad62
JB
14174
14175 /* Fix missing optional operands. FIXME: we don't know at this point how
14176 many arguments we should have, so this makes the assumption that we have
14177 > 1. This is true of all current Neon opcodes, I think, but may not be
14178 true in the future. */
14179 if (!inst.operands[1].present)
14180 inst.operands[1] = inst.operands[0];
14181
037e8744 14182 va_start (ap, shape);
5f4273c7 14183
21d799b5 14184 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
14185 {
14186 unsigned j;
14187 int matches = 1;
14188
14189 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
14190 {
14191 if (!inst.operands[j].present)
14192 {
14193 matches = 0;
14194 break;
14195 }
14196
14197 switch (neon_shape_tab[shape].el[j])
14198 {
d54af2d0
RL
14199 /* If a .f16, .16, .u16, .s16 type specifier is given over
14200 a VFP single precision register operand, it's essentially
14201 means only half of the register is used.
14202
14203 If the type specifier is given after the mnemonics, the
14204 information is stored in inst.vectype. If the type specifier
14205 is given after register operand, the information is stored
14206 in inst.operands[].vectype.
14207
14208 When there is only one type specifier, and all the register
14209 operands are the same type of hardware register, the type
14210 specifier applies to all register operands.
14211
14212 If no type specifier is given, the shape is inferred from
14213 operand information.
14214
14215 for example:
14216 vadd.f16 s0, s1, s2: NS_HHH
14217 vabs.f16 s0, s1: NS_HH
14218 vmov.f16 s0, r1: NS_HR
14219 vmov.f16 r0, s1: NS_RH
14220 vcvt.f16 r0, s1: NS_RH
14221 vcvt.f16.s32 s2, s2, #29: NS_HFI
14222 vcvt.f16.s32 s2, s2: NS_HF
14223 */
14224 case SE_H:
14225 if (!(inst.operands[j].isreg
14226 && inst.operands[j].isvec
14227 && inst.operands[j].issingle
14228 && !inst.operands[j].isquad
14229 && ((inst.vectype.elems == 1
14230 && inst.vectype.el[0].size == 16)
14231 || (inst.vectype.elems > 1
14232 && inst.vectype.el[j].size == 16)
14233 || (inst.vectype.elems == 0
14234 && inst.operands[j].vectype.type != NT_invtype
14235 && inst.operands[j].vectype.size == 16))))
14236 matches = 0;
14237 break;
14238
477330fc
RM
14239 case SE_F:
14240 if (!(inst.operands[j].isreg
14241 && inst.operands[j].isvec
14242 && inst.operands[j].issingle
d54af2d0
RL
14243 && !inst.operands[j].isquad
14244 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
14245 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
14246 || (inst.vectype.elems == 0
14247 && (inst.operands[j].vectype.size == 32
14248 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
14249 matches = 0;
14250 break;
14251
14252 case SE_D:
14253 if (!(inst.operands[j].isreg
14254 && inst.operands[j].isvec
14255 && !inst.operands[j].isquad
14256 && !inst.operands[j].issingle))
14257 matches = 0;
14258 break;
14259
14260 case SE_R:
14261 if (!(inst.operands[j].isreg
14262 && !inst.operands[j].isvec))
14263 matches = 0;
14264 break;
14265
14266 case SE_Q:
14267 if (!(inst.operands[j].isreg
14268 && inst.operands[j].isvec
14269 && inst.operands[j].isquad
14270 && !inst.operands[j].issingle))
14271 matches = 0;
14272 break;
14273
14274 case SE_I:
14275 if (!(!inst.operands[j].isreg
14276 && !inst.operands[j].isscalar))
14277 matches = 0;
14278 break;
14279
14280 case SE_S:
14281 if (!(!inst.operands[j].isreg
14282 && inst.operands[j].isscalar))
14283 matches = 0;
14284 break;
14285
14286 case SE_L:
14287 break;
14288 }
3fde54a2
JZ
14289 if (!matches)
14290 break;
477330fc 14291 }
ad6cec43
MGD
14292 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
14293 /* We've matched all the entries in the shape table, and we don't
14294 have any left over operands which have not been matched. */
477330fc 14295 break;
037e8744 14296 }
5f4273c7 14297
037e8744 14298 va_end (ap);
5287ad62 14299
037e8744
JB
14300 if (shape == NS_NULL && first_shape != NS_NULL)
14301 first_error (_("invalid instruction shape"));
5287ad62 14302
037e8744
JB
14303 return shape;
14304}
5287ad62 14305
037e8744
JB
14306/* True if SHAPE is predominantly a quadword operation (most of the time, this
14307 means the Q bit should be set). */
14308
14309static int
14310neon_quad (enum neon_shape shape)
14311{
14312 return neon_shape_class[shape] == SC_QUAD;
5287ad62 14313}
037e8744 14314
5287ad62
JB
14315static void
14316neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 14317 unsigned *g_size)
5287ad62
JB
14318{
14319 /* Allow modification to be made to types which are constrained to be
14320 based on the key element, based on bits set alongside N_EQK. */
14321 if ((typebits & N_EQK) != 0)
14322 {
14323 if ((typebits & N_HLF) != 0)
14324 *g_size /= 2;
14325 else if ((typebits & N_DBL) != 0)
14326 *g_size *= 2;
14327 if ((typebits & N_SGN) != 0)
14328 *g_type = NT_signed;
14329 else if ((typebits & N_UNS) != 0)
477330fc 14330 *g_type = NT_unsigned;
5287ad62 14331 else if ((typebits & N_INT) != 0)
477330fc 14332 *g_type = NT_integer;
5287ad62 14333 else if ((typebits & N_FLT) != 0)
477330fc 14334 *g_type = NT_float;
dcbf9037 14335 else if ((typebits & N_SIZ) != 0)
477330fc 14336 *g_type = NT_untyped;
5287ad62
JB
14337 }
14338}
5f4273c7 14339
5287ad62
JB
14340/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
14341 operand type, i.e. the single type specified in a Neon instruction when it
14342 is the only one given. */
14343
14344static struct neon_type_el
14345neon_type_promote (struct neon_type_el *key, unsigned thisarg)
14346{
14347 struct neon_type_el dest = *key;
5f4273c7 14348
9c2799c2 14349 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 14350
5287ad62
JB
14351 neon_modify_type_size (thisarg, &dest.type, &dest.size);
14352
14353 return dest;
14354}
14355
14356/* Convert Neon type and size into compact bitmask representation. */
14357
14358static enum neon_type_mask
14359type_chk_of_el_type (enum neon_el_type type, unsigned size)
14360{
14361 switch (type)
14362 {
14363 case NT_untyped:
14364 switch (size)
477330fc
RM
14365 {
14366 case 8: return N_8;
14367 case 16: return N_16;
14368 case 32: return N_32;
14369 case 64: return N_64;
14370 default: ;
14371 }
5287ad62
JB
14372 break;
14373
14374 case NT_integer:
14375 switch (size)
477330fc
RM
14376 {
14377 case 8: return N_I8;
14378 case 16: return N_I16;
14379 case 32: return N_I32;
14380 case 64: return N_I64;
14381 default: ;
14382 }
5287ad62
JB
14383 break;
14384
14385 case NT_float:
037e8744 14386 switch (size)
477330fc 14387 {
8e79c3df 14388 case 16: return N_F16;
477330fc
RM
14389 case 32: return N_F32;
14390 case 64: return N_F64;
14391 default: ;
14392 }
5287ad62
JB
14393 break;
14394
14395 case NT_poly:
14396 switch (size)
477330fc
RM
14397 {
14398 case 8: return N_P8;
14399 case 16: return N_P16;
4f51b4bd 14400 case 64: return N_P64;
477330fc
RM
14401 default: ;
14402 }
5287ad62
JB
14403 break;
14404
14405 case NT_signed:
14406 switch (size)
477330fc
RM
14407 {
14408 case 8: return N_S8;
14409 case 16: return N_S16;
14410 case 32: return N_S32;
14411 case 64: return N_S64;
14412 default: ;
14413 }
5287ad62
JB
14414 break;
14415
14416 case NT_unsigned:
14417 switch (size)
477330fc
RM
14418 {
14419 case 8: return N_U8;
14420 case 16: return N_U16;
14421 case 32: return N_U32;
14422 case 64: return N_U64;
14423 default: ;
14424 }
5287ad62
JB
14425 break;
14426
14427 default: ;
14428 }
5f4273c7 14429
5287ad62
JB
14430 return N_UTYP;
14431}
14432
14433/* Convert compact Neon bitmask type representation to a type and size. Only
14434 handles the case where a single bit is set in the mask. */
14435
dcbf9037 14436static int
5287ad62 14437el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 14438 enum neon_type_mask mask)
5287ad62 14439{
dcbf9037
JB
14440 if ((mask & N_EQK) != 0)
14441 return FAIL;
14442
5287ad62
JB
14443 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
14444 *size = 8;
c70a8987 14445 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 14446 *size = 16;
dcbf9037 14447 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 14448 *size = 32;
4f51b4bd 14449 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 14450 *size = 64;
dcbf9037
JB
14451 else
14452 return FAIL;
14453
5287ad62
JB
14454 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
14455 *type = NT_signed;
dcbf9037 14456 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 14457 *type = NT_unsigned;
dcbf9037 14458 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 14459 *type = NT_integer;
dcbf9037 14460 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 14461 *type = NT_untyped;
4f51b4bd 14462 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 14463 *type = NT_poly;
d54af2d0 14464 else if ((mask & (N_F_ALL)) != 0)
5287ad62 14465 *type = NT_float;
dcbf9037
JB
14466 else
14467 return FAIL;
5f4273c7 14468
dcbf9037 14469 return SUCCESS;
5287ad62
JB
14470}
14471
14472/* Modify a bitmask of allowed types. This is only needed for type
14473 relaxation. */
14474
14475static unsigned
14476modify_types_allowed (unsigned allowed, unsigned mods)
14477{
14478 unsigned size;
14479 enum neon_el_type type;
14480 unsigned destmask;
14481 int i;
5f4273c7 14482
5287ad62 14483 destmask = 0;
5f4273c7 14484
5287ad62
JB
14485 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
14486 {
21d799b5 14487 if (el_type_of_type_chk (&type, &size,
477330fc
RM
14488 (enum neon_type_mask) (allowed & i)) == SUCCESS)
14489 {
14490 neon_modify_type_size (mods, &type, &size);
14491 destmask |= type_chk_of_el_type (type, size);
14492 }
5287ad62 14493 }
5f4273c7 14494
5287ad62
JB
14495 return destmask;
14496}
14497
14498/* Check type and return type classification.
14499 The manual states (paraphrase): If one datatype is given, it indicates the
14500 type given in:
14501 - the second operand, if there is one
14502 - the operand, if there is no second operand
14503 - the result, if there are no operands.
14504 This isn't quite good enough though, so we use a concept of a "key" datatype
14505 which is set on a per-instruction basis, which is the one which matters when
14506 only one data type is written.
14507 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 14508 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
14509
14510static struct neon_type_el
14511neon_check_type (unsigned els, enum neon_shape ns, ...)
14512{
14513 va_list ap;
14514 unsigned i, pass, key_el = 0;
14515 unsigned types[NEON_MAX_TYPE_ELS];
14516 enum neon_el_type k_type = NT_invtype;
14517 unsigned k_size = -1u;
14518 struct neon_type_el badtype = {NT_invtype, -1};
14519 unsigned key_allowed = 0;
14520
14521 /* Optional registers in Neon instructions are always (not) in operand 1.
14522 Fill in the missing operand here, if it was omitted. */
14523 if (els > 1 && !inst.operands[1].present)
14524 inst.operands[1] = inst.operands[0];
14525
14526 /* Suck up all the varargs. */
14527 va_start (ap, ns);
14528 for (i = 0; i < els; i++)
14529 {
14530 unsigned thisarg = va_arg (ap, unsigned);
14531 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
14532 {
14533 va_end (ap);
14534 return badtype;
14535 }
5287ad62
JB
14536 types[i] = thisarg;
14537 if ((thisarg & N_KEY) != 0)
477330fc 14538 key_el = i;
5287ad62
JB
14539 }
14540 va_end (ap);
14541
dcbf9037
JB
14542 if (inst.vectype.elems > 0)
14543 for (i = 0; i < els; i++)
14544 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
14545 {
14546 first_error (_("types specified in both the mnemonic and operands"));
14547 return badtype;
14548 }
dcbf9037 14549
5287ad62
JB
14550 /* Duplicate inst.vectype elements here as necessary.
14551 FIXME: No idea if this is exactly the same as the ARM assembler,
14552 particularly when an insn takes one register and one non-register
14553 operand. */
14554 if (inst.vectype.elems == 1 && els > 1)
14555 {
14556 unsigned j;
14557 inst.vectype.elems = els;
14558 inst.vectype.el[key_el] = inst.vectype.el[0];
14559 for (j = 0; j < els; j++)
477330fc
RM
14560 if (j != key_el)
14561 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14562 types[j]);
dcbf9037
JB
14563 }
14564 else if (inst.vectype.elems == 0 && els > 0)
14565 {
14566 unsigned j;
14567 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
14568 after each operand. We allow some flexibility here; as long as the
14569 "key" operand has a type, we can infer the others. */
dcbf9037 14570 for (j = 0; j < els; j++)
477330fc
RM
14571 if (inst.operands[j].vectype.type != NT_invtype)
14572 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
14573
14574 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
14575 {
14576 for (j = 0; j < els; j++)
14577 if (inst.operands[j].vectype.type == NT_invtype)
14578 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14579 types[j]);
14580 }
dcbf9037 14581 else
477330fc
RM
14582 {
14583 first_error (_("operand types can't be inferred"));
14584 return badtype;
14585 }
5287ad62
JB
14586 }
14587 else if (inst.vectype.elems != els)
14588 {
dcbf9037 14589 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
14590 return badtype;
14591 }
14592
14593 for (pass = 0; pass < 2; pass++)
14594 {
14595 for (i = 0; i < els; i++)
477330fc
RM
14596 {
14597 unsigned thisarg = types[i];
14598 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
14599 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
14600 enum neon_el_type g_type = inst.vectype.el[i].type;
14601 unsigned g_size = inst.vectype.el[i].size;
14602
14603 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 14604 integer types if sign-specific variants are unavailable. */
477330fc 14605 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
14606 && (types_allowed & N_SU_ALL) == 0)
14607 g_type = NT_integer;
14608
477330fc 14609 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
14610 them. Some instructions only care about signs for some element
14611 sizes, so handle that properly. */
477330fc 14612 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
14613 && ((g_size == 8 && (types_allowed & N_8) != 0)
14614 || (g_size == 16 && (types_allowed & N_16) != 0)
14615 || (g_size == 32 && (types_allowed & N_32) != 0)
14616 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
14617 g_type = NT_untyped;
14618
477330fc
RM
14619 if (pass == 0)
14620 {
14621 if ((thisarg & N_KEY) != 0)
14622 {
14623 k_type = g_type;
14624 k_size = g_size;
14625 key_allowed = thisarg & ~N_KEY;
cc933301
JW
14626
14627 /* Check architecture constraint on FP16 extension. */
14628 if (k_size == 16
14629 && k_type == NT_float
14630 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14631 {
14632 inst.error = _(BAD_FP16);
14633 return badtype;
14634 }
477330fc
RM
14635 }
14636 }
14637 else
14638 {
14639 if ((thisarg & N_VFP) != 0)
14640 {
14641 enum neon_shape_el regshape;
14642 unsigned regwidth, match;
99b253c5
NC
14643
14644 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14645 if (ns == NS_NULL)
14646 {
14647 first_error (_("invalid instruction shape"));
14648 return badtype;
14649 }
477330fc
RM
14650 regshape = neon_shape_tab[ns].el[i];
14651 regwidth = neon_shape_el_size[regshape];
14652
14653 /* In VFP mode, operands must match register widths. If we
14654 have a key operand, use its width, else use the width of
14655 the current operand. */
14656 if (k_size != -1u)
14657 match = k_size;
14658 else
14659 match = g_size;
14660
9db2f6b4
RL
14661 /* FP16 will use a single precision register. */
14662 if (regwidth == 32 && match == 16)
14663 {
14664 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14665 match = regwidth;
14666 else
14667 {
14668 inst.error = _(BAD_FP16);
14669 return badtype;
14670 }
14671 }
14672
477330fc
RM
14673 if (regwidth != match)
14674 {
14675 first_error (_("operand size must match register width"));
14676 return badtype;
14677 }
14678 }
14679
14680 if ((thisarg & N_EQK) == 0)
14681 {
14682 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14683
14684 if ((given_type & types_allowed) == 0)
14685 {
5ee91343 14686 first_error (_("bad type in SIMD instruction"));
477330fc
RM
14687 return badtype;
14688 }
14689 }
14690 else
14691 {
14692 enum neon_el_type mod_k_type = k_type;
14693 unsigned mod_k_size = k_size;
14694 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14695 if (g_type != mod_k_type || g_size != mod_k_size)
14696 {
14697 first_error (_("inconsistent types in Neon instruction"));
14698 return badtype;
14699 }
14700 }
14701 }
14702 }
5287ad62
JB
14703 }
14704
14705 return inst.vectype.el[key_el];
14706}
14707
037e8744 14708/* Neon-style VFP instruction forwarding. */
5287ad62 14709
037e8744
JB
14710/* Thumb VFP instructions have 0xE in the condition field. */
14711
14712static void
14713do_vfp_cond_or_thumb (void)
5287ad62 14714{
88714cb8
DG
14715 inst.is_neon = 1;
14716
5287ad62 14717 if (thumb_mode)
037e8744 14718 inst.instruction |= 0xe0000000;
5287ad62 14719 else
037e8744 14720 inst.instruction |= inst.cond << 28;
5287ad62
JB
14721}
14722
037e8744
JB
14723/* Look up and encode a simple mnemonic, for use as a helper function for the
14724 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14725 etc. It is assumed that operand parsing has already been done, and that the
14726 operands are in the form expected by the given opcode (this isn't necessarily
14727 the same as the form in which they were parsed, hence some massaging must
14728 take place before this function is called).
14729 Checks current arch version against that in the looked-up opcode. */
5287ad62 14730
037e8744
JB
14731static void
14732do_vfp_nsyn_opcode (const char *opname)
5287ad62 14733{
037e8744 14734 const struct asm_opcode *opcode;
5f4273c7 14735
21d799b5 14736 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14737
037e8744
JB
14738 if (!opcode)
14739 abort ();
5287ad62 14740
037e8744 14741 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14742 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14743 _(BAD_FPU));
5287ad62 14744
88714cb8
DG
14745 inst.is_neon = 1;
14746
037e8744
JB
14747 if (thumb_mode)
14748 {
14749 inst.instruction = opcode->tvalue;
14750 opcode->tencode ();
14751 }
14752 else
14753 {
14754 inst.instruction = (inst.cond << 28) | opcode->avalue;
14755 opcode->aencode ();
14756 }
14757}
5287ad62
JB
14758
14759static void
037e8744 14760do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14761{
037e8744
JB
14762 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14763
9db2f6b4 14764 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14765 {
14766 if (is_add)
477330fc 14767 do_vfp_nsyn_opcode ("fadds");
037e8744 14768 else
477330fc 14769 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14770
14771 /* ARMv8.2 fp16 instruction. */
14772 if (rs == NS_HHH)
14773 do_scalar_fp16_v82_encode ();
037e8744
JB
14774 }
14775 else
14776 {
14777 if (is_add)
477330fc 14778 do_vfp_nsyn_opcode ("faddd");
037e8744 14779 else
477330fc 14780 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14781 }
14782}
14783
14784/* Check operand types to see if this is a VFP instruction, and if so call
14785 PFN (). */
14786
14787static int
14788try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14789{
14790 enum neon_shape rs;
14791 struct neon_type_el et;
14792
14793 switch (args)
14794 {
14795 case 2:
9db2f6b4
RL
14796 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14797 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14798 break;
5f4273c7 14799
037e8744 14800 case 3:
9db2f6b4
RL
14801 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14802 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14803 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14804 break;
14805
14806 default:
14807 abort ();
14808 }
14809
14810 if (et.type != NT_invtype)
14811 {
14812 pfn (rs);
14813 return SUCCESS;
14814 }
037e8744 14815
99b253c5 14816 inst.error = NULL;
037e8744
JB
14817 return FAIL;
14818}
14819
14820static void
14821do_vfp_nsyn_mla_mls (enum neon_shape rs)
14822{
14823 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14824
9db2f6b4 14825 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14826 {
14827 if (is_mla)
477330fc 14828 do_vfp_nsyn_opcode ("fmacs");
037e8744 14829 else
477330fc 14830 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14831
14832 /* ARMv8.2 fp16 instruction. */
14833 if (rs == NS_HHH)
14834 do_scalar_fp16_v82_encode ();
037e8744
JB
14835 }
14836 else
14837 {
14838 if (is_mla)
477330fc 14839 do_vfp_nsyn_opcode ("fmacd");
037e8744 14840 else
477330fc 14841 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14842 }
14843}
14844
62f3b8c8
PB
14845static void
14846do_vfp_nsyn_fma_fms (enum neon_shape rs)
14847{
14848 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14849
9db2f6b4 14850 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14851 {
14852 if (is_fma)
477330fc 14853 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14854 else
477330fc 14855 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14856
14857 /* ARMv8.2 fp16 instruction. */
14858 if (rs == NS_HHH)
14859 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14860 }
14861 else
14862 {
14863 if (is_fma)
477330fc 14864 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14865 else
477330fc 14866 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14867 }
14868}
14869
037e8744
JB
14870static void
14871do_vfp_nsyn_mul (enum neon_shape rs)
14872{
9db2f6b4
RL
14873 if (rs == NS_FFF || rs == NS_HHH)
14874 {
14875 do_vfp_nsyn_opcode ("fmuls");
14876
14877 /* ARMv8.2 fp16 instruction. */
14878 if (rs == NS_HHH)
14879 do_scalar_fp16_v82_encode ();
14880 }
037e8744
JB
14881 else
14882 do_vfp_nsyn_opcode ("fmuld");
14883}
14884
14885static void
14886do_vfp_nsyn_abs_neg (enum neon_shape rs)
14887{
14888 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14889 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14890
9db2f6b4 14891 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14892 {
14893 if (is_neg)
477330fc 14894 do_vfp_nsyn_opcode ("fnegs");
037e8744 14895 else
477330fc 14896 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14897
14898 /* ARMv8.2 fp16 instruction. */
14899 if (rs == NS_HH)
14900 do_scalar_fp16_v82_encode ();
037e8744
JB
14901 }
14902 else
14903 {
14904 if (is_neg)
477330fc 14905 do_vfp_nsyn_opcode ("fnegd");
037e8744 14906 else
477330fc 14907 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14908 }
14909}
14910
14911/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14912 insns belong to Neon, and are handled elsewhere. */
14913
14914static void
14915do_vfp_nsyn_ldm_stm (int is_dbmode)
14916{
14917 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14918 if (is_ldm)
14919 {
14920 if (is_dbmode)
477330fc 14921 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14922 else
477330fc 14923 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14924 }
14925 else
14926 {
14927 if (is_dbmode)
477330fc 14928 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14929 else
477330fc 14930 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14931 }
14932}
14933
037e8744
JB
14934static void
14935do_vfp_nsyn_sqrt (void)
14936{
9db2f6b4
RL
14937 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14938 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14939
9db2f6b4
RL
14940 if (rs == NS_FF || rs == NS_HH)
14941 {
14942 do_vfp_nsyn_opcode ("fsqrts");
14943
14944 /* ARMv8.2 fp16 instruction. */
14945 if (rs == NS_HH)
14946 do_scalar_fp16_v82_encode ();
14947 }
037e8744
JB
14948 else
14949 do_vfp_nsyn_opcode ("fsqrtd");
14950}
14951
14952static void
14953do_vfp_nsyn_div (void)
14954{
9db2f6b4 14955 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14956 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14957 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14958
9db2f6b4
RL
14959 if (rs == NS_FFF || rs == NS_HHH)
14960 {
14961 do_vfp_nsyn_opcode ("fdivs");
14962
14963 /* ARMv8.2 fp16 instruction. */
14964 if (rs == NS_HHH)
14965 do_scalar_fp16_v82_encode ();
14966 }
037e8744
JB
14967 else
14968 do_vfp_nsyn_opcode ("fdivd");
14969}
14970
14971static void
14972do_vfp_nsyn_nmul (void)
14973{
9db2f6b4 14974 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14975 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14976 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14977
9db2f6b4 14978 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14979 {
88714cb8 14980 NEON_ENCODE (SINGLE, inst);
037e8744 14981 do_vfp_sp_dyadic ();
9db2f6b4
RL
14982
14983 /* ARMv8.2 fp16 instruction. */
14984 if (rs == NS_HHH)
14985 do_scalar_fp16_v82_encode ();
037e8744
JB
14986 }
14987 else
14988 {
88714cb8 14989 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14990 do_vfp_dp_rd_rn_rm ();
14991 }
14992 do_vfp_cond_or_thumb ();
9db2f6b4 14993
037e8744
JB
14994}
14995
14996static void
14997do_vfp_nsyn_cmp (void)
14998{
9db2f6b4 14999 enum neon_shape rs;
037e8744
JB
15000 if (inst.operands[1].isreg)
15001 {
9db2f6b4
RL
15002 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15003 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 15004
9db2f6b4 15005 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
15006 {
15007 NEON_ENCODE (SINGLE, inst);
15008 do_vfp_sp_monadic ();
15009 }
037e8744 15010 else
477330fc
RM
15011 {
15012 NEON_ENCODE (DOUBLE, inst);
15013 do_vfp_dp_rd_rm ();
15014 }
037e8744
JB
15015 }
15016 else
15017 {
9db2f6b4
RL
15018 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
15019 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
15020
15021 switch (inst.instruction & 0x0fffffff)
477330fc
RM
15022 {
15023 case N_MNEM_vcmp:
15024 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
15025 break;
15026 case N_MNEM_vcmpe:
15027 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
15028 break;
15029 default:
15030 abort ();
15031 }
5f4273c7 15032
9db2f6b4 15033 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
15034 {
15035 NEON_ENCODE (SINGLE, inst);
15036 do_vfp_sp_compare_z ();
15037 }
037e8744 15038 else
477330fc
RM
15039 {
15040 NEON_ENCODE (DOUBLE, inst);
15041 do_vfp_dp_rd ();
15042 }
037e8744
JB
15043 }
15044 do_vfp_cond_or_thumb ();
9db2f6b4
RL
15045
15046 /* ARMv8.2 fp16 instruction. */
15047 if (rs == NS_HI || rs == NS_HH)
15048 do_scalar_fp16_v82_encode ();
037e8744
JB
15049}
15050
15051static void
15052nsyn_insert_sp (void)
15053{
15054 inst.operands[1] = inst.operands[0];
15055 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 15056 inst.operands[0].reg = REG_SP;
037e8744
JB
15057 inst.operands[0].isreg = 1;
15058 inst.operands[0].writeback = 1;
15059 inst.operands[0].present = 1;
15060}
15061
15062static void
15063do_vfp_nsyn_push (void)
15064{
15065 nsyn_insert_sp ();
b126985e
NC
15066
15067 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15068 _("register list must contain at least 1 and at most 16 "
15069 "registers"));
15070
037e8744
JB
15071 if (inst.operands[1].issingle)
15072 do_vfp_nsyn_opcode ("fstmdbs");
15073 else
15074 do_vfp_nsyn_opcode ("fstmdbd");
15075}
15076
15077static void
15078do_vfp_nsyn_pop (void)
15079{
15080 nsyn_insert_sp ();
b126985e
NC
15081
15082 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15083 _("register list must contain at least 1 and at most 16 "
15084 "registers"));
15085
037e8744 15086 if (inst.operands[1].issingle)
22b5b651 15087 do_vfp_nsyn_opcode ("fldmias");
037e8744 15088 else
22b5b651 15089 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
15090}
15091
15092/* Fix up Neon data-processing instructions, ORing in the correct bits for
15093 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
15094
88714cb8
DG
15095static void
15096neon_dp_fixup (struct arm_it* insn)
037e8744 15097{
88714cb8
DG
15098 unsigned int i = insn->instruction;
15099 insn->is_neon = 1;
15100
037e8744
JB
15101 if (thumb_mode)
15102 {
15103 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
15104 if (i & (1 << 24))
477330fc 15105 i |= 1 << 28;
5f4273c7 15106
037e8744 15107 i &= ~(1 << 24);
5f4273c7 15108
037e8744
JB
15109 i |= 0xef000000;
15110 }
15111 else
15112 i |= 0xf2000000;
5f4273c7 15113
88714cb8 15114 insn->instruction = i;
037e8744
JB
15115}
15116
15117/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
15118 (0, 1, 2, 3). */
15119
15120static unsigned
15121neon_logbits (unsigned x)
15122{
15123 return ffs (x) - 4;
15124}
15125
15126#define LOW4(R) ((R) & 0xf)
15127#define HI1(R) (((R) >> 4) & 1)
15128
5ee91343
AV
15129static void
15130mve_encode_qqr (int size, int fp)
15131{
15132 if (inst.operands[2].reg == REG_SP)
15133 as_tsktsk (MVE_BAD_SP);
15134 else if (inst.operands[2].reg == REG_PC)
15135 as_tsktsk (MVE_BAD_PC);
15136
15137 if (fp)
15138 {
15139 /* vadd. */
15140 if (((unsigned)inst.instruction) == 0xd00)
15141 inst.instruction = 0xee300f40;
15142 /* vsub. */
15143 else if (((unsigned)inst.instruction) == 0x200d00)
15144 inst.instruction = 0xee301f40;
15145
15146 /* Setting size which is 1 for F16 and 0 for F32. */
15147 inst.instruction |= (size == 16) << 28;
15148 }
15149 else
15150 {
15151 /* vadd. */
15152 if (((unsigned)inst.instruction) == 0x800)
15153 inst.instruction = 0xee010f40;
15154 /* vsub. */
15155 else if (((unsigned)inst.instruction) == 0x1000800)
15156 inst.instruction = 0xee011f40;
15157 /* Setting bits for size. */
15158 inst.instruction |= neon_logbits (size) << 20;
15159 }
15160 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15161 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15162 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15163 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15164 inst.instruction |= inst.operands[2].reg;
15165 inst.is_neon = 1;
15166}
15167
037e8744
JB
15168/* Encode insns with bit pattern:
15169
15170 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
15171 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 15172
037e8744
JB
15173 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
15174 different meaning for some instruction. */
15175
15176static void
15177neon_three_same (int isquad, int ubit, int size)
15178{
15179 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15180 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15181 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15182 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15183 inst.instruction |= LOW4 (inst.operands[2].reg);
15184 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15185 inst.instruction |= (isquad != 0) << 6;
15186 inst.instruction |= (ubit != 0) << 24;
15187 if (size != -1)
15188 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 15189
88714cb8 15190 neon_dp_fixup (&inst);
037e8744
JB
15191}
15192
15193/* Encode instructions of the form:
15194
15195 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
15196 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
15197
15198 Don't write size if SIZE == -1. */
15199
15200static void
15201neon_two_same (int qbit, int ubit, int size)
15202{
15203 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15204 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15205 inst.instruction |= LOW4 (inst.operands[1].reg);
15206 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15207 inst.instruction |= (qbit != 0) << 6;
15208 inst.instruction |= (ubit != 0) << 24;
15209
15210 if (size != -1)
15211 inst.instruction |= neon_logbits (size) << 18;
15212
88714cb8 15213 neon_dp_fixup (&inst);
5287ad62
JB
15214}
15215
15216/* Neon instruction encoders, in approximate order of appearance. */
15217
15218static void
15219do_neon_dyadic_i_su (void)
15220{
037e8744 15221 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15222 struct neon_type_el et = neon_check_type (3, rs,
15223 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 15224 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
15225}
15226
15227static void
15228do_neon_dyadic_i64_su (void)
15229{
037e8744 15230 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15231 struct neon_type_el et = neon_check_type (3, rs,
15232 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 15233 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
15234}
15235
15236static void
15237neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 15238 unsigned immbits)
5287ad62
JB
15239{
15240 unsigned size = et.size >> 3;
15241 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15242 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15243 inst.instruction |= LOW4 (inst.operands[1].reg);
15244 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15245 inst.instruction |= (isquad != 0) << 6;
15246 inst.instruction |= immbits << 16;
15247 inst.instruction |= (size >> 3) << 7;
15248 inst.instruction |= (size & 0x7) << 19;
15249 if (write_ubit)
15250 inst.instruction |= (uval != 0) << 24;
15251
88714cb8 15252 neon_dp_fixup (&inst);
5287ad62
JB
15253}
15254
15255static void
15256do_neon_shl_imm (void)
15257{
15258 if (!inst.operands[2].isreg)
15259 {
037e8744 15260 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 15261 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
15262 int imm = inst.operands[2].imm;
15263
15264 constraint (imm < 0 || (unsigned)imm >= et.size,
15265 _("immediate out of range for shift"));
88714cb8 15266 NEON_ENCODE (IMMED, inst);
cb3b1e65 15267 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15268 }
15269 else
15270 {
037e8744 15271 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15272 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15273 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
15274 unsigned int tmp;
15275
15276 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
15277 vshl.xx Dd, Dm, Dn
15278 whereas other 3-register operations encoded by neon_three_same have
15279 syntax like:
15280 vadd.xx Dd, Dn, Dm
15281 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
15282 here. */
627907b7
JB
15283 tmp = inst.operands[2].reg;
15284 inst.operands[2].reg = inst.operands[1].reg;
15285 inst.operands[1].reg = tmp;
88714cb8 15286 NEON_ENCODE (INTEGER, inst);
037e8744 15287 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
15288 }
15289}
15290
15291static void
15292do_neon_qshl_imm (void)
15293{
15294 if (!inst.operands[2].isreg)
15295 {
037e8744 15296 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 15297 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 15298 int imm = inst.operands[2].imm;
627907b7 15299
cb3b1e65
JB
15300 constraint (imm < 0 || (unsigned)imm >= et.size,
15301 _("immediate out of range for shift"));
88714cb8 15302 NEON_ENCODE (IMMED, inst);
cb3b1e65 15303 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
15304 }
15305 else
15306 {
037e8744 15307 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15308 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15309 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
15310 unsigned int tmp;
15311
15312 /* See note in do_neon_shl_imm. */
15313 tmp = inst.operands[2].reg;
15314 inst.operands[2].reg = inst.operands[1].reg;
15315 inst.operands[1].reg = tmp;
88714cb8 15316 NEON_ENCODE (INTEGER, inst);
037e8744 15317 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
15318 }
15319}
15320
627907b7
JB
15321static void
15322do_neon_rshl (void)
15323{
15324 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15325 struct neon_type_el et = neon_check_type (3, rs,
15326 N_EQK, N_EQK, N_SU_ALL | N_KEY);
15327 unsigned int tmp;
15328
15329 tmp = inst.operands[2].reg;
15330 inst.operands[2].reg = inst.operands[1].reg;
15331 inst.operands[1].reg = tmp;
15332 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
15333}
15334
5287ad62
JB
15335static int
15336neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
15337{
036dc3f7
PB
15338 /* Handle .I8 pseudo-instructions. */
15339 if (size == 8)
5287ad62 15340 {
5287ad62 15341 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
15342 FIXME is this the intended semantics? There doesn't seem much point in
15343 accepting .I8 if so. */
5287ad62
JB
15344 immediate |= immediate << 8;
15345 size = 16;
036dc3f7
PB
15346 }
15347
15348 if (size >= 32)
15349 {
15350 if (immediate == (immediate & 0x000000ff))
15351 {
15352 *immbits = immediate;
15353 return 0x1;
15354 }
15355 else if (immediate == (immediate & 0x0000ff00))
15356 {
15357 *immbits = immediate >> 8;
15358 return 0x3;
15359 }
15360 else if (immediate == (immediate & 0x00ff0000))
15361 {
15362 *immbits = immediate >> 16;
15363 return 0x5;
15364 }
15365 else if (immediate == (immediate & 0xff000000))
15366 {
15367 *immbits = immediate >> 24;
15368 return 0x7;
15369 }
15370 if ((immediate & 0xffff) != (immediate >> 16))
15371 goto bad_immediate;
15372 immediate &= 0xffff;
5287ad62
JB
15373 }
15374
15375 if (immediate == (immediate & 0x000000ff))
15376 {
15377 *immbits = immediate;
036dc3f7 15378 return 0x9;
5287ad62
JB
15379 }
15380 else if (immediate == (immediate & 0x0000ff00))
15381 {
15382 *immbits = immediate >> 8;
036dc3f7 15383 return 0xb;
5287ad62
JB
15384 }
15385
15386 bad_immediate:
dcbf9037 15387 first_error (_("immediate value out of range"));
5287ad62
JB
15388 return FAIL;
15389}
15390
5287ad62
JB
15391static void
15392do_neon_logic (void)
15393{
15394 if (inst.operands[2].present && inst.operands[2].isreg)
15395 {
037e8744 15396 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15397 neon_check_type (3, rs, N_IGNORE_TYPE);
15398 /* U bit and size field were set as part of the bitmask. */
88714cb8 15399 NEON_ENCODE (INTEGER, inst);
037e8744 15400 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
15401 }
15402 else
15403 {
4316f0d2
DG
15404 const int three_ops_form = (inst.operands[2].present
15405 && !inst.operands[2].isreg);
15406 const int immoperand = (three_ops_form ? 2 : 1);
15407 enum neon_shape rs = (three_ops_form
15408 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
15409 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 15410 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15411 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 15412 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
15413 unsigned immbits;
15414 int cmode;
5f4273c7 15415
5287ad62 15416 if (et.type == NT_invtype)
477330fc 15417 return;
5f4273c7 15418
4316f0d2
DG
15419 if (three_ops_form)
15420 constraint (inst.operands[0].reg != inst.operands[1].reg,
15421 _("first and second operands shall be the same register"));
15422
88714cb8 15423 NEON_ENCODE (IMMED, inst);
5287ad62 15424
4316f0d2 15425 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
15426 if (et.size == 64)
15427 {
15428 /* .i64 is a pseudo-op, so the immediate must be a repeating
15429 pattern. */
4316f0d2
DG
15430 if (immbits != (inst.operands[immoperand].regisimm ?
15431 inst.operands[immoperand].reg : 0))
036dc3f7
PB
15432 {
15433 /* Set immbits to an invalid constant. */
15434 immbits = 0xdeadbeef;
15435 }
15436 }
15437
5287ad62 15438 switch (opcode)
477330fc
RM
15439 {
15440 case N_MNEM_vbic:
15441 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
15442 break;
15443
15444 case N_MNEM_vorr:
15445 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
15446 break;
15447
15448 case N_MNEM_vand:
15449 /* Pseudo-instruction for VBIC. */
15450 neon_invert_size (&immbits, 0, et.size);
15451 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
15452 break;
15453
15454 case N_MNEM_vorn:
15455 /* Pseudo-instruction for VORR. */
15456 neon_invert_size (&immbits, 0, et.size);
15457 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
15458 break;
15459
15460 default:
15461 abort ();
15462 }
5287ad62
JB
15463
15464 if (cmode == FAIL)
477330fc 15465 return;
5287ad62 15466
037e8744 15467 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15468 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15469 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15470 inst.instruction |= cmode << 8;
15471 neon_write_immbits (immbits);
5f4273c7 15472
88714cb8 15473 neon_dp_fixup (&inst);
5287ad62
JB
15474 }
15475}
15476
15477static void
15478do_neon_bitfield (void)
15479{
037e8744 15480 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 15481 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 15482 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
15483}
15484
15485static void
dcbf9037 15486neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 15487 unsigned destbits)
5287ad62 15488{
5ee91343 15489 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
dcbf9037 15490 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 15491 types | N_KEY);
5287ad62
JB
15492 if (et.type == NT_float)
15493 {
88714cb8 15494 NEON_ENCODE (FLOAT, inst);
5ee91343
AV
15495 if (rs == NS_QQR)
15496 mve_encode_qqr (et.size, 1);
15497 else
15498 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15499 }
15500 else
15501 {
88714cb8 15502 NEON_ENCODE (INTEGER, inst);
5ee91343
AV
15503 if (rs == NS_QQR)
15504 mve_encode_qqr (et.size, 0);
15505 else
15506 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
15507 }
15508}
15509
5287ad62
JB
15510
15511static void
15512do_neon_dyadic_if_su_d (void)
15513{
15514 /* This version only allow D registers, but that constraint is enforced during
15515 operand parsing so we don't need to do anything extra here. */
dcbf9037 15516 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
15517}
15518
5287ad62
JB
15519static void
15520do_neon_dyadic_if_i_d (void)
15521{
428e3f1f
PB
15522 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15523 affected if we specify unsigned args. */
15524 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
15525}
15526
037e8744
JB
15527enum vfp_or_neon_is_neon_bits
15528{
15529 NEON_CHECK_CC = 1,
73924fbc
MGD
15530 NEON_CHECK_ARCH = 2,
15531 NEON_CHECK_ARCH8 = 4
037e8744
JB
15532};
15533
15534/* Call this function if an instruction which may have belonged to the VFP or
15535 Neon instruction sets, but turned out to be a Neon instruction (due to the
15536 operand types involved, etc.). We have to check and/or fix-up a couple of
15537 things:
15538
15539 - Make sure the user hasn't attempted to make a Neon instruction
15540 conditional.
15541 - Alter the value in the condition code field if necessary.
15542 - Make sure that the arch supports Neon instructions.
15543
15544 Which of these operations take place depends on bits from enum
15545 vfp_or_neon_is_neon_bits.
15546
15547 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
15548 current instruction's condition is COND_ALWAYS, the condition field is
15549 changed to inst.uncond_value. This is necessary because instructions shared
15550 between VFP and Neon may be conditional for the VFP variants only, and the
15551 unconditional Neon version must have, e.g., 0xF in the condition field. */
15552
15553static int
15554vfp_or_neon_is_neon (unsigned check)
15555{
15556 /* Conditions are always legal in Thumb mode (IT blocks). */
15557 if (!thumb_mode && (check & NEON_CHECK_CC))
15558 {
15559 if (inst.cond != COND_ALWAYS)
477330fc
RM
15560 {
15561 first_error (_(BAD_COND));
15562 return FAIL;
15563 }
037e8744 15564 if (inst.uncond_value != -1)
477330fc 15565 inst.instruction |= inst.uncond_value << 28;
037e8744 15566 }
5f4273c7 15567
5ee91343
AV
15568
15569 if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1))
15570 || ((check & NEON_CHECK_ARCH8)
15571 && !mark_feature_used (&fpu_neon_ext_armv8)))
15572 {
15573 first_error (_(BAD_FPU));
15574 return FAIL;
15575 }
15576
15577 return SUCCESS;
15578}
15579
15580static int
15581check_simd_pred_availability (int fp, unsigned check)
15582{
15583 if (inst.cond > COND_ALWAYS)
73924fbc 15584 {
5ee91343
AV
15585 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
15586 {
15587 inst.error = BAD_FPU;
15588 return 1;
15589 }
15590 inst.pred_insn_type = INSIDE_VPT_INSN;
73924fbc 15591 }
5ee91343 15592 else if (inst.cond < COND_ALWAYS)
037e8744 15593 {
5ee91343
AV
15594 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
15595 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15596 else if (vfp_or_neon_is_neon (check) == FAIL)
15597 return 2;
037e8744 15598 }
5ee91343
AV
15599 else
15600 {
15601 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext)
15602 && vfp_or_neon_is_neon (check) == FAIL)
15603 return 3;
5f4273c7 15604
5ee91343
AV
15605 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
15606 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15607 }
15608 return 0;
037e8744
JB
15609}
15610
5287ad62 15611static void
5ee91343 15612do_neon_dyadic_if_su (void)
5287ad62 15613{
5ee91343
AV
15614 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
15615 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
15616 N_SUF_32 | N_KEY);
15617
15618 if (check_simd_pred_availability (et.type == NT_float,
15619 NEON_CHECK_ARCH | NEON_CHECK_CC))
037e8744
JB
15620 return;
15621
5ee91343
AV
15622 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
15623}
15624
15625static void
15626do_neon_addsub_if_i (void)
15627{
15628 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
15629 && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
037e8744
JB
15630 return;
15631
5ee91343
AV
15632 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
15633 struct neon_type_el et = neon_check_type (3, rs, N_EQK,
15634 N_EQK, N_IF_32 | N_I64 | N_KEY);
15635
15636 constraint (rs == NS_QQR && et.size == 64, BAD_FPU);
15637 /* If we are parsing Q registers and the element types match MVE, which NEON
15638 also supports, then we must check whether this is an instruction that can
15639 be used by both MVE/NEON. This distinction can be made based on whether
15640 they are predicated or not. */
15641 if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64)
15642 {
15643 if (check_simd_pred_availability (et.type == NT_float,
15644 NEON_CHECK_ARCH | NEON_CHECK_CC))
15645 return;
15646 }
15647 else
15648 {
15649 /* If they are either in a D register or are using an unsupported. */
15650 if (rs != NS_QQR
15651 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15652 return;
15653 }
15654
5287ad62
JB
15655 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15656 affected if we specify unsigned args. */
dcbf9037 15657 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
15658}
15659
15660/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
15661 result to be:
15662 V<op> A,B (A is operand 0, B is operand 2)
15663 to mean:
15664 V<op> A,B,A
15665 not:
15666 V<op> A,B,B
15667 so handle that case specially. */
15668
15669static void
15670neon_exchange_operands (void)
15671{
5287ad62
JB
15672 if (inst.operands[1].present)
15673 {
e1fa0163
NC
15674 void *scratch = xmalloc (sizeof (inst.operands[0]));
15675
5287ad62
JB
15676 /* Swap operands[1] and operands[2]. */
15677 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
15678 inst.operands[1] = inst.operands[2];
15679 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 15680 free (scratch);
5287ad62
JB
15681 }
15682 else
15683 {
15684 inst.operands[1] = inst.operands[2];
15685 inst.operands[2] = inst.operands[0];
15686 }
15687}
15688
15689static void
15690neon_compare (unsigned regtypes, unsigned immtypes, int invert)
15691{
15692 if (inst.operands[2].isreg)
15693 {
15694 if (invert)
477330fc 15695 neon_exchange_operands ();
dcbf9037 15696 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
15697 }
15698 else
15699 {
037e8744 15700 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 15701 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15702 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 15703
88714cb8 15704 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15705 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15706 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15707 inst.instruction |= LOW4 (inst.operands[1].reg);
15708 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15709 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15710 inst.instruction |= (et.type == NT_float) << 10;
15711 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15712
88714cb8 15713 neon_dp_fixup (&inst);
5287ad62
JB
15714 }
15715}
15716
15717static void
15718do_neon_cmp (void)
15719{
cc933301 15720 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
15721}
15722
15723static void
15724do_neon_cmp_inv (void)
15725{
cc933301 15726 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
15727}
15728
15729static void
15730do_neon_ceq (void)
15731{
15732 neon_compare (N_IF_32, N_IF_32, FALSE);
15733}
15734
15735/* For multiply instructions, we have the possibility of 16-bit or 32-bit
15736 scalars, which are encoded in 5 bits, M : Rm.
15737 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15738 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
15739 index in M.
15740
15741 Dot Product instructions are similar to multiply instructions except elsize
15742 should always be 32.
15743
15744 This function translates SCALAR, which is GAS's internal encoding of indexed
15745 scalar register, to raw encoding. There is also register and index range
15746 check based on ELSIZE. */
5287ad62
JB
15747
15748static unsigned
15749neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15750{
dcbf9037
JB
15751 unsigned regno = NEON_SCALAR_REG (scalar);
15752 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
15753
15754 switch (elsize)
15755 {
15756 case 16:
15757 if (regno > 7 || elno > 3)
477330fc 15758 goto bad_scalar;
5287ad62 15759 return regno | (elno << 3);
5f4273c7 15760
5287ad62
JB
15761 case 32:
15762 if (regno > 15 || elno > 1)
477330fc 15763 goto bad_scalar;
5287ad62
JB
15764 return regno | (elno << 4);
15765
15766 default:
15767 bad_scalar:
dcbf9037 15768 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15769 }
15770
15771 return 0;
15772}
15773
15774/* Encode multiply / multiply-accumulate scalar instructions. */
15775
15776static void
15777neon_mul_mac (struct neon_type_el et, int ubit)
15778{
dcbf9037
JB
15779 unsigned scalar;
15780
15781 /* Give a more helpful error message if we have an invalid type. */
15782 if (et.type == NT_invtype)
15783 return;
5f4273c7 15784
dcbf9037 15785 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15786 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15787 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15788 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15789 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15790 inst.instruction |= LOW4 (scalar);
15791 inst.instruction |= HI1 (scalar) << 5;
15792 inst.instruction |= (et.type == NT_float) << 8;
15793 inst.instruction |= neon_logbits (et.size) << 20;
15794 inst.instruction |= (ubit != 0) << 24;
15795
88714cb8 15796 neon_dp_fixup (&inst);
5287ad62
JB
15797}
15798
15799static void
15800do_neon_mac_maybe_scalar (void)
15801{
037e8744
JB
15802 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15803 return;
15804
15805 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15806 return;
15807
5287ad62
JB
15808 if (inst.operands[2].isscalar)
15809 {
037e8744 15810 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15811 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15812 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15813 NEON_ENCODE (SCALAR, inst);
037e8744 15814 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15815 }
15816 else
428e3f1f
PB
15817 {
15818 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15819 affected if we specify unsigned args. */
15820 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15821 }
5287ad62
JB
15822}
15823
62f3b8c8
PB
15824static void
15825do_neon_fmac (void)
15826{
15827 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15828 return;
15829
15830 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15831 return;
15832
15833 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15834}
15835
5287ad62
JB
15836static void
15837do_neon_tst (void)
15838{
037e8744 15839 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15840 struct neon_type_el et = neon_check_type (3, rs,
15841 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15842 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15843}
15844
15845/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15846 same types as the MAC equivalents. The polynomial type for this instruction
15847 is encoded the same as the integer type. */
15848
15849static void
15850do_neon_mul (void)
15851{
037e8744
JB
15852 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15853 return;
15854
15855 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15856 return;
15857
5287ad62
JB
15858 if (inst.operands[2].isscalar)
15859 do_neon_mac_maybe_scalar ();
15860 else
cc933301 15861 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15862}
15863
15864static void
15865do_neon_qdmulh (void)
15866{
15867 if (inst.operands[2].isscalar)
15868 {
037e8744 15869 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15870 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15871 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15872 NEON_ENCODE (SCALAR, inst);
037e8744 15873 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15874 }
15875 else
15876 {
037e8744 15877 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15878 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15879 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15880 NEON_ENCODE (INTEGER, inst);
5287ad62 15881 /* The U bit (rounding) comes from bit mask. */
037e8744 15882 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15883 }
15884}
15885
643afb90
MW
15886static void
15887do_neon_qrdmlah (void)
15888{
15889 /* Check we're on the correct architecture. */
15890 if (!mark_feature_used (&fpu_neon_ext_armv8))
15891 inst.error =
15892 _("instruction form not available on this architecture.");
15893 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15894 {
15895 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15896 record_feature_use (&fpu_neon_ext_v8_1);
15897 }
15898
15899 if (inst.operands[2].isscalar)
15900 {
15901 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15902 struct neon_type_el et = neon_check_type (3, rs,
15903 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15904 NEON_ENCODE (SCALAR, inst);
15905 neon_mul_mac (et, neon_quad (rs));
15906 }
15907 else
15908 {
15909 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15910 struct neon_type_el et = neon_check_type (3, rs,
15911 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15912 NEON_ENCODE (INTEGER, inst);
15913 /* The U bit (rounding) comes from bit mask. */
15914 neon_three_same (neon_quad (rs), 0, et.size);
15915 }
15916}
15917
5287ad62
JB
15918static void
15919do_neon_fcmp_absolute (void)
15920{
037e8744 15921 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15922 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15923 N_F_16_32 | N_KEY);
5287ad62 15924 /* Size field comes from bit mask. */
cc933301 15925 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15926}
15927
15928static void
15929do_neon_fcmp_absolute_inv (void)
15930{
15931 neon_exchange_operands ();
15932 do_neon_fcmp_absolute ();
15933}
15934
15935static void
15936do_neon_step (void)
15937{
037e8744 15938 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15939 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15940 N_F_16_32 | N_KEY);
15941 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15942}
15943
15944static void
15945do_neon_abs_neg (void)
15946{
037e8744
JB
15947 enum neon_shape rs;
15948 struct neon_type_el et;
5f4273c7 15949
037e8744
JB
15950 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15951 return;
15952
15953 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15954 return;
15955
15956 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15957 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15958
5287ad62
JB
15959 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15960 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15961 inst.instruction |= LOW4 (inst.operands[1].reg);
15962 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15963 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15964 inst.instruction |= (et.type == NT_float) << 10;
15965 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15966
88714cb8 15967 neon_dp_fixup (&inst);
5287ad62
JB
15968}
15969
15970static void
15971do_neon_sli (void)
15972{
037e8744 15973 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15974 struct neon_type_el et = neon_check_type (2, rs,
15975 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15976 int imm = inst.operands[2].imm;
15977 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15978 _("immediate out of range for insert"));
037e8744 15979 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15980}
15981
15982static void
15983do_neon_sri (void)
15984{
037e8744 15985 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15986 struct neon_type_el et = neon_check_type (2, rs,
15987 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15988 int imm = inst.operands[2].imm;
15989 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15990 _("immediate out of range for insert"));
037e8744 15991 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15992}
15993
15994static void
15995do_neon_qshlu_imm (void)
15996{
037e8744 15997 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15998 struct neon_type_el et = neon_check_type (2, rs,
15999 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
16000 int imm = inst.operands[2].imm;
16001 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 16002 _("immediate out of range for shift"));
5287ad62
JB
16003 /* Only encodes the 'U present' variant of the instruction.
16004 In this case, signed types have OP (bit 8) set to 0.
16005 Unsigned types have OP set to 1. */
16006 inst.instruction |= (et.type == NT_unsigned) << 8;
16007 /* The rest of the bits are the same as other immediate shifts. */
037e8744 16008 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
16009}
16010
16011static void
16012do_neon_qmovn (void)
16013{
16014 struct neon_type_el et = neon_check_type (2, NS_DQ,
16015 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
16016 /* Saturating move where operands can be signed or unsigned, and the
16017 destination has the same signedness. */
88714cb8 16018 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16019 if (et.type == NT_unsigned)
16020 inst.instruction |= 0xc0;
16021 else
16022 inst.instruction |= 0x80;
16023 neon_two_same (0, 1, et.size / 2);
16024}
16025
16026static void
16027do_neon_qmovun (void)
16028{
16029 struct neon_type_el et = neon_check_type (2, NS_DQ,
16030 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
16031 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 16032 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16033 neon_two_same (0, 1, et.size / 2);
16034}
16035
16036static void
16037do_neon_rshift_sat_narrow (void)
16038{
16039 /* FIXME: Types for narrowing. If operands are signed, results can be signed
16040 or unsigned. If operands are unsigned, results must also be unsigned. */
16041 struct neon_type_el et = neon_check_type (2, NS_DQI,
16042 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
16043 int imm = inst.operands[2].imm;
16044 /* This gets the bounds check, size encoding and immediate bits calculation
16045 right. */
16046 et.size /= 2;
5f4273c7 16047
5287ad62
JB
16048 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
16049 VQMOVN.I<size> <Dd>, <Qm>. */
16050 if (imm == 0)
16051 {
16052 inst.operands[2].present = 0;
16053 inst.instruction = N_MNEM_vqmovn;
16054 do_neon_qmovn ();
16055 return;
16056 }
5f4273c7 16057
5287ad62 16058 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16059 _("immediate out of range"));
5287ad62
JB
16060 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
16061}
16062
16063static void
16064do_neon_rshift_sat_narrow_u (void)
16065{
16066 /* FIXME: Types for narrowing. If operands are signed, results can be signed
16067 or unsigned. If operands are unsigned, results must also be unsigned. */
16068 struct neon_type_el et = neon_check_type (2, NS_DQI,
16069 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
16070 int imm = inst.operands[2].imm;
16071 /* This gets the bounds check, size encoding and immediate bits calculation
16072 right. */
16073 et.size /= 2;
16074
16075 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
16076 VQMOVUN.I<size> <Dd>, <Qm>. */
16077 if (imm == 0)
16078 {
16079 inst.operands[2].present = 0;
16080 inst.instruction = N_MNEM_vqmovun;
16081 do_neon_qmovun ();
16082 return;
16083 }
16084
16085 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16086 _("immediate out of range"));
5287ad62
JB
16087 /* FIXME: The manual is kind of unclear about what value U should have in
16088 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
16089 must be 1. */
16090 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
16091}
16092
16093static void
16094do_neon_movn (void)
16095{
16096 struct neon_type_el et = neon_check_type (2, NS_DQ,
16097 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 16098 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16099 neon_two_same (0, 1, et.size / 2);
16100}
16101
16102static void
16103do_neon_rshift_narrow (void)
16104{
16105 struct neon_type_el et = neon_check_type (2, NS_DQI,
16106 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
16107 int imm = inst.operands[2].imm;
16108 /* This gets the bounds check, size encoding and immediate bits calculation
16109 right. */
16110 et.size /= 2;
5f4273c7 16111
5287ad62
JB
16112 /* If immediate is zero then we are a pseudo-instruction for
16113 VMOVN.I<size> <Dd>, <Qm> */
16114 if (imm == 0)
16115 {
16116 inst.operands[2].present = 0;
16117 inst.instruction = N_MNEM_vmovn;
16118 do_neon_movn ();
16119 return;
16120 }
5f4273c7 16121
5287ad62 16122 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16123 _("immediate out of range for narrowing operation"));
5287ad62
JB
16124 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
16125}
16126
16127static void
16128do_neon_shll (void)
16129{
16130 /* FIXME: Type checking when lengthening. */
16131 struct neon_type_el et = neon_check_type (2, NS_QDI,
16132 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
16133 unsigned imm = inst.operands[2].imm;
16134
16135 if (imm == et.size)
16136 {
16137 /* Maximum shift variant. */
88714cb8 16138 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16139 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16140 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16141 inst.instruction |= LOW4 (inst.operands[1].reg);
16142 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16143 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 16144
88714cb8 16145 neon_dp_fixup (&inst);
5287ad62
JB
16146 }
16147 else
16148 {
16149 /* A more-specific type check for non-max versions. */
16150 et = neon_check_type (2, NS_QDI,
477330fc 16151 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 16152 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16153 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
16154 }
16155}
16156
037e8744 16157/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
16158 the current instruction is. */
16159
6b9a8b67
MGD
16160#define CVT_FLAVOUR_VAR \
16161 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
16162 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
16163 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
16164 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
16165 /* Half-precision conversions. */ \
cc933301
JW
16166 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
16167 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
16168 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
16169 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
16170 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
16171 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
16172 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
16173 Compared with single/double precision variants, only the co-processor \
16174 field is different, so the encoding flow is reused here. */ \
16175 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
16176 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
16177 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
16178 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
16179 /* VFP instructions. */ \
16180 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
16181 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
16182 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
16183 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
16184 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
16185 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
16186 /* VFP instructions with bitshift. */ \
16187 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
16188 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
16189 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
16190 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
16191 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
16192 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
16193 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
16194 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
16195
16196#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
16197 neon_cvt_flavour_##C,
16198
16199/* The different types of conversions we can do. */
16200enum neon_cvt_flavour
16201{
16202 CVT_FLAVOUR_VAR
16203 neon_cvt_flavour_invalid,
16204 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
16205};
16206
16207#undef CVT_VAR
16208
16209static enum neon_cvt_flavour
16210get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 16211{
6b9a8b67
MGD
16212#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
16213 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
16214 if (et.type != NT_invtype) \
16215 { \
16216 inst.error = NULL; \
16217 return (neon_cvt_flavour_##C); \
5287ad62 16218 }
6b9a8b67 16219
5287ad62 16220 struct neon_type_el et;
037e8744 16221 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 16222 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
16223 /* The instruction versions which take an immediate take one register
16224 argument, which is extended to the width of the full register. Thus the
16225 "source" and "destination" registers must have the same width. Hack that
16226 here by making the size equal to the key (wider, in this case) operand. */
16227 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 16228
6b9a8b67
MGD
16229 CVT_FLAVOUR_VAR;
16230
16231 return neon_cvt_flavour_invalid;
5287ad62
JB
16232#undef CVT_VAR
16233}
16234
7e8e6784
MGD
16235enum neon_cvt_mode
16236{
16237 neon_cvt_mode_a,
16238 neon_cvt_mode_n,
16239 neon_cvt_mode_p,
16240 neon_cvt_mode_m,
16241 neon_cvt_mode_z,
30bdf752
MGD
16242 neon_cvt_mode_x,
16243 neon_cvt_mode_r
7e8e6784
MGD
16244};
16245
037e8744
JB
16246/* Neon-syntax VFP conversions. */
16247
5287ad62 16248static void
6b9a8b67 16249do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 16250{
037e8744 16251 const char *opname = 0;
5f4273c7 16252
d54af2d0
RL
16253 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
16254 || rs == NS_FHI || rs == NS_HFI)
5287ad62 16255 {
037e8744
JB
16256 /* Conversions with immediate bitshift. */
16257 const char *enc[] =
477330fc 16258 {
6b9a8b67
MGD
16259#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
16260 CVT_FLAVOUR_VAR
16261 NULL
16262#undef CVT_VAR
477330fc 16263 };
037e8744 16264
6b9a8b67 16265 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
16266 {
16267 opname = enc[flavour];
16268 constraint (inst.operands[0].reg != inst.operands[1].reg,
16269 _("operands 0 and 1 must be the same register"));
16270 inst.operands[1] = inst.operands[2];
16271 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
16272 }
5287ad62
JB
16273 }
16274 else
16275 {
037e8744
JB
16276 /* Conversions without bitshift. */
16277 const char *enc[] =
477330fc 16278 {
6b9a8b67
MGD
16279#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
16280 CVT_FLAVOUR_VAR
16281 NULL
16282#undef CVT_VAR
477330fc 16283 };
037e8744 16284
6b9a8b67 16285 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 16286 opname = enc[flavour];
037e8744
JB
16287 }
16288
16289 if (opname)
16290 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
16291
16292 /* ARMv8.2 fp16 VCVT instruction. */
16293 if (flavour == neon_cvt_flavour_s32_f16
16294 || flavour == neon_cvt_flavour_u32_f16
16295 || flavour == neon_cvt_flavour_f16_u32
16296 || flavour == neon_cvt_flavour_f16_s32)
16297 do_scalar_fp16_v82_encode ();
037e8744
JB
16298}
16299
16300static void
16301do_vfp_nsyn_cvtz (void)
16302{
d54af2d0 16303 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 16304 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
16305 const char *enc[] =
16306 {
6b9a8b67
MGD
16307#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
16308 CVT_FLAVOUR_VAR
16309 NULL
16310#undef CVT_VAR
037e8744
JB
16311 };
16312
6b9a8b67 16313 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
16314 do_vfp_nsyn_opcode (enc[flavour]);
16315}
f31fef98 16316
037e8744 16317static void
bacebabc 16318do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
16319 enum neon_cvt_mode mode)
16320{
16321 int sz, op;
16322 int rm;
16323
a715796b
TG
16324 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16325 D register operands. */
16326 if (flavour == neon_cvt_flavour_s32_f64
16327 || flavour == neon_cvt_flavour_u32_f64)
16328 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16329 _(BAD_FPU));
16330
9db2f6b4
RL
16331 if (flavour == neon_cvt_flavour_s32_f16
16332 || flavour == neon_cvt_flavour_u32_f16)
16333 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
16334 _(BAD_FP16));
16335
5ee91343 16336 set_pred_insn_type (OUTSIDE_PRED_INSN);
7e8e6784
MGD
16337
16338 switch (flavour)
16339 {
16340 case neon_cvt_flavour_s32_f64:
16341 sz = 1;
827f64ff 16342 op = 1;
7e8e6784
MGD
16343 break;
16344 case neon_cvt_flavour_s32_f32:
16345 sz = 0;
16346 op = 1;
16347 break;
9db2f6b4
RL
16348 case neon_cvt_flavour_s32_f16:
16349 sz = 0;
16350 op = 1;
16351 break;
7e8e6784
MGD
16352 case neon_cvt_flavour_u32_f64:
16353 sz = 1;
16354 op = 0;
16355 break;
16356 case neon_cvt_flavour_u32_f32:
16357 sz = 0;
16358 op = 0;
16359 break;
9db2f6b4
RL
16360 case neon_cvt_flavour_u32_f16:
16361 sz = 0;
16362 op = 0;
16363 break;
7e8e6784
MGD
16364 default:
16365 first_error (_("invalid instruction shape"));
16366 return;
16367 }
16368
16369 switch (mode)
16370 {
16371 case neon_cvt_mode_a: rm = 0; break;
16372 case neon_cvt_mode_n: rm = 1; break;
16373 case neon_cvt_mode_p: rm = 2; break;
16374 case neon_cvt_mode_m: rm = 3; break;
16375 default: first_error (_("invalid rounding mode")); return;
16376 }
16377
16378 NEON_ENCODE (FPV8, inst);
16379 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
16380 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
16381 inst.instruction |= sz << 8;
9db2f6b4
RL
16382
16383 /* ARMv8.2 fp16 VCVT instruction. */
16384 if (flavour == neon_cvt_flavour_s32_f16
16385 ||flavour == neon_cvt_flavour_u32_f16)
16386 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
16387 inst.instruction |= op << 7;
16388 inst.instruction |= rm << 16;
16389 inst.instruction |= 0xf0000000;
16390 inst.is_neon = TRUE;
16391}
16392
16393static void
16394do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
16395{
16396 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
16397 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
16398 NS_FH, NS_HF, NS_FHI, NS_HFI,
16399 NS_NULL);
6b9a8b67 16400 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 16401
cc933301
JW
16402 if (flavour == neon_cvt_flavour_invalid)
16403 return;
16404
e3e535bc 16405 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 16406 if (mode == neon_cvt_mode_z
e3e535bc 16407 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
16408 && (flavour == neon_cvt_flavour_s16_f16
16409 || flavour == neon_cvt_flavour_u16_f16
16410 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
16411 || flavour == neon_cvt_flavour_u32_f32
16412 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 16413 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
16414 && (rs == NS_FD || rs == NS_FF))
16415 {
16416 do_vfp_nsyn_cvtz ();
16417 return;
16418 }
16419
9db2f6b4
RL
16420 /* ARMv8.2 fp16 VCVT conversions. */
16421 if (mode == neon_cvt_mode_z
16422 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
16423 && (flavour == neon_cvt_flavour_s32_f16
16424 || flavour == neon_cvt_flavour_u32_f16)
16425 && (rs == NS_FH))
16426 {
16427 do_vfp_nsyn_cvtz ();
16428 do_scalar_fp16_v82_encode ();
16429 return;
16430 }
16431
037e8744 16432 /* VFP rather than Neon conversions. */
6b9a8b67 16433 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 16434 {
7e8e6784
MGD
16435 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
16436 do_vfp_nsyn_cvt (rs, flavour);
16437 else
16438 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
16439
037e8744
JB
16440 return;
16441 }
16442
16443 switch (rs)
16444 {
16445 case NS_DDI:
16446 case NS_QQI:
16447 {
477330fc 16448 unsigned immbits;
cc933301
JW
16449 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
16450 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 16451
477330fc
RM
16452 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16453 return;
037e8744 16454
477330fc
RM
16455 /* Fixed-point conversion with #0 immediate is encoded as an
16456 integer conversion. */
16457 if (inst.operands[2].present && inst.operands[2].imm == 0)
16458 goto int_encode;
477330fc
RM
16459 NEON_ENCODE (IMMED, inst);
16460 if (flavour != neon_cvt_flavour_invalid)
16461 inst.instruction |= enctab[flavour];
16462 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16463 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16464 inst.instruction |= LOW4 (inst.operands[1].reg);
16465 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16466 inst.instruction |= neon_quad (rs) << 6;
16467 inst.instruction |= 1 << 21;
cc933301
JW
16468 if (flavour < neon_cvt_flavour_s16_f16)
16469 {
16470 inst.instruction |= 1 << 21;
16471 immbits = 32 - inst.operands[2].imm;
16472 inst.instruction |= immbits << 16;
16473 }
16474 else
16475 {
16476 inst.instruction |= 3 << 20;
16477 immbits = 16 - inst.operands[2].imm;
16478 inst.instruction |= immbits << 16;
16479 inst.instruction &= ~(1 << 9);
16480 }
477330fc
RM
16481
16482 neon_dp_fixup (&inst);
037e8744
JB
16483 }
16484 break;
16485
16486 case NS_DD:
16487 case NS_QQ:
7e8e6784
MGD
16488 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
16489 {
16490 NEON_ENCODE (FLOAT, inst);
5ee91343 16491 set_pred_insn_type (OUTSIDE_PRED_INSN);
7e8e6784
MGD
16492
16493 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16494 return;
16495
16496 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16497 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16498 inst.instruction |= LOW4 (inst.operands[1].reg);
16499 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16500 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
16501 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
16502 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 16503 inst.instruction |= mode << 8;
cc933301
JW
16504 if (flavour == neon_cvt_flavour_u16_f16
16505 || flavour == neon_cvt_flavour_s16_f16)
16506 /* Mask off the original size bits and reencode them. */
16507 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
16508
7e8e6784
MGD
16509 if (thumb_mode)
16510 inst.instruction |= 0xfc000000;
16511 else
16512 inst.instruction |= 0xf0000000;
16513 }
16514 else
16515 {
037e8744 16516 int_encode:
7e8e6784 16517 {
cc933301
JW
16518 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
16519 0x100, 0x180, 0x0, 0x080};
037e8744 16520
7e8e6784 16521 NEON_ENCODE (INTEGER, inst);
037e8744 16522
7e8e6784
MGD
16523 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16524 return;
037e8744 16525
7e8e6784
MGD
16526 if (flavour != neon_cvt_flavour_invalid)
16527 inst.instruction |= enctab[flavour];
037e8744 16528
7e8e6784
MGD
16529 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16530 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16531 inst.instruction |= LOW4 (inst.operands[1].reg);
16532 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16533 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
16534 if (flavour >= neon_cvt_flavour_s16_f16
16535 && flavour <= neon_cvt_flavour_f16_u16)
16536 /* Half precision. */
16537 inst.instruction |= 1 << 18;
16538 else
16539 inst.instruction |= 2 << 18;
037e8744 16540
7e8e6784
MGD
16541 neon_dp_fixup (&inst);
16542 }
16543 }
16544 break;
037e8744 16545
8e79c3df
CM
16546 /* Half-precision conversions for Advanced SIMD -- neon. */
16547 case NS_QD:
16548 case NS_DQ:
bc52d49c
MM
16549 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16550 return;
8e79c3df
CM
16551
16552 if ((rs == NS_DQ)
16553 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
16554 {
16555 as_bad (_("operand size must match register width"));
16556 break;
16557 }
16558
16559 if ((rs == NS_QD)
16560 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
16561 {
16562 as_bad (_("operand size must match register width"));
16563 break;
16564 }
16565
16566 if (rs == NS_DQ)
477330fc 16567 inst.instruction = 0x3b60600;
8e79c3df
CM
16568 else
16569 inst.instruction = 0x3b60700;
16570
16571 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16572 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16573 inst.instruction |= LOW4 (inst.operands[1].reg);
16574 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 16575 neon_dp_fixup (&inst);
8e79c3df
CM
16576 break;
16577
037e8744
JB
16578 default:
16579 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
16580 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
16581 do_vfp_nsyn_cvt (rs, flavour);
16582 else
16583 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 16584 }
5287ad62
JB
16585}
16586
e3e535bc
NC
16587static void
16588do_neon_cvtr (void)
16589{
7e8e6784 16590 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
16591}
16592
16593static void
16594do_neon_cvt (void)
16595{
7e8e6784
MGD
16596 do_neon_cvt_1 (neon_cvt_mode_z);
16597}
16598
16599static void
16600do_neon_cvta (void)
16601{
16602 do_neon_cvt_1 (neon_cvt_mode_a);
16603}
16604
16605static void
16606do_neon_cvtn (void)
16607{
16608 do_neon_cvt_1 (neon_cvt_mode_n);
16609}
16610
16611static void
16612do_neon_cvtp (void)
16613{
16614 do_neon_cvt_1 (neon_cvt_mode_p);
16615}
16616
16617static void
16618do_neon_cvtm (void)
16619{
16620 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
16621}
16622
8e79c3df 16623static void
c70a8987 16624do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 16625{
c70a8987
MGD
16626 if (is_double)
16627 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 16628
c70a8987
MGD
16629 encode_arm_vfp_reg (inst.operands[0].reg,
16630 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
16631 encode_arm_vfp_reg (inst.operands[1].reg,
16632 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
16633 inst.instruction |= to ? 0x10000 : 0;
16634 inst.instruction |= t ? 0x80 : 0;
16635 inst.instruction |= is_double ? 0x100 : 0;
16636 do_vfp_cond_or_thumb ();
16637}
8e79c3df 16638
c70a8987
MGD
16639static void
16640do_neon_cvttb_1 (bfd_boolean t)
16641{
d54af2d0
RL
16642 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
16643 NS_DF, NS_DH, NS_NULL);
8e79c3df 16644
c70a8987
MGD
16645 if (rs == NS_NULL)
16646 return;
16647 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
16648 {
16649 inst.error = NULL;
16650 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
16651 }
16652 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
16653 {
16654 inst.error = NULL;
16655 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
16656 }
16657 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
16658 {
a715796b
TG
16659 /* The VCVTB and VCVTT instructions with D-register operands
16660 don't work for SP only targets. */
16661 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16662 _(BAD_FPU));
16663
c70a8987
MGD
16664 inst.error = NULL;
16665 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
16666 }
16667 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
16668 {
a715796b
TG
16669 /* The VCVTB and VCVTT instructions with D-register operands
16670 don't work for SP only targets. */
16671 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16672 _(BAD_FPU));
16673
c70a8987
MGD
16674 inst.error = NULL;
16675 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
16676 }
16677 else
16678 return;
16679}
16680
16681static void
16682do_neon_cvtb (void)
16683{
16684 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
16685}
16686
16687
16688static void
16689do_neon_cvtt (void)
16690{
c70a8987 16691 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
16692}
16693
5287ad62
JB
16694static void
16695neon_move_immediate (void)
16696{
037e8744
JB
16697 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
16698 struct neon_type_el et = neon_check_type (2, rs,
16699 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 16700 unsigned immlo, immhi = 0, immbits;
c96612cc 16701 int op, cmode, float_p;
5287ad62 16702
037e8744 16703 constraint (et.type == NT_invtype,
477330fc 16704 _("operand size must be specified for immediate VMOV"));
037e8744 16705
5287ad62
JB
16706 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
16707 op = (inst.instruction & (1 << 5)) != 0;
16708
16709 immlo = inst.operands[1].imm;
16710 if (inst.operands[1].regisimm)
16711 immhi = inst.operands[1].reg;
16712
16713 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 16714 _("immediate has bits set outside the operand size"));
5287ad62 16715
c96612cc
JB
16716 float_p = inst.operands[1].immisfloat;
16717
16718 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 16719 et.size, et.type)) == FAIL)
5287ad62
JB
16720 {
16721 /* Invert relevant bits only. */
16722 neon_invert_size (&immlo, &immhi, et.size);
16723 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
16724 with one or the other; those cases are caught by
16725 neon_cmode_for_move_imm. */
5287ad62 16726 op = !op;
c96612cc
JB
16727 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16728 &op, et.size, et.type)) == FAIL)
477330fc
RM
16729 {
16730 first_error (_("immediate out of range"));
16731 return;
16732 }
5287ad62
JB
16733 }
16734
16735 inst.instruction &= ~(1 << 5);
16736 inst.instruction |= op << 5;
16737
16738 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16739 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 16740 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16741 inst.instruction |= cmode << 8;
16742
16743 neon_write_immbits (immbits);
16744}
16745
16746static void
16747do_neon_mvn (void)
16748{
16749 if (inst.operands[1].isreg)
16750 {
037e8744 16751 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16752
88714cb8 16753 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16754 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16755 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16756 inst.instruction |= LOW4 (inst.operands[1].reg);
16757 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16758 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16759 }
16760 else
16761 {
88714cb8 16762 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16763 neon_move_immediate ();
16764 }
16765
88714cb8 16766 neon_dp_fixup (&inst);
5287ad62
JB
16767}
16768
16769/* Encode instructions of form:
16770
16771 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16772 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16773
16774static void
16775neon_mixed_length (struct neon_type_el et, unsigned size)
16776{
16777 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16778 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16779 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16780 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16781 inst.instruction |= LOW4 (inst.operands[2].reg);
16782 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16783 inst.instruction |= (et.type == NT_unsigned) << 24;
16784 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16785
88714cb8 16786 neon_dp_fixup (&inst);
5287ad62
JB
16787}
16788
16789static void
16790do_neon_dyadic_long (void)
16791{
5ee91343
AV
16792 enum neon_shape rs = neon_select_shape (NS_QDD, NS_QQQ, NS_QQR, NS_NULL);
16793 if (rs == NS_QDD)
16794 {
16795 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL)
16796 return;
16797
16798 NEON_ENCODE (INTEGER, inst);
16799 /* FIXME: Type checking for lengthening op. */
16800 struct neon_type_el et = neon_check_type (3, NS_QDD,
16801 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16802 neon_mixed_length (et, et.size);
16803 }
16804 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
16805 && (inst.cond == 0xf || inst.cond == 0x10))
16806 {
16807 /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd
16808 in an IT block with le/lt conditions. */
16809
16810 if (inst.cond == 0xf)
16811 inst.cond = 0xb;
16812 else if (inst.cond == 0x10)
16813 inst.cond = 0xd;
16814
16815 inst.pred_insn_type = INSIDE_IT_INSN;
16816
16817 if (inst.instruction == N_MNEM_vaddl)
16818 {
16819 inst.instruction = N_MNEM_vadd;
16820 do_neon_addsub_if_i ();
16821 }
16822 else if (inst.instruction == N_MNEM_vsubl)
16823 {
16824 inst.instruction = N_MNEM_vsub;
16825 do_neon_addsub_if_i ();
16826 }
16827 else if (inst.instruction == N_MNEM_vabdl)
16828 {
16829 inst.instruction = N_MNEM_vabd;
16830 do_neon_dyadic_if_su ();
16831 }
16832 }
16833 else
16834 first_error (BAD_FPU);
5287ad62
JB
16835}
16836
16837static void
16838do_neon_abal (void)
16839{
16840 struct neon_type_el et = neon_check_type (3, NS_QDD,
16841 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16842 neon_mixed_length (et, et.size);
16843}
16844
16845static void
16846neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16847{
16848 if (inst.operands[2].isscalar)
16849 {
dcbf9037 16850 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16851 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16852 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16853 neon_mul_mac (et, et.type == NT_unsigned);
16854 }
16855 else
16856 {
16857 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16858 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16859 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16860 neon_mixed_length (et, et.size);
16861 }
16862}
16863
16864static void
16865do_neon_mac_maybe_scalar_long (void)
16866{
16867 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16868}
16869
dec41383
JW
16870/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
16871 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
16872
16873static unsigned
16874neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
16875{
16876 unsigned regno = NEON_SCALAR_REG (scalar);
16877 unsigned elno = NEON_SCALAR_INDEX (scalar);
16878
16879 if (quad_p)
16880 {
16881 if (regno > 7 || elno > 3)
16882 goto bad_scalar;
16883
16884 return ((regno & 0x7)
16885 | ((elno & 0x1) << 3)
16886 | (((elno >> 1) & 0x1) << 5));
16887 }
16888 else
16889 {
16890 if (regno > 15 || elno > 1)
16891 goto bad_scalar;
16892
16893 return (((regno & 0x1) << 5)
16894 | ((regno >> 1) & 0x7)
16895 | ((elno & 0x1) << 3));
16896 }
16897
16898bad_scalar:
16899 first_error (_("scalar out of range for multiply instruction"));
16900 return 0;
16901}
16902
16903static void
16904do_neon_fmac_maybe_scalar_long (int subtype)
16905{
16906 enum neon_shape rs;
16907 int high8;
16908 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
16909 field (bits[21:20]) has different meaning. For scalar index variant, it's
16910 used to differentiate add and subtract, otherwise it's with fixed value
16911 0x2. */
16912 int size = -1;
16913
16914 if (inst.cond != COND_ALWAYS)
16915 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
16916 "behaviour is UNPREDICTABLE"));
16917
01f48020 16918 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
dec41383
JW
16919 _(BAD_FP16));
16920
16921 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
16922 _(BAD_FPU));
16923
16924 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
16925 be a scalar index register. */
16926 if (inst.operands[2].isscalar)
16927 {
16928 high8 = 0xfe000000;
16929 if (subtype)
16930 size = 16;
16931 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
16932 }
16933 else
16934 {
16935 high8 = 0xfc000000;
16936 size = 32;
16937 if (subtype)
16938 inst.instruction |= (0x1 << 23);
16939 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
16940 }
16941
16942 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
16943
16944 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
16945 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
16946 so we simply pass -1 as size. */
16947 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
16948 neon_three_same (quad_p, 0, size);
16949
16950 /* Undo neon_dp_fixup. Redo the high eight bits. */
16951 inst.instruction &= 0x00ffffff;
16952 inst.instruction |= high8;
16953
16954#define LOW1(R) ((R) & 0x1)
16955#define HI4(R) (((R) >> 1) & 0xf)
16956 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
16957 whether the instruction is in Q form and whether Vm is a scalar indexed
16958 operand. */
16959 if (inst.operands[2].isscalar)
16960 {
16961 unsigned rm
16962 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
16963 inst.instruction &= 0xffffffd0;
16964 inst.instruction |= rm;
16965
16966 if (!quad_p)
16967 {
16968 /* Redo Rn as well. */
16969 inst.instruction &= 0xfff0ff7f;
16970 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16971 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16972 }
16973 }
16974 else if (!quad_p)
16975 {
16976 /* Redo Rn and Rm. */
16977 inst.instruction &= 0xfff0ff50;
16978 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16979 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16980 inst.instruction |= HI4 (inst.operands[2].reg);
16981 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
16982 }
16983}
16984
16985static void
16986do_neon_vfmal (void)
16987{
16988 return do_neon_fmac_maybe_scalar_long (0);
16989}
16990
16991static void
16992do_neon_vfmsl (void)
16993{
16994 return do_neon_fmac_maybe_scalar_long (1);
16995}
16996
5287ad62
JB
16997static void
16998do_neon_dyadic_wide (void)
16999{
17000 struct neon_type_el et = neon_check_type (3, NS_QQD,
17001 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
17002 neon_mixed_length (et, et.size);
17003}
17004
17005static void
17006do_neon_dyadic_narrow (void)
17007{
17008 struct neon_type_el et = neon_check_type (3, NS_QDD,
17009 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
17010 /* Operand sign is unimportant, and the U bit is part of the opcode,
17011 so force the operand type to integer. */
17012 et.type = NT_integer;
5287ad62
JB
17013 neon_mixed_length (et, et.size / 2);
17014}
17015
17016static void
17017do_neon_mul_sat_scalar_long (void)
17018{
17019 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
17020}
17021
17022static void
17023do_neon_vmull (void)
17024{
17025 if (inst.operands[2].isscalar)
17026 do_neon_mac_maybe_scalar_long ();
17027 else
17028 {
17029 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 17030 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 17031
5287ad62 17032 if (et.type == NT_poly)
477330fc 17033 NEON_ENCODE (POLY, inst);
5287ad62 17034 else
477330fc 17035 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
17036
17037 /* For polynomial encoding the U bit must be zero, and the size must
17038 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
17039 obviously, as 0b10). */
17040 if (et.size == 64)
17041 {
17042 /* Check we're on the correct architecture. */
17043 if (!mark_feature_used (&fpu_crypto_ext_armv8))
17044 inst.error =
17045 _("Instruction form not available on this architecture.");
17046
17047 et.size = 32;
17048 }
17049
5287ad62
JB
17050 neon_mixed_length (et, et.size);
17051 }
17052}
17053
17054static void
17055do_neon_ext (void)
17056{
037e8744 17057 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
17058 struct neon_type_el et = neon_check_type (3, rs,
17059 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
17060 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
17061
17062 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
17063 _("shift out of range"));
5287ad62
JB
17064 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17065 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17066 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17067 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17068 inst.instruction |= LOW4 (inst.operands[2].reg);
17069 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 17070 inst.instruction |= neon_quad (rs) << 6;
5287ad62 17071 inst.instruction |= imm << 8;
5f4273c7 17072
88714cb8 17073 neon_dp_fixup (&inst);
5287ad62
JB
17074}
17075
17076static void
17077do_neon_rev (void)
17078{
037e8744 17079 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17080 struct neon_type_el et = neon_check_type (2, rs,
17081 N_EQK, N_8 | N_16 | N_32 | N_KEY);
17082 unsigned op = (inst.instruction >> 7) & 3;
17083 /* N (width of reversed regions) is encoded as part of the bitmask. We
17084 extract it here to check the elements to be reversed are smaller.
17085 Otherwise we'd get a reserved instruction. */
17086 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 17087 gas_assert (elsize != 0);
5287ad62 17088 constraint (et.size >= elsize,
477330fc 17089 _("elements must be smaller than reversal region"));
037e8744 17090 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17091}
17092
17093static void
17094do_neon_dup (void)
17095{
17096 if (inst.operands[1].isscalar)
17097 {
037e8744 17098 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 17099 struct neon_type_el et = neon_check_type (2, rs,
477330fc 17100 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 17101 unsigned sizebits = et.size >> 3;
dcbf9037 17102 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 17103 int logsize = neon_logbits (et.size);
dcbf9037 17104 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
17105
17106 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 17107 return;
037e8744 17108
88714cb8 17109 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
17110 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17111 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17112 inst.instruction |= LOW4 (dm);
17113 inst.instruction |= HI1 (dm) << 5;
037e8744 17114 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17115 inst.instruction |= x << 17;
17116 inst.instruction |= sizebits << 16;
5f4273c7 17117
88714cb8 17118 neon_dp_fixup (&inst);
5287ad62
JB
17119 }
17120 else
17121 {
037e8744
JB
17122 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
17123 struct neon_type_el et = neon_check_type (2, rs,
477330fc 17124 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 17125 /* Duplicate ARM register to lanes of vector. */
88714cb8 17126 NEON_ENCODE (ARMREG, inst);
5287ad62 17127 switch (et.size)
477330fc
RM
17128 {
17129 case 8: inst.instruction |= 0x400000; break;
17130 case 16: inst.instruction |= 0x000020; break;
17131 case 32: inst.instruction |= 0x000000; break;
17132 default: break;
17133 }
5287ad62
JB
17134 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
17135 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
17136 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 17137 inst.instruction |= neon_quad (rs) << 21;
5287ad62 17138 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 17139 variants, except for the condition field. */
037e8744 17140 do_vfp_cond_or_thumb ();
5287ad62
JB
17141 }
17142}
17143
17144/* VMOV has particularly many variations. It can be one of:
17145 0. VMOV<c><q> <Qd>, <Qm>
17146 1. VMOV<c><q> <Dd>, <Dm>
17147 (Register operations, which are VORR with Rm = Rn.)
17148 2. VMOV<c><q>.<dt> <Qd>, #<imm>
17149 3. VMOV<c><q>.<dt> <Dd>, #<imm>
17150 (Immediate loads.)
17151 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
17152 (ARM register to scalar.)
17153 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
17154 (Two ARM registers to vector.)
17155 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
17156 (Scalar to ARM register.)
17157 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
17158 (Vector to two ARM registers.)
037e8744
JB
17159 8. VMOV.F32 <Sd>, <Sm>
17160 9. VMOV.F64 <Dd>, <Dm>
17161 (VFP register moves.)
17162 10. VMOV.F32 <Sd>, #imm
17163 11. VMOV.F64 <Dd>, #imm
17164 (VFP float immediate load.)
17165 12. VMOV <Rd>, <Sm>
17166 (VFP single to ARM reg.)
17167 13. VMOV <Sd>, <Rm>
17168 (ARM reg to VFP single.)
17169 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
17170 (Two ARM regs to two VFP singles.)
17171 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
17172 (Two VFP singles to two ARM regs.)
5f4273c7 17173
037e8744
JB
17174 These cases can be disambiguated using neon_select_shape, except cases 1/9
17175 and 3/11 which depend on the operand type too.
5f4273c7 17176
5287ad62 17177 All the encoded bits are hardcoded by this function.
5f4273c7 17178
b7fc2769
JB
17179 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
17180 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 17181
5287ad62 17182 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 17183 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
17184
17185static void
17186do_neon_mov (void)
17187{
037e8744 17188 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
17189 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
17190 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
17191 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
17192 struct neon_type_el et;
17193 const char *ldconst = 0;
5287ad62 17194
037e8744 17195 switch (rs)
5287ad62 17196 {
037e8744
JB
17197 case NS_DD: /* case 1/9. */
17198 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
17199 /* It is not an error here if no type is given. */
17200 inst.error = NULL;
17201 if (et.type == NT_float && et.size == 64)
477330fc
RM
17202 {
17203 do_vfp_nsyn_opcode ("fcpyd");
17204 break;
17205 }
037e8744 17206 /* fall through. */
5287ad62 17207
037e8744
JB
17208 case NS_QQ: /* case 0/1. */
17209 {
477330fc
RM
17210 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17211 return;
17212 /* The architecture manual I have doesn't explicitly state which
17213 value the U bit should have for register->register moves, but
17214 the equivalent VORR instruction has U = 0, so do that. */
17215 inst.instruction = 0x0200110;
17216 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17217 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17218 inst.instruction |= LOW4 (inst.operands[1].reg);
17219 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17220 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17221 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17222 inst.instruction |= neon_quad (rs) << 6;
17223
17224 neon_dp_fixup (&inst);
037e8744
JB
17225 }
17226 break;
5f4273c7 17227
037e8744
JB
17228 case NS_DI: /* case 3/11. */
17229 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
17230 inst.error = NULL;
17231 if (et.type == NT_float && et.size == 64)
477330fc
RM
17232 {
17233 /* case 11 (fconstd). */
17234 ldconst = "fconstd";
17235 goto encode_fconstd;
17236 }
037e8744
JB
17237 /* fall through. */
17238
17239 case NS_QI: /* case 2/3. */
17240 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 17241 return;
037e8744
JB
17242 inst.instruction = 0x0800010;
17243 neon_move_immediate ();
88714cb8 17244 neon_dp_fixup (&inst);
5287ad62 17245 break;
5f4273c7 17246
037e8744
JB
17247 case NS_SR: /* case 4. */
17248 {
477330fc
RM
17249 unsigned bcdebits = 0;
17250 int logsize;
17251 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
17252 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 17253
05ac0ffb
JB
17254 /* .<size> is optional here, defaulting to .32. */
17255 if (inst.vectype.elems == 0
17256 && inst.operands[0].vectype.type == NT_invtype
17257 && inst.operands[1].vectype.type == NT_invtype)
17258 {
17259 inst.vectype.el[0].type = NT_untyped;
17260 inst.vectype.el[0].size = 32;
17261 inst.vectype.elems = 1;
17262 }
17263
477330fc
RM
17264 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
17265 logsize = neon_logbits (et.size);
17266
17267 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
17268 _(BAD_FPU));
17269 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
17270 && et.size != 32, _(BAD_FPU));
17271 constraint (et.type == NT_invtype, _("bad type for scalar"));
17272 constraint (x >= 64 / et.size, _("scalar index out of range"));
17273
17274 switch (et.size)
17275 {
17276 case 8: bcdebits = 0x8; break;
17277 case 16: bcdebits = 0x1; break;
17278 case 32: bcdebits = 0x0; break;
17279 default: ;
17280 }
17281
17282 bcdebits |= x << logsize;
17283
17284 inst.instruction = 0xe000b10;
17285 do_vfp_cond_or_thumb ();
17286 inst.instruction |= LOW4 (dn) << 16;
17287 inst.instruction |= HI1 (dn) << 7;
17288 inst.instruction |= inst.operands[1].reg << 12;
17289 inst.instruction |= (bcdebits & 3) << 5;
17290 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
17291 }
17292 break;
5f4273c7 17293
037e8744 17294 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 17295 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 17296 _(BAD_FPU));
b7fc2769 17297
037e8744
JB
17298 inst.instruction = 0xc400b10;
17299 do_vfp_cond_or_thumb ();
17300 inst.instruction |= LOW4 (inst.operands[0].reg);
17301 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
17302 inst.instruction |= inst.operands[1].reg << 12;
17303 inst.instruction |= inst.operands[2].reg << 16;
17304 break;
5f4273c7 17305
037e8744
JB
17306 case NS_RS: /* case 6. */
17307 {
477330fc
RM
17308 unsigned logsize;
17309 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
17310 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
17311 unsigned abcdebits = 0;
037e8744 17312
05ac0ffb
JB
17313 /* .<dt> is optional here, defaulting to .32. */
17314 if (inst.vectype.elems == 0
17315 && inst.operands[0].vectype.type == NT_invtype
17316 && inst.operands[1].vectype.type == NT_invtype)
17317 {
17318 inst.vectype.el[0].type = NT_untyped;
17319 inst.vectype.el[0].size = 32;
17320 inst.vectype.elems = 1;
17321 }
17322
91d6fa6a
NC
17323 et = neon_check_type (2, NS_NULL,
17324 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
17325 logsize = neon_logbits (et.size);
17326
17327 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
17328 _(BAD_FPU));
17329 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
17330 && et.size != 32, _(BAD_FPU));
17331 constraint (et.type == NT_invtype, _("bad type for scalar"));
17332 constraint (x >= 64 / et.size, _("scalar index out of range"));
17333
17334 switch (et.size)
17335 {
17336 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
17337 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
17338 case 32: abcdebits = 0x00; break;
17339 default: ;
17340 }
17341
17342 abcdebits |= x << logsize;
17343 inst.instruction = 0xe100b10;
17344 do_vfp_cond_or_thumb ();
17345 inst.instruction |= LOW4 (dn) << 16;
17346 inst.instruction |= HI1 (dn) << 7;
17347 inst.instruction |= inst.operands[0].reg << 12;
17348 inst.instruction |= (abcdebits & 3) << 5;
17349 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
17350 }
17351 break;
5f4273c7 17352
037e8744
JB
17353 case NS_RRD: /* case 7 (fmrrd). */
17354 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 17355 _(BAD_FPU));
037e8744
JB
17356
17357 inst.instruction = 0xc500b10;
17358 do_vfp_cond_or_thumb ();
17359 inst.instruction |= inst.operands[0].reg << 12;
17360 inst.instruction |= inst.operands[1].reg << 16;
17361 inst.instruction |= LOW4 (inst.operands[2].reg);
17362 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
17363 break;
5f4273c7 17364
037e8744
JB
17365 case NS_FF: /* case 8 (fcpys). */
17366 do_vfp_nsyn_opcode ("fcpys");
17367 break;
5f4273c7 17368
9db2f6b4 17369 case NS_HI:
037e8744
JB
17370 case NS_FI: /* case 10 (fconsts). */
17371 ldconst = "fconsts";
4ef4710f 17372 encode_fconstd:
58ed5c38
TC
17373 if (!inst.operands[1].immisfloat)
17374 {
4ef4710f 17375 unsigned new_imm;
58ed5c38 17376 /* Immediate has to fit in 8 bits so float is enough. */
4ef4710f
NC
17377 float imm = (float) inst.operands[1].imm;
17378 memcpy (&new_imm, &imm, sizeof (float));
17379 /* But the assembly may have been written to provide an integer
17380 bit pattern that equates to a float, so check that the
17381 conversion has worked. */
17382 if (is_quarter_float (new_imm))
17383 {
17384 if (is_quarter_float (inst.operands[1].imm))
17385 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
17386
17387 inst.operands[1].imm = new_imm;
17388 inst.operands[1].immisfloat = 1;
17389 }
58ed5c38
TC
17390 }
17391
037e8744 17392 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
17393 {
17394 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
17395 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
17396
17397 /* ARMv8.2 fp16 vmov.f16 instruction. */
17398 if (rs == NS_HI)
17399 do_scalar_fp16_v82_encode ();
477330fc 17400 }
5287ad62 17401 else
477330fc 17402 first_error (_("immediate out of range"));
037e8744 17403 break;
5f4273c7 17404
9db2f6b4 17405 case NS_RH:
037e8744
JB
17406 case NS_RF: /* case 12 (fmrs). */
17407 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
17408 /* ARMv8.2 fp16 vmov.f16 instruction. */
17409 if (rs == NS_RH)
17410 do_scalar_fp16_v82_encode ();
037e8744 17411 break;
5f4273c7 17412
9db2f6b4 17413 case NS_HR:
037e8744
JB
17414 case NS_FR: /* case 13 (fmsr). */
17415 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
17416 /* ARMv8.2 fp16 vmov.f16 instruction. */
17417 if (rs == NS_HR)
17418 do_scalar_fp16_v82_encode ();
037e8744 17419 break;
5f4273c7 17420
037e8744
JB
17421 /* The encoders for the fmrrs and fmsrr instructions expect three operands
17422 (one of which is a list), but we have parsed four. Do some fiddling to
17423 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
17424 expect. */
17425 case NS_RRFF: /* case 14 (fmrrs). */
17426 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 17427 _("VFP registers must be adjacent"));
037e8744
JB
17428 inst.operands[2].imm = 2;
17429 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
17430 do_vfp_nsyn_opcode ("fmrrs");
17431 break;
5f4273c7 17432
037e8744
JB
17433 case NS_FFRR: /* case 15 (fmsrr). */
17434 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 17435 _("VFP registers must be adjacent"));
037e8744
JB
17436 inst.operands[1] = inst.operands[2];
17437 inst.operands[2] = inst.operands[3];
17438 inst.operands[0].imm = 2;
17439 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
17440 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 17441 break;
5f4273c7 17442
4c261dff
NC
17443 case NS_NULL:
17444 /* neon_select_shape has determined that the instruction
17445 shape is wrong and has already set the error message. */
17446 break;
17447
5287ad62
JB
17448 default:
17449 abort ();
17450 }
17451}
17452
17453static void
17454do_neon_rshift_round_imm (void)
17455{
037e8744 17456 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
17457 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
17458 int imm = inst.operands[2].imm;
17459
17460 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
17461 if (imm == 0)
17462 {
17463 inst.operands[2].present = 0;
17464 do_neon_mov ();
17465 return;
17466 }
17467
17468 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 17469 _("immediate out of range for shift"));
037e8744 17470 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 17471 et.size - imm);
5287ad62
JB
17472}
17473
9db2f6b4
RL
17474static void
17475do_neon_movhf (void)
17476{
17477 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
17478 constraint (rs != NS_HH, _("invalid suffix"));
17479
7bdf778b
ASDV
17480 if (inst.cond != COND_ALWAYS)
17481 {
17482 if (thumb_mode)
17483 {
17484 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
17485 " the behaviour is UNPREDICTABLE"));
17486 }
17487 else
17488 {
17489 inst.error = BAD_COND;
17490 return;
17491 }
17492 }
17493
9db2f6b4
RL
17494 do_vfp_sp_monadic ();
17495
17496 inst.is_neon = 1;
17497 inst.instruction |= 0xf0000000;
17498}
17499
5287ad62
JB
17500static void
17501do_neon_movl (void)
17502{
17503 struct neon_type_el et = neon_check_type (2, NS_QD,
17504 N_EQK | N_DBL, N_SU_32 | N_KEY);
17505 unsigned sizebits = et.size >> 3;
17506 inst.instruction |= sizebits << 19;
17507 neon_two_same (0, et.type == NT_unsigned, -1);
17508}
17509
17510static void
17511do_neon_trn (void)
17512{
037e8744 17513 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17514 struct neon_type_el et = neon_check_type (2, rs,
17515 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 17516 NEON_ENCODE (INTEGER, inst);
037e8744 17517 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17518}
17519
17520static void
17521do_neon_zip_uzp (void)
17522{
037e8744 17523 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17524 struct neon_type_el et = neon_check_type (2, rs,
17525 N_EQK, N_8 | N_16 | N_32 | N_KEY);
17526 if (rs == NS_DD && et.size == 32)
17527 {
17528 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
17529 inst.instruction = N_MNEM_vtrn;
17530 do_neon_trn ();
17531 return;
17532 }
037e8744 17533 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17534}
17535
17536static void
17537do_neon_sat_abs_neg (void)
17538{
037e8744 17539 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17540 struct neon_type_el et = neon_check_type (2, rs,
17541 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 17542 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17543}
17544
17545static void
17546do_neon_pair_long (void)
17547{
037e8744 17548 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17549 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
17550 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
17551 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 17552 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17553}
17554
17555static void
17556do_neon_recip_est (void)
17557{
037e8744 17558 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 17559 struct neon_type_el et = neon_check_type (2, rs,
cc933301 17560 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 17561 inst.instruction |= (et.type == NT_float) << 8;
037e8744 17562 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17563}
17564
17565static void
17566do_neon_cls (void)
17567{
037e8744 17568 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17569 struct neon_type_el et = neon_check_type (2, rs,
17570 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 17571 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17572}
17573
17574static void
17575do_neon_clz (void)
17576{
037e8744 17577 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17578 struct neon_type_el et = neon_check_type (2, rs,
17579 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 17580 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17581}
17582
17583static void
17584do_neon_cnt (void)
17585{
037e8744 17586 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17587 struct neon_type_el et = neon_check_type (2, rs,
17588 N_EQK | N_INT, N_8 | N_KEY);
037e8744 17589 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17590}
17591
17592static void
17593do_neon_swp (void)
17594{
037e8744
JB
17595 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
17596 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
17597}
17598
17599static void
17600do_neon_tbl_tbx (void)
17601{
17602 unsigned listlenbits;
dcbf9037 17603 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 17604
5287ad62
JB
17605 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
17606 {
dcbf9037 17607 first_error (_("bad list length for table lookup"));
5287ad62
JB
17608 return;
17609 }
5f4273c7 17610
5287ad62
JB
17611 listlenbits = inst.operands[1].imm - 1;
17612 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17613 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17614 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17615 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17616 inst.instruction |= LOW4 (inst.operands[2].reg);
17617 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
17618 inst.instruction |= listlenbits << 8;
5f4273c7 17619
88714cb8 17620 neon_dp_fixup (&inst);
5287ad62
JB
17621}
17622
17623static void
17624do_neon_ldm_stm (void)
17625{
17626 /* P, U and L bits are part of bitmask. */
17627 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
17628 unsigned offsetbits = inst.operands[1].imm * 2;
17629
037e8744
JB
17630 if (inst.operands[1].issingle)
17631 {
17632 do_vfp_nsyn_ldm_stm (is_dbmode);
17633 return;
17634 }
17635
5287ad62 17636 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 17637 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
17638
17639 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
17640 _("register list must contain at least 1 and at most 16 "
17641 "registers"));
5287ad62
JB
17642
17643 inst.instruction |= inst.operands[0].reg << 16;
17644 inst.instruction |= inst.operands[0].writeback << 21;
17645 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
17646 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
17647
17648 inst.instruction |= offsetbits;
5f4273c7 17649
037e8744 17650 do_vfp_cond_or_thumb ();
5287ad62
JB
17651}
17652
17653static void
17654do_neon_ldr_str (void)
17655{
5287ad62 17656 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 17657
6844b2c2
MGD
17658 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
17659 And is UNPREDICTABLE in thumb mode. */
fa94de6b 17660 if (!is_ldr
6844b2c2 17661 && inst.operands[1].reg == REG_PC
ba86b375 17662 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 17663 {
94dcf8bf 17664 if (thumb_mode)
6844b2c2 17665 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 17666 else if (warn_on_deprecated)
5c3696f8 17667 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
17668 }
17669
037e8744
JB
17670 if (inst.operands[0].issingle)
17671 {
cd2f129f 17672 if (is_ldr)
477330fc 17673 do_vfp_nsyn_opcode ("flds");
cd2f129f 17674 else
477330fc 17675 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
17676
17677 /* ARMv8.2 vldr.16/vstr.16 instruction. */
17678 if (inst.vectype.el[0].size == 16)
17679 do_scalar_fp16_v82_encode ();
5287ad62
JB
17680 }
17681 else
5287ad62 17682 {
cd2f129f 17683 if (is_ldr)
477330fc 17684 do_vfp_nsyn_opcode ("fldd");
5287ad62 17685 else
477330fc 17686 do_vfp_nsyn_opcode ("fstd");
5287ad62 17687 }
5287ad62
JB
17688}
17689
32c36c3c
AV
17690static void
17691do_t_vldr_vstr_sysreg (void)
17692{
17693 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
17694 bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
17695
17696 /* Use of PC is UNPREDICTABLE. */
17697 if (inst.operands[1].reg == REG_PC)
17698 inst.error = _("Use of PC here is UNPREDICTABLE");
17699
17700 if (inst.operands[1].immisreg)
17701 inst.error = _("instruction does not accept register index");
17702
17703 if (!inst.operands[1].isreg)
17704 inst.error = _("instruction does not accept PC-relative addressing");
17705
17706 if (abs (inst.operands[1].imm) >= (1 << 7))
17707 inst.error = _("immediate value out of range");
17708
17709 inst.instruction = 0xec000f80;
17710 if (is_vldr)
17711 inst.instruction |= 1 << sysreg_vldr_bitno;
17712 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
17713 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
17714 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
17715}
17716
17717static void
17718do_vldr_vstr (void)
17719{
17720 bfd_boolean sysreg_op = !inst.operands[0].isreg;
17721
17722 /* VLDR/VSTR (System Register). */
17723 if (sysreg_op)
17724 {
17725 if (!mark_feature_used (&arm_ext_v8_1m_main))
17726 as_bad (_("Instruction not permitted on this architecture"));
17727
17728 do_t_vldr_vstr_sysreg ();
17729 }
17730 /* VLDR/VSTR. */
17731 else
17732 {
17733 if (!mark_feature_used (&fpu_vfp_ext_v1xd))
17734 as_bad (_("Instruction not permitted on this architecture"));
17735 do_neon_ldr_str ();
17736 }
17737}
17738
5287ad62
JB
17739/* "interleave" version also handles non-interleaving register VLD1/VST1
17740 instructions. */
17741
17742static void
17743do_neon_ld_st_interleave (void)
17744{
037e8744 17745 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 17746 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
17747 unsigned alignbits = 0;
17748 unsigned idx;
17749 /* The bits in this table go:
17750 0: register stride of one (0) or two (1)
17751 1,2: register list length, minus one (1, 2, 3, 4).
17752 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
17753 We use -1 for invalid entries. */
17754 const int typetable[] =
17755 {
17756 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
17757 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
17758 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
17759 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
17760 };
17761 int typebits;
17762
dcbf9037
JB
17763 if (et.type == NT_invtype)
17764 return;
17765
5287ad62
JB
17766 if (inst.operands[1].immisalign)
17767 switch (inst.operands[1].imm >> 8)
17768 {
17769 case 64: alignbits = 1; break;
17770 case 128:
477330fc 17771 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 17772 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
17773 goto bad_alignment;
17774 alignbits = 2;
17775 break;
5287ad62 17776 case 256:
477330fc
RM
17777 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
17778 goto bad_alignment;
17779 alignbits = 3;
17780 break;
5287ad62
JB
17781 default:
17782 bad_alignment:
477330fc
RM
17783 first_error (_("bad alignment"));
17784 return;
5287ad62
JB
17785 }
17786
17787 inst.instruction |= alignbits << 4;
17788 inst.instruction |= neon_logbits (et.size) << 6;
17789
17790 /* Bits [4:6] of the immediate in a list specifier encode register stride
17791 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
17792 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
17793 up the right value for "type" in a table based on this value and the given
17794 list style, then stick it back. */
17795 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 17796 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
17797
17798 typebits = typetable[idx];
5f4273c7 17799
5287ad62 17800 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
17801 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
17802 _("bad element type for instruction"));
5287ad62
JB
17803
17804 inst.instruction &= ~0xf00;
17805 inst.instruction |= typebits << 8;
17806}
17807
17808/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
17809 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
17810 otherwise. The variable arguments are a list of pairs of legal (size, align)
17811 values, terminated with -1. */
17812
17813static int
aa8a0863 17814neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
17815{
17816 va_list ap;
17817 int result = FAIL, thissize, thisalign;
5f4273c7 17818
5287ad62
JB
17819 if (!inst.operands[1].immisalign)
17820 {
aa8a0863 17821 *do_alignment = 0;
5287ad62
JB
17822 return SUCCESS;
17823 }
5f4273c7 17824
aa8a0863 17825 va_start (ap, do_alignment);
5287ad62
JB
17826
17827 do
17828 {
17829 thissize = va_arg (ap, int);
17830 if (thissize == -1)
477330fc 17831 break;
5287ad62
JB
17832 thisalign = va_arg (ap, int);
17833
17834 if (size == thissize && align == thisalign)
477330fc 17835 result = SUCCESS;
5287ad62
JB
17836 }
17837 while (result != SUCCESS);
17838
17839 va_end (ap);
17840
17841 if (result == SUCCESS)
aa8a0863 17842 *do_alignment = 1;
5287ad62 17843 else
dcbf9037 17844 first_error (_("unsupported alignment for instruction"));
5f4273c7 17845
5287ad62
JB
17846 return result;
17847}
17848
17849static void
17850do_neon_ld_st_lane (void)
17851{
037e8744 17852 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17853 int align_good, do_alignment = 0;
5287ad62
JB
17854 int logsize = neon_logbits (et.size);
17855 int align = inst.operands[1].imm >> 8;
17856 int n = (inst.instruction >> 8) & 3;
17857 int max_el = 64 / et.size;
5f4273c7 17858
dcbf9037
JB
17859 if (et.type == NT_invtype)
17860 return;
5f4273c7 17861
5287ad62 17862 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 17863 _("bad list length"));
5287ad62 17864 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 17865 _("scalar index out of range"));
5287ad62 17866 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
17867 && et.size == 8,
17868 _("stride of 2 unavailable when element size is 8"));
5f4273c7 17869
5287ad62
JB
17870 switch (n)
17871 {
17872 case 0: /* VLD1 / VST1. */
aa8a0863 17873 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 17874 32, 32, -1);
5287ad62 17875 if (align_good == FAIL)
477330fc 17876 return;
aa8a0863 17877 if (do_alignment)
477330fc
RM
17878 {
17879 unsigned alignbits = 0;
17880 switch (et.size)
17881 {
17882 case 16: alignbits = 0x1; break;
17883 case 32: alignbits = 0x3; break;
17884 default: ;
17885 }
17886 inst.instruction |= alignbits << 4;
17887 }
5287ad62
JB
17888 break;
17889
17890 case 1: /* VLD2 / VST2. */
aa8a0863
TS
17891 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
17892 16, 32, 32, 64, -1);
5287ad62 17893 if (align_good == FAIL)
477330fc 17894 return;
aa8a0863 17895 if (do_alignment)
477330fc 17896 inst.instruction |= 1 << 4;
5287ad62
JB
17897 break;
17898
17899 case 2: /* VLD3 / VST3. */
17900 constraint (inst.operands[1].immisalign,
477330fc 17901 _("can't use alignment with this instruction"));
5287ad62
JB
17902 break;
17903
17904 case 3: /* VLD4 / VST4. */
aa8a0863 17905 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 17906 16, 64, 32, 64, 32, 128, -1);
5287ad62 17907 if (align_good == FAIL)
477330fc 17908 return;
aa8a0863 17909 if (do_alignment)
477330fc
RM
17910 {
17911 unsigned alignbits = 0;
17912 switch (et.size)
17913 {
17914 case 8: alignbits = 0x1; break;
17915 case 16: alignbits = 0x1; break;
17916 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
17917 default: ;
17918 }
17919 inst.instruction |= alignbits << 4;
17920 }
5287ad62
JB
17921 break;
17922
17923 default: ;
17924 }
17925
17926 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
17927 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17928 inst.instruction |= 1 << (4 + logsize);
5f4273c7 17929
5287ad62
JB
17930 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
17931 inst.instruction |= logsize << 10;
17932}
17933
17934/* Encode single n-element structure to all lanes VLD<n> instructions. */
17935
17936static void
17937do_neon_ld_dup (void)
17938{
037e8744 17939 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17940 int align_good, do_alignment = 0;
5287ad62 17941
dcbf9037
JB
17942 if (et.type == NT_invtype)
17943 return;
17944
5287ad62
JB
17945 switch ((inst.instruction >> 8) & 3)
17946 {
17947 case 0: /* VLD1. */
9c2799c2 17948 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 17949 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 17950 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 17951 if (align_good == FAIL)
477330fc 17952 return;
5287ad62 17953 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
17954 {
17955 case 1: break;
17956 case 2: inst.instruction |= 1 << 5; break;
17957 default: first_error (_("bad list length")); return;
17958 }
5287ad62
JB
17959 inst.instruction |= neon_logbits (et.size) << 6;
17960 break;
17961
17962 case 1: /* VLD2. */
17963 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
17964 &do_alignment, 8, 16, 16, 32, 32, 64,
17965 -1);
5287ad62 17966 if (align_good == FAIL)
477330fc 17967 return;
5287ad62 17968 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 17969 _("bad list length"));
5287ad62 17970 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17971 inst.instruction |= 1 << 5;
5287ad62
JB
17972 inst.instruction |= neon_logbits (et.size) << 6;
17973 break;
17974
17975 case 2: /* VLD3. */
17976 constraint (inst.operands[1].immisalign,
477330fc 17977 _("can't use alignment with this instruction"));
5287ad62 17978 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 17979 _("bad list length"));
5287ad62 17980 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17981 inst.instruction |= 1 << 5;
5287ad62
JB
17982 inst.instruction |= neon_logbits (et.size) << 6;
17983 break;
17984
17985 case 3: /* VLD4. */
17986 {
477330fc 17987 int align = inst.operands[1].imm >> 8;
aa8a0863 17988 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17989 16, 64, 32, 64, 32, 128, -1);
17990 if (align_good == FAIL)
17991 return;
17992 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17993 _("bad list length"));
17994 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17995 inst.instruction |= 1 << 5;
17996 if (et.size == 32 && align == 128)
17997 inst.instruction |= 0x3 << 6;
17998 else
17999 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
18000 }
18001 break;
18002
18003 default: ;
18004 }
18005
aa8a0863 18006 inst.instruction |= do_alignment << 4;
5287ad62
JB
18007}
18008
18009/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
18010 apart from bits [11:4]. */
18011
18012static void
18013do_neon_ldx_stx (void)
18014{
b1a769ed
DG
18015 if (inst.operands[1].isreg)
18016 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18017
5287ad62
JB
18018 switch (NEON_LANE (inst.operands[0].imm))
18019 {
18020 case NEON_INTERLEAVE_LANES:
88714cb8 18021 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
18022 do_neon_ld_st_interleave ();
18023 break;
5f4273c7 18024
5287ad62 18025 case NEON_ALL_LANES:
88714cb8 18026 NEON_ENCODE (DUP, inst);
2d51fb74
JB
18027 if (inst.instruction == N_INV)
18028 {
18029 first_error ("only loads support such operands");
18030 break;
18031 }
5287ad62
JB
18032 do_neon_ld_dup ();
18033 break;
5f4273c7 18034
5287ad62 18035 default:
88714cb8 18036 NEON_ENCODE (LANE, inst);
5287ad62
JB
18037 do_neon_ld_st_lane ();
18038 }
18039
18040 /* L bit comes from bit mask. */
18041 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18042 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18043 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 18044
5287ad62
JB
18045 if (inst.operands[1].postind)
18046 {
18047 int postreg = inst.operands[1].imm & 0xf;
18048 constraint (!inst.operands[1].immisreg,
477330fc 18049 _("post-index must be a register"));
5287ad62 18050 constraint (postreg == 0xd || postreg == 0xf,
477330fc 18051 _("bad register for post-index"));
5287ad62
JB
18052 inst.instruction |= postreg;
18053 }
4f2374c7 18054 else
5287ad62 18055 {
4f2374c7 18056 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
e2b0ab59
AV
18057 constraint (inst.relocs[0].exp.X_op != O_constant
18058 || inst.relocs[0].exp.X_add_number != 0,
4f2374c7
WN
18059 BAD_ADDR_MODE);
18060
18061 if (inst.operands[1].writeback)
18062 {
18063 inst.instruction |= 0xd;
18064 }
18065 else
18066 inst.instruction |= 0xf;
5287ad62 18067 }
5f4273c7 18068
5287ad62
JB
18069 if (thumb_mode)
18070 inst.instruction |= 0xf9000000;
18071 else
18072 inst.instruction |= 0xf4000000;
18073}
33399f07
MGD
18074
18075/* FP v8. */
18076static void
18077do_vfp_nsyn_fpv8 (enum neon_shape rs)
18078{
a715796b
TG
18079 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18080 D register operands. */
18081 if (neon_shape_class[rs] == SC_DOUBLE)
18082 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18083 _(BAD_FPU));
18084
33399f07
MGD
18085 NEON_ENCODE (FPV8, inst);
18086
9db2f6b4
RL
18087 if (rs == NS_FFF || rs == NS_HHH)
18088 {
18089 do_vfp_sp_dyadic ();
18090
18091 /* ARMv8.2 fp16 instruction. */
18092 if (rs == NS_HHH)
18093 do_scalar_fp16_v82_encode ();
18094 }
33399f07
MGD
18095 else
18096 do_vfp_dp_rd_rn_rm ();
18097
18098 if (rs == NS_DDD)
18099 inst.instruction |= 0x100;
18100
18101 inst.instruction |= 0xf0000000;
18102}
18103
18104static void
18105do_vsel (void)
18106{
5ee91343 18107 set_pred_insn_type (OUTSIDE_PRED_INSN);
33399f07
MGD
18108
18109 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
18110 first_error (_("invalid instruction shape"));
18111}
18112
73924fbc
MGD
18113static void
18114do_vmaxnm (void)
18115{
5ee91343 18116 set_pred_insn_type (OUTSIDE_PRED_INSN);
73924fbc
MGD
18117
18118 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
18119 return;
18120
18121 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
18122 return;
18123
cc933301 18124 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
18125}
18126
30bdf752
MGD
18127static void
18128do_vrint_1 (enum neon_cvt_mode mode)
18129{
9db2f6b4 18130 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
18131 struct neon_type_el et;
18132
18133 if (rs == NS_NULL)
18134 return;
18135
a715796b
TG
18136 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18137 D register operands. */
18138 if (neon_shape_class[rs] == SC_DOUBLE)
18139 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18140 _(BAD_FPU));
18141
9db2f6b4
RL
18142 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
18143 | N_VFP);
30bdf752
MGD
18144 if (et.type != NT_invtype)
18145 {
18146 /* VFP encodings. */
18147 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
18148 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
5ee91343 18149 set_pred_insn_type (OUTSIDE_PRED_INSN);
30bdf752
MGD
18150
18151 NEON_ENCODE (FPV8, inst);
9db2f6b4 18152 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
18153 do_vfp_sp_monadic ();
18154 else
18155 do_vfp_dp_rd_rm ();
18156
18157 switch (mode)
18158 {
18159 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
18160 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
18161 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
18162 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
18163 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
18164 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
18165 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
18166 default: abort ();
18167 }
18168
18169 inst.instruction |= (rs == NS_DD) << 8;
18170 do_vfp_cond_or_thumb ();
9db2f6b4
RL
18171
18172 /* ARMv8.2 fp16 vrint instruction. */
18173 if (rs == NS_HH)
18174 do_scalar_fp16_v82_encode ();
30bdf752
MGD
18175 }
18176 else
18177 {
18178 /* Neon encodings (or something broken...). */
18179 inst.error = NULL;
cc933301 18180 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
18181
18182 if (et.type == NT_invtype)
18183 return;
18184
5ee91343 18185 set_pred_insn_type (OUTSIDE_PRED_INSN);
30bdf752
MGD
18186 NEON_ENCODE (FLOAT, inst);
18187
18188 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
18189 return;
18190
18191 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18192 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18193 inst.instruction |= LOW4 (inst.operands[1].reg);
18194 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18195 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
18196 /* Mask off the original size bits and reencode them. */
18197 inst.instruction = ((inst.instruction & 0xfff3ffff)
18198 | neon_logbits (et.size) << 18);
18199
30bdf752
MGD
18200 switch (mode)
18201 {
18202 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
18203 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
18204 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
18205 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
18206 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
18207 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
18208 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
18209 default: abort ();
18210 }
18211
18212 if (thumb_mode)
18213 inst.instruction |= 0xfc000000;
18214 else
18215 inst.instruction |= 0xf0000000;
18216 }
18217}
18218
18219static void
18220do_vrintx (void)
18221{
18222 do_vrint_1 (neon_cvt_mode_x);
18223}
18224
18225static void
18226do_vrintz (void)
18227{
18228 do_vrint_1 (neon_cvt_mode_z);
18229}
18230
18231static void
18232do_vrintr (void)
18233{
18234 do_vrint_1 (neon_cvt_mode_r);
18235}
18236
18237static void
18238do_vrinta (void)
18239{
18240 do_vrint_1 (neon_cvt_mode_a);
18241}
18242
18243static void
18244do_vrintn (void)
18245{
18246 do_vrint_1 (neon_cvt_mode_n);
18247}
18248
18249static void
18250do_vrintp (void)
18251{
18252 do_vrint_1 (neon_cvt_mode_p);
18253}
18254
18255static void
18256do_vrintm (void)
18257{
18258 do_vrint_1 (neon_cvt_mode_m);
18259}
18260
c28eeff2
SN
18261static unsigned
18262neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
18263{
18264 unsigned regno = NEON_SCALAR_REG (opnd);
18265 unsigned elno = NEON_SCALAR_INDEX (opnd);
18266
18267 if (elsize == 16 && elno < 2 && regno < 16)
18268 return regno | (elno << 4);
18269 else if (elsize == 32 && elno == 0)
18270 return regno;
18271
18272 first_error (_("scalar out of range"));
18273 return 0;
18274}
18275
18276static void
18277do_vcmla (void)
18278{
18279 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
18280 _(BAD_FPU));
e2b0ab59
AV
18281 constraint (inst.relocs[0].exp.X_op != O_constant,
18282 _("expression too complex"));
18283 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
18284 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
18285 _("immediate out of range"));
18286 rot /= 90;
18287 if (inst.operands[2].isscalar)
18288 {
18289 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
18290 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
18291 N_KEY | N_F16 | N_F32).size;
18292 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
18293 inst.is_neon = 1;
18294 inst.instruction = 0xfe000800;
18295 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18296 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18297 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
18298 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
18299 inst.instruction |= LOW4 (m);
18300 inst.instruction |= HI1 (m) << 5;
18301 inst.instruction |= neon_quad (rs) << 6;
18302 inst.instruction |= rot << 20;
18303 inst.instruction |= (size == 32) << 23;
18304 }
18305 else
18306 {
18307 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
18308 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
18309 N_KEY | N_F16 | N_F32).size;
18310 neon_three_same (neon_quad (rs), 0, -1);
18311 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
18312 inst.instruction |= 0xfc200800;
18313 inst.instruction |= rot << 23;
18314 inst.instruction |= (size == 32) << 20;
18315 }
18316}
18317
18318static void
18319do_vcadd (void)
18320{
18321 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
18322 _(BAD_FPU));
e2b0ab59
AV
18323 constraint (inst.relocs[0].exp.X_op != O_constant,
18324 _("expression too complex"));
18325 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
18326 constraint (rot != 90 && rot != 270, _("immediate out of range"));
18327 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
18328 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
18329 N_KEY | N_F16 | N_F32).size;
18330 neon_three_same (neon_quad (rs), 0, -1);
18331 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
18332 inst.instruction |= 0xfc800800;
18333 inst.instruction |= (rot == 270) << 24;
18334 inst.instruction |= (size == 32) << 20;
18335}
18336
c604a79a
JW
18337/* Dot Product instructions encoding support. */
18338
18339static void
18340do_neon_dotproduct (int unsigned_p)
18341{
18342 enum neon_shape rs;
18343 unsigned scalar_oprd2 = 0;
18344 int high8;
18345
18346 if (inst.cond != COND_ALWAYS)
18347 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
18348 "is UNPREDICTABLE"));
18349
18350 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
18351 _(BAD_FPU));
18352
18353 /* Dot Product instructions are in three-same D/Q register format or the third
18354 operand can be a scalar index register. */
18355 if (inst.operands[2].isscalar)
18356 {
18357 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
18358 high8 = 0xfe000000;
18359 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18360 }
18361 else
18362 {
18363 high8 = 0xfc000000;
18364 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18365 }
18366
18367 if (unsigned_p)
18368 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
18369 else
18370 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
18371
18372 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
18373 Product instruction, so we pass 0 as the "ubit" parameter. And the
18374 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
18375 neon_three_same (neon_quad (rs), 0, 32);
18376
18377 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
18378 different NEON three-same encoding. */
18379 inst.instruction &= 0x00ffffff;
18380 inst.instruction |= high8;
18381 /* Encode 'U' bit which indicates signedness. */
18382 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
18383 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
18384 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
18385 the instruction encoding. */
18386 if (inst.operands[2].isscalar)
18387 {
18388 inst.instruction &= 0xffffffd0;
18389 inst.instruction |= LOW4 (scalar_oprd2);
18390 inst.instruction |= HI1 (scalar_oprd2) << 5;
18391 }
18392}
18393
18394/* Dot Product instructions for signed integer. */
18395
18396static void
18397do_neon_dotproduct_s (void)
18398{
18399 return do_neon_dotproduct (0);
18400}
18401
18402/* Dot Product instructions for unsigned integer. */
18403
18404static void
18405do_neon_dotproduct_u (void)
18406{
18407 return do_neon_dotproduct (1);
18408}
18409
91ff7894
MGD
18410/* Crypto v1 instructions. */
18411static void
18412do_crypto_2op_1 (unsigned elttype, int op)
18413{
5ee91343 18414 set_pred_insn_type (OUTSIDE_PRED_INSN);
91ff7894
MGD
18415
18416 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
18417 == NT_invtype)
18418 return;
18419
18420 inst.error = NULL;
18421
18422 NEON_ENCODE (INTEGER, inst);
18423 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18424 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18425 inst.instruction |= LOW4 (inst.operands[1].reg);
18426 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18427 if (op != -1)
18428 inst.instruction |= op << 6;
18429
18430 if (thumb_mode)
18431 inst.instruction |= 0xfc000000;
18432 else
18433 inst.instruction |= 0xf0000000;
18434}
18435
48adcd8e
MGD
18436static void
18437do_crypto_3op_1 (int u, int op)
18438{
5ee91343 18439 set_pred_insn_type (OUTSIDE_PRED_INSN);
48adcd8e
MGD
18440
18441 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
18442 N_32 | N_UNT | N_KEY).type == NT_invtype)
18443 return;
18444
18445 inst.error = NULL;
18446
18447 NEON_ENCODE (INTEGER, inst);
18448 neon_three_same (1, u, 8 << op);
18449}
18450
91ff7894
MGD
18451static void
18452do_aese (void)
18453{
18454 do_crypto_2op_1 (N_8, 0);
18455}
18456
18457static void
18458do_aesd (void)
18459{
18460 do_crypto_2op_1 (N_8, 1);
18461}
18462
18463static void
18464do_aesmc (void)
18465{
18466 do_crypto_2op_1 (N_8, 2);
18467}
18468
18469static void
18470do_aesimc (void)
18471{
18472 do_crypto_2op_1 (N_8, 3);
18473}
18474
48adcd8e
MGD
18475static void
18476do_sha1c (void)
18477{
18478 do_crypto_3op_1 (0, 0);
18479}
18480
18481static void
18482do_sha1p (void)
18483{
18484 do_crypto_3op_1 (0, 1);
18485}
18486
18487static void
18488do_sha1m (void)
18489{
18490 do_crypto_3op_1 (0, 2);
18491}
18492
18493static void
18494do_sha1su0 (void)
18495{
18496 do_crypto_3op_1 (0, 3);
18497}
91ff7894 18498
48adcd8e
MGD
18499static void
18500do_sha256h (void)
18501{
18502 do_crypto_3op_1 (1, 0);
18503}
18504
18505static void
18506do_sha256h2 (void)
18507{
18508 do_crypto_3op_1 (1, 1);
18509}
18510
18511static void
18512do_sha256su1 (void)
18513{
18514 do_crypto_3op_1 (1, 2);
18515}
3c9017d2
MGD
18516
18517static void
18518do_sha1h (void)
18519{
18520 do_crypto_2op_1 (N_32, -1);
18521}
18522
18523static void
18524do_sha1su1 (void)
18525{
18526 do_crypto_2op_1 (N_32, 0);
18527}
18528
18529static void
18530do_sha256su0 (void)
18531{
18532 do_crypto_2op_1 (N_32, 1);
18533}
dd5181d5
KT
18534
18535static void
18536do_crc32_1 (unsigned int poly, unsigned int sz)
18537{
18538 unsigned int Rd = inst.operands[0].reg;
18539 unsigned int Rn = inst.operands[1].reg;
18540 unsigned int Rm = inst.operands[2].reg;
18541
5ee91343 18542 set_pred_insn_type (OUTSIDE_PRED_INSN);
dd5181d5
KT
18543 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
18544 inst.instruction |= LOW4 (Rn) << 16;
18545 inst.instruction |= LOW4 (Rm);
18546 inst.instruction |= sz << (thumb_mode ? 4 : 21);
18547 inst.instruction |= poly << (thumb_mode ? 20 : 9);
18548
18549 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
18550 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
18551}
18552
18553static void
18554do_crc32b (void)
18555{
18556 do_crc32_1 (0, 0);
18557}
18558
18559static void
18560do_crc32h (void)
18561{
18562 do_crc32_1 (0, 1);
18563}
18564
18565static void
18566do_crc32w (void)
18567{
18568 do_crc32_1 (0, 2);
18569}
18570
18571static void
18572do_crc32cb (void)
18573{
18574 do_crc32_1 (1, 0);
18575}
18576
18577static void
18578do_crc32ch (void)
18579{
18580 do_crc32_1 (1, 1);
18581}
18582
18583static void
18584do_crc32cw (void)
18585{
18586 do_crc32_1 (1, 2);
18587}
18588
49e8a725
SN
18589static void
18590do_vjcvt (void)
18591{
18592 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18593 _(BAD_FPU));
18594 neon_check_type (2, NS_FD, N_S32, N_F64);
18595 do_vfp_sp_dp_cvt ();
18596 do_vfp_cond_or_thumb ();
18597}
18598
5287ad62
JB
18599\f
18600/* Overall per-instruction processing. */
18601
18602/* We need to be able to fix up arbitrary expressions in some statements.
18603 This is so that we can handle symbols that are an arbitrary distance from
18604 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
18605 which returns part of an address in a form which will be valid for
18606 a data instruction. We do this by pushing the expression into a symbol
18607 in the expr_section, and creating a fix for that. */
18608
18609static void
18610fix_new_arm (fragS * frag,
18611 int where,
18612 short int size,
18613 expressionS * exp,
18614 int pc_rel,
18615 int reloc)
18616{
18617 fixS * new_fix;
18618
18619 switch (exp->X_op)
18620 {
18621 case O_constant:
6e7ce2cd
PB
18622 if (pc_rel)
18623 {
18624 /* Create an absolute valued symbol, so we have something to
477330fc
RM
18625 refer to in the object file. Unfortunately for us, gas's
18626 generic expression parsing will already have folded out
18627 any use of .set foo/.type foo %function that may have
18628 been used to set type information of the target location,
18629 that's being specified symbolically. We have to presume
18630 the user knows what they are doing. */
6e7ce2cd
PB
18631 char name[16 + 8];
18632 symbolS *symbol;
18633
18634 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
18635
18636 symbol = symbol_find_or_make (name);
18637 S_SET_SEGMENT (symbol, absolute_section);
18638 symbol_set_frag (symbol, &zero_address_frag);
18639 S_SET_VALUE (symbol, exp->X_add_number);
18640 exp->X_op = O_symbol;
18641 exp->X_add_symbol = symbol;
18642 exp->X_add_number = 0;
18643 }
18644 /* FALLTHROUGH */
5287ad62
JB
18645 case O_symbol:
18646 case O_add:
18647 case O_subtract:
21d799b5 18648 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 18649 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
18650 break;
18651
18652 default:
21d799b5 18653 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 18654 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
18655 break;
18656 }
18657
18658 /* Mark whether the fix is to a THUMB instruction, or an ARM
18659 instruction. */
18660 new_fix->tc_fix_data = thumb_mode;
18661}
18662
18663/* Create a frg for an instruction requiring relaxation. */
18664static void
18665output_relax_insn (void)
18666{
18667 char * to;
18668 symbolS *sym;
0110f2b8
PB
18669 int offset;
18670
6e1cb1a6
PB
18671 /* The size of the instruction is unknown, so tie the debug info to the
18672 start of the instruction. */
18673 dwarf2_emit_insn (0);
6e1cb1a6 18674
e2b0ab59 18675 switch (inst.relocs[0].exp.X_op)
0110f2b8
PB
18676 {
18677 case O_symbol:
e2b0ab59
AV
18678 sym = inst.relocs[0].exp.X_add_symbol;
18679 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
18680 break;
18681 case O_constant:
18682 sym = NULL;
e2b0ab59 18683 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
18684 break;
18685 default:
e2b0ab59 18686 sym = make_expr_symbol (&inst.relocs[0].exp);
0110f2b8
PB
18687 offset = 0;
18688 break;
18689 }
18690 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
18691 inst.relax, sym, offset, NULL/*offset, opcode*/);
18692 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
18693}
18694
18695/* Write a 32-bit thumb instruction to buf. */
18696static void
18697put_thumb32_insn (char * buf, unsigned long insn)
18698{
18699 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
18700 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
18701}
18702
b99bd4ef 18703static void
c19d1205 18704output_inst (const char * str)
b99bd4ef 18705{
c19d1205 18706 char * to = NULL;
b99bd4ef 18707
c19d1205 18708 if (inst.error)
b99bd4ef 18709 {
c19d1205 18710 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
18711 return;
18712 }
5f4273c7
NC
18713 if (inst.relax)
18714 {
18715 output_relax_insn ();
0110f2b8 18716 return;
5f4273c7 18717 }
c19d1205
ZW
18718 if (inst.size == 0)
18719 return;
b99bd4ef 18720
c19d1205 18721 to = frag_more (inst.size);
8dc2430f
NC
18722 /* PR 9814: Record the thumb mode into the current frag so that we know
18723 what type of NOP padding to use, if necessary. We override any previous
18724 setting so that if the mode has changed then the NOPS that we use will
18725 match the encoding of the last instruction in the frag. */
cd000bff 18726 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
18727
18728 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 18729 {
9c2799c2 18730 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 18731 put_thumb32_insn (to, inst.instruction);
b99bd4ef 18732 }
c19d1205 18733 else if (inst.size > INSN_SIZE)
b99bd4ef 18734 {
9c2799c2 18735 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
18736 md_number_to_chars (to, inst.instruction, INSN_SIZE);
18737 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 18738 }
c19d1205
ZW
18739 else
18740 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 18741
e2b0ab59
AV
18742 int r;
18743 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
18744 {
18745 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
18746 fix_new_arm (frag_now, to - frag_now->fr_literal,
18747 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
18748 inst.relocs[r].type);
18749 }
b99bd4ef 18750
c19d1205 18751 dwarf2_emit_insn (inst.size);
c19d1205 18752}
b99bd4ef 18753
e07e6e58
NC
18754static char *
18755output_it_inst (int cond, int mask, char * to)
18756{
18757 unsigned long instruction = 0xbf00;
18758
18759 mask &= 0xf;
18760 instruction |= mask;
18761 instruction |= cond << 4;
18762
18763 if (to == NULL)
18764 {
18765 to = frag_more (2);
18766#ifdef OBJ_ELF
18767 dwarf2_emit_insn (2);
18768#endif
18769 }
18770
18771 md_number_to_chars (to, instruction, 2);
18772
18773 return to;
18774}
18775
c19d1205
ZW
18776/* Tag values used in struct asm_opcode's tag field. */
18777enum opcode_tag
18778{
18779 OT_unconditional, /* Instruction cannot be conditionalized.
18780 The ARM condition field is still 0xE. */
18781 OT_unconditionalF, /* Instruction cannot be conditionalized
18782 and carries 0xF in its ARM condition field. */
18783 OT_csuffix, /* Instruction takes a conditional suffix. */
5ee91343
AV
18784 OT_csuffixF, /* Some forms of the instruction take a scalar
18785 conditional suffix, others place 0xF where the
18786 condition field would be, others take a vector
18787 conditional suffix. */
c19d1205
ZW
18788 OT_cinfix3, /* Instruction takes a conditional infix,
18789 beginning at character index 3. (In
18790 unified mode, it becomes a suffix.) */
088fa78e
KH
18791 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
18792 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
18793 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
18794 character index 3, even in unified mode. Used for
18795 legacy instructions where suffix and infix forms
18796 may be ambiguous. */
c19d1205 18797 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 18798 suffix or an infix at character index 3. */
c19d1205
ZW
18799 OT_odd_infix_unc, /* This is the unconditional variant of an
18800 instruction that takes a conditional infix
18801 at an unusual position. In unified mode,
18802 this variant will accept a suffix. */
18803 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
18804 are the conditional variants of instructions that
18805 take conditional infixes in unusual positions.
18806 The infix appears at character index
18807 (tag - OT_odd_infix_0). These are not accepted
18808 in unified mode. */
18809};
b99bd4ef 18810
c19d1205
ZW
18811/* Subroutine of md_assemble, responsible for looking up the primary
18812 opcode from the mnemonic the user wrote. STR points to the
18813 beginning of the mnemonic.
18814
18815 This is not simply a hash table lookup, because of conditional
18816 variants. Most instructions have conditional variants, which are
18817 expressed with a _conditional affix_ to the mnemonic. If we were
18818 to encode each conditional variant as a literal string in the opcode
18819 table, it would have approximately 20,000 entries.
18820
18821 Most mnemonics take this affix as a suffix, and in unified syntax,
18822 'most' is upgraded to 'all'. However, in the divided syntax, some
18823 instructions take the affix as an infix, notably the s-variants of
18824 the arithmetic instructions. Of those instructions, all but six
18825 have the infix appear after the third character of the mnemonic.
18826
18827 Accordingly, the algorithm for looking up primary opcodes given
18828 an identifier is:
18829
18830 1. Look up the identifier in the opcode table.
18831 If we find a match, go to step U.
18832
18833 2. Look up the last two characters of the identifier in the
18834 conditions table. If we find a match, look up the first N-2
18835 characters of the identifier in the opcode table. If we
18836 find a match, go to step CE.
18837
18838 3. Look up the fourth and fifth characters of the identifier in
18839 the conditions table. If we find a match, extract those
18840 characters from the identifier, and look up the remaining
18841 characters in the opcode table. If we find a match, go
18842 to step CM.
18843
18844 4. Fail.
18845
18846 U. Examine the tag field of the opcode structure, in case this is
18847 one of the six instructions with its conditional infix in an
18848 unusual place. If it is, the tag tells us where to find the
18849 infix; look it up in the conditions table and set inst.cond
18850 accordingly. Otherwise, this is an unconditional instruction.
18851 Again set inst.cond accordingly. Return the opcode structure.
18852
18853 CE. Examine the tag field to make sure this is an instruction that
18854 should receive a conditional suffix. If it is not, fail.
18855 Otherwise, set inst.cond from the suffix we already looked up,
18856 and return the opcode structure.
18857
18858 CM. Examine the tag field to make sure this is an instruction that
18859 should receive a conditional infix after the third character.
18860 If it is not, fail. Otherwise, undo the edits to the current
18861 line of input and proceed as for case CE. */
18862
18863static const struct asm_opcode *
18864opcode_lookup (char **str)
18865{
18866 char *end, *base;
18867 char *affix;
18868 const struct asm_opcode *opcode;
18869 const struct asm_cond *cond;
e3cb604e 18870 char save[2];
c19d1205
ZW
18871
18872 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 18873 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 18874 for (base = end = *str; *end != '\0'; end++)
721a8186 18875 if (*end == ' ' || *end == '.')
c19d1205 18876 break;
b99bd4ef 18877
c19d1205 18878 if (end == base)
c921be7d 18879 return NULL;
b99bd4ef 18880
5287ad62 18881 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 18882 if (end[0] == '.')
b99bd4ef 18883 {
5287ad62 18884 int offset = 2;
5f4273c7 18885
267d2029 18886 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 18887 use. */
267d2029 18888 if (unified_syntax && end[1] == 'w')
c19d1205 18889 inst.size_req = 4;
267d2029 18890 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
18891 inst.size_req = 2;
18892 else
477330fc 18893 offset = 0;
5287ad62
JB
18894
18895 inst.vectype.elems = 0;
18896
18897 *str = end + offset;
b99bd4ef 18898
5f4273c7 18899 if (end[offset] == '.')
5287ad62 18900 {
267d2029 18901 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
18902 non-unified ARM syntax mode). */
18903 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 18904 return NULL;
477330fc 18905 }
5287ad62 18906 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 18907 return NULL;
b99bd4ef 18908 }
c19d1205
ZW
18909 else
18910 *str = end;
b99bd4ef 18911
c19d1205 18912 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 18913 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18914 end - base);
c19d1205 18915 if (opcode)
b99bd4ef 18916 {
c19d1205
ZW
18917 /* step U */
18918 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 18919 {
c19d1205
ZW
18920 inst.cond = COND_ALWAYS;
18921 return opcode;
b99bd4ef 18922 }
b99bd4ef 18923
278df34e 18924 if (warn_on_deprecated && unified_syntax)
5c3696f8 18925 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 18926 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 18927 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 18928 gas_assert (cond);
b99bd4ef 18929
c19d1205
ZW
18930 inst.cond = cond->value;
18931 return opcode;
18932 }
5ee91343
AV
18933 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18934 {
18935 /* Cannot have a conditional suffix on a mnemonic of less than a character.
18936 */
18937 if (end - base < 2)
18938 return NULL;
18939 affix = end - 1;
18940 cond = (const struct asm_cond *) hash_find_n (arm_vcond_hsh, affix, 1);
18941 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
18942 affix - base);
18943 /* If this opcode can not be vector predicated then don't accept it with a
18944 vector predication code. */
18945 if (opcode && !opcode->mayBeVecPred)
18946 opcode = NULL;
18947 }
18948 if (!opcode || !cond)
18949 {
18950 /* Cannot have a conditional suffix on a mnemonic of less than two
18951 characters. */
18952 if (end - base < 3)
18953 return NULL;
b99bd4ef 18954
5ee91343
AV
18955 /* Look for suffixed mnemonic. */
18956 affix = end - 2;
18957 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18958 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
18959 affix - base);
18960 }
b99bd4ef 18961
c19d1205
ZW
18962 if (opcode && cond)
18963 {
18964 /* step CE */
18965 switch (opcode->tag)
18966 {
e3cb604e
PB
18967 case OT_cinfix3_legacy:
18968 /* Ignore conditional suffixes matched on infix only mnemonics. */
18969 break;
18970
c19d1205 18971 case OT_cinfix3:
088fa78e 18972 case OT_cinfix3_deprecated:
c19d1205
ZW
18973 case OT_odd_infix_unc:
18974 if (!unified_syntax)
0198d5e6 18975 return NULL;
1a0670f3 18976 /* Fall through. */
c19d1205
ZW
18977
18978 case OT_csuffix:
477330fc 18979 case OT_csuffixF:
c19d1205
ZW
18980 case OT_csuf_or_in3:
18981 inst.cond = cond->value;
18982 return opcode;
18983
18984 case OT_unconditional:
18985 case OT_unconditionalF:
dfa9f0d5 18986 if (thumb_mode)
c921be7d 18987 inst.cond = cond->value;
dfa9f0d5
PB
18988 else
18989 {
c921be7d 18990 /* Delayed diagnostic. */
dfa9f0d5
PB
18991 inst.error = BAD_COND;
18992 inst.cond = COND_ALWAYS;
18993 }
c19d1205 18994 return opcode;
b99bd4ef 18995
c19d1205 18996 default:
c921be7d 18997 return NULL;
c19d1205
ZW
18998 }
18999 }
b99bd4ef 19000
c19d1205
ZW
19001 /* Cannot have a usual-position infix on a mnemonic of less than
19002 six characters (five would be a suffix). */
19003 if (end - base < 6)
c921be7d 19004 return NULL;
b99bd4ef 19005
c19d1205
ZW
19006 /* Look for infixed mnemonic in the usual position. */
19007 affix = base + 3;
21d799b5 19008 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 19009 if (!cond)
c921be7d 19010 return NULL;
e3cb604e
PB
19011
19012 memcpy (save, affix, 2);
19013 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 19014 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 19015 (end - base) - 2);
e3cb604e
PB
19016 memmove (affix + 2, affix, (end - affix) - 2);
19017 memcpy (affix, save, 2);
19018
088fa78e
KH
19019 if (opcode
19020 && (opcode->tag == OT_cinfix3
19021 || opcode->tag == OT_cinfix3_deprecated
19022 || opcode->tag == OT_csuf_or_in3
19023 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 19024 {
c921be7d 19025 /* Step CM. */
278df34e 19026 if (warn_on_deprecated && unified_syntax
088fa78e
KH
19027 && (opcode->tag == OT_cinfix3
19028 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 19029 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
19030
19031 inst.cond = cond->value;
19032 return opcode;
b99bd4ef
NC
19033 }
19034
c921be7d 19035 return NULL;
b99bd4ef
NC
19036}
19037
e07e6e58
NC
19038/* This function generates an initial IT instruction, leaving its block
19039 virtually open for the new instructions. Eventually,
5ee91343 19040 the mask will be updated by now_pred_add_mask () each time
e07e6e58
NC
19041 a new instruction needs to be included in the IT block.
19042 Finally, the block is closed with close_automatic_it_block ().
19043 The block closure can be requested either from md_assemble (),
19044 a tencode (), or due to a label hook. */
19045
19046static void
19047new_automatic_it_block (int cond)
19048{
5ee91343
AV
19049 now_pred.state = AUTOMATIC_PRED_BLOCK;
19050 now_pred.mask = 0x18;
19051 now_pred.cc = cond;
19052 now_pred.block_length = 1;
cd000bff 19053 mapping_state (MAP_THUMB);
5ee91343
AV
19054 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
19055 now_pred.warn_deprecated = FALSE;
19056 now_pred.insn_cond = TRUE;
e07e6e58
NC
19057}
19058
19059/* Close an automatic IT block.
19060 See comments in new_automatic_it_block (). */
19061
19062static void
19063close_automatic_it_block (void)
19064{
5ee91343
AV
19065 now_pred.mask = 0x10;
19066 now_pred.block_length = 0;
e07e6e58
NC
19067}
19068
19069/* Update the mask of the current automatically-generated IT
19070 instruction. See comments in new_automatic_it_block (). */
19071
19072static void
5ee91343 19073now_pred_add_mask (int cond)
e07e6e58
NC
19074{
19075#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
19076#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 19077 | ((bitvalue) << (nbit)))
e07e6e58 19078 const int resulting_bit = (cond & 1);
c921be7d 19079
5ee91343
AV
19080 now_pred.mask &= 0xf;
19081 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 19082 resulting_bit,
5ee91343
AV
19083 (5 - now_pred.block_length));
19084 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 19085 1,
5ee91343
AV
19086 ((5 - now_pred.block_length) - 1));
19087 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
e07e6e58
NC
19088
19089#undef CLEAR_BIT
19090#undef SET_BIT_VALUE
e07e6e58
NC
19091}
19092
19093/* The IT blocks handling machinery is accessed through the these functions:
19094 it_fsm_pre_encode () from md_assemble ()
5ee91343
AV
19095 set_pred_insn_type () optional, from the tencode functions
19096 set_pred_insn_type_last () ditto
19097 in_pred_block () ditto
e07e6e58 19098 it_fsm_post_encode () from md_assemble ()
33eaf5de 19099 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
19100
19101 Rationale:
19102 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
19103 initializing the IT insn type with a generic initial value depending
19104 on the inst.condition.
e07e6e58 19105 2) During the tencode function, two things may happen:
477330fc 19106 a) The tencode function overrides the IT insn type by
5ee91343
AV
19107 calling either set_pred_insn_type (type) or
19108 set_pred_insn_type_last ().
477330fc 19109 b) The tencode function queries the IT block state by
5ee91343 19110 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
477330fc 19111
5ee91343
AV
19112 Both set_pred_insn_type and in_pred_block run the internal FSM state
19113 handling function (handle_pred_state), because: a) setting the IT insn
477330fc
RM
19114 type may incur in an invalid state (exiting the function),
19115 and b) querying the state requires the FSM to be updated.
19116 Specifically we want to avoid creating an IT block for conditional
19117 branches, so it_fsm_pre_encode is actually a guess and we can't
19118 determine whether an IT block is required until the tencode () routine
19119 has decided what type of instruction this actually it.
5ee91343
AV
19120 Because of this, if set_pred_insn_type and in_pred_block have to be
19121 used, set_pred_insn_type has to be called first.
477330fc 19122
5ee91343
AV
19123 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
19124 that determines the insn IT type depending on the inst.cond code.
477330fc
RM
19125 When a tencode () routine encodes an instruction that can be
19126 either outside an IT block, or, in the case of being inside, has to be
5ee91343 19127 the last one, set_pred_insn_type_last () will determine the proper
477330fc 19128 IT instruction type based on the inst.cond code. Otherwise,
5ee91343 19129 set_pred_insn_type can be called for overriding that logic or
477330fc
RM
19130 for covering other cases.
19131
5ee91343
AV
19132 Calling handle_pred_state () may not transition the IT block state to
19133 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
477330fc 19134 still queried. Instead, if the FSM determines that the state should
5ee91343 19135 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
477330fc
RM
19136 after the tencode () function: that's what it_fsm_post_encode () does.
19137
5ee91343 19138 Since in_pred_block () calls the state handling function to get an
477330fc
RM
19139 updated state, an error may occur (due to invalid insns combination).
19140 In that case, inst.error is set.
19141 Therefore, inst.error has to be checked after the execution of
19142 the tencode () routine.
e07e6e58
NC
19143
19144 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc 19145 any pending state change (if any) that didn't take place in
5ee91343 19146 handle_pred_state () as explained above. */
e07e6e58
NC
19147
19148static void
19149it_fsm_pre_encode (void)
19150{
19151 if (inst.cond != COND_ALWAYS)
5ee91343 19152 inst.pred_insn_type = INSIDE_IT_INSN;
e07e6e58 19153 else
5ee91343 19154 inst.pred_insn_type = OUTSIDE_PRED_INSN;
e07e6e58 19155
5ee91343 19156 now_pred.state_handled = 0;
e07e6e58
NC
19157}
19158
19159/* IT state FSM handling function. */
5ee91343
AV
19160/* MVE instructions and non-MVE instructions are handled differently because of
19161 the introduction of VPT blocks.
19162 Specifications say that any non-MVE instruction inside a VPT block is
19163 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
19164 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
19165 few exceptions this will be handled at their respective handler functions.
19166 The error messages provided depending on the different combinations possible
19167 are described in the cases below:
19168 For 'most' MVE instructions:
19169 1) In an IT block, with an IT code: syntax error
19170 2) In an IT block, with a VPT code: error: must be in a VPT block
19171 3) In an IT block, with no code: warning: UNPREDICTABLE
19172 4) In a VPT block, with an IT code: syntax error
19173 5) In a VPT block, with a VPT code: OK!
19174 6) In a VPT block, with no code: error: missing code
19175 7) Outside a pred block, with an IT code: error: syntax error
19176 8) Outside a pred block, with a VPT code: error: should be in a VPT block
19177 9) Outside a pred block, with no code: OK!
19178 For non-MVE instructions:
19179 10) In an IT block, with an IT code: OK!
19180 11) In an IT block, with a VPT code: syntax error
19181 12) In an IT block, with no code: error: missing code
19182 13) In a VPT block, with an IT code: error: should be in an IT block
19183 14) In a VPT block, with a VPT code: syntax error
19184 15) In a VPT block, with no code: UNPREDICTABLE
19185 16) Outside a pred block, with an IT code: error: should be in an IT block
19186 17) Outside a pred block, with a VPT code: syntax error
19187 18) Outside a pred block, with no code: OK!
19188 */
19189
e07e6e58
NC
19190
19191static int
5ee91343 19192handle_pred_state (void)
e07e6e58 19193{
5ee91343
AV
19194 now_pred.state_handled = 1;
19195 now_pred.insn_cond = FALSE;
e07e6e58 19196
5ee91343 19197 switch (now_pred.state)
e07e6e58 19198 {
5ee91343
AV
19199 case OUTSIDE_PRED_BLOCK:
19200 switch (inst.pred_insn_type)
e07e6e58 19201 {
5ee91343
AV
19202 case MVE_OUTSIDE_PRED_INSN:
19203 if (inst.cond < COND_ALWAYS)
19204 {
19205 /* Case 7: Outside a pred block, with an IT code: error: syntax
19206 error. */
19207 inst.error = BAD_SYNTAX;
19208 return FAIL;
19209 }
19210 /* Case 9: Outside a pred block, with no code: OK! */
19211 break;
19212 case OUTSIDE_PRED_INSN:
19213 if (inst.cond > COND_ALWAYS)
19214 {
19215 /* Case 17: Outside a pred block, with a VPT code: syntax error.
19216 */
19217 inst.error = BAD_SYNTAX;
19218 return FAIL;
19219 }
19220 /* Case 18: Outside a pred block, with no code: OK! */
e07e6e58
NC
19221 break;
19222
5ee91343
AV
19223 case INSIDE_VPT_INSN:
19224 /* Case 8: Outside a pred block, with a VPT code: error: should be in
19225 a VPT block. */
19226 inst.error = BAD_OUT_VPT;
19227 return FAIL;
19228
e07e6e58
NC
19229 case INSIDE_IT_INSN:
19230 case INSIDE_IT_LAST_INSN:
5ee91343 19231 if (inst.cond < COND_ALWAYS)
e07e6e58 19232 {
5ee91343
AV
19233 /* Case 16: Outside a pred block, with an IT code: error: should
19234 be in an IT block. */
19235 if (thumb_mode == 0)
e07e6e58 19236 {
5ee91343
AV
19237 if (unified_syntax
19238 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
19239 as_tsktsk (_("Warning: conditional outside an IT block"\
19240 " for Thumb."));
e07e6e58
NC
19241 }
19242 else
19243 {
5ee91343
AV
19244 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
19245 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
19246 {
19247 /* Automatically generate the IT instruction. */
19248 new_automatic_it_block (inst.cond);
19249 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
19250 close_automatic_it_block ();
19251 }
19252 else
19253 {
19254 inst.error = BAD_OUT_IT;
19255 return FAIL;
19256 }
e07e6e58 19257 }
5ee91343 19258 break;
e07e6e58 19259 }
5ee91343
AV
19260 else if (inst.cond > COND_ALWAYS)
19261 {
19262 /* Case 17: Outside a pred block, with a VPT code: syntax error.
19263 */
19264 inst.error = BAD_SYNTAX;
19265 return FAIL;
19266 }
19267 else
19268 gas_assert (0);
e07e6e58
NC
19269 case IF_INSIDE_IT_LAST_INSN:
19270 case NEUTRAL_IT_INSN:
19271 break;
19272
5ee91343
AV
19273 case VPT_INSN:
19274 if (inst.cond != COND_ALWAYS)
19275 first_error (BAD_SYNTAX);
19276 now_pred.state = MANUAL_PRED_BLOCK;
19277 now_pred.block_length = 0;
19278 now_pred.type = VECTOR_PRED;
19279 now_pred.cc = 0;
19280 break;
e07e6e58 19281 case IT_INSN:
5ee91343
AV
19282 now_pred.state = MANUAL_PRED_BLOCK;
19283 now_pred.block_length = 0;
19284 now_pred.type = SCALAR_PRED;
e07e6e58
NC
19285 break;
19286 }
19287 break;
19288
5ee91343 19289 case AUTOMATIC_PRED_BLOCK:
e07e6e58
NC
19290 /* Three things may happen now:
19291 a) We should increment current it block size;
19292 b) We should close current it block (closing insn or 4 insns);
19293 c) We should close current it block and start a new one (due
19294 to incompatible conditions or
19295 4 insns-length block reached). */
19296
5ee91343 19297 switch (inst.pred_insn_type)
e07e6e58 19298 {
5ee91343
AV
19299 case INSIDE_VPT_INSN:
19300 case VPT_INSN:
19301 case MVE_OUTSIDE_PRED_INSN:
19302 gas_assert (0);
19303 case OUTSIDE_PRED_INSN:
2b0f3761 19304 /* The closure of the block shall happen immediately,
5ee91343 19305 so any in_pred_block () call reports the block as closed. */
e07e6e58
NC
19306 force_automatic_it_block_close ();
19307 break;
19308
19309 case INSIDE_IT_INSN:
19310 case INSIDE_IT_LAST_INSN:
19311 case IF_INSIDE_IT_LAST_INSN:
5ee91343 19312 now_pred.block_length++;
e07e6e58 19313
5ee91343
AV
19314 if (now_pred.block_length > 4
19315 || !now_pred_compatible (inst.cond))
e07e6e58
NC
19316 {
19317 force_automatic_it_block_close ();
5ee91343 19318 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
e07e6e58
NC
19319 new_automatic_it_block (inst.cond);
19320 }
19321 else
19322 {
5ee91343
AV
19323 now_pred.insn_cond = TRUE;
19324 now_pred_add_mask (inst.cond);
e07e6e58
NC
19325 }
19326
5ee91343
AV
19327 if (now_pred.state == AUTOMATIC_PRED_BLOCK
19328 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
19329 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
e07e6e58
NC
19330 close_automatic_it_block ();
19331 break;
19332
19333 case NEUTRAL_IT_INSN:
5ee91343
AV
19334 now_pred.block_length++;
19335 now_pred.insn_cond = TRUE;
e07e6e58 19336
5ee91343 19337 if (now_pred.block_length > 4)
e07e6e58
NC
19338 force_automatic_it_block_close ();
19339 else
5ee91343 19340 now_pred_add_mask (now_pred.cc & 1);
e07e6e58
NC
19341 break;
19342
19343 case IT_INSN:
19344 close_automatic_it_block ();
5ee91343 19345 now_pred.state = MANUAL_PRED_BLOCK;
e07e6e58
NC
19346 break;
19347 }
19348 break;
19349
5ee91343 19350 case MANUAL_PRED_BLOCK:
e07e6e58 19351 {
5ee91343
AV
19352 int cond, is_last;
19353 if (now_pred.type == SCALAR_PRED)
e07e6e58 19354 {
5ee91343
AV
19355 /* Check conditional suffixes. */
19356 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
19357 now_pred.mask <<= 1;
19358 now_pred.mask &= 0x1f;
19359 is_last = (now_pred.mask == 0x10);
19360 }
19361 else
19362 {
19363 now_pred.cc ^= (now_pred.mask >> 4);
19364 cond = now_pred.cc + 0xf;
19365 now_pred.mask <<= 1;
19366 now_pred.mask &= 0x1f;
19367 is_last = now_pred.mask == 0x10;
19368 }
19369 now_pred.insn_cond = TRUE;
e07e6e58 19370
5ee91343
AV
19371 switch (inst.pred_insn_type)
19372 {
19373 case OUTSIDE_PRED_INSN:
19374 if (now_pred.type == SCALAR_PRED)
19375 {
19376 if (inst.cond == COND_ALWAYS)
19377 {
19378 /* Case 12: In an IT block, with no code: error: missing
19379 code. */
19380 inst.error = BAD_NOT_IT;
19381 return FAIL;
19382 }
19383 else if (inst.cond > COND_ALWAYS)
19384 {
19385 /* Case 11: In an IT block, with a VPT code: syntax error.
19386 */
19387 inst.error = BAD_SYNTAX;
19388 return FAIL;
19389 }
19390 else if (thumb_mode)
19391 {
19392 /* This is for some special cases where a non-MVE
19393 instruction is not allowed in an IT block, such as cbz,
19394 but are put into one with a condition code.
19395 You could argue this should be a syntax error, but we
19396 gave the 'not allowed in IT block' diagnostic in the
19397 past so we will keep doing so. */
19398 inst.error = BAD_NOT_IT;
19399 return FAIL;
19400 }
19401 break;
19402 }
19403 else
19404 {
19405 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
19406 as_tsktsk (MVE_NOT_VPT);
19407 return SUCCESS;
19408 }
19409 case MVE_OUTSIDE_PRED_INSN:
19410 if (now_pred.type == SCALAR_PRED)
19411 {
19412 if (inst.cond == COND_ALWAYS)
19413 {
19414 /* Case 3: In an IT block, with no code: warning:
19415 UNPREDICTABLE. */
19416 as_tsktsk (MVE_NOT_IT);
19417 return SUCCESS;
19418 }
19419 else if (inst.cond < COND_ALWAYS)
19420 {
19421 /* Case 1: In an IT block, with an IT code: syntax error.
19422 */
19423 inst.error = BAD_SYNTAX;
19424 return FAIL;
19425 }
19426 else
19427 gas_assert (0);
19428 }
19429 else
19430 {
19431 if (inst.cond < COND_ALWAYS)
19432 {
19433 /* Case 4: In a VPT block, with an IT code: syntax error.
19434 */
19435 inst.error = BAD_SYNTAX;
19436 return FAIL;
19437 }
19438 else if (inst.cond == COND_ALWAYS)
19439 {
19440 /* Case 6: In a VPT block, with no code: error: missing
19441 code. */
19442 inst.error = BAD_NOT_VPT;
19443 return FAIL;
19444 }
19445 else
19446 {
19447 gas_assert (0);
19448 }
19449 }
e07e6e58 19450 case INSIDE_IT_INSN:
5ee91343 19451 if (inst.cond > COND_ALWAYS)
e07e6e58 19452 {
5ee91343
AV
19453 /* Case 11: In an IT block, with a VPT code: syntax error. */
19454 /* Case 14: In a VPT block, with a VPT code: syntax error. */
19455 inst.error = BAD_SYNTAX;
19456 return FAIL;
19457 }
19458 else if (now_pred.type == SCALAR_PRED)
19459 {
19460 /* Case 10: In an IT block, with an IT code: OK! */
19461 if (cond != inst.cond)
19462 {
19463 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
19464 BAD_VPT_COND;
19465 return FAIL;
19466 }
19467 }
19468 else
19469 {
19470 /* Case 13: In a VPT block, with an IT code: error: should be
19471 in an IT block. */
19472 inst.error = BAD_OUT_IT;
e07e6e58
NC
19473 return FAIL;
19474 }
19475 break;
19476
5ee91343
AV
19477 case INSIDE_VPT_INSN:
19478 if (now_pred.type == SCALAR_PRED)
19479 {
19480 /* Case 2: In an IT block, with a VPT code: error: must be in a
19481 VPT block. */
19482 inst.error = BAD_OUT_VPT;
19483 return FAIL;
19484 }
19485 /* Case 5: In a VPT block, with a VPT code: OK! */
19486 else if (cond != inst.cond)
19487 {
19488 inst.error = BAD_VPT_COND;
19489 return FAIL;
19490 }
19491 break;
e07e6e58
NC
19492 case INSIDE_IT_LAST_INSN:
19493 case IF_INSIDE_IT_LAST_INSN:
5ee91343
AV
19494 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
19495 {
19496 /* Case 4: In a VPT block, with an IT code: syntax error. */
19497 /* Case 11: In an IT block, with a VPT code: syntax error. */
19498 inst.error = BAD_SYNTAX;
19499 return FAIL;
19500 }
19501 else if (cond != inst.cond)
e07e6e58
NC
19502 {
19503 inst.error = BAD_IT_COND;
19504 return FAIL;
19505 }
19506 if (!is_last)
19507 {
19508 inst.error = BAD_BRANCH;
19509 return FAIL;
19510 }
19511 break;
19512
19513 case NEUTRAL_IT_INSN:
5ee91343
AV
19514 /* The BKPT instruction is unconditional even in a IT or VPT
19515 block. */
e07e6e58
NC
19516 break;
19517
19518 case IT_INSN:
5ee91343
AV
19519 if (now_pred.type == SCALAR_PRED)
19520 {
19521 inst.error = BAD_IT_IT;
19522 return FAIL;
19523 }
19524 /* fall through. */
19525 case VPT_INSN:
19526 if (inst.cond == COND_ALWAYS)
19527 {
19528 /* Executing a VPT/VPST instruction inside an IT block or a
19529 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
19530 */
19531 if (now_pred.type == SCALAR_PRED)
19532 as_tsktsk (MVE_NOT_IT);
19533 else
19534 as_tsktsk (MVE_NOT_VPT);
19535 return SUCCESS;
19536 }
19537 else
19538 {
19539 /* VPT/VPST do not accept condition codes. */
19540 inst.error = BAD_SYNTAX;
19541 return FAIL;
19542 }
e07e6e58 19543 }
5ee91343 19544 }
e07e6e58
NC
19545 break;
19546 }
19547
19548 return SUCCESS;
19549}
19550
5a01bb1d
MGD
19551struct depr_insn_mask
19552{
19553 unsigned long pattern;
19554 unsigned long mask;
19555 const char* description;
19556};
19557
19558/* List of 16-bit instruction patterns deprecated in an IT block in
19559 ARMv8. */
19560static const struct depr_insn_mask depr_it_insns[] = {
19561 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
19562 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
19563 { 0xa000, 0xb800, N_("ADR") },
19564 { 0x4800, 0xf800, N_("Literal loads") },
19565 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
19566 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
19567 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
19568 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
19569 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
19570 { 0, 0, NULL }
19571};
19572
e07e6e58
NC
19573static void
19574it_fsm_post_encode (void)
19575{
19576 int is_last;
19577
5ee91343
AV
19578 if (!now_pred.state_handled)
19579 handle_pred_state ();
e07e6e58 19580
5ee91343
AV
19581 if (now_pred.insn_cond
19582 && !now_pred.warn_deprecated
5a01bb1d 19583 && warn_on_deprecated
df9909b8
TP
19584 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
19585 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
5a01bb1d
MGD
19586 {
19587 if (inst.instruction >= 0x10000)
19588 {
5c3696f8 19589 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
df9909b8 19590 "performance deprecated in ARMv8-A and ARMv8-R"));
5ee91343 19591 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
19592 }
19593 else
19594 {
19595 const struct depr_insn_mask *p = depr_it_insns;
19596
19597 while (p->mask != 0)
19598 {
19599 if ((inst.instruction & p->mask) == p->pattern)
19600 {
df9909b8
TP
19601 as_tsktsk (_("IT blocks containing 16-bit Thumb "
19602 "instructions of the following class are "
19603 "performance deprecated in ARMv8-A and "
19604 "ARMv8-R: %s"), p->description);
5ee91343 19605 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
19606 break;
19607 }
19608
19609 ++p;
19610 }
19611 }
19612
5ee91343 19613 if (now_pred.block_length > 1)
5a01bb1d 19614 {
5c3696f8 19615 as_tsktsk (_("IT blocks containing more than one conditional "
df9909b8
TP
19616 "instruction are performance deprecated in ARMv8-A and "
19617 "ARMv8-R"));
5ee91343 19618 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
19619 }
19620 }
19621
5ee91343
AV
19622 is_last = (now_pred.mask == 0x10);
19623 if (is_last)
19624 {
19625 now_pred.state = OUTSIDE_PRED_BLOCK;
19626 now_pred.mask = 0;
19627 }
e07e6e58
NC
19628}
19629
19630static void
19631force_automatic_it_block_close (void)
19632{
5ee91343 19633 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
e07e6e58
NC
19634 {
19635 close_automatic_it_block ();
5ee91343
AV
19636 now_pred.state = OUTSIDE_PRED_BLOCK;
19637 now_pred.mask = 0;
e07e6e58
NC
19638 }
19639}
19640
19641static int
5ee91343 19642in_pred_block (void)
e07e6e58 19643{
5ee91343
AV
19644 if (!now_pred.state_handled)
19645 handle_pred_state ();
e07e6e58 19646
5ee91343 19647 return now_pred.state != OUTSIDE_PRED_BLOCK;
e07e6e58
NC
19648}
19649
ff8646ee
TP
19650/* Whether OPCODE only has T32 encoding. Since this function is only used by
19651 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
19652 here, hence the "known" in the function name. */
fc289b0a
TP
19653
19654static bfd_boolean
ff8646ee 19655known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
19656{
19657 /* Original Thumb-1 wide instruction. */
19658 if (opcode->tencode == do_t_blx
19659 || opcode->tencode == do_t_branch23
19660 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
19661 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
19662 return TRUE;
19663
16a1fa25
TP
19664 /* Wide-only instruction added to ARMv8-M Baseline. */
19665 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
19666 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
19667 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
19668 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
19669 return TRUE;
19670
19671 return FALSE;
19672}
19673
19674/* Whether wide instruction variant can be used if available for a valid OPCODE
19675 in ARCH. */
19676
19677static bfd_boolean
19678t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
19679{
19680 if (known_t32_only_insn (opcode))
19681 return TRUE;
19682
19683 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
19684 of variant T3 of B.W is checked in do_t_branch. */
19685 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
19686 && opcode->tencode == do_t_branch)
19687 return TRUE;
19688
bada4342
JW
19689 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
19690 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
19691 && opcode->tencode == do_t_mov_cmp
19692 /* Make sure CMP instruction is not affected. */
19693 && opcode->aencode == do_mov)
19694 return TRUE;
19695
ff8646ee
TP
19696 /* Wide instruction variants of all instructions with narrow *and* wide
19697 variants become available with ARMv6t2. Other opcodes are either
19698 narrow-only or wide-only and are thus available if OPCODE is valid. */
19699 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
19700 return TRUE;
19701
19702 /* OPCODE with narrow only instruction variant or wide variant not
19703 available. */
fc289b0a
TP
19704 return FALSE;
19705}
19706
c19d1205
ZW
19707void
19708md_assemble (char *str)
b99bd4ef 19709{
c19d1205
ZW
19710 char *p = str;
19711 const struct asm_opcode * opcode;
b99bd4ef 19712
c19d1205
ZW
19713 /* Align the previous label if needed. */
19714 if (last_label_seen != NULL)
b99bd4ef 19715 {
c19d1205
ZW
19716 symbol_set_frag (last_label_seen, frag_now);
19717 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
19718 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
19719 }
19720
c19d1205 19721 memset (&inst, '\0', sizeof (inst));
e2b0ab59
AV
19722 int r;
19723 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
19724 inst.relocs[r].type = BFD_RELOC_UNUSED;
b99bd4ef 19725
c19d1205
ZW
19726 opcode = opcode_lookup (&p);
19727 if (!opcode)
b99bd4ef 19728 {
c19d1205 19729 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 19730 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 19731 if (! create_register_alias (str, p)
477330fc 19732 && ! create_neon_reg_alias (str, p))
c19d1205 19733 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 19734
b99bd4ef
NC
19735 return;
19736 }
19737
278df34e 19738 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 19739 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 19740
037e8744
JB
19741 /* The value which unconditional instructions should have in place of the
19742 condition field. */
19743 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
19744
c19d1205 19745 if (thumb_mode)
b99bd4ef 19746 {
e74cfd16 19747 arm_feature_set variant;
8f06b2d8
PB
19748
19749 variant = cpu_variant;
19750 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
19751 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
19752 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 19753 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
19754 if (!opcode->tvariant
19755 || (thumb_mode == 1
19756 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 19757 {
173205ca
TP
19758 if (opcode->tencode == do_t_swi)
19759 as_bad (_("SVC is not permitted on this architecture"));
19760 else
19761 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
19762 return;
19763 }
c19d1205
ZW
19764 if (inst.cond != COND_ALWAYS && !unified_syntax
19765 && opcode->tencode != do_t_branch)
b99bd4ef 19766 {
c19d1205 19767 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
19768 return;
19769 }
19770
fc289b0a
TP
19771 /* Two things are addressed here:
19772 1) Implicit require narrow instructions on Thumb-1.
19773 This avoids relaxation accidentally introducing Thumb-2
19774 instructions.
19775 2) Reject wide instructions in non Thumb-2 cores.
19776
19777 Only instructions with narrow and wide variants need to be handled
19778 but selecting all non wide-only instructions is easier. */
19779 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 19780 && !t32_insn_ok (variant, opcode))
076d447c 19781 {
fc289b0a
TP
19782 if (inst.size_req == 0)
19783 inst.size_req = 2;
19784 else if (inst.size_req == 4)
752d5da4 19785 {
ff8646ee
TP
19786 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
19787 as_bad (_("selected processor does not support 32bit wide "
19788 "variant of instruction `%s'"), str);
19789 else
19790 as_bad (_("selected processor does not support `%s' in "
19791 "Thumb-2 mode"), str);
fc289b0a 19792 return;
752d5da4 19793 }
076d447c
PB
19794 }
19795
c19d1205
ZW
19796 inst.instruction = opcode->tvalue;
19797
5be8be5d 19798 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc 19799 {
5ee91343 19800 /* Prepare the pred_insn_type for those encodings that don't set
477330fc
RM
19801 it. */
19802 it_fsm_pre_encode ();
c19d1205 19803
477330fc 19804 opcode->tencode ();
e07e6e58 19805
477330fc
RM
19806 it_fsm_post_encode ();
19807 }
e27ec89e 19808
0110f2b8 19809 if (!(inst.error || inst.relax))
b99bd4ef 19810 {
9c2799c2 19811 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
19812 inst.size = (inst.instruction > 0xffff ? 4 : 2);
19813 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 19814 {
c19d1205 19815 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
19816 return;
19817 }
19818 }
076d447c
PB
19819
19820 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 19821 instruction. */
9c2799c2 19822 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 19823
e74cfd16
PB
19824 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
19825 *opcode->tvariant);
ee065d83 19826 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
19827 set those bits when Thumb-2 32-bit instructions are seen. The impact
19828 of relaxable instructions will be considered later after we finish all
19829 relaxation. */
ff8646ee
TP
19830 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
19831 variant = arm_arch_none;
19832 else
19833 variant = cpu_variant;
19834 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
19835 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
19836 arm_ext_v6t2);
cd000bff 19837
88714cb8
DG
19838 check_neon_suffixes;
19839
cd000bff 19840 if (!inst.error)
c877a2f2
NC
19841 {
19842 mapping_state (MAP_THUMB);
19843 }
c19d1205 19844 }
3e9e4fcf 19845 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 19846 {
845b51d6
PB
19847 bfd_boolean is_bx;
19848
19849 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
19850 is_bx = (opcode->aencode == do_bx);
19851
c19d1205 19852 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
19853 if (!(is_bx && fix_v4bx)
19854 && !(opcode->avariant &&
19855 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 19856 {
84b52b66 19857 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 19858 return;
b99bd4ef 19859 }
c19d1205 19860 if (inst.size_req)
b99bd4ef 19861 {
c19d1205
ZW
19862 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
19863 return;
b99bd4ef
NC
19864 }
19865
c19d1205
ZW
19866 inst.instruction = opcode->avalue;
19867 if (opcode->tag == OT_unconditionalF)
eff0bc54 19868 inst.instruction |= 0xFU << 28;
c19d1205
ZW
19869 else
19870 inst.instruction |= inst.cond << 28;
19871 inst.size = INSN_SIZE;
5be8be5d 19872 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
19873 {
19874 it_fsm_pre_encode ();
19875 opcode->aencode ();
19876 it_fsm_post_encode ();
19877 }
ee065d83 19878 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 19879 on a hypothetical non-thumb v5 core. */
845b51d6 19880 if (is_bx)
e74cfd16 19881 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 19882 else
e74cfd16
PB
19883 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
19884 *opcode->avariant);
88714cb8
DG
19885
19886 check_neon_suffixes;
19887
cd000bff 19888 if (!inst.error)
c877a2f2
NC
19889 {
19890 mapping_state (MAP_ARM);
19891 }
b99bd4ef 19892 }
3e9e4fcf
JB
19893 else
19894 {
19895 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
19896 "-- `%s'"), str);
19897 return;
19898 }
c19d1205
ZW
19899 output_inst (str);
19900}
b99bd4ef 19901
e07e6e58 19902static void
5ee91343 19903check_pred_blocks_finished (void)
e07e6e58
NC
19904{
19905#ifdef OBJ_ELF
19906 asection *sect;
19907
19908 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
5ee91343
AV
19909 if (seg_info (sect)->tc_segment_info_data.current_pred.state
19910 == MANUAL_PRED_BLOCK)
e07e6e58 19911 {
5ee91343
AV
19912 if (now_pred.type == SCALAR_PRED)
19913 as_warn (_("section '%s' finished with an open IT block."),
19914 sect->name);
19915 else
19916 as_warn (_("section '%s' finished with an open VPT/VPST block."),
19917 sect->name);
e07e6e58
NC
19918 }
19919#else
5ee91343
AV
19920 if (now_pred.state == MANUAL_PRED_BLOCK)
19921 {
19922 if (now_pred.type == SCALAR_PRED)
19923 as_warn (_("file finished with an open IT block."));
19924 else
19925 as_warn (_("file finished with an open VPT/VPST block."));
19926 }
e07e6e58
NC
19927#endif
19928}
19929
c19d1205
ZW
19930/* Various frobbings of labels and their addresses. */
19931
19932void
19933arm_start_line_hook (void)
19934{
19935 last_label_seen = NULL;
b99bd4ef
NC
19936}
19937
c19d1205
ZW
19938void
19939arm_frob_label (symbolS * sym)
b99bd4ef 19940{
c19d1205 19941 last_label_seen = sym;
b99bd4ef 19942
c19d1205 19943 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 19944
c19d1205
ZW
19945#if defined OBJ_COFF || defined OBJ_ELF
19946 ARM_SET_INTERWORK (sym, support_interwork);
19947#endif
b99bd4ef 19948
e07e6e58
NC
19949 force_automatic_it_block_close ();
19950
5f4273c7 19951 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
19952 as Thumb functions. This is because these labels, whilst
19953 they exist inside Thumb code, are not the entry points for
19954 possible ARM->Thumb calls. Also, these labels can be used
19955 as part of a computed goto or switch statement. eg gcc
19956 can generate code that looks like this:
b99bd4ef 19957
c19d1205
ZW
19958 ldr r2, [pc, .Laaa]
19959 lsl r3, r3, #2
19960 ldr r2, [r3, r2]
19961 mov pc, r2
b99bd4ef 19962
c19d1205
ZW
19963 .Lbbb: .word .Lxxx
19964 .Lccc: .word .Lyyy
19965 ..etc...
19966 .Laaa: .word Lbbb
b99bd4ef 19967
c19d1205
ZW
19968 The first instruction loads the address of the jump table.
19969 The second instruction converts a table index into a byte offset.
19970 The third instruction gets the jump address out of the table.
19971 The fourth instruction performs the jump.
b99bd4ef 19972
c19d1205
ZW
19973 If the address stored at .Laaa is that of a symbol which has the
19974 Thumb_Func bit set, then the linker will arrange for this address
19975 to have the bottom bit set, which in turn would mean that the
19976 address computation performed by the third instruction would end
19977 up with the bottom bit set. Since the ARM is capable of unaligned
19978 word loads, the instruction would then load the incorrect address
19979 out of the jump table, and chaos would ensue. */
19980 if (label_is_thumb_function_name
19981 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
19982 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 19983 {
c19d1205
ZW
19984 /* When the address of a Thumb function is taken the bottom
19985 bit of that address should be set. This will allow
19986 interworking between Arm and Thumb functions to work
19987 correctly. */
b99bd4ef 19988
c19d1205 19989 THUMB_SET_FUNC (sym, 1);
b99bd4ef 19990
c19d1205 19991 label_is_thumb_function_name = FALSE;
b99bd4ef 19992 }
07a53e5c 19993
07a53e5c 19994 dwarf2_emit_label (sym);
b99bd4ef
NC
19995}
19996
c921be7d 19997bfd_boolean
c19d1205 19998arm_data_in_code (void)
b99bd4ef 19999{
c19d1205 20000 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 20001 {
c19d1205
ZW
20002 *input_line_pointer = '/';
20003 input_line_pointer += 5;
20004 *input_line_pointer = 0;
c921be7d 20005 return TRUE;
b99bd4ef
NC
20006 }
20007
c921be7d 20008 return FALSE;
b99bd4ef
NC
20009}
20010
c19d1205
ZW
20011char *
20012arm_canonicalize_symbol_name (char * name)
b99bd4ef 20013{
c19d1205 20014 int len;
b99bd4ef 20015
c19d1205
ZW
20016 if (thumb_mode && (len = strlen (name)) > 5
20017 && streq (name + len - 5, "/data"))
20018 *(name + len - 5) = 0;
b99bd4ef 20019
c19d1205 20020 return name;
b99bd4ef 20021}
c19d1205
ZW
20022\f
20023/* Table of all register names defined by default. The user can
20024 define additional names with .req. Note that all register names
20025 should appear in both upper and lowercase variants. Some registers
20026 also have mixed-case names. */
b99bd4ef 20027
dcbf9037 20028#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 20029#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 20030#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
20031#define REGSET(p,t) \
20032 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
20033 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
20034 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
20035 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
20036#define REGSETH(p,t) \
20037 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
20038 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
20039 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
20040 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
20041#define REGSET2(p,t) \
20042 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
20043 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
20044 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
20045 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
20046#define SPLRBANK(base,bank,t) \
20047 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
20048 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
20049 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
20050 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
20051 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
20052 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 20053
c19d1205 20054static const struct reg_entry reg_names[] =
7ed4c4c5 20055{
c19d1205
ZW
20056 /* ARM integer registers. */
20057 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 20058
c19d1205
ZW
20059 /* ATPCS synonyms. */
20060 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
20061 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
20062 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 20063
c19d1205
ZW
20064 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
20065 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
20066 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 20067
c19d1205
ZW
20068 /* Well-known aliases. */
20069 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
20070 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
20071
20072 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
20073 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
20074
20075 /* Coprocessor numbers. */
20076 REGSET(p, CP), REGSET(P, CP),
20077
20078 /* Coprocessor register numbers. The "cr" variants are for backward
20079 compatibility. */
20080 REGSET(c, CN), REGSET(C, CN),
20081 REGSET(cr, CN), REGSET(CR, CN),
20082
90ec0d68
MGD
20083 /* ARM banked registers. */
20084 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
20085 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
20086 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
20087 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
20088 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
20089 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
20090 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
20091
20092 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
20093 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
20094 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
20095 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
20096 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 20097 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
20098 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
20099 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
20100
20101 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
20102 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
20103 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
20104 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
20105 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
20106 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
20107 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 20108 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
20109 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
20110
c19d1205
ZW
20111 /* FPA registers. */
20112 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
20113 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
20114
20115 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
20116 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
20117
20118 /* VFP SP registers. */
5287ad62
JB
20119 REGSET(s,VFS), REGSET(S,VFS),
20120 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
20121
20122 /* VFP DP Registers. */
5287ad62
JB
20123 REGSET(d,VFD), REGSET(D,VFD),
20124 /* Extra Neon DP registers. */
20125 REGSETH(d,VFD), REGSETH(D,VFD),
20126
20127 /* Neon QP registers. */
20128 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
20129
20130 /* VFP control registers. */
20131 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
20132 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
20133 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
20134 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
20135 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
20136 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 20137 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
c19d1205
ZW
20138
20139 /* Maverick DSP coprocessor registers. */
20140 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
20141 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
20142
20143 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
20144 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
20145 REGDEF(dspsc,0,DSPSC),
20146
20147 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
20148 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
20149 REGDEF(DSPSC,0,DSPSC),
20150
20151 /* iWMMXt data registers - p0, c0-15. */
20152 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
20153
20154 /* iWMMXt control registers - p1, c0-3. */
20155 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
20156 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
20157 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
20158 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
20159
20160 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
20161 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
20162 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
20163 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
20164 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
20165
20166 /* XScale accumulator registers. */
20167 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
20168};
20169#undef REGDEF
20170#undef REGNUM
20171#undef REGSET
7ed4c4c5 20172
c19d1205
ZW
20173/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
20174 within psr_required_here. */
20175static const struct asm_psr psrs[] =
20176{
20177 /* Backward compatibility notation. Note that "all" is no longer
20178 truly all possible PSR bits. */
20179 {"all", PSR_c | PSR_f},
20180 {"flg", PSR_f},
20181 {"ctl", PSR_c},
20182
20183 /* Individual flags. */
20184 {"f", PSR_f},
20185 {"c", PSR_c},
20186 {"x", PSR_x},
20187 {"s", PSR_s},
59b42a0d 20188
c19d1205
ZW
20189 /* Combinations of flags. */
20190 {"fs", PSR_f | PSR_s},
20191 {"fx", PSR_f | PSR_x},
20192 {"fc", PSR_f | PSR_c},
20193 {"sf", PSR_s | PSR_f},
20194 {"sx", PSR_s | PSR_x},
20195 {"sc", PSR_s | PSR_c},
20196 {"xf", PSR_x | PSR_f},
20197 {"xs", PSR_x | PSR_s},
20198 {"xc", PSR_x | PSR_c},
20199 {"cf", PSR_c | PSR_f},
20200 {"cs", PSR_c | PSR_s},
20201 {"cx", PSR_c | PSR_x},
20202 {"fsx", PSR_f | PSR_s | PSR_x},
20203 {"fsc", PSR_f | PSR_s | PSR_c},
20204 {"fxs", PSR_f | PSR_x | PSR_s},
20205 {"fxc", PSR_f | PSR_x | PSR_c},
20206 {"fcs", PSR_f | PSR_c | PSR_s},
20207 {"fcx", PSR_f | PSR_c | PSR_x},
20208 {"sfx", PSR_s | PSR_f | PSR_x},
20209 {"sfc", PSR_s | PSR_f | PSR_c},
20210 {"sxf", PSR_s | PSR_x | PSR_f},
20211 {"sxc", PSR_s | PSR_x | PSR_c},
20212 {"scf", PSR_s | PSR_c | PSR_f},
20213 {"scx", PSR_s | PSR_c | PSR_x},
20214 {"xfs", PSR_x | PSR_f | PSR_s},
20215 {"xfc", PSR_x | PSR_f | PSR_c},
20216 {"xsf", PSR_x | PSR_s | PSR_f},
20217 {"xsc", PSR_x | PSR_s | PSR_c},
20218 {"xcf", PSR_x | PSR_c | PSR_f},
20219 {"xcs", PSR_x | PSR_c | PSR_s},
20220 {"cfs", PSR_c | PSR_f | PSR_s},
20221 {"cfx", PSR_c | PSR_f | PSR_x},
20222 {"csf", PSR_c | PSR_s | PSR_f},
20223 {"csx", PSR_c | PSR_s | PSR_x},
20224 {"cxf", PSR_c | PSR_x | PSR_f},
20225 {"cxs", PSR_c | PSR_x | PSR_s},
20226 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
20227 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
20228 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
20229 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
20230 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
20231 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
20232 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
20233 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
20234 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
20235 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
20236 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
20237 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
20238 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
20239 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
20240 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
20241 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
20242 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
20243 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
20244 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
20245 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
20246 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
20247 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
20248 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
20249 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
20250};
20251
62b3e311
PB
20252/* Table of V7M psr names. */
20253static const struct asm_psr v7m_psrs[] =
20254{
1a336194
TP
20255 {"apsr", 0x0 }, {"APSR", 0x0 },
20256 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
20257 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
20258 {"psr", 0x3 }, {"PSR", 0x3 },
20259 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
20260 {"ipsr", 0x5 }, {"IPSR", 0x5 },
20261 {"epsr", 0x6 }, {"EPSR", 0x6 },
20262 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
20263 {"msp", 0x8 }, {"MSP", 0x8 },
20264 {"psp", 0x9 }, {"PSP", 0x9 },
20265 {"msplim", 0xa }, {"MSPLIM", 0xa },
20266 {"psplim", 0xb }, {"PSPLIM", 0xb },
20267 {"primask", 0x10}, {"PRIMASK", 0x10},
20268 {"basepri", 0x11}, {"BASEPRI", 0x11},
20269 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
20270 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
20271 {"control", 0x14}, {"CONTROL", 0x14},
20272 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
20273 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
20274 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
20275 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
20276 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
20277 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
20278 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
20279 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
20280 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
20281};
20282
c19d1205
ZW
20283/* Table of all shift-in-operand names. */
20284static const struct asm_shift_name shift_names [] =
b99bd4ef 20285{
c19d1205
ZW
20286 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
20287 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
20288 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
20289 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
20290 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
20291 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
20292};
b99bd4ef 20293
c19d1205
ZW
20294/* Table of all explicit relocation names. */
20295#ifdef OBJ_ELF
20296static struct reloc_entry reloc_names[] =
20297{
20298 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
20299 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
20300 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
20301 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
20302 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
20303 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
20304 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
20305 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
20306 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
20307 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 20308 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
20309 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
20310 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 20311 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 20312 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 20313 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 20314 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
188fd7ae
CL
20315 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
20316 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
20317 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
20318 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
20319 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
20320 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
5c5a4843
CL
20321 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
20322 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
20323 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
20324 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
c19d1205
ZW
20325};
20326#endif
b99bd4ef 20327
5ee91343 20328/* Table of all conditional affixes. */
c19d1205
ZW
20329static const struct asm_cond conds[] =
20330{
20331 {"eq", 0x0},
20332 {"ne", 0x1},
20333 {"cs", 0x2}, {"hs", 0x2},
20334 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
20335 {"mi", 0x4},
20336 {"pl", 0x5},
20337 {"vs", 0x6},
20338 {"vc", 0x7},
20339 {"hi", 0x8},
20340 {"ls", 0x9},
20341 {"ge", 0xa},
20342 {"lt", 0xb},
20343 {"gt", 0xc},
20344 {"le", 0xd},
20345 {"al", 0xe}
20346};
5ee91343
AV
20347static const struct asm_cond vconds[] =
20348{
20349 {"t", 0xf},
20350 {"e", 0x10}
20351};
bfae80f2 20352
e797f7e0 20353#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
20354 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
20355 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 20356
62b3e311
PB
20357static struct asm_barrier_opt barrier_opt_names[] =
20358{
e797f7e0
MGD
20359 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
20360 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
20361 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
20362 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
20363 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
20364 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
20365 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
20366 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
20367 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
20368 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
20369 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
20370 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
20371 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
20372 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
20373 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
20374 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
20375};
20376
e797f7e0
MGD
20377#undef UL_BARRIER
20378
c19d1205
ZW
20379/* Table of ARM-format instructions. */
20380
20381/* Macros for gluing together operand strings. N.B. In all cases
20382 other than OPS0, the trailing OP_stop comes from default
20383 zero-initialization of the unspecified elements of the array. */
20384#define OPS0() { OP_stop, }
20385#define OPS1(a) { OP_##a, }
20386#define OPS2(a,b) { OP_##a,OP_##b, }
20387#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
20388#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
20389#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
20390#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
20391
5be8be5d
DG
20392/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
20393 This is useful when mixing operands for ARM and THUMB, i.e. using the
20394 MIX_ARM_THUMB_OPERANDS macro.
20395 In order to use these macros, prefix the number of operands with _
20396 e.g. _3. */
20397#define OPS_1(a) { a, }
20398#define OPS_2(a,b) { a,b, }
20399#define OPS_3(a,b,c) { a,b,c, }
20400#define OPS_4(a,b,c,d) { a,b,c,d, }
20401#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
20402#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
20403
c19d1205
ZW
20404/* These macros abstract out the exact format of the mnemonic table and
20405 save some repeated characters. */
20406
20407/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
20408#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 20409 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
5ee91343 20410 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
20411
20412/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
20413 a T_MNEM_xyz enumerator. */
20414#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 20415 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 20416#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 20417 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
20418
20419/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
20420 infix after the third character. */
20421#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 20422 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
5ee91343 20423 THUMB_VARIANT, do_##ae, do_##te, 0 }
088fa78e 20424#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 20425 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
5ee91343 20426 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 20427#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 20428 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 20429#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 20430 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 20431#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 20432 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 20433#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 20434 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 20435
c19d1205 20436/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
20437 field is still 0xE. Many of the Thumb variants can be executed
20438 conditionally, so this is checked separately. */
c19d1205 20439#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 20440 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 20441 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 20442
dd5181d5
KT
20443/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
20444 Used by mnemonics that have very minimal differences in the encoding for
20445 ARM and Thumb variants and can be handled in a common function. */
20446#define TUEc(mnem, op, top, nops, ops, en) \
20447 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 20448 THUMB_VARIANT, do_##en, do_##en, 0 }
dd5181d5 20449
c19d1205
ZW
20450/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
20451 condition code field. */
20452#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 20453 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 20454 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
20455
20456/* ARM-only variants of all the above. */
6a86118a 20457#define CE(mnem, op, nops, ops, ae) \
5ee91343 20458 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
20459
20460#define C3(mnem, op, nops, ops, ae) \
5ee91343 20461 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 20462
cf3cf39d
TP
20463/* Thumb-only variants of TCE and TUE. */
20464#define ToC(mnem, top, nops, ops, te) \
20465 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
5ee91343 20466 do_##te, 0 }
cf3cf39d
TP
20467
20468#define ToU(mnem, top, nops, ops, te) \
20469 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
5ee91343 20470 NULL, do_##te, 0 }
cf3cf39d 20471
4389b29a
AV
20472/* T_MNEM_xyz enumerator variants of ToC. */
20473#define toC(mnem, top, nops, ops, te) \
20474 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
5ee91343 20475 do_##te, 0 }
4389b29a 20476
f6b2b12d
AV
20477/* T_MNEM_xyz enumerator variants of ToU. */
20478#define toU(mnem, top, nops, ops, te) \
20479 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
5ee91343 20480 NULL, do_##te, 0 }
f6b2b12d 20481
e3cb604e
PB
20482/* Legacy mnemonics that always have conditional infix after the third
20483 character. */
20484#define CL(mnem, op, nops, ops, ae) \
21d799b5 20485 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 20486 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
e3cb604e 20487
8f06b2d8
PB
20488/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
20489#define cCE(mnem, op, nops, ops, ae) \
5ee91343 20490 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 20491
e3cb604e
PB
20492/* Legacy coprocessor instructions where conditional infix and conditional
20493 suffix are ambiguous. For consistency this includes all FPA instructions,
20494 not just the potentially ambiguous ones. */
20495#define cCL(mnem, op, nops, ops, ae) \
21d799b5 20496 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 20497 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
e3cb604e
PB
20498
20499/* Coprocessor, takes either a suffix or a position-3 infix
20500 (for an FPA corner case). */
20501#define C3E(mnem, op, nops, ops, ae) \
21d799b5 20502 { mnem, OPS##nops ops, OT_csuf_or_in3, \
5ee91343 20503 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 20504
6a86118a 20505#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
20506 { m1 #m2 m3, OPS##nops ops, \
20507 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
5ee91343 20508 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
20509
20510#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
20511 xCM_ (m1, , m2, op, nops, ops, ae), \
20512 xCM_ (m1, eq, m2, op, nops, ops, ae), \
20513 xCM_ (m1, ne, m2, op, nops, ops, ae), \
20514 xCM_ (m1, cs, m2, op, nops, ops, ae), \
20515 xCM_ (m1, hs, m2, op, nops, ops, ae), \
20516 xCM_ (m1, cc, m2, op, nops, ops, ae), \
20517 xCM_ (m1, ul, m2, op, nops, ops, ae), \
20518 xCM_ (m1, lo, m2, op, nops, ops, ae), \
20519 xCM_ (m1, mi, m2, op, nops, ops, ae), \
20520 xCM_ (m1, pl, m2, op, nops, ops, ae), \
20521 xCM_ (m1, vs, m2, op, nops, ops, ae), \
20522 xCM_ (m1, vc, m2, op, nops, ops, ae), \
20523 xCM_ (m1, hi, m2, op, nops, ops, ae), \
20524 xCM_ (m1, ls, m2, op, nops, ops, ae), \
20525 xCM_ (m1, ge, m2, op, nops, ops, ae), \
20526 xCM_ (m1, lt, m2, op, nops, ops, ae), \
20527 xCM_ (m1, gt, m2, op, nops, ops, ae), \
20528 xCM_ (m1, le, m2, op, nops, ops, ae), \
20529 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
20530
20531#define UE(mnem, op, nops, ops, ae) \
5ee91343 20532 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
20533
20534#define UF(mnem, op, nops, ops, ae) \
5ee91343 20535 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 20536
5287ad62
JB
20537/* Neon data-processing. ARM versions are unconditional with cond=0xf.
20538 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
20539 use the same encoding function for each. */
20540#define NUF(mnem, op, nops, ops, enc) \
20541 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
5ee91343 20542 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
20543
20544/* Neon data processing, version which indirects through neon_enc_tab for
20545 the various overloaded versions of opcodes. */
20546#define nUF(mnem, op, nops, ops, enc) \
21d799b5 20547 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5ee91343 20548 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
20549
20550/* Neon insn with conditional suffix for the ARM version, non-overloaded
20551 version. */
5ee91343 20552#define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
037e8744 20553 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5ee91343 20554 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 20555
037e8744 20556#define NCE(mnem, op, nops, ops, enc) \
5ee91343 20557 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
20558
20559#define NCEF(mnem, op, nops, ops, enc) \
5ee91343 20560 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
037e8744 20561
5287ad62 20562/* Neon insn with conditional suffix for the ARM version, overloaded types. */
5ee91343 20563#define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
21d799b5 20564 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5ee91343 20565 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 20566
037e8744 20567#define nCE(mnem, op, nops, ops, enc) \
5ee91343 20568 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
20569
20570#define nCEF(mnem, op, nops, ops, enc) \
5ee91343
AV
20571 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
20572
20573/* */
20574#define mCEF(mnem, op, nops, ops, enc) \
20575 { #mnem, OPS##nops ops, OT_csuffixF, 0, M_MNEM##op, \
20576 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
20577
20578
20579/* nCEF but for MVE predicated instructions. */
20580#define mnCEF(mnem, op, nops, ops, enc) \
20581 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
20582
20583/* nCE but for MVE predicated instructions. */
20584#define mnCE(mnem, op, nops, ops, enc) \
20585 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
037e8744 20586
5ee91343
AV
20587/* NUF but for potentially MVE predicated instructions. */
20588#define MNUF(mnem, op, nops, ops, enc) \
20589 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
20590 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
20591
20592/* nUF but for potentially MVE predicated instructions. */
20593#define mnUF(mnem, op, nops, ops, enc) \
20594 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
20595 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
20596
20597/* ToC but for potentially MVE predicated instructions. */
20598#define mToC(mnem, top, nops, ops, te) \
20599 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
20600 do_##te, 1 }
20601
20602/* NCE but for MVE predicated instructions. */
20603#define MNCE(mnem, op, nops, ops, enc) \
20604 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
20605
20606/* NCEF but for MVE predicated instructions. */
20607#define MNCEF(mnem, op, nops, ops, enc) \
20608 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
c19d1205
ZW
20609#define do_0 0
20610
c19d1205 20611static const struct asm_opcode insns[] =
bfae80f2 20612{
74db7efb
NC
20613#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
20614#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
20615 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
20616 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
20617 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
20618 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
20619 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
20620 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
20621 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
20622 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
20623 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
20624 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
20625 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
20626 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
20627 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
20628 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
20629 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
20630 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
20631
20632 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
20633 for setting PSR flag bits. They are obsolete in V6 and do not
20634 have Thumb equivalents. */
21d799b5
NC
20635 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
20636 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
20637 CL("tstp", 110f000, 2, (RR, SH), cmp),
20638 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
20639 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
20640 CL("cmpp", 150f000, 2, (RR, SH), cmp),
20641 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
20642 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
20643 CL("cmnp", 170f000, 2, (RR, SH), cmp),
20644
20645 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 20646 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
20647 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
20648 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
20649
20650 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
20651 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
20652 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
20653 OP_RRnpc),
20654 OP_ADDRGLDR),ldst, t_ldst),
20655 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
20656
20657 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20658 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20659 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20660 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20661 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20662 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20663
21d799b5
NC
20664 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
20665 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 20666
c19d1205 20667 /* Pseudo ops. */
21d799b5 20668 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 20669 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 20670 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 20671 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
20672
20673 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
20674 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
20675 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
20676 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
20677 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
20678 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
20679 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
20680 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
20681 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
20682 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
20683 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
20684 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
20685 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 20686
16a4cf17 20687 /* These may simplify to neg. */
21d799b5
NC
20688 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
20689 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 20690
173205ca
TP
20691#undef THUMB_VARIANT
20692#define THUMB_VARIANT & arm_ext_os
20693
20694 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
20695 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
20696
c921be7d
NC
20697#undef THUMB_VARIANT
20698#define THUMB_VARIANT & arm_ext_v6
20699
21d799b5 20700 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
20701
20702 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
20703#undef THUMB_VARIANT
20704#define THUMB_VARIANT & arm_ext_v6t2
20705
21d799b5
NC
20706 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
20707 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
20708 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 20709
5be8be5d
DG
20710 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
20711 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
20712 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
20713 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 20714
21d799b5
NC
20715 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20716 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 20717
21d799b5
NC
20718 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20719 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
20720
20721 /* V1 instructions with no Thumb analogue at all. */
21d799b5 20722 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
20723 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
20724
20725 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
20726 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
20727 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
20728 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
20729 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
20730 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
20731 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
20732 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
20733
c921be7d
NC
20734#undef ARM_VARIANT
20735#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
20736#undef THUMB_VARIANT
20737#define THUMB_VARIANT & arm_ext_v4t
20738
21d799b5
NC
20739 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
20740 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 20741
c921be7d
NC
20742#undef THUMB_VARIANT
20743#define THUMB_VARIANT & arm_ext_v6t2
20744
21d799b5 20745 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
20746 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
20747
20748 /* Generic coprocessor instructions. */
21d799b5
NC
20749 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
20750 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20751 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20752 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20753 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20754 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 20755 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 20756
c921be7d
NC
20757#undef ARM_VARIANT
20758#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
20759
21d799b5 20760 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
20761 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
20762
c921be7d
NC
20763#undef ARM_VARIANT
20764#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
20765#undef THUMB_VARIANT
20766#define THUMB_VARIANT & arm_ext_msr
20767
d2cd1205
JB
20768 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
20769 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 20770
c921be7d
NC
20771#undef ARM_VARIANT
20772#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
20773#undef THUMB_VARIANT
20774#define THUMB_VARIANT & arm_ext_v6t2
20775
21d799b5
NC
20776 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20777 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
20778 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20779 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
20780 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20781 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
20782 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20783 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 20784
c921be7d
NC
20785#undef ARM_VARIANT
20786#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
20787#undef THUMB_VARIANT
20788#define THUMB_VARIANT & arm_ext_v4t
20789
5be8be5d
DG
20790 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20791 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20792 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20793 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
20794 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20795 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 20796
c921be7d
NC
20797#undef ARM_VARIANT
20798#define ARM_VARIANT & arm_ext_v4t_5
20799
c19d1205
ZW
20800 /* ARM Architecture 4T. */
20801 /* Note: bx (and blx) are required on V5, even if the processor does
20802 not support Thumb. */
21d799b5 20803 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 20804
c921be7d
NC
20805#undef ARM_VARIANT
20806#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
20807#undef THUMB_VARIANT
20808#define THUMB_VARIANT & arm_ext_v5t
20809
c19d1205
ZW
20810 /* Note: blx has 2 variants; the .value coded here is for
20811 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
20812 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
20813 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 20814
c921be7d
NC
20815#undef THUMB_VARIANT
20816#define THUMB_VARIANT & arm_ext_v6t2
20817
21d799b5
NC
20818 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
20819 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20820 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20821 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20822 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20823 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
20824 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
20825 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 20826
c921be7d 20827#undef ARM_VARIANT
74db7efb
NC
20828#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
20829#undef THUMB_VARIANT
20830#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 20831
21d799b5
NC
20832 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20833 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20834 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20835 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 20836
21d799b5
NC
20837 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20838 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 20839
21d799b5
NC
20840 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
20841 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
20842 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
20843 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 20844
21d799b5
NC
20845 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20846 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20847 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20848 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 20849
21d799b5
NC
20850 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20851 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 20852
03ee1b7f
NC
20853 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
20854 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
20855 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
20856 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 20857
c921be7d 20858#undef ARM_VARIANT
74db7efb
NC
20859#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
20860#undef THUMB_VARIANT
20861#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 20862
21d799b5 20863 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
20864 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
20865 ldrd, t_ldstd),
20866 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
20867 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 20868
21d799b5
NC
20869 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
20870 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 20871
c921be7d
NC
20872#undef ARM_VARIANT
20873#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
20874
21d799b5 20875 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 20876
c921be7d
NC
20877#undef ARM_VARIANT
20878#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
20879#undef THUMB_VARIANT
20880#define THUMB_VARIANT & arm_ext_v6
20881
21d799b5
NC
20882 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
20883 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
20884 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
20885 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
20886 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
20887 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20888 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20889 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20890 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20891 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 20892
c921be7d 20893#undef THUMB_VARIANT
ff8646ee 20894#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 20895
5be8be5d
DG
20896 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
20897 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
20898 strex, t_strex),
ff8646ee
TP
20899#undef THUMB_VARIANT
20900#define THUMB_VARIANT & arm_ext_v6t2
20901
21d799b5
NC
20902 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
20903 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 20904
21d799b5
NC
20905 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
20906 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 20907
9e3c6df6 20908/* ARM V6 not included in V7M. */
c921be7d
NC
20909#undef THUMB_VARIANT
20910#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 20911 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 20912 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
20913 UF(rfeib, 9900a00, 1, (RRw), rfe),
20914 UF(rfeda, 8100a00, 1, (RRw), rfe),
20915 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
20916 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
20917 UF(rfefa, 8100a00, 1, (RRw), rfe),
20918 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
20919 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 20920 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
20921 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
20922 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 20923 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 20924 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 20925 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 20926 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 20927 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 20928 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 20929 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 20930
9e3c6df6
PB
20931/* ARM V6 not included in V7M (eg. integer SIMD). */
20932#undef THUMB_VARIANT
20933#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
20934 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
20935 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
20936 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20937 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20938 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20939 /* Old name for QASX. */
74db7efb 20940 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 20941 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20942 /* Old name for QSAX. */
74db7efb 20943 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20944 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20945 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20946 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20947 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20948 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20949 /* Old name for SASX. */
74db7efb 20950 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20951 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20952 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20953 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20954 /* Old name for SHASX. */
21d799b5 20955 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20956 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20957 /* Old name for SHSAX. */
21d799b5
NC
20958 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20959 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20960 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20961 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20962 /* Old name for SSAX. */
74db7efb 20963 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20964 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20965 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20966 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20967 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20968 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20969 /* Old name for UASX. */
74db7efb 20970 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20971 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20972 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20973 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20974 /* Old name for UHASX. */
21d799b5
NC
20975 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20976 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20977 /* Old name for UHSAX. */
21d799b5
NC
20978 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20979 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20980 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20981 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20982 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20983 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20984 /* Old name for UQASX. */
21d799b5
NC
20985 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20986 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20987 /* Old name for UQSAX. */
21d799b5
NC
20988 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20989 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20990 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20991 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20992 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20993 /* Old name for USAX. */
74db7efb 20994 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 20995 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20996 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20997 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20998 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20999 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
21000 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
21001 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
21002 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
21003 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
21004 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21005 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21006 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21007 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
21008 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
21009 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21010 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21011 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
21012 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
21013 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21014 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21015 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21016 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21017 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21018 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21019 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21020 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21021 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21022 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
21023 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
21024 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
21025 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21026 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21027 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 21028
c921be7d 21029#undef ARM_VARIANT
55e8aae7 21030#define ARM_VARIANT & arm_ext_v6k_v6t2
c921be7d 21031#undef THUMB_VARIANT
55e8aae7 21032#define THUMB_VARIANT & arm_ext_v6k_v6t2
c921be7d 21033
21d799b5
NC
21034 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
21035 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
21036 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
21037 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 21038
c921be7d
NC
21039#undef THUMB_VARIANT
21040#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
21041 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
21042 ldrexd, t_ldrexd),
21043 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
21044 RRnpcb), strexd, t_strexd),
ebdca51a 21045
c921be7d 21046#undef THUMB_VARIANT
ff8646ee 21047#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
21048 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
21049 rd_rn, rd_rn),
21050 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
21051 rd_rn, rd_rn),
21052 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 21053 strex, t_strexbh),
5be8be5d 21054 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 21055 strex, t_strexbh),
21d799b5 21056 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 21057
c921be7d 21058#undef ARM_VARIANT
f4c65163 21059#define ARM_VARIANT & arm_ext_sec
74db7efb 21060#undef THUMB_VARIANT
f4c65163 21061#define THUMB_VARIANT & arm_ext_sec
c921be7d 21062
21d799b5 21063 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 21064
90ec0d68
MGD
21065#undef ARM_VARIANT
21066#define ARM_VARIANT & arm_ext_virt
21067#undef THUMB_VARIANT
21068#define THUMB_VARIANT & arm_ext_virt
21069
21070 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
21071 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
21072
ddfded2f
MW
21073#undef ARM_VARIANT
21074#define ARM_VARIANT & arm_ext_pan
21075#undef THUMB_VARIANT
21076#define THUMB_VARIANT & arm_ext_pan
21077
21078 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
21079
c921be7d 21080#undef ARM_VARIANT
74db7efb 21081#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
21082#undef THUMB_VARIANT
21083#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 21084
21d799b5
NC
21085 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
21086 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
21087 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
21088 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 21089
21d799b5 21090 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 21091 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 21092
5be8be5d
DG
21093 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
21094 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
21095 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
21096 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 21097
91d8b670
JG
21098#undef ARM_VARIANT
21099#define ARM_VARIANT & arm_ext_v3
21100#undef THUMB_VARIANT
21101#define THUMB_VARIANT & arm_ext_v6t2
21102
21103 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
c597cc3d
SD
21104 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
21105 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
91d8b670
JG
21106
21107#undef ARM_VARIANT
21108#define ARM_VARIANT & arm_ext_v6t2
ff8646ee
TP
21109#undef THUMB_VARIANT
21110#define THUMB_VARIANT & arm_ext_v6t2_v8m
21111 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
21112 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
21113
bf3eeda7 21114 /* Thumb-only instructions. */
74db7efb 21115#undef ARM_VARIANT
bf3eeda7
NS
21116#define ARM_VARIANT NULL
21117 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
21118 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
21119
21120 /* ARM does not really have an IT instruction, so always allow it.
21121 The opcode is copied from Thumb in order to allow warnings in
21122 -mimplicit-it=[never | arm] modes. */
21123#undef ARM_VARIANT
21124#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
21125#undef THUMB_VARIANT
21126#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 21127
21d799b5
NC
21128 TUE("it", bf08, bf08, 1, (COND), it, t_it),
21129 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
21130 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
21131 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
21132 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
21133 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
21134 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
21135 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
21136 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
21137 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
21138 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
21139 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
21140 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
21141 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
21142 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 21143 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
21144 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
21145 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 21146
92e90b6e 21147 /* Thumb2 only instructions. */
c921be7d
NC
21148#undef ARM_VARIANT
21149#define ARM_VARIANT NULL
92e90b6e 21150
21d799b5
NC
21151 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
21152 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
21153 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
21154 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
21155 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
21156 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 21157
eea54501
MGD
21158 /* Hardware division instructions. */
21159#undef ARM_VARIANT
21160#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
21161#undef THUMB_VARIANT
21162#define THUMB_VARIANT & arm_ext_div
21163
eea54501
MGD
21164 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
21165 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 21166
7e806470 21167 /* ARM V6M/V7 instructions. */
c921be7d
NC
21168#undef ARM_VARIANT
21169#define ARM_VARIANT & arm_ext_barrier
21170#undef THUMB_VARIANT
21171#define THUMB_VARIANT & arm_ext_barrier
21172
ccb84d65
JB
21173 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
21174 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
21175 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 21176
62b3e311 21177 /* ARM V7 instructions. */
c921be7d
NC
21178#undef ARM_VARIANT
21179#define ARM_VARIANT & arm_ext_v7
21180#undef THUMB_VARIANT
21181#define THUMB_VARIANT & arm_ext_v7
21182
21d799b5
NC
21183 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
21184 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 21185
74db7efb 21186#undef ARM_VARIANT
60e5ef9f 21187#define ARM_VARIANT & arm_ext_mp
74db7efb 21188#undef THUMB_VARIANT
60e5ef9f
MGD
21189#define THUMB_VARIANT & arm_ext_mp
21190
21191 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
21192
53c4b28b
MGD
21193 /* AArchv8 instructions. */
21194#undef ARM_VARIANT
21195#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
21196
21197/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 21198#undef THUMB_VARIANT
4ed7ed8d 21199#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 21200
4ed7ed8d
TP
21201 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
21202 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
21203 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
21204 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
21205 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
21206 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 21207 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
21208 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
21209 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
21210 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
21211 stlex, t_stlex),
4b8c8c02
RE
21212 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
21213 stlex, t_stlex),
21214 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
21215 stlex, t_stlex),
4ed7ed8d
TP
21216#undef THUMB_VARIANT
21217#define THUMB_VARIANT & arm_ext_v8
53c4b28b 21218
4ed7ed8d 21219 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
4ed7ed8d
TP
21220 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
21221 ldrexd, t_ldrexd),
21222 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
21223 strexd, t_strexd),
f7dd2fb2
TC
21224
21225/* Defined in V8 but is in undefined encoding space for earlier
21226 architectures. However earlier architectures are required to treat
21227 this instuction as a semihosting trap as well. Hence while not explicitly
21228 defined as such, it is in fact correct to define the instruction for all
21229 architectures. */
21230#undef THUMB_VARIANT
21231#define THUMB_VARIANT & arm_ext_v1
21232#undef ARM_VARIANT
21233#define ARM_VARIANT & arm_ext_v1
21234 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
21235
8884b720 21236 /* ARMv8 T32 only. */
74db7efb 21237#undef ARM_VARIANT
b79f7053
MGD
21238#define ARM_VARIANT NULL
21239 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
21240 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
21241 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
21242
33399f07
MGD
21243 /* FP for ARMv8. */
21244#undef ARM_VARIANT
a715796b 21245#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 21246#undef THUMB_VARIANT
a715796b 21247#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
21248
21249 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
21250 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
21251 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
21252 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
21253 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
21254 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
21255 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
21256 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
21257 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
21258 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
21259 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
21260 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
21261 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
21262 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
21263 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
21264 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
21265 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 21266
91ff7894
MGD
21267 /* Crypto v1 extensions. */
21268#undef ARM_VARIANT
21269#define ARM_VARIANT & fpu_crypto_ext_armv8
21270#undef THUMB_VARIANT
21271#define THUMB_VARIANT & fpu_crypto_ext_armv8
21272
21273 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
21274 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
21275 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
21276 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
21277 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
21278 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
21279 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
21280 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
21281 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
21282 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
21283 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
21284 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
21285 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
21286 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 21287
dd5181d5 21288#undef ARM_VARIANT
74db7efb 21289#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
21290#undef THUMB_VARIANT
21291#define THUMB_VARIANT & crc_ext_armv8
21292 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
21293 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
21294 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
21295 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
21296 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
21297 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
21298
105bde57
MW
21299 /* ARMv8.2 RAS extension. */
21300#undef ARM_VARIANT
4d1464f2 21301#define ARM_VARIANT & arm_ext_ras
105bde57 21302#undef THUMB_VARIANT
4d1464f2 21303#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
21304 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
21305
49e8a725
SN
21306#undef ARM_VARIANT
21307#define ARM_VARIANT & arm_ext_v8_3
21308#undef THUMB_VARIANT
21309#define THUMB_VARIANT & arm_ext_v8_3
21310 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
21311 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
21312 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 21313
c604a79a
JW
21314#undef ARM_VARIANT
21315#define ARM_VARIANT & fpu_neon_ext_dotprod
21316#undef THUMB_VARIANT
21317#define THUMB_VARIANT & fpu_neon_ext_dotprod
21318 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
21319 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
21320
c921be7d
NC
21321#undef ARM_VARIANT
21322#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
21323#undef THUMB_VARIANT
21324#define THUMB_VARIANT NULL
c921be7d 21325
21d799b5
NC
21326 cCE("wfs", e200110, 1, (RR), rd),
21327 cCE("rfs", e300110, 1, (RR), rd),
21328 cCE("wfc", e400110, 1, (RR), rd),
21329 cCE("rfc", e500110, 1, (RR), rd),
21330
21331 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
21332 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
21333 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
21334 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
21335
21336 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
21337 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
21338 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
21339 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
21340
21341 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
21342 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
21343 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
21344 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
21345 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
21346 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
21347 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
21348 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
21349 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
21350 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
21351 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
21352 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
21353
21354 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
21355 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
21356 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
21357 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
21358 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
21359 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
21360 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
21361 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
21362 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
21363 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
21364 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
21365 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
21366
21367 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
21368 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
21369 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
21370 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
21371 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
21372 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
21373 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
21374 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
21375 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
21376 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
21377 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
21378 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
21379
21380 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
21381 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
21382 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
21383 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
21384 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
21385 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
21386 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
21387 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
21388 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
21389 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
21390 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
21391 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
21392
21393 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
21394 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
21395 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
21396 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
21397 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
21398 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
21399 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
21400 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
21401 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
21402 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
21403 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
21404 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
21405
21406 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
21407 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
21408 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
21409 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
21410 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
21411 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
21412 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
21413 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
21414 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
21415 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
21416 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
21417 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
21418
21419 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
21420 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
21421 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
21422 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
21423 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
21424 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
21425 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
21426 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
21427 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
21428 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
21429 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
21430 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
21431
21432 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
21433 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
21434 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
21435 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
21436 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
21437 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
21438 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
21439 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
21440 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
21441 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
21442 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
21443 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
21444
21445 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
21446 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
21447 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
21448 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
21449 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
21450 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
21451 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
21452 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
21453 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
21454 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
21455 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
21456 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
21457
21458 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
21459 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
21460 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
21461 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
21462 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
21463 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
21464 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
21465 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
21466 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
21467 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
21468 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
21469 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
21470
21471 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
21472 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
21473 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
21474 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
21475 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
21476 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
21477 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
21478 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
21479 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
21480 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
21481 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
21482 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
21483
21484 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
21485 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
21486 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
21487 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
21488 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
21489 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
21490 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
21491 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
21492 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
21493 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
21494 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
21495 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
21496
21497 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
21498 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
21499 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
21500 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
21501 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
21502 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
21503 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
21504 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
21505 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
21506 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
21507 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
21508 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
21509
21510 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
21511 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
21512 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
21513 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
21514 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
21515 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
21516 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
21517 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
21518 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
21519 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
21520 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
21521 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
21522
21523 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
21524 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
21525 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
21526 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
21527 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
21528 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
21529 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
21530 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
21531 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
21532 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
21533 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
21534 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
21535
21536 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
21537 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
21538 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
21539 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
21540 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
21541 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
21542 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
21543 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
21544 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
21545 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
21546 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
21547 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
21548
21549 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
21550 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
21551 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
21552 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
21553 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
21554 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21555 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21556 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21557 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
21558 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
21559 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
21560 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
21561
21562 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
21563 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
21564 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
21565 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
21566 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
21567 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21568 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21569 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21570 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
21571 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
21572 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
21573 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
21574
21575 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
21576 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
21577 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
21578 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
21579 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
21580 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21581 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21582 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21583 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
21584 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
21585 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
21586 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
21587
21588 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
21589 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
21590 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
21591 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
21592 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
21593 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21594 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21595 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21596 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
21597 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
21598 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
21599 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
21600
21601 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
21602 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
21603 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
21604 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
21605 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
21606 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21607 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21608 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21609 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
21610 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
21611 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
21612 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
21613
21614 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
21615 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
21616 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
21617 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
21618 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
21619 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21620 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21621 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21622 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
21623 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
21624 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
21625 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
21626
21627 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
21628 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
21629 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
21630 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
21631 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
21632 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21633 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21634 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21635 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
21636 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
21637 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
21638 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
21639
21640 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
21641 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
21642 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
21643 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
21644 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
21645 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21646 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21647 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21648 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
21649 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
21650 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
21651 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
21652
21653 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
21654 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
21655 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
21656 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
21657 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
21658 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21659 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21660 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21661 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
21662 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
21663 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
21664 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
21665
21666 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
21667 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
21668 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
21669 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
21670 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
21671 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21672 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21673 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21674 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
21675 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
21676 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
21677 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
21678
21679 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
21680 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
21681 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
21682 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
21683 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
21684 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21685 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21686 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21687 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
21688 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
21689 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
21690 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
21691
21692 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
21693 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
21694 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
21695 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
21696 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
21697 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21698 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21699 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21700 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
21701 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
21702 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
21703 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
21704
21705 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
21706 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
21707 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
21708 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
21709 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
21710 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21711 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21712 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21713 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
21714 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
21715 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
21716 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
21717
21718 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
21719 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
21720 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
21721 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
21722
21723 cCL("flts", e000110, 2, (RF, RR), rn_rd),
21724 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
21725 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
21726 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
21727 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
21728 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
21729 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
21730 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
21731 cCL("flte", e080110, 2, (RF, RR), rn_rd),
21732 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
21733 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
21734 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 21735
c19d1205
ZW
21736 /* The implementation of the FIX instruction is broken on some
21737 assemblers, in that it accepts a precision specifier as well as a
21738 rounding specifier, despite the fact that this is meaningless.
21739 To be more compatible, we accept it as well, though of course it
21740 does not set any bits. */
21d799b5
NC
21741 cCE("fix", e100110, 2, (RR, RF), rd_rm),
21742 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
21743 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
21744 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
21745 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
21746 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
21747 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
21748 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
21749 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
21750 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
21751 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
21752 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
21753 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 21754
c19d1205 21755 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
21756#undef ARM_VARIANT
21757#define ARM_VARIANT & fpu_fpa_ext_v2
21758
21d799b5
NC
21759 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21760 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21761 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21762 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21763 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21764 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 21765
c921be7d
NC
21766#undef ARM_VARIANT
21767#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
21768
c19d1205 21769 /* Moves and type conversions. */
21d799b5
NC
21770 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
21771 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
21772 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
21773 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
21774 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
21775 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
21776 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
21777 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
21778 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
21779 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
21780 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
21781 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
21782 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
21783 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
21784
21785 /* Memory operations. */
21d799b5
NC
21786 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
21787 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
21788 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21789 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21790 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21791 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21792 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21793 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21794 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
21795 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
21796 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21797 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21798 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21799 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21800 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21801 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21802 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
21803 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 21804
c19d1205 21805 /* Monadic operations. */
21d799b5
NC
21806 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
21807 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
21808 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
21809
21810 /* Dyadic operations. */
21d799b5
NC
21811 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21812 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21813 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21814 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21815 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21816 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21817 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21818 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21819 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 21820
c19d1205 21821 /* Comparisons. */
21d799b5
NC
21822 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
21823 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
21824 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
21825 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 21826
62f3b8c8
PB
21827 /* Double precision load/store are still present on single precision
21828 implementations. */
21829 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
21830 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
21831 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21832 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21833 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
21834 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
21835 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21836 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21837 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
21838 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 21839
c921be7d
NC
21840#undef ARM_VARIANT
21841#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
21842
c19d1205 21843 /* Moves and type conversions. */
21d799b5
NC
21844 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
21845 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
21846 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
21847 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
21848 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
21849 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
21850 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
21851 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
21852 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
21853 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
21854 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
21855 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
21856 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 21857
c19d1205 21858 /* Monadic operations. */
21d799b5
NC
21859 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
21860 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
21861 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
21862
21863 /* Dyadic operations. */
21d799b5
NC
21864 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21865 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21866 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21867 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21868 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21869 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21870 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21871 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21872 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 21873
c19d1205 21874 /* Comparisons. */
21d799b5
NC
21875 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
21876 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
21877 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
21878 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 21879
c921be7d
NC
21880#undef ARM_VARIANT
21881#define ARM_VARIANT & fpu_vfp_ext_v2
21882
21d799b5
NC
21883 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
21884 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
21885 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
21886 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 21887
037e8744
JB
21888/* Instructions which may belong to either the Neon or VFP instruction sets.
21889 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
21890#undef ARM_VARIANT
21891#define ARM_VARIANT & fpu_vfp_ext_v1xd
21892#undef THUMB_VARIANT
21893#define THUMB_VARIANT & fpu_vfp_ext_v1xd
21894
037e8744
JB
21895 /* These mnemonics are unique to VFP. */
21896 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
21897 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
21898 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21899 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21900 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
21901 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
21902 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
21903 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
21904 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
21905 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
21906
21907 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
21908 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
21909 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
21910 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 21911
037e8744
JB
21912 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
21913 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
21914
55881a11
MGD
21915 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21916 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21917 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21918 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21919 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21920 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
037e8744 21921
5f1af56b 21922 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 21923 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
21924 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
21925 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 21926
037e8744
JB
21927
21928 /* NOTE: All VMOV encoding is special-cased! */
21929 NCE(vmov, 0, 1, (VMOV), neon_mov),
21930 NCE(vmovq, 0, 1, (VMOV), neon_mov),
21931
32c36c3c
AV
21932#undef THUMB_VARIANT
21933/* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
21934 by different feature bits. Since we are setting the Thumb guard, we can
21935 require Thumb-1 which makes it a nop guard and set the right feature bit in
21936 do_vldr_vstr (). */
21937#define THUMB_VARIANT & arm_ext_v4t
21938 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
21939 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
21940
9db2f6b4
RL
21941#undef ARM_VARIANT
21942#define ARM_VARIANT & arm_ext_fp16
21943#undef THUMB_VARIANT
21944#define THUMB_VARIANT & arm_ext_fp16
21945 /* New instructions added from v8.2, allowing the extraction and insertion of
21946 the upper 16 bits of a 32-bit vector register. */
21947 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
21948 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
21949
dec41383
JW
21950 /* New backported fma/fms instructions optional in v8.2. */
21951 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
21952 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
21953
c921be7d
NC
21954#undef THUMB_VARIANT
21955#define THUMB_VARIANT & fpu_neon_ext_v1
21956#undef ARM_VARIANT
21957#define ARM_VARIANT & fpu_neon_ext_v1
21958
5287ad62
JB
21959 /* Data processing with three registers of the same length. */
21960 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
21961 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
21962 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
21963 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21964 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21965 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21966 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21967 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21968 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21969 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
21970 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
21971 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
21972 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
21973 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
21974 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
21975 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
21976 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
21977 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
21978 /* If not immediate, fall back to neon_dyadic_i64_su.
21979 shl_imm should accept I8 I16 I32 I64,
21980 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
21981 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
21982 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
21983 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
21984 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 21985 /* Logic ops, types optional & ignored. */
4316f0d2
DG
21986 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21987 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21988 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21989 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21990 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21991 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21992 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21993 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21994 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
21995 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
21996 /* Bitfield ops, untyped. */
21997 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
21998 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
21999 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
22000 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
22001 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
22002 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 22003 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
22004 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
22005 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
22006 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
22007 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
22008 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
22009 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
22010 back to neon_dyadic_if_su. */
21d799b5
NC
22011 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
22012 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
22013 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
22014 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
22015 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
22016 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
22017 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
22018 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 22019 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
22020 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
22021 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 22022 /* As above, D registers only. */
21d799b5
NC
22023 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
22024 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 22025 /* Int and float variants, signedness unimportant. */
21d799b5
NC
22026 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
22027 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
22028 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 22029 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
22030 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
22031 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
22032 /* vtst takes sizes 8, 16, 32. */
22033 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
22034 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
22035 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 22036 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 22037 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
22038 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
22039 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
22040 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
22041 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
22042 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
22043 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
22044 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
22045 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
22046 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
22047 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
22048 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
22049 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
22050 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
22051 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
22052 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
22053 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 22054 /* ARM v8.1 extension. */
643afb90
MW
22055 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
22056 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
22057 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
22058 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
22059
22060 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 22061 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
22062 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
22063
22064 /* Data processing with two registers and a shift amount. */
22065 /* Right shifts, and variants with rounding.
22066 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
22067 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
22068 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
22069 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
22070 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
22071 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
22072 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
22073 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
22074 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
22075 /* Shift and insert. Sizes accepted 8 16 32 64. */
22076 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
22077 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
22078 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
22079 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
22080 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
22081 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
22082 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
22083 /* Right shift immediate, saturating & narrowing, with rounding variants.
22084 Types accepted S16 S32 S64 U16 U32 U64. */
22085 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
22086 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
22087 /* As above, unsigned. Types accepted S16 S32 S64. */
22088 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
22089 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
22090 /* Right shift narrowing. Types accepted I16 I32 I64. */
22091 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
22092 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
22093 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 22094 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 22095 /* CVT with optional immediate for fixed-point variant. */
21d799b5 22096 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 22097
4316f0d2
DG
22098 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
22099 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
22100
22101 /* Data processing, three registers of different lengths. */
22102 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
22103 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
5287ad62
JB
22104 /* If not scalar, fall back to neon_dyadic_long.
22105 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
22106 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
22107 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
22108 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
22109 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
22110 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
22111 /* Dyadic, narrowing insns. Types I16 I32 I64. */
22112 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
22113 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
22114 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
22115 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
22116 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
22117 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
22118 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
22119 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
22120 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
22121 S16 S32 U16 U32. */
21d799b5 22122 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
22123
22124 /* Extract. Size 8. */
3b8d421e
PB
22125 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
22126 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
22127
22128 /* Two registers, miscellaneous. */
22129 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
22130 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
22131 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
22132 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
22133 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
22134 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
22135 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
22136 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
22137 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
22138 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
22139 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
22140 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
22141 /* VMOVN. Types I16 I32 I64. */
21d799b5 22142 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 22143 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 22144 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 22145 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 22146 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
22147 /* VZIP / VUZP. Sizes 8 16 32. */
22148 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
22149 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
22150 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
22151 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
22152 /* VQABS / VQNEG. Types S8 S16 S32. */
22153 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
22154 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
22155 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
22156 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
22157 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
22158 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
22159 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
22160 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
22161 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 22162 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
22163 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
22164 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
22165 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
22166 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
22167 /* VCLS. Types S8 S16 S32. */
22168 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
22169 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
22170 /* VCLZ. Types I8 I16 I32. */
22171 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
22172 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
22173 /* VCNT. Size 8. */
22174 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
22175 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
22176 /* Two address, untyped. */
22177 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
22178 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
22179 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
22180 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
22181 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
22182
22183 /* Table lookup. Size 8. */
22184 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
22185 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
22186
c921be7d
NC
22187#undef THUMB_VARIANT
22188#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
22189#undef ARM_VARIANT
22190#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
22191
5287ad62 22192 /* Neon element/structure load/store. */
21d799b5
NC
22193 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
22194 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
22195 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
22196 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
22197 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
22198 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
22199 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
22200 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 22201
c921be7d 22202#undef THUMB_VARIANT
74db7efb
NC
22203#define THUMB_VARIANT & fpu_vfp_ext_v3xd
22204#undef ARM_VARIANT
22205#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
22206 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
22207 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
22208 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
22209 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
22210 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
22211 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
22212 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
22213 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
22214 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
22215
74db7efb 22216#undef THUMB_VARIANT
c921be7d
NC
22217#define THUMB_VARIANT & fpu_vfp_ext_v3
22218#undef ARM_VARIANT
22219#define ARM_VARIANT & fpu_vfp_ext_v3
22220
21d799b5 22221 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 22222 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 22223 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 22224 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 22225 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 22226 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 22227 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 22228 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 22229 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 22230
74db7efb
NC
22231#undef ARM_VARIANT
22232#define ARM_VARIANT & fpu_vfp_ext_fma
22233#undef THUMB_VARIANT
22234#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
22235 /* Mnemonics shared by Neon and VFP. These are included in the
22236 VFP FMA variant; NEON and VFP FMA always includes the NEON
22237 FMA instructions. */
22238 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
22239 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
22240 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
22241 the v form should always be used. */
22242 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
22243 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
22244 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
22245 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
22246 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
22247 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
22248
5287ad62 22249#undef THUMB_VARIANT
c921be7d
NC
22250#undef ARM_VARIANT
22251#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
22252
21d799b5
NC
22253 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22254 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22255 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22256 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22257 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22258 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22259 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
22260 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 22261
c921be7d
NC
22262#undef ARM_VARIANT
22263#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
22264
21d799b5
NC
22265 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
22266 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
22267 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
22268 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
22269 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
22270 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
22271 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
22272 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
22273 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
22274 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
22275 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
22276 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
22277 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
22278 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
22279 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
22280 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
22281 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
22282 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
22283 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
22284 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
22285 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22286 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22287 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22288 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22289 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22290 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
22291 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
22292 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
22293 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
22294 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
22295 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
22296 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
22297 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
22298 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
22299 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
22300 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
22301 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
22302 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22303 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22304 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22305 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22306 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22307 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22308 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22309 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22310 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22311 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
22312 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22313 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22314 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22315 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
22316 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22317 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22318 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22319 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22320 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22321 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22322 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22323 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22324 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
22325 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22326 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22327 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22328 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22329 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22330 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
22331 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
22332 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
22333 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
22334 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
22335 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22336 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22337 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22338 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22339 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22340 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22341 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22342 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22343 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22344 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22345 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22346 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22347 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22348 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22349 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22350 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22351 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22352 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22353 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
22354 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22355 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22356 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22357 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22358 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
22359 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22360 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22361 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22362 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22363 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22364 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
22365 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22366 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22367 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22368 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22369 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22370 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22371 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22372 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22373 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22374 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22375 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
22376 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22377 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22378 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22379 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22380 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22381 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22382 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22383 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22384 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22385 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22386 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22387 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22388 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22389 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22390 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22391 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22392 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22393 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22394 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
22395 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
22396 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
22397 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
22398 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22399 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22400 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22401 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22402 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22403 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22404 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22405 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22406 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22407 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
22408 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
22409 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
22410 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
22411 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
22412 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
22413 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22414 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22415 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22416 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
22417 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
22418 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
22419 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
22420 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
22421 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
22422 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22423 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22424 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22425 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22426 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 22427
c921be7d
NC
22428#undef ARM_VARIANT
22429#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
22430
21d799b5
NC
22431 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
22432 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
22433 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
22434 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
22435 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
22436 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
22437 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22438 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22439 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22440 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22441 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22442 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22443 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22444 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22445 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22446 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22447 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22448 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22449 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22450 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22451 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
22452 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22453 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22454 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22455 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22456 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22457 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22458 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22459 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22460 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22461 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22462 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22463 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22464 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22465 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22466 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22467 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22468 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22469 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22470 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22471 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22472 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22473 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22474 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22475 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22476 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22477 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22478 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22479 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22480 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22481 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22482 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22483 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22484 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22485 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22486 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22487 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 22488
c921be7d
NC
22489#undef ARM_VARIANT
22490#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
22491
21d799b5
NC
22492 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
22493 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
22494 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
22495 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
22496 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
22497 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
22498 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
22499 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
22500 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
22501 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
22502 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
22503 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
22504 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
22505 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
22506 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
22507 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
22508 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
22509 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
22510 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
22511 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
22512 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
22513 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
22514 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
22515 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
22516 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
22517 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
22518 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
22519 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
22520 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
22521 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
22522 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
22523 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
22524 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
22525 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
22526 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
22527 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
22528 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
22529 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
22530 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
22531 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
22532 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
22533 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
22534 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
22535 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
22536 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
22537 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
22538 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
22539 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
22540 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
22541 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
22542 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
22543 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
22544 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
22545 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
22546 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
22547 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
22548 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
22549 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
22550 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
22551 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
22552 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
22553 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
22554 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
22555 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
22556 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
22557 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
22558 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
22559 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
22560 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
22561 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
22562 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
22563 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
22564 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
22565 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
22566 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
22567 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 22568
7fadb25d
SD
22569 /* ARMv8.5-A instructions. */
22570#undef ARM_VARIANT
22571#define ARM_VARIANT & arm_ext_sb
22572#undef THUMB_VARIANT
22573#define THUMB_VARIANT & arm_ext_sb
22574 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
22575
dad0c3bf
SD
22576#undef ARM_VARIANT
22577#define ARM_VARIANT & arm_ext_predres
22578#undef THUMB_VARIANT
22579#define THUMB_VARIANT & arm_ext_predres
22580 CE("cfprctx", e070f93, 1, (RRnpc), rd),
22581 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
22582 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
22583
16a1fa25 22584 /* ARMv8-M instructions. */
4ed7ed8d
TP
22585#undef ARM_VARIANT
22586#define ARM_VARIANT NULL
22587#undef THUMB_VARIANT
22588#define THUMB_VARIANT & arm_ext_v8m
cf3cf39d
TP
22589 ToU("sg", e97fe97f, 0, (), noargs),
22590 ToC("blxns", 4784, 1, (RRnpc), t_blx),
22591 ToC("bxns", 4704, 1, (RRnpc), t_bx),
22592 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
22593 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
22594 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
22595 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
16a1fa25
TP
22596
22597 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
22598 instructions behave as nop if no VFP is present. */
22599#undef THUMB_VARIANT
22600#define THUMB_VARIANT & arm_ext_v8m_main
cf3cf39d
TP
22601 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
22602 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
4389b29a
AV
22603
22604 /* Armv8.1-M Mainline instructions. */
22605#undef THUMB_VARIANT
22606#define THUMB_VARIANT & arm_ext_v8_1m_main
22607 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
f6b2b12d 22608 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
f1c7f421 22609 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
65d1bc05 22610 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
f1c7f421 22611 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
60f993ce
AV
22612
22613 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
22614 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
22615 toU("le", _le, 2, (oLR, EXP), t_loloop),
4b5a202f 22616
efd6b359 22617 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
5ee91343
AV
22618 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
22619
22620#undef THUMB_VARIANT
22621#define THUMB_VARIANT & mve_ext
22622 ToC("vpst", fe710f4d, 0, (), mve_vpt),
22623 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
22624 ToC("vpste", fe718f4d, 0, (), mve_vpt),
22625 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
22626 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
22627 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
22628 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
22629 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
22630 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
22631 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
22632 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
22633 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
22634 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
22635 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
22636 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
22637
22638#undef ARM_VARIANT
22639#define ARM_VARIANT & fpu_vfp_ext_v1xd
22640#undef THUMB_VARIANT
22641#define THUMB_VARIANT & arm_ext_v6t2
22642
22643 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
22644 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
22645
22646#undef ARM_VARIANT
22647#define ARM_VARIANT & fpu_neon_ext_v1
22648 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
22649 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
22650 mnUF(vaddl, _vaddl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
22651 mnUF(vsubl, _vsubl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
c19d1205
ZW
22652};
22653#undef ARM_VARIANT
22654#undef THUMB_VARIANT
22655#undef TCE
c19d1205
ZW
22656#undef TUE
22657#undef TUF
22658#undef TCC
8f06b2d8 22659#undef cCE
e3cb604e
PB
22660#undef cCL
22661#undef C3E
4389b29a 22662#undef C3
c19d1205
ZW
22663#undef CE
22664#undef CM
4389b29a 22665#undef CL
c19d1205
ZW
22666#undef UE
22667#undef UF
22668#undef UT
5287ad62
JB
22669#undef NUF
22670#undef nUF
22671#undef NCE
22672#undef nCE
c19d1205
ZW
22673#undef OPS0
22674#undef OPS1
22675#undef OPS2
22676#undef OPS3
22677#undef OPS4
22678#undef OPS5
22679#undef OPS6
22680#undef do_0
4389b29a
AV
22681#undef ToC
22682#undef toC
22683#undef ToU
f6b2b12d 22684#undef toU
c19d1205
ZW
22685\f
22686/* MD interface: bits in the object file. */
bfae80f2 22687
c19d1205
ZW
22688/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
22689 for use in the a.out file, and stores them in the array pointed to by buf.
22690 This knows about the endian-ness of the target machine and does
22691 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
22692 2 (short) and 4 (long) Floating numbers are put out as a series of
22693 LITTLENUMS (shorts, here at least). */
b99bd4ef 22694
c19d1205
ZW
22695void
22696md_number_to_chars (char * buf, valueT val, int n)
22697{
22698 if (target_big_endian)
22699 number_to_chars_bigendian (buf, val, n);
22700 else
22701 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
22702}
22703
c19d1205
ZW
22704static valueT
22705md_chars_to_number (char * buf, int n)
bfae80f2 22706{
c19d1205
ZW
22707 valueT result = 0;
22708 unsigned char * where = (unsigned char *) buf;
bfae80f2 22709
c19d1205 22710 if (target_big_endian)
b99bd4ef 22711 {
c19d1205
ZW
22712 while (n--)
22713 {
22714 result <<= 8;
22715 result |= (*where++ & 255);
22716 }
b99bd4ef 22717 }
c19d1205 22718 else
b99bd4ef 22719 {
c19d1205
ZW
22720 while (n--)
22721 {
22722 result <<= 8;
22723 result |= (where[n] & 255);
22724 }
bfae80f2 22725 }
b99bd4ef 22726
c19d1205 22727 return result;
bfae80f2 22728}
b99bd4ef 22729
c19d1205 22730/* MD interface: Sections. */
b99bd4ef 22731
fa94de6b
RM
22732/* Calculate the maximum variable size (i.e., excluding fr_fix)
22733 that an rs_machine_dependent frag may reach. */
22734
22735unsigned int
22736arm_frag_max_var (fragS *fragp)
22737{
22738 /* We only use rs_machine_dependent for variable-size Thumb instructions,
22739 which are either THUMB_SIZE (2) or INSN_SIZE (4).
22740
22741 Note that we generate relaxable instructions even for cases that don't
22742 really need it, like an immediate that's a trivial constant. So we're
22743 overestimating the instruction size for some of those cases. Rather
22744 than putting more intelligence here, it would probably be better to
22745 avoid generating a relaxation frag in the first place when it can be
22746 determined up front that a short instruction will suffice. */
22747
22748 gas_assert (fragp->fr_type == rs_machine_dependent);
22749 return INSN_SIZE;
22750}
22751
0110f2b8
PB
22752/* Estimate the size of a frag before relaxing. Assume everything fits in
22753 2 bytes. */
22754
c19d1205 22755int
0110f2b8 22756md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
22757 segT segtype ATTRIBUTE_UNUSED)
22758{
0110f2b8
PB
22759 fragp->fr_var = 2;
22760 return 2;
22761}
22762
22763/* Convert a machine dependent frag. */
22764
22765void
22766md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
22767{
22768 unsigned long insn;
22769 unsigned long old_op;
22770 char *buf;
22771 expressionS exp;
22772 fixS *fixp;
22773 int reloc_type;
22774 int pc_rel;
22775 int opcode;
22776
22777 buf = fragp->fr_literal + fragp->fr_fix;
22778
22779 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
22780 if (fragp->fr_symbol)
22781 {
0110f2b8
PB
22782 exp.X_op = O_symbol;
22783 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
22784 }
22785 else
22786 {
0110f2b8 22787 exp.X_op = O_constant;
5f4273c7 22788 }
0110f2b8
PB
22789 exp.X_add_number = fragp->fr_offset;
22790 opcode = fragp->fr_subtype;
22791 switch (opcode)
22792 {
22793 case T_MNEM_ldr_pc:
22794 case T_MNEM_ldr_pc2:
22795 case T_MNEM_ldr_sp:
22796 case T_MNEM_str_sp:
22797 case T_MNEM_ldr:
22798 case T_MNEM_ldrb:
22799 case T_MNEM_ldrh:
22800 case T_MNEM_str:
22801 case T_MNEM_strb:
22802 case T_MNEM_strh:
22803 if (fragp->fr_var == 4)
22804 {
5f4273c7 22805 insn = THUMB_OP32 (opcode);
0110f2b8
PB
22806 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
22807 {
22808 insn |= (old_op & 0x700) << 4;
22809 }
22810 else
22811 {
22812 insn |= (old_op & 7) << 12;
22813 insn |= (old_op & 0x38) << 13;
22814 }
22815 insn |= 0x00000c00;
22816 put_thumb32_insn (buf, insn);
22817 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
22818 }
22819 else
22820 {
22821 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
22822 }
22823 pc_rel = (opcode == T_MNEM_ldr_pc2);
22824 break;
22825 case T_MNEM_adr:
22826 if (fragp->fr_var == 4)
22827 {
22828 insn = THUMB_OP32 (opcode);
22829 insn |= (old_op & 0xf0) << 4;
22830 put_thumb32_insn (buf, insn);
22831 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
22832 }
22833 else
22834 {
22835 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
22836 exp.X_add_number -= 4;
22837 }
22838 pc_rel = 1;
22839 break;
22840 case T_MNEM_mov:
22841 case T_MNEM_movs:
22842 case T_MNEM_cmp:
22843 case T_MNEM_cmn:
22844 if (fragp->fr_var == 4)
22845 {
22846 int r0off = (opcode == T_MNEM_mov
22847 || opcode == T_MNEM_movs) ? 0 : 8;
22848 insn = THUMB_OP32 (opcode);
22849 insn = (insn & 0xe1ffffff) | 0x10000000;
22850 insn |= (old_op & 0x700) << r0off;
22851 put_thumb32_insn (buf, insn);
22852 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
22853 }
22854 else
22855 {
22856 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
22857 }
22858 pc_rel = 0;
22859 break;
22860 case T_MNEM_b:
22861 if (fragp->fr_var == 4)
22862 {
22863 insn = THUMB_OP32(opcode);
22864 put_thumb32_insn (buf, insn);
22865 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
22866 }
22867 else
22868 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
22869 pc_rel = 1;
22870 break;
22871 case T_MNEM_bcond:
22872 if (fragp->fr_var == 4)
22873 {
22874 insn = THUMB_OP32(opcode);
22875 insn |= (old_op & 0xf00) << 14;
22876 put_thumb32_insn (buf, insn);
22877 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
22878 }
22879 else
22880 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
22881 pc_rel = 1;
22882 break;
22883 case T_MNEM_add_sp:
22884 case T_MNEM_add_pc:
22885 case T_MNEM_inc_sp:
22886 case T_MNEM_dec_sp:
22887 if (fragp->fr_var == 4)
22888 {
22889 /* ??? Choose between add and addw. */
22890 insn = THUMB_OP32 (opcode);
22891 insn |= (old_op & 0xf0) << 4;
22892 put_thumb32_insn (buf, insn);
16805f35
PB
22893 if (opcode == T_MNEM_add_pc)
22894 reloc_type = BFD_RELOC_ARM_T32_IMM12;
22895 else
22896 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
22897 }
22898 else
22899 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
22900 pc_rel = 0;
22901 break;
22902
22903 case T_MNEM_addi:
22904 case T_MNEM_addis:
22905 case T_MNEM_subi:
22906 case T_MNEM_subis:
22907 if (fragp->fr_var == 4)
22908 {
22909 insn = THUMB_OP32 (opcode);
22910 insn |= (old_op & 0xf0) << 4;
22911 insn |= (old_op & 0xf) << 16;
22912 put_thumb32_insn (buf, insn);
16805f35
PB
22913 if (insn & (1 << 20))
22914 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
22915 else
22916 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
22917 }
22918 else
22919 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
22920 pc_rel = 0;
22921 break;
22922 default:
5f4273c7 22923 abort ();
0110f2b8
PB
22924 }
22925 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 22926 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
22927 fixp->fx_file = fragp->fr_file;
22928 fixp->fx_line = fragp->fr_line;
22929 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
22930
22931 /* Set whether we use thumb-2 ISA based on final relaxation results. */
22932 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
22933 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
22934 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
22935}
22936
22937/* Return the size of a relaxable immediate operand instruction.
22938 SHIFT and SIZE specify the form of the allowable immediate. */
22939static int
22940relax_immediate (fragS *fragp, int size, int shift)
22941{
22942 offsetT offset;
22943 offsetT mask;
22944 offsetT low;
22945
22946 /* ??? Should be able to do better than this. */
22947 if (fragp->fr_symbol)
22948 return 4;
22949
22950 low = (1 << shift) - 1;
22951 mask = (1 << (shift + size)) - (1 << shift);
22952 offset = fragp->fr_offset;
22953 /* Force misaligned offsets to 32-bit variant. */
22954 if (offset & low)
5e77afaa 22955 return 4;
0110f2b8
PB
22956 if (offset & ~mask)
22957 return 4;
22958 return 2;
22959}
22960
5e77afaa
PB
22961/* Get the address of a symbol during relaxation. */
22962static addressT
5f4273c7 22963relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
22964{
22965 fragS *sym_frag;
22966 addressT addr;
22967 symbolS *sym;
22968
22969 sym = fragp->fr_symbol;
22970 sym_frag = symbol_get_frag (sym);
22971 know (S_GET_SEGMENT (sym) != absolute_section
22972 || sym_frag == &zero_address_frag);
22973 addr = S_GET_VALUE (sym) + fragp->fr_offset;
22974
22975 /* If frag has yet to be reached on this pass, assume it will
22976 move by STRETCH just as we did. If this is not so, it will
22977 be because some frag between grows, and that will force
22978 another pass. */
22979
22980 if (stretch != 0
22981 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
22982 {
22983 fragS *f;
22984
22985 /* Adjust stretch for any alignment frag. Note that if have
22986 been expanding the earlier code, the symbol may be
22987 defined in what appears to be an earlier frag. FIXME:
22988 This doesn't handle the fr_subtype field, which specifies
22989 a maximum number of bytes to skip when doing an
22990 alignment. */
22991 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
22992 {
22993 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
22994 {
22995 if (stretch < 0)
22996 stretch = - ((- stretch)
22997 & ~ ((1 << (int) f->fr_offset) - 1));
22998 else
22999 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
23000 if (stretch == 0)
23001 break;
23002 }
23003 }
23004 if (f != NULL)
23005 addr += stretch;
23006 }
5e77afaa
PB
23007
23008 return addr;
23009}
23010
0110f2b8
PB
23011/* Return the size of a relaxable adr pseudo-instruction or PC-relative
23012 load. */
23013static int
5e77afaa 23014relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
23015{
23016 addressT addr;
23017 offsetT val;
23018
23019 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
23020 if (fragp->fr_symbol == NULL
23021 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
23022 || sec != S_GET_SEGMENT (fragp->fr_symbol)
23023 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
23024 return 4;
23025
5f4273c7 23026 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
23027 addr = fragp->fr_address + fragp->fr_fix;
23028 addr = (addr + 4) & ~3;
5e77afaa 23029 /* Force misaligned targets to 32-bit variant. */
0110f2b8 23030 if (val & 3)
5e77afaa 23031 return 4;
0110f2b8
PB
23032 val -= addr;
23033 if (val < 0 || val > 1020)
23034 return 4;
23035 return 2;
23036}
23037
23038/* Return the size of a relaxable add/sub immediate instruction. */
23039static int
23040relax_addsub (fragS *fragp, asection *sec)
23041{
23042 char *buf;
23043 int op;
23044
23045 buf = fragp->fr_literal + fragp->fr_fix;
23046 op = bfd_get_16(sec->owner, buf);
23047 if ((op & 0xf) == ((op >> 4) & 0xf))
23048 return relax_immediate (fragp, 8, 0);
23049 else
23050 return relax_immediate (fragp, 3, 0);
23051}
23052
e83a675f
RE
23053/* Return TRUE iff the definition of symbol S could be pre-empted
23054 (overridden) at link or load time. */
23055static bfd_boolean
23056symbol_preemptible (symbolS *s)
23057{
23058 /* Weak symbols can always be pre-empted. */
23059 if (S_IS_WEAK (s))
23060 return TRUE;
23061
23062 /* Non-global symbols cannot be pre-empted. */
23063 if (! S_IS_EXTERNAL (s))
23064 return FALSE;
23065
23066#ifdef OBJ_ELF
23067 /* In ELF, a global symbol can be marked protected, or private. In that
23068 case it can't be pre-empted (other definitions in the same link unit
23069 would violate the ODR). */
23070 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
23071 return FALSE;
23072#endif
23073
23074 /* Other global symbols might be pre-empted. */
23075 return TRUE;
23076}
0110f2b8
PB
23077
23078/* Return the size of a relaxable branch instruction. BITS is the
23079 size of the offset field in the narrow instruction. */
23080
23081static int
5e77afaa 23082relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
23083{
23084 addressT addr;
23085 offsetT val;
23086 offsetT limit;
23087
23088 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 23089 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
23090 || sec != S_GET_SEGMENT (fragp->fr_symbol)
23091 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
23092 return 4;
23093
267bf995 23094#ifdef OBJ_ELF
e83a675f 23095 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
23096 if (S_IS_DEFINED (fragp->fr_symbol)
23097 && ARM_IS_FUNC (fragp->fr_symbol))
23098 return 4;
e83a675f 23099#endif
0d9b4b55 23100
e83a675f 23101 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 23102 return 4;
267bf995 23103
5f4273c7 23104 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
23105 addr = fragp->fr_address + fragp->fr_fix + 4;
23106 val -= addr;
23107
23108 /* Offset is a signed value *2 */
23109 limit = 1 << bits;
23110 if (val >= limit || val < -limit)
23111 return 4;
23112 return 2;
23113}
23114
23115
23116/* Relax a machine dependent frag. This returns the amount by which
23117 the current size of the frag should change. */
23118
23119int
5e77afaa 23120arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
23121{
23122 int oldsize;
23123 int newsize;
23124
23125 oldsize = fragp->fr_var;
23126 switch (fragp->fr_subtype)
23127 {
23128 case T_MNEM_ldr_pc2:
5f4273c7 23129 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
23130 break;
23131 case T_MNEM_ldr_pc:
23132 case T_MNEM_ldr_sp:
23133 case T_MNEM_str_sp:
5f4273c7 23134 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
23135 break;
23136 case T_MNEM_ldr:
23137 case T_MNEM_str:
5f4273c7 23138 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
23139 break;
23140 case T_MNEM_ldrh:
23141 case T_MNEM_strh:
5f4273c7 23142 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
23143 break;
23144 case T_MNEM_ldrb:
23145 case T_MNEM_strb:
5f4273c7 23146 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
23147 break;
23148 case T_MNEM_adr:
5f4273c7 23149 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
23150 break;
23151 case T_MNEM_mov:
23152 case T_MNEM_movs:
23153 case T_MNEM_cmp:
23154 case T_MNEM_cmn:
5f4273c7 23155 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
23156 break;
23157 case T_MNEM_b:
5f4273c7 23158 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
23159 break;
23160 case T_MNEM_bcond:
5f4273c7 23161 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
23162 break;
23163 case T_MNEM_add_sp:
23164 case T_MNEM_add_pc:
23165 newsize = relax_immediate (fragp, 8, 2);
23166 break;
23167 case T_MNEM_inc_sp:
23168 case T_MNEM_dec_sp:
23169 newsize = relax_immediate (fragp, 7, 2);
23170 break;
23171 case T_MNEM_addi:
23172 case T_MNEM_addis:
23173 case T_MNEM_subi:
23174 case T_MNEM_subis:
23175 newsize = relax_addsub (fragp, sec);
23176 break;
23177 default:
5f4273c7 23178 abort ();
0110f2b8 23179 }
5e77afaa
PB
23180
23181 fragp->fr_var = newsize;
23182 /* Freeze wide instructions that are at or before the same location as
23183 in the previous pass. This avoids infinite loops.
5f4273c7
NC
23184 Don't freeze them unconditionally because targets may be artificially
23185 misaligned by the expansion of preceding frags. */
5e77afaa 23186 if (stretch <= 0 && newsize > 2)
0110f2b8 23187 {
0110f2b8 23188 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 23189 frag_wane (fragp);
0110f2b8 23190 }
5e77afaa 23191
0110f2b8 23192 return newsize - oldsize;
c19d1205 23193}
b99bd4ef 23194
c19d1205 23195/* Round up a section size to the appropriate boundary. */
b99bd4ef 23196
c19d1205
ZW
23197valueT
23198md_section_align (segT segment ATTRIBUTE_UNUSED,
23199 valueT size)
23200{
6844c0cc 23201 return size;
bfae80f2 23202}
b99bd4ef 23203
c19d1205
ZW
23204/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
23205 of an rs_align_code fragment. */
23206
23207void
23208arm_handle_align (fragS * fragP)
bfae80f2 23209{
d9235011 23210 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
23211 {
23212 { /* ARMv1 */
23213 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
23214 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
23215 },
23216 { /* ARMv6k */
23217 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
23218 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
23219 },
23220 };
d9235011 23221 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
23222 {
23223 { /* Thumb-1 */
23224 {0xc0, 0x46}, /* LE */
23225 {0x46, 0xc0}, /* BE */
23226 },
23227 { /* Thumb-2 */
23228 {0x00, 0xbf}, /* LE */
23229 {0xbf, 0x00} /* BE */
23230 }
23231 };
d9235011 23232 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
23233 { /* Wide Thumb-2 */
23234 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
23235 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
23236 };
c921be7d 23237
e7495e45 23238 unsigned bytes, fix, noop_size;
c19d1205 23239 char * p;
d9235011
TS
23240 const unsigned char * noop;
23241 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
23242#ifdef OBJ_ELF
23243 enum mstate state;
23244#endif
bfae80f2 23245
c19d1205 23246 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
23247 return;
23248
c19d1205
ZW
23249 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
23250 p = fragP->fr_literal + fragP->fr_fix;
23251 fix = 0;
bfae80f2 23252
c19d1205
ZW
23253 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
23254 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 23255
cd000bff 23256 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 23257
cd000bff 23258 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 23259 {
7f78eb34
JW
23260 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
23261 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
23262 {
23263 narrow_noop = thumb_noop[1][target_big_endian];
23264 noop = wide_thumb_noop[target_big_endian];
23265 }
c19d1205 23266 else
e7495e45
NS
23267 noop = thumb_noop[0][target_big_endian];
23268 noop_size = 2;
cd000bff
DJ
23269#ifdef OBJ_ELF
23270 state = MAP_THUMB;
23271#endif
7ed4c4c5
NC
23272 }
23273 else
23274 {
7f78eb34
JW
23275 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
23276 ? selected_cpu : arm_arch_none,
23277 arm_ext_v6k) != 0]
e7495e45
NS
23278 [target_big_endian];
23279 noop_size = 4;
cd000bff
DJ
23280#ifdef OBJ_ELF
23281 state = MAP_ARM;
23282#endif
7ed4c4c5 23283 }
c921be7d 23284
e7495e45 23285 fragP->fr_var = noop_size;
c921be7d 23286
c19d1205 23287 if (bytes & (noop_size - 1))
7ed4c4c5 23288 {
c19d1205 23289 fix = bytes & (noop_size - 1);
cd000bff
DJ
23290#ifdef OBJ_ELF
23291 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
23292#endif
c19d1205
ZW
23293 memset (p, 0, fix);
23294 p += fix;
23295 bytes -= fix;
a737bd4d 23296 }
a737bd4d 23297
e7495e45
NS
23298 if (narrow_noop)
23299 {
23300 if (bytes & noop_size)
23301 {
23302 /* Insert a narrow noop. */
23303 memcpy (p, narrow_noop, noop_size);
23304 p += noop_size;
23305 bytes -= noop_size;
23306 fix += noop_size;
23307 }
23308
23309 /* Use wide noops for the remainder */
23310 noop_size = 4;
23311 }
23312
c19d1205 23313 while (bytes >= noop_size)
a737bd4d 23314 {
c19d1205
ZW
23315 memcpy (p, noop, noop_size);
23316 p += noop_size;
23317 bytes -= noop_size;
23318 fix += noop_size;
a737bd4d
NC
23319 }
23320
c19d1205 23321 fragP->fr_fix += fix;
a737bd4d
NC
23322}
23323
c19d1205
ZW
23324/* Called from md_do_align. Used to create an alignment
23325 frag in a code section. */
23326
23327void
23328arm_frag_align_code (int n, int max)
bfae80f2 23329{
c19d1205 23330 char * p;
7ed4c4c5 23331
c19d1205 23332 /* We assume that there will never be a requirement
6ec8e702 23333 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 23334 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
23335 {
23336 char err_msg[128];
23337
fa94de6b 23338 sprintf (err_msg,
477330fc
RM
23339 _("alignments greater than %d bytes not supported in .text sections."),
23340 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 23341 as_fatal ("%s", err_msg);
6ec8e702 23342 }
bfae80f2 23343
c19d1205
ZW
23344 p = frag_var (rs_align_code,
23345 MAX_MEM_FOR_RS_ALIGN_CODE,
23346 1,
23347 (relax_substateT) max,
23348 (symbolS *) NULL,
23349 (offsetT) n,
23350 (char *) NULL);
23351 *p = 0;
23352}
bfae80f2 23353
8dc2430f
NC
23354/* Perform target specific initialisation of a frag.
23355 Note - despite the name this initialisation is not done when the frag
23356 is created, but only when its type is assigned. A frag can be created
23357 and used a long time before its type is set, so beware of assuming that
33eaf5de 23358 this initialisation is performed first. */
bfae80f2 23359
cd000bff
DJ
23360#ifndef OBJ_ELF
23361void
23362arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
23363{
23364 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 23365 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
23366}
23367
23368#else /* OBJ_ELF is defined. */
c19d1205 23369void
cd000bff 23370arm_init_frag (fragS * fragP, int max_chars)
c19d1205 23371{
e8d84ca1 23372 bfd_boolean frag_thumb_mode;
b968d18a 23373
8dc2430f
NC
23374 /* If the current ARM vs THUMB mode has not already
23375 been recorded into this frag then do so now. */
cd000bff 23376 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
23377 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
23378
e8d84ca1
NC
23379 /* PR 21809: Do not set a mapping state for debug sections
23380 - it just confuses other tools. */
23381 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
23382 return;
23383
b968d18a 23384 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 23385
f9c1b181
RL
23386 /* Record a mapping symbol for alignment frags. We will delete this
23387 later if the alignment ends up empty. */
23388 switch (fragP->fr_type)
23389 {
23390 case rs_align:
23391 case rs_align_test:
23392 case rs_fill:
23393 mapping_state_2 (MAP_DATA, max_chars);
23394 break;
23395 case rs_align_code:
b968d18a 23396 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
23397 break;
23398 default:
23399 break;
cd000bff 23400 }
bfae80f2
RE
23401}
23402
c19d1205
ZW
23403/* When we change sections we need to issue a new mapping symbol. */
23404
23405void
23406arm_elf_change_section (void)
bfae80f2 23407{
c19d1205
ZW
23408 /* Link an unlinked unwind index table section to the .text section. */
23409 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
23410 && elf_linked_to_section (now_seg) == NULL)
23411 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
23412}
23413
c19d1205
ZW
23414int
23415arm_elf_section_type (const char * str, size_t len)
e45d0630 23416{
c19d1205
ZW
23417 if (len == 5 && strncmp (str, "exidx", 5) == 0)
23418 return SHT_ARM_EXIDX;
e45d0630 23419
c19d1205
ZW
23420 return -1;
23421}
23422\f
23423/* Code to deal with unwinding tables. */
e45d0630 23424
c19d1205 23425static void add_unwind_adjustsp (offsetT);
e45d0630 23426
5f4273c7 23427/* Generate any deferred unwind frame offset. */
e45d0630 23428
bfae80f2 23429static void
c19d1205 23430flush_pending_unwind (void)
bfae80f2 23431{
c19d1205 23432 offsetT offset;
bfae80f2 23433
c19d1205
ZW
23434 offset = unwind.pending_offset;
23435 unwind.pending_offset = 0;
23436 if (offset != 0)
23437 add_unwind_adjustsp (offset);
bfae80f2
RE
23438}
23439
c19d1205
ZW
23440/* Add an opcode to this list for this function. Two-byte opcodes should
23441 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
23442 order. */
23443
bfae80f2 23444static void
c19d1205 23445add_unwind_opcode (valueT op, int length)
bfae80f2 23446{
c19d1205
ZW
23447 /* Add any deferred stack adjustment. */
23448 if (unwind.pending_offset)
23449 flush_pending_unwind ();
bfae80f2 23450
c19d1205 23451 unwind.sp_restored = 0;
bfae80f2 23452
c19d1205 23453 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 23454 {
c19d1205
ZW
23455 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
23456 if (unwind.opcodes)
325801bd
TS
23457 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
23458 unwind.opcode_alloc);
c19d1205 23459 else
325801bd 23460 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 23461 }
c19d1205 23462 while (length > 0)
bfae80f2 23463 {
c19d1205
ZW
23464 length--;
23465 unwind.opcodes[unwind.opcode_count] = op & 0xff;
23466 op >>= 8;
23467 unwind.opcode_count++;
bfae80f2 23468 }
bfae80f2
RE
23469}
23470
c19d1205
ZW
23471/* Add unwind opcodes to adjust the stack pointer. */
23472
bfae80f2 23473static void
c19d1205 23474add_unwind_adjustsp (offsetT offset)
bfae80f2 23475{
c19d1205 23476 valueT op;
bfae80f2 23477
c19d1205 23478 if (offset > 0x200)
bfae80f2 23479 {
c19d1205
ZW
23480 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
23481 char bytes[5];
23482 int n;
23483 valueT o;
bfae80f2 23484
c19d1205
ZW
23485 /* Long form: 0xb2, uleb128. */
23486 /* This might not fit in a word so add the individual bytes,
23487 remembering the list is built in reverse order. */
23488 o = (valueT) ((offset - 0x204) >> 2);
23489 if (o == 0)
23490 add_unwind_opcode (0, 1);
bfae80f2 23491
c19d1205
ZW
23492 /* Calculate the uleb128 encoding of the offset. */
23493 n = 0;
23494 while (o)
23495 {
23496 bytes[n] = o & 0x7f;
23497 o >>= 7;
23498 if (o)
23499 bytes[n] |= 0x80;
23500 n++;
23501 }
23502 /* Add the insn. */
23503 for (; n; n--)
23504 add_unwind_opcode (bytes[n - 1], 1);
23505 add_unwind_opcode (0xb2, 1);
23506 }
23507 else if (offset > 0x100)
bfae80f2 23508 {
c19d1205
ZW
23509 /* Two short opcodes. */
23510 add_unwind_opcode (0x3f, 1);
23511 op = (offset - 0x104) >> 2;
23512 add_unwind_opcode (op, 1);
bfae80f2 23513 }
c19d1205
ZW
23514 else if (offset > 0)
23515 {
23516 /* Short opcode. */
23517 op = (offset - 4) >> 2;
23518 add_unwind_opcode (op, 1);
23519 }
23520 else if (offset < 0)
bfae80f2 23521 {
c19d1205
ZW
23522 offset = -offset;
23523 while (offset > 0x100)
bfae80f2 23524 {
c19d1205
ZW
23525 add_unwind_opcode (0x7f, 1);
23526 offset -= 0x100;
bfae80f2 23527 }
c19d1205
ZW
23528 op = ((offset - 4) >> 2) | 0x40;
23529 add_unwind_opcode (op, 1);
bfae80f2 23530 }
bfae80f2
RE
23531}
23532
c19d1205 23533/* Finish the list of unwind opcodes for this function. */
0198d5e6 23534
c19d1205
ZW
23535static void
23536finish_unwind_opcodes (void)
bfae80f2 23537{
c19d1205 23538 valueT op;
bfae80f2 23539
c19d1205 23540 if (unwind.fp_used)
bfae80f2 23541 {
708587a4 23542 /* Adjust sp as necessary. */
c19d1205
ZW
23543 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
23544 flush_pending_unwind ();
bfae80f2 23545
c19d1205
ZW
23546 /* After restoring sp from the frame pointer. */
23547 op = 0x90 | unwind.fp_reg;
23548 add_unwind_opcode (op, 1);
23549 }
23550 else
23551 flush_pending_unwind ();
bfae80f2
RE
23552}
23553
bfae80f2 23554
c19d1205
ZW
23555/* Start an exception table entry. If idx is nonzero this is an index table
23556 entry. */
bfae80f2
RE
23557
23558static void
c19d1205 23559start_unwind_section (const segT text_seg, int idx)
bfae80f2 23560{
c19d1205
ZW
23561 const char * text_name;
23562 const char * prefix;
23563 const char * prefix_once;
23564 const char * group_name;
c19d1205 23565 char * sec_name;
c19d1205
ZW
23566 int type;
23567 int flags;
23568 int linkonce;
bfae80f2 23569
c19d1205 23570 if (idx)
bfae80f2 23571 {
c19d1205
ZW
23572 prefix = ELF_STRING_ARM_unwind;
23573 prefix_once = ELF_STRING_ARM_unwind_once;
23574 type = SHT_ARM_EXIDX;
bfae80f2 23575 }
c19d1205 23576 else
bfae80f2 23577 {
c19d1205
ZW
23578 prefix = ELF_STRING_ARM_unwind_info;
23579 prefix_once = ELF_STRING_ARM_unwind_info_once;
23580 type = SHT_PROGBITS;
bfae80f2
RE
23581 }
23582
c19d1205
ZW
23583 text_name = segment_name (text_seg);
23584 if (streq (text_name, ".text"))
23585 text_name = "";
23586
23587 if (strncmp (text_name, ".gnu.linkonce.t.",
23588 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 23589 {
c19d1205
ZW
23590 prefix = prefix_once;
23591 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
23592 }
23593
29a2809e 23594 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 23595
c19d1205
ZW
23596 flags = SHF_ALLOC;
23597 linkonce = 0;
23598 group_name = 0;
bfae80f2 23599
c19d1205
ZW
23600 /* Handle COMDAT group. */
23601 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 23602 {
c19d1205
ZW
23603 group_name = elf_group_name (text_seg);
23604 if (group_name == NULL)
23605 {
bd3ba5d1 23606 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
23607 segment_name (text_seg));
23608 ignore_rest_of_line ();
23609 return;
23610 }
23611 flags |= SHF_GROUP;
23612 linkonce = 1;
bfae80f2
RE
23613 }
23614
a91e1603
L
23615 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
23616 linkonce, 0);
bfae80f2 23617
5f4273c7 23618 /* Set the section link for index tables. */
c19d1205
ZW
23619 if (idx)
23620 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
23621}
23622
bfae80f2 23623
c19d1205
ZW
23624/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
23625 personality routine data. Returns zero, or the index table value for
cad0da33 23626 an inline entry. */
c19d1205
ZW
23627
23628static valueT
23629create_unwind_entry (int have_data)
bfae80f2 23630{
c19d1205
ZW
23631 int size;
23632 addressT where;
23633 char *ptr;
23634 /* The current word of data. */
23635 valueT data;
23636 /* The number of bytes left in this word. */
23637 int n;
bfae80f2 23638
c19d1205 23639 finish_unwind_opcodes ();
bfae80f2 23640
c19d1205
ZW
23641 /* Remember the current text section. */
23642 unwind.saved_seg = now_seg;
23643 unwind.saved_subseg = now_subseg;
bfae80f2 23644
c19d1205 23645 start_unwind_section (now_seg, 0);
bfae80f2 23646
c19d1205 23647 if (unwind.personality_routine == NULL)
bfae80f2 23648 {
c19d1205
ZW
23649 if (unwind.personality_index == -2)
23650 {
23651 if (have_data)
5f4273c7 23652 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
23653 return 1; /* EXIDX_CANTUNWIND. */
23654 }
bfae80f2 23655
c19d1205
ZW
23656 /* Use a default personality routine if none is specified. */
23657 if (unwind.personality_index == -1)
23658 {
23659 if (unwind.opcode_count > 3)
23660 unwind.personality_index = 1;
23661 else
23662 unwind.personality_index = 0;
23663 }
bfae80f2 23664
c19d1205
ZW
23665 /* Space for the personality routine entry. */
23666 if (unwind.personality_index == 0)
23667 {
23668 if (unwind.opcode_count > 3)
23669 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 23670
c19d1205
ZW
23671 if (!have_data)
23672 {
23673 /* All the data is inline in the index table. */
23674 data = 0x80;
23675 n = 3;
23676 while (unwind.opcode_count > 0)
23677 {
23678 unwind.opcode_count--;
23679 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
23680 n--;
23681 }
bfae80f2 23682
c19d1205
ZW
23683 /* Pad with "finish" opcodes. */
23684 while (n--)
23685 data = (data << 8) | 0xb0;
bfae80f2 23686
c19d1205
ZW
23687 return data;
23688 }
23689 size = 0;
23690 }
23691 else
23692 /* We get two opcodes "free" in the first word. */
23693 size = unwind.opcode_count - 2;
23694 }
23695 else
5011093d 23696 {
cad0da33
NC
23697 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
23698 if (unwind.personality_index != -1)
23699 {
23700 as_bad (_("attempt to recreate an unwind entry"));
23701 return 1;
23702 }
5011093d
NC
23703
23704 /* An extra byte is required for the opcode count. */
23705 size = unwind.opcode_count + 1;
23706 }
bfae80f2 23707
c19d1205
ZW
23708 size = (size + 3) >> 2;
23709 if (size > 0xff)
23710 as_bad (_("too many unwind opcodes"));
bfae80f2 23711
c19d1205
ZW
23712 frag_align (2, 0, 0);
23713 record_alignment (now_seg, 2);
23714 unwind.table_entry = expr_build_dot ();
23715
23716 /* Allocate the table entry. */
23717 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
23718 /* PR 13449: Zero the table entries in case some of them are not used. */
23719 memset (ptr, 0, (size << 2) + 4);
c19d1205 23720 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 23721
c19d1205 23722 switch (unwind.personality_index)
bfae80f2 23723 {
c19d1205
ZW
23724 case -1:
23725 /* ??? Should this be a PLT generating relocation? */
23726 /* Custom personality routine. */
23727 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
23728 BFD_RELOC_ARM_PREL31);
bfae80f2 23729
c19d1205
ZW
23730 where += 4;
23731 ptr += 4;
bfae80f2 23732
c19d1205 23733 /* Set the first byte to the number of additional words. */
5011093d 23734 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
23735 n = 3;
23736 break;
bfae80f2 23737
c19d1205
ZW
23738 /* ABI defined personality routines. */
23739 case 0:
23740 /* Three opcodes bytes are packed into the first word. */
23741 data = 0x80;
23742 n = 3;
23743 break;
bfae80f2 23744
c19d1205
ZW
23745 case 1:
23746 case 2:
23747 /* The size and first two opcode bytes go in the first word. */
23748 data = ((0x80 + unwind.personality_index) << 8) | size;
23749 n = 2;
23750 break;
bfae80f2 23751
c19d1205
ZW
23752 default:
23753 /* Should never happen. */
23754 abort ();
23755 }
bfae80f2 23756
c19d1205
ZW
23757 /* Pack the opcodes into words (MSB first), reversing the list at the same
23758 time. */
23759 while (unwind.opcode_count > 0)
23760 {
23761 if (n == 0)
23762 {
23763 md_number_to_chars (ptr, data, 4);
23764 ptr += 4;
23765 n = 4;
23766 data = 0;
23767 }
23768 unwind.opcode_count--;
23769 n--;
23770 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
23771 }
23772
23773 /* Finish off the last word. */
23774 if (n < 4)
23775 {
23776 /* Pad with "finish" opcodes. */
23777 while (n--)
23778 data = (data << 8) | 0xb0;
23779
23780 md_number_to_chars (ptr, data, 4);
23781 }
23782
23783 if (!have_data)
23784 {
23785 /* Add an empty descriptor if there is no user-specified data. */
23786 ptr = frag_more (4);
23787 md_number_to_chars (ptr, 0, 4);
23788 }
23789
23790 return 0;
bfae80f2
RE
23791}
23792
f0927246
NC
23793
23794/* Initialize the DWARF-2 unwind information for this procedure. */
23795
23796void
23797tc_arm_frame_initial_instructions (void)
23798{
23799 cfi_add_CFA_def_cfa (REG_SP, 0);
23800}
23801#endif /* OBJ_ELF */
23802
c19d1205
ZW
23803/* Convert REGNAME to a DWARF-2 register number. */
23804
23805int
1df69f4f 23806tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 23807{
1df69f4f 23808 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
23809 if (reg != FAIL)
23810 return reg;
c19d1205 23811
1f5afe1c
NC
23812 /* PR 16694: Allow VFP registers as well. */
23813 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
23814 if (reg != FAIL)
23815 return 64 + reg;
c19d1205 23816
1f5afe1c
NC
23817 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
23818 if (reg != FAIL)
23819 return reg + 256;
23820
0198d5e6 23821 return FAIL;
bfae80f2
RE
23822}
23823
f0927246 23824#ifdef TE_PE
c19d1205 23825void
f0927246 23826tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 23827{
91d6fa6a 23828 expressionS exp;
bfae80f2 23829
91d6fa6a
NC
23830 exp.X_op = O_secrel;
23831 exp.X_add_symbol = symbol;
23832 exp.X_add_number = 0;
23833 emit_expr (&exp, size);
f0927246
NC
23834}
23835#endif
bfae80f2 23836
c19d1205 23837/* MD interface: Symbol and relocation handling. */
bfae80f2 23838
2fc8bdac
ZW
23839/* Return the address within the segment that a PC-relative fixup is
23840 relative to. For ARM, PC-relative fixups applied to instructions
23841 are generally relative to the location of the fixup plus 8 bytes.
23842 Thumb branches are offset by 4, and Thumb loads relative to PC
23843 require special handling. */
bfae80f2 23844
c19d1205 23845long
2fc8bdac 23846md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 23847{
2fc8bdac
ZW
23848 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
23849
23850 /* If this is pc-relative and we are going to emit a relocation
23851 then we just want to put out any pipeline compensation that the linker
53baae48
NC
23852 will need. Otherwise we want to use the calculated base.
23853 For WinCE we skip the bias for externals as well, since this
23854 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 23855 if (fixP->fx_pcrel
2fc8bdac 23856 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
23857 || (arm_force_relocation (fixP)
23858#ifdef TE_WINCE
23859 && !S_IS_EXTERNAL (fixP->fx_addsy)
23860#endif
23861 )))
2fc8bdac 23862 base = 0;
bfae80f2 23863
267bf995 23864
c19d1205 23865 switch (fixP->fx_r_type)
bfae80f2 23866 {
2fc8bdac
ZW
23867 /* PC relative addressing on the Thumb is slightly odd as the
23868 bottom two bits of the PC are forced to zero for the
23869 calculation. This happens *after* application of the
23870 pipeline offset. However, Thumb adrl already adjusts for
23871 this, so we need not do it again. */
c19d1205 23872 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 23873 return base & ~3;
c19d1205
ZW
23874
23875 case BFD_RELOC_ARM_THUMB_OFFSET:
23876 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 23877 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 23878 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 23879 return (base + 4) & ~3;
c19d1205 23880
2fc8bdac 23881 /* Thumb branches are simply offset by +4. */
e12437dc 23882 case BFD_RELOC_THUMB_PCREL_BRANCH5:
2fc8bdac
ZW
23883 case BFD_RELOC_THUMB_PCREL_BRANCH7:
23884 case BFD_RELOC_THUMB_PCREL_BRANCH9:
23885 case BFD_RELOC_THUMB_PCREL_BRANCH12:
23886 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 23887 case BFD_RELOC_THUMB_PCREL_BRANCH25:
f6b2b12d 23888 case BFD_RELOC_THUMB_PCREL_BFCSEL:
e5d6e09e 23889 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 23890 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 23891 case BFD_RELOC_ARM_THUMB_BF13:
60f993ce 23892 case BFD_RELOC_ARM_THUMB_LOOP12:
2fc8bdac 23893 return base + 4;
bfae80f2 23894
267bf995 23895 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
23896 if (fixP->fx_addsy
23897 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23898 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 23899 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
23900 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23901 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
23902 return base + 4;
23903
00adf2d4
JB
23904 /* BLX is like branches above, but forces the low two bits of PC to
23905 zero. */
486499d0
CL
23906 case BFD_RELOC_THUMB_PCREL_BLX:
23907 if (fixP->fx_addsy
23908 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23909 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
23910 && THUMB_IS_FUNC (fixP->fx_addsy)
23911 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23912 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
23913 return (base + 4) & ~3;
23914
2fc8bdac
ZW
23915 /* ARM mode branches are offset by +8. However, the Windows CE
23916 loader expects the relocation not to take this into account. */
267bf995 23917 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
23918 if (fixP->fx_addsy
23919 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23920 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
23921 && ARM_IS_FUNC (fixP->fx_addsy)
23922 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23923 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 23924 return base + 8;
267bf995 23925
486499d0
CL
23926 case BFD_RELOC_ARM_PCREL_CALL:
23927 if (fixP->fx_addsy
23928 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23929 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
23930 && THUMB_IS_FUNC (fixP->fx_addsy)
23931 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23932 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 23933 return base + 8;
267bf995 23934
2fc8bdac 23935 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 23936 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 23937 case BFD_RELOC_ARM_PLT32:
c19d1205 23938#ifdef TE_WINCE
5f4273c7 23939 /* When handling fixups immediately, because we have already
477330fc 23940 discovered the value of a symbol, or the address of the frag involved
53baae48 23941 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
23942 see fixup_segment() in write.c
23943 The S_IS_EXTERNAL test handles the case of global symbols.
23944 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
23945 if (fixP->fx_pcrel
23946 && fixP->fx_addsy != NULL
23947 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23948 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
23949 return base + 8;
2fc8bdac 23950 return base;
c19d1205 23951#else
2fc8bdac 23952 return base + 8;
c19d1205 23953#endif
2fc8bdac 23954
267bf995 23955
2fc8bdac
ZW
23956 /* ARM mode loads relative to PC are also offset by +8. Unlike
23957 branches, the Windows CE loader *does* expect the relocation
23958 to take this into account. */
23959 case BFD_RELOC_ARM_OFFSET_IMM:
23960 case BFD_RELOC_ARM_OFFSET_IMM8:
23961 case BFD_RELOC_ARM_HWLITERAL:
23962 case BFD_RELOC_ARM_LITERAL:
23963 case BFD_RELOC_ARM_CP_OFF_IMM:
23964 return base + 8;
23965
23966
23967 /* Other PC-relative relocations are un-offset. */
23968 default:
23969 return base;
23970 }
bfae80f2
RE
23971}
23972
8b2d793c
NC
23973static bfd_boolean flag_warn_syms = TRUE;
23974
ae8714c2
NC
23975bfd_boolean
23976arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 23977{
8b2d793c
NC
23978 /* PR 18347 - Warn if the user attempts to create a symbol with the same
23979 name as an ARM instruction. Whilst strictly speaking it is allowed, it
23980 does mean that the resulting code might be very confusing to the reader.
23981 Also this warning can be triggered if the user omits an operand before
23982 an immediate address, eg:
23983
23984 LDR =foo
23985
23986 GAS treats this as an assignment of the value of the symbol foo to a
23987 symbol LDR, and so (without this code) it will not issue any kind of
23988 warning or error message.
23989
23990 Note - ARM instructions are case-insensitive but the strings in the hash
23991 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
23992 lower case too. */
23993 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
23994 {
23995 char * nbuf = strdup (name);
23996 char * p;
23997
23998 for (p = nbuf; *p; p++)
23999 *p = TOLOWER (*p);
24000 if (hash_find (arm_ops_hsh, nbuf) != NULL)
24001 {
24002 static struct hash_control * already_warned = NULL;
24003
24004 if (already_warned == NULL)
24005 already_warned = hash_new ();
24006 /* Only warn about the symbol once. To keep the code
24007 simple we let hash_insert do the lookup for us. */
3076e594 24008 if (hash_insert (already_warned, nbuf, NULL) == NULL)
ae8714c2 24009 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
24010 }
24011 else
24012 free (nbuf);
24013 }
3739860c 24014
ae8714c2
NC
24015 return FALSE;
24016}
24017
24018/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
24019 Otherwise we have no need to default values of symbols. */
24020
24021symbolS *
24022md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
24023{
24024#ifdef OBJ_ELF
24025 if (name[0] == '_' && name[1] == 'G'
24026 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
24027 {
24028 if (!GOT_symbol)
24029 {
24030 if (symbol_find (name))
24031 as_bad (_("GOT already in the symbol table"));
24032
24033 GOT_symbol = symbol_new (name, undefined_section,
24034 (valueT) 0, & zero_address_frag);
24035 }
24036
24037 return GOT_symbol;
24038 }
24039#endif
24040
c921be7d 24041 return NULL;
bfae80f2
RE
24042}
24043
55cf6793 24044/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
24045 computed as two separate immediate values, added together. We
24046 already know that this value cannot be computed by just one ARM
24047 instruction. */
24048
24049static unsigned int
24050validate_immediate_twopart (unsigned int val,
24051 unsigned int * highpart)
bfae80f2 24052{
c19d1205
ZW
24053 unsigned int a;
24054 unsigned int i;
bfae80f2 24055
c19d1205
ZW
24056 for (i = 0; i < 32; i += 2)
24057 if (((a = rotate_left (val, i)) & 0xff) != 0)
24058 {
24059 if (a & 0xff00)
24060 {
24061 if (a & ~ 0xffff)
24062 continue;
24063 * highpart = (a >> 8) | ((i + 24) << 7);
24064 }
24065 else if (a & 0xff0000)
24066 {
24067 if (a & 0xff000000)
24068 continue;
24069 * highpart = (a >> 16) | ((i + 16) << 7);
24070 }
24071 else
24072 {
9c2799c2 24073 gas_assert (a & 0xff000000);
c19d1205
ZW
24074 * highpart = (a >> 24) | ((i + 8) << 7);
24075 }
bfae80f2 24076
c19d1205
ZW
24077 return (a & 0xff) | (i << 7);
24078 }
bfae80f2 24079
c19d1205 24080 return FAIL;
bfae80f2
RE
24081}
24082
c19d1205
ZW
24083static int
24084validate_offset_imm (unsigned int val, int hwse)
24085{
24086 if ((hwse && val > 255) || val > 4095)
24087 return FAIL;
24088 return val;
24089}
bfae80f2 24090
55cf6793 24091/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
24092 negative immediate constant by altering the instruction. A bit of
24093 a hack really.
24094 MOV <-> MVN
24095 AND <-> BIC
24096 ADC <-> SBC
24097 by inverting the second operand, and
24098 ADD <-> SUB
24099 CMP <-> CMN
24100 by negating the second operand. */
bfae80f2 24101
c19d1205
ZW
24102static int
24103negate_data_op (unsigned long * instruction,
24104 unsigned long value)
bfae80f2 24105{
c19d1205
ZW
24106 int op, new_inst;
24107 unsigned long negated, inverted;
bfae80f2 24108
c19d1205
ZW
24109 negated = encode_arm_immediate (-value);
24110 inverted = encode_arm_immediate (~value);
bfae80f2 24111
c19d1205
ZW
24112 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
24113 switch (op)
bfae80f2 24114 {
c19d1205
ZW
24115 /* First negates. */
24116 case OPCODE_SUB: /* ADD <-> SUB */
24117 new_inst = OPCODE_ADD;
24118 value = negated;
24119 break;
bfae80f2 24120
c19d1205
ZW
24121 case OPCODE_ADD:
24122 new_inst = OPCODE_SUB;
24123 value = negated;
24124 break;
bfae80f2 24125
c19d1205
ZW
24126 case OPCODE_CMP: /* CMP <-> CMN */
24127 new_inst = OPCODE_CMN;
24128 value = negated;
24129 break;
bfae80f2 24130
c19d1205
ZW
24131 case OPCODE_CMN:
24132 new_inst = OPCODE_CMP;
24133 value = negated;
24134 break;
bfae80f2 24135
c19d1205
ZW
24136 /* Now Inverted ops. */
24137 case OPCODE_MOV: /* MOV <-> MVN */
24138 new_inst = OPCODE_MVN;
24139 value = inverted;
24140 break;
bfae80f2 24141
c19d1205
ZW
24142 case OPCODE_MVN:
24143 new_inst = OPCODE_MOV;
24144 value = inverted;
24145 break;
bfae80f2 24146
c19d1205
ZW
24147 case OPCODE_AND: /* AND <-> BIC */
24148 new_inst = OPCODE_BIC;
24149 value = inverted;
24150 break;
bfae80f2 24151
c19d1205
ZW
24152 case OPCODE_BIC:
24153 new_inst = OPCODE_AND;
24154 value = inverted;
24155 break;
bfae80f2 24156
c19d1205
ZW
24157 case OPCODE_ADC: /* ADC <-> SBC */
24158 new_inst = OPCODE_SBC;
24159 value = inverted;
24160 break;
bfae80f2 24161
c19d1205
ZW
24162 case OPCODE_SBC:
24163 new_inst = OPCODE_ADC;
24164 value = inverted;
24165 break;
bfae80f2 24166
c19d1205
ZW
24167 /* We cannot do anything. */
24168 default:
24169 return FAIL;
b99bd4ef
NC
24170 }
24171
c19d1205
ZW
24172 if (value == (unsigned) FAIL)
24173 return FAIL;
24174
24175 *instruction &= OPCODE_MASK;
24176 *instruction |= new_inst << DATA_OP_SHIFT;
24177 return value;
b99bd4ef
NC
24178}
24179
ef8d22e6
PB
24180/* Like negate_data_op, but for Thumb-2. */
24181
24182static unsigned int
16dd5e42 24183thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
24184{
24185 int op, new_inst;
24186 int rd;
16dd5e42 24187 unsigned int negated, inverted;
ef8d22e6
PB
24188
24189 negated = encode_thumb32_immediate (-value);
24190 inverted = encode_thumb32_immediate (~value);
24191
24192 rd = (*instruction >> 8) & 0xf;
24193 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
24194 switch (op)
24195 {
24196 /* ADD <-> SUB. Includes CMP <-> CMN. */
24197 case T2_OPCODE_SUB:
24198 new_inst = T2_OPCODE_ADD;
24199 value = negated;
24200 break;
24201
24202 case T2_OPCODE_ADD:
24203 new_inst = T2_OPCODE_SUB;
24204 value = negated;
24205 break;
24206
24207 /* ORR <-> ORN. Includes MOV <-> MVN. */
24208 case T2_OPCODE_ORR:
24209 new_inst = T2_OPCODE_ORN;
24210 value = inverted;
24211 break;
24212
24213 case T2_OPCODE_ORN:
24214 new_inst = T2_OPCODE_ORR;
24215 value = inverted;
24216 break;
24217
24218 /* AND <-> BIC. TST has no inverted equivalent. */
24219 case T2_OPCODE_AND:
24220 new_inst = T2_OPCODE_BIC;
24221 if (rd == 15)
24222 value = FAIL;
24223 else
24224 value = inverted;
24225 break;
24226
24227 case T2_OPCODE_BIC:
24228 new_inst = T2_OPCODE_AND;
24229 value = inverted;
24230 break;
24231
24232 /* ADC <-> SBC */
24233 case T2_OPCODE_ADC:
24234 new_inst = T2_OPCODE_SBC;
24235 value = inverted;
24236 break;
24237
24238 case T2_OPCODE_SBC:
24239 new_inst = T2_OPCODE_ADC;
24240 value = inverted;
24241 break;
24242
24243 /* We cannot do anything. */
24244 default:
24245 return FAIL;
24246 }
24247
16dd5e42 24248 if (value == (unsigned int)FAIL)
ef8d22e6
PB
24249 return FAIL;
24250
24251 *instruction &= T2_OPCODE_MASK;
24252 *instruction |= new_inst << T2_DATA_OP_SHIFT;
24253 return value;
24254}
24255
8f06b2d8 24256/* Read a 32-bit thumb instruction from buf. */
0198d5e6 24257
8f06b2d8
PB
24258static unsigned long
24259get_thumb32_insn (char * buf)
24260{
24261 unsigned long insn;
24262 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
24263 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24264
24265 return insn;
24266}
24267
a8bc6c78
PB
24268/* We usually want to set the low bit on the address of thumb function
24269 symbols. In particular .word foo - . should have the low bit set.
24270 Generic code tries to fold the difference of two symbols to
24271 a constant. Prevent this and force a relocation when the first symbols
24272 is a thumb function. */
c921be7d
NC
24273
24274bfd_boolean
a8bc6c78
PB
24275arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
24276{
24277 if (op == O_subtract
24278 && l->X_op == O_symbol
24279 && r->X_op == O_symbol
24280 && THUMB_IS_FUNC (l->X_add_symbol))
24281 {
24282 l->X_op = O_subtract;
24283 l->X_op_symbol = r->X_add_symbol;
24284 l->X_add_number -= r->X_add_number;
c921be7d 24285 return TRUE;
a8bc6c78 24286 }
c921be7d 24287
a8bc6c78 24288 /* Process as normal. */
c921be7d 24289 return FALSE;
a8bc6c78
PB
24290}
24291
4a42ebbc
RR
24292/* Encode Thumb2 unconditional branches and calls. The encoding
24293 for the 2 are identical for the immediate values. */
24294
24295static void
24296encode_thumb2_b_bl_offset (char * buf, offsetT value)
24297{
24298#define T2I1I2MASK ((1 << 13) | (1 << 11))
24299 offsetT newval;
24300 offsetT newval2;
24301 addressT S, I1, I2, lo, hi;
24302
24303 S = (value >> 24) & 0x01;
24304 I1 = (value >> 23) & 0x01;
24305 I2 = (value >> 22) & 0x01;
24306 hi = (value >> 12) & 0x3ff;
fa94de6b 24307 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
24308 newval = md_chars_to_number (buf, THUMB_SIZE);
24309 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24310 newval |= (S << 10) | hi;
24311 newval2 &= ~T2I1I2MASK;
24312 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
24313 md_number_to_chars (buf, newval, THUMB_SIZE);
24314 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
24315}
24316
c19d1205 24317void
55cf6793 24318md_apply_fix (fixS * fixP,
c19d1205
ZW
24319 valueT * valP,
24320 segT seg)
24321{
24322 offsetT value = * valP;
24323 offsetT newval;
24324 unsigned int newimm;
24325 unsigned long temp;
24326 int sign;
24327 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 24328
9c2799c2 24329 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 24330
c19d1205 24331 /* Note whether this will delete the relocation. */
4962c51a 24332
c19d1205
ZW
24333 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
24334 fixP->fx_done = 1;
b99bd4ef 24335
adbaf948 24336 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 24337 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
24338 for emit_reloc. */
24339 value &= 0xffffffff;
24340 value ^= 0x80000000;
5f4273c7 24341 value -= 0x80000000;
adbaf948
ZW
24342
24343 *valP = value;
c19d1205 24344 fixP->fx_addnumber = value;
b99bd4ef 24345
adbaf948
ZW
24346 /* Same treatment for fixP->fx_offset. */
24347 fixP->fx_offset &= 0xffffffff;
24348 fixP->fx_offset ^= 0x80000000;
24349 fixP->fx_offset -= 0x80000000;
24350
c19d1205 24351 switch (fixP->fx_r_type)
b99bd4ef 24352 {
c19d1205
ZW
24353 case BFD_RELOC_NONE:
24354 /* This will need to go in the object file. */
24355 fixP->fx_done = 0;
24356 break;
b99bd4ef 24357
c19d1205
ZW
24358 case BFD_RELOC_ARM_IMMEDIATE:
24359 /* We claim that this fixup has been processed here,
24360 even if in fact we generate an error because we do
24361 not have a reloc for it, so tc_gen_reloc will reject it. */
24362 fixP->fx_done = 1;
b99bd4ef 24363
77db8e2e 24364 if (fixP->fx_addsy)
b99bd4ef 24365 {
77db8e2e 24366 const char *msg = 0;
b99bd4ef 24367
77db8e2e
NC
24368 if (! S_IS_DEFINED (fixP->fx_addsy))
24369 msg = _("undefined symbol %s used as an immediate value");
24370 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
24371 msg = _("symbol %s is in a different section");
24372 else if (S_IS_WEAK (fixP->fx_addsy))
24373 msg = _("symbol %s is weak and may be overridden later");
24374
24375 if (msg)
24376 {
24377 as_bad_where (fixP->fx_file, fixP->fx_line,
24378 msg, S_GET_NAME (fixP->fx_addsy));
24379 break;
24380 }
42e5fcbf
AS
24381 }
24382
c19d1205
ZW
24383 temp = md_chars_to_number (buf, INSN_SIZE);
24384
5e73442d
SL
24385 /* If the offset is negative, we should use encoding A2 for ADR. */
24386 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
24387 newimm = negate_data_op (&temp, value);
24388 else
24389 {
24390 newimm = encode_arm_immediate (value);
24391
24392 /* If the instruction will fail, see if we can fix things up by
24393 changing the opcode. */
24394 if (newimm == (unsigned int) FAIL)
24395 newimm = negate_data_op (&temp, value);
bada4342
JW
24396 /* MOV accepts both ARM modified immediate (A1 encoding) and
24397 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
24398 When disassembling, MOV is preferred when there is no encoding
24399 overlap. */
24400 if (newimm == (unsigned int) FAIL
24401 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
24402 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
24403 && !((temp >> SBIT_SHIFT) & 0x1)
24404 && value >= 0 && value <= 0xffff)
24405 {
24406 /* Clear bits[23:20] to change encoding from A1 to A2. */
24407 temp &= 0xff0fffff;
24408 /* Encoding high 4bits imm. Code below will encode the remaining
24409 low 12bits. */
24410 temp |= (value & 0x0000f000) << 4;
24411 newimm = value & 0x00000fff;
24412 }
5e73442d
SL
24413 }
24414
24415 if (newimm == (unsigned int) FAIL)
b99bd4ef 24416 {
c19d1205
ZW
24417 as_bad_where (fixP->fx_file, fixP->fx_line,
24418 _("invalid constant (%lx) after fixup"),
24419 (unsigned long) value);
24420 break;
b99bd4ef 24421 }
b99bd4ef 24422
c19d1205
ZW
24423 newimm |= (temp & 0xfffff000);
24424 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
24425 break;
b99bd4ef 24426
c19d1205
ZW
24427 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24428 {
24429 unsigned int highpart = 0;
24430 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 24431
77db8e2e 24432 if (fixP->fx_addsy)
42e5fcbf 24433 {
77db8e2e 24434 const char *msg = 0;
42e5fcbf 24435
77db8e2e
NC
24436 if (! S_IS_DEFINED (fixP->fx_addsy))
24437 msg = _("undefined symbol %s used as an immediate value");
24438 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
24439 msg = _("symbol %s is in a different section");
24440 else if (S_IS_WEAK (fixP->fx_addsy))
24441 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 24442
77db8e2e
NC
24443 if (msg)
24444 {
24445 as_bad_where (fixP->fx_file, fixP->fx_line,
24446 msg, S_GET_NAME (fixP->fx_addsy));
24447 break;
24448 }
24449 }
fa94de6b 24450
c19d1205
ZW
24451 newimm = encode_arm_immediate (value);
24452 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 24453
c19d1205
ZW
24454 /* If the instruction will fail, see if we can fix things up by
24455 changing the opcode. */
24456 if (newimm == (unsigned int) FAIL
24457 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
24458 {
24459 /* No ? OK - try using two ADD instructions to generate
24460 the value. */
24461 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 24462
c19d1205
ZW
24463 /* Yes - then make sure that the second instruction is
24464 also an add. */
24465 if (newimm != (unsigned int) FAIL)
24466 newinsn = temp;
24467 /* Still No ? Try using a negated value. */
24468 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
24469 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
24470 /* Otherwise - give up. */
24471 else
24472 {
24473 as_bad_where (fixP->fx_file, fixP->fx_line,
24474 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
24475 (long) value);
24476 break;
24477 }
b99bd4ef 24478
c19d1205
ZW
24479 /* Replace the first operand in the 2nd instruction (which
24480 is the PC) with the destination register. We have
24481 already added in the PC in the first instruction and we
24482 do not want to do it again. */
24483 newinsn &= ~ 0xf0000;
24484 newinsn |= ((newinsn & 0x0f000) << 4);
24485 }
b99bd4ef 24486
c19d1205
ZW
24487 newimm |= (temp & 0xfffff000);
24488 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 24489
c19d1205
ZW
24490 highpart |= (newinsn & 0xfffff000);
24491 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
24492 }
24493 break;
b99bd4ef 24494
c19d1205 24495 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24496 if (!fixP->fx_done && seg->use_rela_p)
24497 value = 0;
1a0670f3 24498 /* Fall through. */
00a97672 24499
c19d1205 24500 case BFD_RELOC_ARM_LITERAL:
26d97720 24501 sign = value > 0;
b99bd4ef 24502
c19d1205
ZW
24503 if (value < 0)
24504 value = - value;
b99bd4ef 24505
c19d1205 24506 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 24507 {
c19d1205
ZW
24508 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
24509 as_bad_where (fixP->fx_file, fixP->fx_line,
24510 _("invalid literal constant: pool needs to be closer"));
24511 else
24512 as_bad_where (fixP->fx_file, fixP->fx_line,
24513 _("bad immediate value for offset (%ld)"),
24514 (long) value);
24515 break;
f03698e6
RE
24516 }
24517
c19d1205 24518 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
24519 if (value == 0)
24520 newval &= 0xfffff000;
24521 else
24522 {
24523 newval &= 0xff7ff000;
24524 newval |= value | (sign ? INDEX_UP : 0);
24525 }
c19d1205
ZW
24526 md_number_to_chars (buf, newval, INSN_SIZE);
24527 break;
b99bd4ef 24528
c19d1205
ZW
24529 case BFD_RELOC_ARM_OFFSET_IMM8:
24530 case BFD_RELOC_ARM_HWLITERAL:
26d97720 24531 sign = value > 0;
b99bd4ef 24532
c19d1205
ZW
24533 if (value < 0)
24534 value = - value;
b99bd4ef 24535
c19d1205 24536 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 24537 {
c19d1205
ZW
24538 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
24539 as_bad_where (fixP->fx_file, fixP->fx_line,
24540 _("invalid literal constant: pool needs to be closer"));
24541 else
427d0db6
RM
24542 as_bad_where (fixP->fx_file, fixP->fx_line,
24543 _("bad immediate value for 8-bit offset (%ld)"),
24544 (long) value);
c19d1205 24545 break;
b99bd4ef
NC
24546 }
24547
c19d1205 24548 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
24549 if (value == 0)
24550 newval &= 0xfffff0f0;
24551 else
24552 {
24553 newval &= 0xff7ff0f0;
24554 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
24555 }
c19d1205
ZW
24556 md_number_to_chars (buf, newval, INSN_SIZE);
24557 break;
b99bd4ef 24558
c19d1205
ZW
24559 case BFD_RELOC_ARM_T32_OFFSET_U8:
24560 if (value < 0 || value > 1020 || value % 4 != 0)
24561 as_bad_where (fixP->fx_file, fixP->fx_line,
24562 _("bad immediate value for offset (%ld)"), (long) value);
24563 value /= 4;
b99bd4ef 24564
c19d1205 24565 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
24566 newval |= value;
24567 md_number_to_chars (buf+2, newval, THUMB_SIZE);
24568 break;
b99bd4ef 24569
c19d1205
ZW
24570 case BFD_RELOC_ARM_T32_OFFSET_IMM:
24571 /* This is a complicated relocation used for all varieties of Thumb32
24572 load/store instruction with immediate offset:
24573
24574 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 24575 *4, optional writeback(W)
c19d1205
ZW
24576 (doubleword load/store)
24577
24578 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
24579 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
24580 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
24581 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
24582 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
24583
24584 Uppercase letters indicate bits that are already encoded at
24585 this point. Lowercase letters are our problem. For the
24586 second block of instructions, the secondary opcode nybble
24587 (bits 8..11) is present, and bit 23 is zero, even if this is
24588 a PC-relative operation. */
24589 newval = md_chars_to_number (buf, THUMB_SIZE);
24590 newval <<= 16;
24591 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 24592
c19d1205 24593 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 24594 {
c19d1205
ZW
24595 /* Doubleword load/store: 8-bit offset, scaled by 4. */
24596 if (value >= 0)
24597 newval |= (1 << 23);
24598 else
24599 value = -value;
24600 if (value % 4 != 0)
24601 {
24602 as_bad_where (fixP->fx_file, fixP->fx_line,
24603 _("offset not a multiple of 4"));
24604 break;
24605 }
24606 value /= 4;
216d22bc 24607 if (value > 0xff)
c19d1205
ZW
24608 {
24609 as_bad_where (fixP->fx_file, fixP->fx_line,
24610 _("offset out of range"));
24611 break;
24612 }
24613 newval &= ~0xff;
b99bd4ef 24614 }
c19d1205 24615 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 24616 {
c19d1205
ZW
24617 /* PC-relative, 12-bit offset. */
24618 if (value >= 0)
24619 newval |= (1 << 23);
24620 else
24621 value = -value;
216d22bc 24622 if (value > 0xfff)
c19d1205
ZW
24623 {
24624 as_bad_where (fixP->fx_file, fixP->fx_line,
24625 _("offset out of range"));
24626 break;
24627 }
24628 newval &= ~0xfff;
b99bd4ef 24629 }
c19d1205 24630 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 24631 {
c19d1205
ZW
24632 /* Writeback: 8-bit, +/- offset. */
24633 if (value >= 0)
24634 newval |= (1 << 9);
24635 else
24636 value = -value;
216d22bc 24637 if (value > 0xff)
c19d1205
ZW
24638 {
24639 as_bad_where (fixP->fx_file, fixP->fx_line,
24640 _("offset out of range"));
24641 break;
24642 }
24643 newval &= ~0xff;
b99bd4ef 24644 }
c19d1205 24645 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 24646 {
c19d1205 24647 /* T-instruction: positive 8-bit offset. */
216d22bc 24648 if (value < 0 || value > 0xff)
b99bd4ef 24649 {
c19d1205
ZW
24650 as_bad_where (fixP->fx_file, fixP->fx_line,
24651 _("offset out of range"));
24652 break;
b99bd4ef 24653 }
c19d1205
ZW
24654 newval &= ~0xff;
24655 newval |= value;
b99bd4ef
NC
24656 }
24657 else
b99bd4ef 24658 {
c19d1205
ZW
24659 /* Positive 12-bit or negative 8-bit offset. */
24660 int limit;
24661 if (value >= 0)
b99bd4ef 24662 {
c19d1205
ZW
24663 newval |= (1 << 23);
24664 limit = 0xfff;
24665 }
24666 else
24667 {
24668 value = -value;
24669 limit = 0xff;
24670 }
24671 if (value > limit)
24672 {
24673 as_bad_where (fixP->fx_file, fixP->fx_line,
24674 _("offset out of range"));
24675 break;
b99bd4ef 24676 }
c19d1205 24677 newval &= ~limit;
b99bd4ef 24678 }
b99bd4ef 24679
c19d1205
ZW
24680 newval |= value;
24681 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
24682 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
24683 break;
404ff6b5 24684
c19d1205
ZW
24685 case BFD_RELOC_ARM_SHIFT_IMM:
24686 newval = md_chars_to_number (buf, INSN_SIZE);
24687 if (((unsigned long) value) > 32
24688 || (value == 32
24689 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
24690 {
24691 as_bad_where (fixP->fx_file, fixP->fx_line,
24692 _("shift expression is too large"));
24693 break;
24694 }
404ff6b5 24695
c19d1205
ZW
24696 if (value == 0)
24697 /* Shifts of zero must be done as lsl. */
24698 newval &= ~0x60;
24699 else if (value == 32)
24700 value = 0;
24701 newval &= 0xfffff07f;
24702 newval |= (value & 0x1f) << 7;
24703 md_number_to_chars (buf, newval, INSN_SIZE);
24704 break;
404ff6b5 24705
c19d1205 24706 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 24707 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 24708 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 24709 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
24710 /* We claim that this fixup has been processed here,
24711 even if in fact we generate an error because we do
24712 not have a reloc for it, so tc_gen_reloc will reject it. */
24713 fixP->fx_done = 1;
404ff6b5 24714
c19d1205
ZW
24715 if (fixP->fx_addsy
24716 && ! S_IS_DEFINED (fixP->fx_addsy))
24717 {
24718 as_bad_where (fixP->fx_file, fixP->fx_line,
24719 _("undefined symbol %s used as an immediate value"),
24720 S_GET_NAME (fixP->fx_addsy));
24721 break;
24722 }
404ff6b5 24723
c19d1205
ZW
24724 newval = md_chars_to_number (buf, THUMB_SIZE);
24725 newval <<= 16;
24726 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 24727
16805f35 24728 newimm = FAIL;
bada4342
JW
24729 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24730 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
24731 Thumb2 modified immediate encoding (T2). */
24732 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 24733 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
24734 {
24735 newimm = encode_thumb32_immediate (value);
24736 if (newimm == (unsigned int) FAIL)
24737 newimm = thumb32_negate_data_op (&newval, value);
24738 }
bada4342 24739 if (newimm == (unsigned int) FAIL)
92e90b6e 24740 {
bada4342 24741 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 24742 {
bada4342
JW
24743 /* Turn add/sum into addw/subw. */
24744 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
24745 newval = (newval & 0xfeffffff) | 0x02000000;
24746 /* No flat 12-bit imm encoding for addsw/subsw. */
24747 if ((newval & 0x00100000) == 0)
40f246e3 24748 {
bada4342
JW
24749 /* 12 bit immediate for addw/subw. */
24750 if (value < 0)
24751 {
24752 value = -value;
24753 newval ^= 0x00a00000;
24754 }
24755 if (value > 0xfff)
24756 newimm = (unsigned int) FAIL;
24757 else
24758 newimm = value;
24759 }
24760 }
24761 else
24762 {
24763 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
24764 UINT16 (T3 encoding), MOVW only accepts UINT16. When
24765 disassembling, MOV is preferred when there is no encoding
db7bf105 24766 overlap. */
bada4342 24767 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
db7bf105
NC
24768 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
24769 but with the Rn field [19:16] set to 1111. */
24770 && (((newval >> 16) & 0xf) == 0xf)
bada4342
JW
24771 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
24772 && !((newval >> T2_SBIT_SHIFT) & 0x1)
db7bf105 24773 && value >= 0 && value <= 0xffff)
bada4342
JW
24774 {
24775 /* Toggle bit[25] to change encoding from T2 to T3. */
24776 newval ^= 1 << 25;
24777 /* Clear bits[19:16]. */
24778 newval &= 0xfff0ffff;
24779 /* Encoding high 4bits imm. Code below will encode the
24780 remaining low 12bits. */
24781 newval |= (value & 0x0000f000) << 4;
24782 newimm = value & 0x00000fff;
40f246e3 24783 }
e9f89963 24784 }
92e90b6e 24785 }
cc8a6dd0 24786
c19d1205 24787 if (newimm == (unsigned int)FAIL)
3631a3c8 24788 {
c19d1205
ZW
24789 as_bad_where (fixP->fx_file, fixP->fx_line,
24790 _("invalid constant (%lx) after fixup"),
24791 (unsigned long) value);
24792 break;
3631a3c8
NC
24793 }
24794
c19d1205
ZW
24795 newval |= (newimm & 0x800) << 15;
24796 newval |= (newimm & 0x700) << 4;
24797 newval |= (newimm & 0x0ff);
cc8a6dd0 24798
c19d1205
ZW
24799 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
24800 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
24801 break;
a737bd4d 24802
3eb17e6b 24803 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
24804 if (((unsigned long) value) > 0xffff)
24805 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 24806 _("invalid smc expression"));
2fc8bdac 24807 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
24808 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
24809 md_number_to_chars (buf, newval, INSN_SIZE);
24810 break;
a737bd4d 24811
90ec0d68
MGD
24812 case BFD_RELOC_ARM_HVC:
24813 if (((unsigned long) value) > 0xffff)
24814 as_bad_where (fixP->fx_file, fixP->fx_line,
24815 _("invalid hvc expression"));
24816 newval = md_chars_to_number (buf, INSN_SIZE);
24817 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
24818 md_number_to_chars (buf, newval, INSN_SIZE);
24819 break;
24820
c19d1205 24821 case BFD_RELOC_ARM_SWI:
adbaf948 24822 if (fixP->tc_fix_data != 0)
c19d1205
ZW
24823 {
24824 if (((unsigned long) value) > 0xff)
24825 as_bad_where (fixP->fx_file, fixP->fx_line,
24826 _("invalid swi expression"));
2fc8bdac 24827 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
24828 newval |= value;
24829 md_number_to_chars (buf, newval, THUMB_SIZE);
24830 }
24831 else
24832 {
24833 if (((unsigned long) value) > 0x00ffffff)
24834 as_bad_where (fixP->fx_file, fixP->fx_line,
24835 _("invalid swi expression"));
2fc8bdac 24836 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
24837 newval |= value;
24838 md_number_to_chars (buf, newval, INSN_SIZE);
24839 }
24840 break;
a737bd4d 24841
c19d1205
ZW
24842 case BFD_RELOC_ARM_MULTI:
24843 if (((unsigned long) value) > 0xffff)
24844 as_bad_where (fixP->fx_file, fixP->fx_line,
24845 _("invalid expression in load/store multiple"));
24846 newval = value | md_chars_to_number (buf, INSN_SIZE);
24847 md_number_to_chars (buf, newval, INSN_SIZE);
24848 break;
a737bd4d 24849
c19d1205 24850#ifdef OBJ_ELF
39b41c9c 24851 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
24852
24853 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
24854 && fixP->fx_addsy
34e77a92 24855 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24856 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24857 && THUMB_IS_FUNC (fixP->fx_addsy))
24858 /* Flip the bl to blx. This is a simple flip
24859 bit here because we generate PCREL_CALL for
24860 unconditional bls. */
24861 {
24862 newval = md_chars_to_number (buf, INSN_SIZE);
24863 newval = newval | 0x10000000;
24864 md_number_to_chars (buf, newval, INSN_SIZE);
24865 temp = 1;
24866 fixP->fx_done = 1;
24867 }
39b41c9c
PB
24868 else
24869 temp = 3;
24870 goto arm_branch_common;
24871
24872 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
24873 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
24874 && fixP->fx_addsy
34e77a92 24875 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24876 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24877 && THUMB_IS_FUNC (fixP->fx_addsy))
24878 {
24879 /* This would map to a bl<cond>, b<cond>,
24880 b<always> to a Thumb function. We
24881 need to force a relocation for this particular
24882 case. */
24883 newval = md_chars_to_number (buf, INSN_SIZE);
24884 fixP->fx_done = 0;
24885 }
1a0670f3 24886 /* Fall through. */
267bf995 24887
2fc8bdac 24888 case BFD_RELOC_ARM_PLT32:
c19d1205 24889#endif
39b41c9c
PB
24890 case BFD_RELOC_ARM_PCREL_BRANCH:
24891 temp = 3;
24892 goto arm_branch_common;
a737bd4d 24893
39b41c9c 24894 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 24895
39b41c9c 24896 temp = 1;
267bf995
RR
24897 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
24898 && fixP->fx_addsy
34e77a92 24899 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24900 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24901 && ARM_IS_FUNC (fixP->fx_addsy))
24902 {
24903 /* Flip the blx to a bl and warn. */
24904 const char *name = S_GET_NAME (fixP->fx_addsy);
24905 newval = 0xeb000000;
24906 as_warn_where (fixP->fx_file, fixP->fx_line,
24907 _("blx to '%s' an ARM ISA state function changed to bl"),
24908 name);
24909 md_number_to_chars (buf, newval, INSN_SIZE);
24910 temp = 3;
24911 fixP->fx_done = 1;
24912 }
24913
24914#ifdef OBJ_ELF
24915 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 24916 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
24917#endif
24918
39b41c9c 24919 arm_branch_common:
c19d1205 24920 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
24921 instruction, in a 24 bit, signed field. Bits 26 through 32 either
24922 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 24923 also be clear. */
39b41c9c 24924 if (value & temp)
c19d1205 24925 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
24926 _("misaligned branch destination"));
24927 if ((value & (offsetT)0xfe000000) != (offsetT)0
24928 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 24929 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 24930
2fc8bdac 24931 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 24932 {
2fc8bdac
ZW
24933 newval = md_chars_to_number (buf, INSN_SIZE);
24934 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
24935 /* Set the H bit on BLX instructions. */
24936 if (temp == 1)
24937 {
24938 if (value & 2)
24939 newval |= 0x01000000;
24940 else
24941 newval &= ~0x01000000;
24942 }
2fc8bdac 24943 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 24944 }
c19d1205 24945 break;
a737bd4d 24946
25fe350b
MS
24947 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
24948 /* CBZ can only branch forward. */
a737bd4d 24949
738755b0 24950 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
24951 (which, strictly speaking, are prohibited) will be turned into
24952 no-ops.
738755b0
MS
24953
24954 FIXME: It may be better to remove the instruction completely and
24955 perform relaxation. */
24956 if (value == -2)
2fc8bdac
ZW
24957 {
24958 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 24959 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
24960 md_number_to_chars (buf, newval, THUMB_SIZE);
24961 }
738755b0
MS
24962 else
24963 {
24964 if (value & ~0x7e)
08f10d51 24965 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 24966
477330fc 24967 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
24968 {
24969 newval = md_chars_to_number (buf, THUMB_SIZE);
24970 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
24971 md_number_to_chars (buf, newval, THUMB_SIZE);
24972 }
24973 }
c19d1205 24974 break;
a737bd4d 24975
c19d1205 24976 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 24977 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 24978 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 24979
2fc8bdac
ZW
24980 if (fixP->fx_done || !seg->use_rela_p)
24981 {
24982 newval = md_chars_to_number (buf, THUMB_SIZE);
24983 newval |= (value & 0x1ff) >> 1;
24984 md_number_to_chars (buf, newval, THUMB_SIZE);
24985 }
c19d1205 24986 break;
a737bd4d 24987
c19d1205 24988 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 24989 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 24990 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 24991
2fc8bdac
ZW
24992 if (fixP->fx_done || !seg->use_rela_p)
24993 {
24994 newval = md_chars_to_number (buf, THUMB_SIZE);
24995 newval |= (value & 0xfff) >> 1;
24996 md_number_to_chars (buf, newval, THUMB_SIZE);
24997 }
c19d1205 24998 break;
a737bd4d 24999
c19d1205 25000 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
25001 if (fixP->fx_addsy
25002 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 25003 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
25004 && ARM_IS_FUNC (fixP->fx_addsy)
25005 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
25006 {
25007 /* Force a relocation for a branch 20 bits wide. */
25008 fixP->fx_done = 0;
25009 }
08f10d51 25010 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
25011 as_bad_where (fixP->fx_file, fixP->fx_line,
25012 _("conditional branch out of range"));
404ff6b5 25013
2fc8bdac
ZW
25014 if (fixP->fx_done || !seg->use_rela_p)
25015 {
25016 offsetT newval2;
25017 addressT S, J1, J2, lo, hi;
404ff6b5 25018
2fc8bdac
ZW
25019 S = (value & 0x00100000) >> 20;
25020 J2 = (value & 0x00080000) >> 19;
25021 J1 = (value & 0x00040000) >> 18;
25022 hi = (value & 0x0003f000) >> 12;
25023 lo = (value & 0x00000ffe) >> 1;
6c43fab6 25024
2fc8bdac
ZW
25025 newval = md_chars_to_number (buf, THUMB_SIZE);
25026 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25027 newval |= (S << 10) | hi;
25028 newval2 |= (J1 << 13) | (J2 << 11) | lo;
25029 md_number_to_chars (buf, newval, THUMB_SIZE);
25030 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25031 }
c19d1205 25032 break;
6c43fab6 25033
c19d1205 25034 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
25035 /* If there is a blx from a thumb state function to
25036 another thumb function flip this to a bl and warn
25037 about it. */
25038
25039 if (fixP->fx_addsy
34e77a92 25040 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
25041 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25042 && THUMB_IS_FUNC (fixP->fx_addsy))
25043 {
25044 const char *name = S_GET_NAME (fixP->fx_addsy);
25045 as_warn_where (fixP->fx_file, fixP->fx_line,
25046 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
25047 name);
25048 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25049 newval = newval | 0x1000;
25050 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
25051 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
25052 fixP->fx_done = 1;
25053 }
25054
25055
25056 goto thumb_bl_common;
25057
c19d1205 25058 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
25059 /* A bl from Thumb state ISA to an internal ARM state function
25060 is converted to a blx. */
25061 if (fixP->fx_addsy
25062 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 25063 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
25064 && ARM_IS_FUNC (fixP->fx_addsy)
25065 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
25066 {
25067 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25068 newval = newval & ~0x1000;
25069 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
25070 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
25071 fixP->fx_done = 1;
25072 }
25073
25074 thumb_bl_common:
25075
2fc8bdac
ZW
25076 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
25077 /* For a BLX instruction, make sure that the relocation is rounded up
25078 to a word boundary. This follows the semantics of the instruction
25079 which specifies that bit 1 of the target address will come from bit
25080 1 of the base address. */
d406f3e4
JB
25081 value = (value + 3) & ~ 3;
25082
25083#ifdef OBJ_ELF
25084 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
25085 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
25086 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
25087#endif
404ff6b5 25088
2b2f5df9
NC
25089 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
25090 {
fc289b0a 25091 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
25092 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
25093 else if ((value & ~0x1ffffff)
25094 && ((value & ~0x1ffffff) != ~0x1ffffff))
25095 as_bad_where (fixP->fx_file, fixP->fx_line,
25096 _("Thumb2 branch out of range"));
25097 }
4a42ebbc
RR
25098
25099 if (fixP->fx_done || !seg->use_rela_p)
25100 encode_thumb2_b_bl_offset (buf, value);
25101
c19d1205 25102 break;
404ff6b5 25103
c19d1205 25104 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
25105 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
25106 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 25107
2fc8bdac 25108 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 25109 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 25110
2fc8bdac 25111 break;
a737bd4d 25112
2fc8bdac
ZW
25113 case BFD_RELOC_8:
25114 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 25115 *buf = value;
c19d1205 25116 break;
a737bd4d 25117
c19d1205 25118 case BFD_RELOC_16:
2fc8bdac 25119 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 25120 md_number_to_chars (buf, value, 2);
c19d1205 25121 break;
a737bd4d 25122
c19d1205 25123#ifdef OBJ_ELF
0855e32b
NS
25124 case BFD_RELOC_ARM_TLS_CALL:
25125 case BFD_RELOC_ARM_THM_TLS_CALL:
25126 case BFD_RELOC_ARM_TLS_DESCSEQ:
25127 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 25128 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
25129 case BFD_RELOC_ARM_TLS_GD32:
25130 case BFD_RELOC_ARM_TLS_LE32:
25131 case BFD_RELOC_ARM_TLS_IE32:
25132 case BFD_RELOC_ARM_TLS_LDM32:
25133 case BFD_RELOC_ARM_TLS_LDO32:
25134 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 25135 break;
6c43fab6 25136
5c5a4843
CL
25137 /* Same handling as above, but with the arm_fdpic guard. */
25138 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
25139 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
25140 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
25141 if (arm_fdpic)
25142 {
25143 S_SET_THREAD_LOCAL (fixP->fx_addsy);
25144 }
25145 else
25146 {
25147 as_bad_where (fixP->fx_file, fixP->fx_line,
25148 _("Relocation supported only in FDPIC mode"));
25149 }
25150 break;
25151
c19d1205
ZW
25152 case BFD_RELOC_ARM_GOT32:
25153 case BFD_RELOC_ARM_GOTOFF:
c19d1205 25154 break;
b43420e6
NC
25155
25156 case BFD_RELOC_ARM_GOT_PREL:
25157 if (fixP->fx_done || !seg->use_rela_p)
477330fc 25158 md_number_to_chars (buf, value, 4);
b43420e6
NC
25159 break;
25160
9a6f4e97
NS
25161 case BFD_RELOC_ARM_TARGET2:
25162 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
25163 addend here for REL targets, because it won't be written out
25164 during reloc processing later. */
9a6f4e97
NS
25165 if (fixP->fx_done || !seg->use_rela_p)
25166 md_number_to_chars (buf, fixP->fx_offset, 4);
25167 break;
188fd7ae
CL
25168
25169 /* Relocations for FDPIC. */
25170 case BFD_RELOC_ARM_GOTFUNCDESC:
25171 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
25172 case BFD_RELOC_ARM_FUNCDESC:
25173 if (arm_fdpic)
25174 {
25175 if (fixP->fx_done || !seg->use_rela_p)
25176 md_number_to_chars (buf, 0, 4);
25177 }
25178 else
25179 {
25180 as_bad_where (fixP->fx_file, fixP->fx_line,
25181 _("Relocation supported only in FDPIC mode"));
25182 }
25183 break;
c19d1205 25184#endif
6c43fab6 25185
c19d1205
ZW
25186 case BFD_RELOC_RVA:
25187 case BFD_RELOC_32:
25188 case BFD_RELOC_ARM_TARGET1:
25189 case BFD_RELOC_ARM_ROSEGREL32:
25190 case BFD_RELOC_ARM_SBREL32:
25191 case BFD_RELOC_32_PCREL:
f0927246
NC
25192#ifdef TE_PE
25193 case BFD_RELOC_32_SECREL:
25194#endif
2fc8bdac 25195 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
25196#ifdef TE_WINCE
25197 /* For WinCE we only do this for pcrel fixups. */
25198 if (fixP->fx_done || fixP->fx_pcrel)
25199#endif
25200 md_number_to_chars (buf, value, 4);
c19d1205 25201 break;
6c43fab6 25202
c19d1205
ZW
25203#ifdef OBJ_ELF
25204 case BFD_RELOC_ARM_PREL31:
2fc8bdac 25205 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
25206 {
25207 newval = md_chars_to_number (buf, 4) & 0x80000000;
25208 if ((value ^ (value >> 1)) & 0x40000000)
25209 {
25210 as_bad_where (fixP->fx_file, fixP->fx_line,
25211 _("rel31 relocation overflow"));
25212 }
25213 newval |= value & 0x7fffffff;
25214 md_number_to_chars (buf, newval, 4);
25215 }
25216 break;
c19d1205 25217#endif
a737bd4d 25218
c19d1205 25219 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 25220 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
32c36c3c 25221 case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM:
9db2f6b4
RL
25222 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
25223 newval = md_chars_to_number (buf, INSN_SIZE);
25224 else
25225 newval = get_thumb32_insn (buf);
25226 if ((newval & 0x0f200f00) == 0x0d000900)
25227 {
25228 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
25229 has permitted values that are multiples of 2, in the range 0
25230 to 510. */
25231 if (value < -510 || value > 510 || (value & 1))
25232 as_bad_where (fixP->fx_file, fixP->fx_line,
25233 _("co-processor offset out of range"));
25234 }
32c36c3c
AV
25235 else if ((newval & 0xfe001f80) == 0xec000f80)
25236 {
25237 if (value < -511 || value > 512 || (value & 3))
25238 as_bad_where (fixP->fx_file, fixP->fx_line,
25239 _("co-processor offset out of range"));
25240 }
9db2f6b4 25241 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
25242 as_bad_where (fixP->fx_file, fixP->fx_line,
25243 _("co-processor offset out of range"));
25244 cp_off_common:
26d97720 25245 sign = value > 0;
c19d1205
ZW
25246 if (value < 0)
25247 value = -value;
8f06b2d8
PB
25248 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
25249 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
25250 newval = md_chars_to_number (buf, INSN_SIZE);
25251 else
25252 newval = get_thumb32_insn (buf);
26d97720 25253 if (value == 0)
32c36c3c
AV
25254 {
25255 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
25256 newval &= 0xffffff80;
25257 else
25258 newval &= 0xffffff00;
25259 }
26d97720
NS
25260 else
25261 {
32c36c3c
AV
25262 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
25263 newval &= 0xff7fff80;
25264 else
25265 newval &= 0xff7fff00;
9db2f6b4
RL
25266 if ((newval & 0x0f200f00) == 0x0d000900)
25267 {
25268 /* This is a fp16 vstr/vldr.
25269
25270 It requires the immediate offset in the instruction is shifted
25271 left by 1 to be a half-word offset.
25272
25273 Here, left shift by 1 first, and later right shift by 2
25274 should get the right offset. */
25275 value <<= 1;
25276 }
26d97720
NS
25277 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
25278 }
8f06b2d8
PB
25279 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
25280 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
25281 md_number_to_chars (buf, newval, INSN_SIZE);
25282 else
25283 put_thumb32_insn (buf, newval);
c19d1205 25284 break;
a737bd4d 25285
c19d1205 25286 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 25287 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
25288 if (value < -255 || value > 255)
25289 as_bad_where (fixP->fx_file, fixP->fx_line,
25290 _("co-processor offset out of range"));
df7849c5 25291 value *= 4;
c19d1205 25292 goto cp_off_common;
6c43fab6 25293
c19d1205
ZW
25294 case BFD_RELOC_ARM_THUMB_OFFSET:
25295 newval = md_chars_to_number (buf, THUMB_SIZE);
25296 /* Exactly what ranges, and where the offset is inserted depends
25297 on the type of instruction, we can establish this from the
25298 top 4 bits. */
25299 switch (newval >> 12)
25300 {
25301 case 4: /* PC load. */
25302 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
25303 forced to zero for these loads; md_pcrel_from has already
25304 compensated for this. */
25305 if (value & 3)
25306 as_bad_where (fixP->fx_file, fixP->fx_line,
25307 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
25308 (((unsigned long) fixP->fx_frag->fr_address
25309 + (unsigned long) fixP->fx_where) & ~3)
25310 + (unsigned long) value);
a737bd4d 25311
c19d1205
ZW
25312 if (value & ~0x3fc)
25313 as_bad_where (fixP->fx_file, fixP->fx_line,
25314 _("invalid offset, value too big (0x%08lX)"),
25315 (long) value);
a737bd4d 25316
c19d1205
ZW
25317 newval |= value >> 2;
25318 break;
a737bd4d 25319
c19d1205
ZW
25320 case 9: /* SP load/store. */
25321 if (value & ~0x3fc)
25322 as_bad_where (fixP->fx_file, fixP->fx_line,
25323 _("invalid offset, value too big (0x%08lX)"),
25324 (long) value);
25325 newval |= value >> 2;
25326 break;
6c43fab6 25327
c19d1205
ZW
25328 case 6: /* Word load/store. */
25329 if (value & ~0x7c)
25330 as_bad_where (fixP->fx_file, fixP->fx_line,
25331 _("invalid offset, value too big (0x%08lX)"),
25332 (long) value);
25333 newval |= value << 4; /* 6 - 2. */
25334 break;
a737bd4d 25335
c19d1205
ZW
25336 case 7: /* Byte load/store. */
25337 if (value & ~0x1f)
25338 as_bad_where (fixP->fx_file, fixP->fx_line,
25339 _("invalid offset, value too big (0x%08lX)"),
25340 (long) value);
25341 newval |= value << 6;
25342 break;
a737bd4d 25343
c19d1205
ZW
25344 case 8: /* Halfword load/store. */
25345 if (value & ~0x3e)
25346 as_bad_where (fixP->fx_file, fixP->fx_line,
25347 _("invalid offset, value too big (0x%08lX)"),
25348 (long) value);
25349 newval |= value << 5; /* 6 - 1. */
25350 break;
a737bd4d 25351
c19d1205
ZW
25352 default:
25353 as_bad_where (fixP->fx_file, fixP->fx_line,
25354 "Unable to process relocation for thumb opcode: %lx",
25355 (unsigned long) newval);
25356 break;
25357 }
25358 md_number_to_chars (buf, newval, THUMB_SIZE);
25359 break;
a737bd4d 25360
c19d1205
ZW
25361 case BFD_RELOC_ARM_THUMB_ADD:
25362 /* This is a complicated relocation, since we use it for all of
25363 the following immediate relocations:
a737bd4d 25364
c19d1205
ZW
25365 3bit ADD/SUB
25366 8bit ADD/SUB
25367 9bit ADD/SUB SP word-aligned
25368 10bit ADD PC/SP word-aligned
a737bd4d 25369
c19d1205
ZW
25370 The type of instruction being processed is encoded in the
25371 instruction field:
a737bd4d 25372
c19d1205
ZW
25373 0x8000 SUB
25374 0x00F0 Rd
25375 0x000F Rs
25376 */
25377 newval = md_chars_to_number (buf, THUMB_SIZE);
25378 {
25379 int rd = (newval >> 4) & 0xf;
25380 int rs = newval & 0xf;
25381 int subtract = !!(newval & 0x8000);
a737bd4d 25382
c19d1205
ZW
25383 /* Check for HI regs, only very restricted cases allowed:
25384 Adjusting SP, and using PC or SP to get an address. */
25385 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
25386 || (rs > 7 && rs != REG_SP && rs != REG_PC))
25387 as_bad_where (fixP->fx_file, fixP->fx_line,
25388 _("invalid Hi register with immediate"));
a737bd4d 25389
c19d1205
ZW
25390 /* If value is negative, choose the opposite instruction. */
25391 if (value < 0)
25392 {
25393 value = -value;
25394 subtract = !subtract;
25395 if (value < 0)
25396 as_bad_where (fixP->fx_file, fixP->fx_line,
25397 _("immediate value out of range"));
25398 }
a737bd4d 25399
c19d1205
ZW
25400 if (rd == REG_SP)
25401 {
75c11999 25402 if (value & ~0x1fc)
c19d1205
ZW
25403 as_bad_where (fixP->fx_file, fixP->fx_line,
25404 _("invalid immediate for stack address calculation"));
25405 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
25406 newval |= value >> 2;
25407 }
25408 else if (rs == REG_PC || rs == REG_SP)
25409 {
c12d2c9d
NC
25410 /* PR gas/18541. If the addition is for a defined symbol
25411 within range of an ADR instruction then accept it. */
25412 if (subtract
25413 && value == 4
25414 && fixP->fx_addsy != NULL)
25415 {
25416 subtract = 0;
25417
25418 if (! S_IS_DEFINED (fixP->fx_addsy)
25419 || S_GET_SEGMENT (fixP->fx_addsy) != seg
25420 || S_IS_WEAK (fixP->fx_addsy))
25421 {
25422 as_bad_where (fixP->fx_file, fixP->fx_line,
25423 _("address calculation needs a strongly defined nearby symbol"));
25424 }
25425 else
25426 {
25427 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
25428
25429 /* Round up to the next 4-byte boundary. */
25430 if (v & 3)
25431 v = (v + 3) & ~ 3;
25432 else
25433 v += 4;
25434 v = S_GET_VALUE (fixP->fx_addsy) - v;
25435
25436 if (v & ~0x3fc)
25437 {
25438 as_bad_where (fixP->fx_file, fixP->fx_line,
25439 _("symbol too far away"));
25440 }
25441 else
25442 {
25443 fixP->fx_done = 1;
25444 value = v;
25445 }
25446 }
25447 }
25448
c19d1205
ZW
25449 if (subtract || value & ~0x3fc)
25450 as_bad_where (fixP->fx_file, fixP->fx_line,
25451 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 25452 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
25453 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
25454 newval |= rd << 8;
25455 newval |= value >> 2;
25456 }
25457 else if (rs == rd)
25458 {
25459 if (value & ~0xff)
25460 as_bad_where (fixP->fx_file, fixP->fx_line,
25461 _("immediate value out of range"));
25462 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
25463 newval |= (rd << 8) | value;
25464 }
25465 else
25466 {
25467 if (value & ~0x7)
25468 as_bad_where (fixP->fx_file, fixP->fx_line,
25469 _("immediate value out of range"));
25470 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
25471 newval |= rd | (rs << 3) | (value << 6);
25472 }
25473 }
25474 md_number_to_chars (buf, newval, THUMB_SIZE);
25475 break;
a737bd4d 25476
c19d1205
ZW
25477 case BFD_RELOC_ARM_THUMB_IMM:
25478 newval = md_chars_to_number (buf, THUMB_SIZE);
25479 if (value < 0 || value > 255)
25480 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 25481 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
25482 (long) value);
25483 newval |= value;
25484 md_number_to_chars (buf, newval, THUMB_SIZE);
25485 break;
a737bd4d 25486
c19d1205
ZW
25487 case BFD_RELOC_ARM_THUMB_SHIFT:
25488 /* 5bit shift value (0..32). LSL cannot take 32. */
25489 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
25490 temp = newval & 0xf800;
25491 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
25492 as_bad_where (fixP->fx_file, fixP->fx_line,
25493 _("invalid shift value: %ld"), (long) value);
25494 /* Shifts of zero must be encoded as LSL. */
25495 if (value == 0)
25496 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
25497 /* Shifts of 32 are encoded as zero. */
25498 else if (value == 32)
25499 value = 0;
25500 newval |= value << 6;
25501 md_number_to_chars (buf, newval, THUMB_SIZE);
25502 break;
a737bd4d 25503
c19d1205
ZW
25504 case BFD_RELOC_VTABLE_INHERIT:
25505 case BFD_RELOC_VTABLE_ENTRY:
25506 fixP->fx_done = 0;
25507 return;
6c43fab6 25508
b6895b4f
PB
25509 case BFD_RELOC_ARM_MOVW:
25510 case BFD_RELOC_ARM_MOVT:
25511 case BFD_RELOC_ARM_THUMB_MOVW:
25512 case BFD_RELOC_ARM_THUMB_MOVT:
25513 if (fixP->fx_done || !seg->use_rela_p)
25514 {
25515 /* REL format relocations are limited to a 16-bit addend. */
25516 if (!fixP->fx_done)
25517 {
39623e12 25518 if (value < -0x8000 || value > 0x7fff)
b6895b4f 25519 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 25520 _("offset out of range"));
b6895b4f
PB
25521 }
25522 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
25523 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
25524 {
25525 value >>= 16;
25526 }
25527
25528 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
25529 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
25530 {
25531 newval = get_thumb32_insn (buf);
25532 newval &= 0xfbf08f00;
25533 newval |= (value & 0xf000) << 4;
25534 newval |= (value & 0x0800) << 15;
25535 newval |= (value & 0x0700) << 4;
25536 newval |= (value & 0x00ff);
25537 put_thumb32_insn (buf, newval);
25538 }
25539 else
25540 {
25541 newval = md_chars_to_number (buf, 4);
25542 newval &= 0xfff0f000;
25543 newval |= value & 0x0fff;
25544 newval |= (value & 0xf000) << 4;
25545 md_number_to_chars (buf, newval, 4);
25546 }
25547 }
25548 return;
25549
72d98d16
MG
25550 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
25551 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
25552 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
25553 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
25554 gas_assert (!fixP->fx_done);
25555 {
25556 bfd_vma insn;
25557 bfd_boolean is_mov;
25558 bfd_vma encoded_addend = value;
25559
25560 /* Check that addend can be encoded in instruction. */
25561 if (!seg->use_rela_p && (value < 0 || value > 255))
25562 as_bad_where (fixP->fx_file, fixP->fx_line,
25563 _("the offset 0x%08lX is not representable"),
25564 (unsigned long) encoded_addend);
25565
25566 /* Extract the instruction. */
25567 insn = md_chars_to_number (buf, THUMB_SIZE);
25568 is_mov = (insn & 0xf800) == 0x2000;
25569
25570 /* Encode insn. */
25571 if (is_mov)
25572 {
25573 if (!seg->use_rela_p)
25574 insn |= encoded_addend;
25575 }
25576 else
25577 {
25578 int rd, rs;
25579
25580 /* Extract the instruction. */
25581 /* Encoding is the following
25582 0x8000 SUB
25583 0x00F0 Rd
25584 0x000F Rs
25585 */
25586 /* The following conditions must be true :
25587 - ADD
25588 - Rd == Rs
25589 - Rd <= 7
25590 */
25591 rd = (insn >> 4) & 0xf;
25592 rs = insn & 0xf;
25593 if ((insn & 0x8000) || (rd != rs) || rd > 7)
25594 as_bad_where (fixP->fx_file, fixP->fx_line,
25595 _("Unable to process relocation for thumb opcode: %lx"),
25596 (unsigned long) insn);
25597
25598 /* Encode as ADD immediate8 thumb 1 code. */
25599 insn = 0x3000 | (rd << 8);
25600
25601 /* Place the encoded addend into the first 8 bits of the
25602 instruction. */
25603 if (!seg->use_rela_p)
25604 insn |= encoded_addend;
25605 }
25606
25607 /* Update the instruction. */
25608 md_number_to_chars (buf, insn, THUMB_SIZE);
25609 }
25610 break;
25611
4962c51a
MS
25612 case BFD_RELOC_ARM_ALU_PC_G0_NC:
25613 case BFD_RELOC_ARM_ALU_PC_G0:
25614 case BFD_RELOC_ARM_ALU_PC_G1_NC:
25615 case BFD_RELOC_ARM_ALU_PC_G1:
25616 case BFD_RELOC_ARM_ALU_PC_G2:
25617 case BFD_RELOC_ARM_ALU_SB_G0_NC:
25618 case BFD_RELOC_ARM_ALU_SB_G0:
25619 case BFD_RELOC_ARM_ALU_SB_G1_NC:
25620 case BFD_RELOC_ARM_ALU_SB_G1:
25621 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 25622 gas_assert (!fixP->fx_done);
4962c51a
MS
25623 if (!seg->use_rela_p)
25624 {
477330fc
RM
25625 bfd_vma insn;
25626 bfd_vma encoded_addend;
3ca4a8ec 25627 bfd_vma addend_abs = llabs (value);
477330fc
RM
25628
25629 /* Check that the absolute value of the addend can be
25630 expressed as an 8-bit constant plus a rotation. */
25631 encoded_addend = encode_arm_immediate (addend_abs);
25632 if (encoded_addend == (unsigned int) FAIL)
4962c51a 25633 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
25634 _("the offset 0x%08lX is not representable"),
25635 (unsigned long) addend_abs);
25636
25637 /* Extract the instruction. */
25638 insn = md_chars_to_number (buf, INSN_SIZE);
25639
25640 /* If the addend is positive, use an ADD instruction.
25641 Otherwise use a SUB. Take care not to destroy the S bit. */
25642 insn &= 0xff1fffff;
25643 if (value < 0)
25644 insn |= 1 << 22;
25645 else
25646 insn |= 1 << 23;
25647
25648 /* Place the encoded addend into the first 12 bits of the
25649 instruction. */
25650 insn &= 0xfffff000;
25651 insn |= encoded_addend;
25652
25653 /* Update the instruction. */
25654 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
25655 }
25656 break;
25657
25658 case BFD_RELOC_ARM_LDR_PC_G0:
25659 case BFD_RELOC_ARM_LDR_PC_G1:
25660 case BFD_RELOC_ARM_LDR_PC_G2:
25661 case BFD_RELOC_ARM_LDR_SB_G0:
25662 case BFD_RELOC_ARM_LDR_SB_G1:
25663 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 25664 gas_assert (!fixP->fx_done);
4962c51a 25665 if (!seg->use_rela_p)
477330fc
RM
25666 {
25667 bfd_vma insn;
3ca4a8ec 25668 bfd_vma addend_abs = llabs (value);
4962c51a 25669
477330fc
RM
25670 /* Check that the absolute value of the addend can be
25671 encoded in 12 bits. */
25672 if (addend_abs >= 0x1000)
4962c51a 25673 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
25674 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
25675 (unsigned long) addend_abs);
25676
25677 /* Extract the instruction. */
25678 insn = md_chars_to_number (buf, INSN_SIZE);
25679
25680 /* If the addend is negative, clear bit 23 of the instruction.
25681 Otherwise set it. */
25682 if (value < 0)
25683 insn &= ~(1 << 23);
25684 else
25685 insn |= 1 << 23;
25686
25687 /* Place the absolute value of the addend into the first 12 bits
25688 of the instruction. */
25689 insn &= 0xfffff000;
25690 insn |= addend_abs;
25691
25692 /* Update the instruction. */
25693 md_number_to_chars (buf, insn, INSN_SIZE);
25694 }
4962c51a
MS
25695 break;
25696
25697 case BFD_RELOC_ARM_LDRS_PC_G0:
25698 case BFD_RELOC_ARM_LDRS_PC_G1:
25699 case BFD_RELOC_ARM_LDRS_PC_G2:
25700 case BFD_RELOC_ARM_LDRS_SB_G0:
25701 case BFD_RELOC_ARM_LDRS_SB_G1:
25702 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 25703 gas_assert (!fixP->fx_done);
4962c51a 25704 if (!seg->use_rela_p)
477330fc
RM
25705 {
25706 bfd_vma insn;
3ca4a8ec 25707 bfd_vma addend_abs = llabs (value);
4962c51a 25708
477330fc
RM
25709 /* Check that the absolute value of the addend can be
25710 encoded in 8 bits. */
25711 if (addend_abs >= 0x100)
4962c51a 25712 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
25713 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
25714 (unsigned long) addend_abs);
25715
25716 /* Extract the instruction. */
25717 insn = md_chars_to_number (buf, INSN_SIZE);
25718
25719 /* If the addend is negative, clear bit 23 of the instruction.
25720 Otherwise set it. */
25721 if (value < 0)
25722 insn &= ~(1 << 23);
25723 else
25724 insn |= 1 << 23;
25725
25726 /* Place the first four bits of the absolute value of the addend
25727 into the first 4 bits of the instruction, and the remaining
25728 four into bits 8 .. 11. */
25729 insn &= 0xfffff0f0;
25730 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
25731
25732 /* Update the instruction. */
25733 md_number_to_chars (buf, insn, INSN_SIZE);
25734 }
4962c51a
MS
25735 break;
25736
25737 case BFD_RELOC_ARM_LDC_PC_G0:
25738 case BFD_RELOC_ARM_LDC_PC_G1:
25739 case BFD_RELOC_ARM_LDC_PC_G2:
25740 case BFD_RELOC_ARM_LDC_SB_G0:
25741 case BFD_RELOC_ARM_LDC_SB_G1:
25742 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 25743 gas_assert (!fixP->fx_done);
4962c51a 25744 if (!seg->use_rela_p)
477330fc
RM
25745 {
25746 bfd_vma insn;
3ca4a8ec 25747 bfd_vma addend_abs = llabs (value);
4962c51a 25748
477330fc
RM
25749 /* Check that the absolute value of the addend is a multiple of
25750 four and, when divided by four, fits in 8 bits. */
25751 if (addend_abs & 0x3)
4962c51a 25752 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
25753 _("bad offset 0x%08lX (must be word-aligned)"),
25754 (unsigned long) addend_abs);
4962c51a 25755
477330fc 25756 if ((addend_abs >> 2) > 0xff)
4962c51a 25757 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
25758 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
25759 (unsigned long) addend_abs);
25760
25761 /* Extract the instruction. */
25762 insn = md_chars_to_number (buf, INSN_SIZE);
25763
25764 /* If the addend is negative, clear bit 23 of the instruction.
25765 Otherwise set it. */
25766 if (value < 0)
25767 insn &= ~(1 << 23);
25768 else
25769 insn |= 1 << 23;
25770
25771 /* Place the addend (divided by four) into the first eight
25772 bits of the instruction. */
25773 insn &= 0xfffffff0;
25774 insn |= addend_abs >> 2;
25775
25776 /* Update the instruction. */
25777 md_number_to_chars (buf, insn, INSN_SIZE);
25778 }
4962c51a
MS
25779 break;
25780
e12437dc
AV
25781 case BFD_RELOC_THUMB_PCREL_BRANCH5:
25782 if (fixP->fx_addsy
25783 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25784 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25785 && ARM_IS_FUNC (fixP->fx_addsy)
25786 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25787 {
25788 /* Force a relocation for a branch 5 bits wide. */
25789 fixP->fx_done = 0;
25790 }
25791 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
25792 as_bad_where (fixP->fx_file, fixP->fx_line,
25793 BAD_BRANCH_OFF);
25794
25795 if (fixP->fx_done || !seg->use_rela_p)
25796 {
25797 addressT boff = value >> 1;
25798
25799 newval = md_chars_to_number (buf, THUMB_SIZE);
25800 newval |= (boff << 7);
25801 md_number_to_chars (buf, newval, THUMB_SIZE);
25802 }
25803 break;
25804
f6b2b12d
AV
25805 case BFD_RELOC_THUMB_PCREL_BFCSEL:
25806 if (fixP->fx_addsy
25807 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25808 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25809 && ARM_IS_FUNC (fixP->fx_addsy)
25810 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25811 {
25812 fixP->fx_done = 0;
25813 }
25814 if ((value & ~0x7f) && ((value & ~0x3f) != ~0x3f))
25815 as_bad_where (fixP->fx_file, fixP->fx_line,
25816 _("branch out of range"));
25817
25818 if (fixP->fx_done || !seg->use_rela_p)
25819 {
25820 newval = md_chars_to_number (buf, THUMB_SIZE);
25821
25822 addressT boff = ((newval & 0x0780) >> 7) << 1;
25823 addressT diff = value - boff;
25824
25825 if (diff == 4)
25826 {
25827 newval |= 1 << 1; /* T bit. */
25828 }
25829 else if (diff != 2)
25830 {
25831 as_bad_where (fixP->fx_file, fixP->fx_line,
25832 _("out of range label-relative fixup value"));
25833 }
25834 md_number_to_chars (buf, newval, THUMB_SIZE);
25835 }
25836 break;
25837
e5d6e09e
AV
25838 case BFD_RELOC_ARM_THUMB_BF17:
25839 if (fixP->fx_addsy
25840 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25841 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25842 && ARM_IS_FUNC (fixP->fx_addsy)
25843 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25844 {
25845 /* Force a relocation for a branch 17 bits wide. */
25846 fixP->fx_done = 0;
25847 }
25848
25849 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
25850 as_bad_where (fixP->fx_file, fixP->fx_line,
25851 BAD_BRANCH_OFF);
25852
25853 if (fixP->fx_done || !seg->use_rela_p)
25854 {
25855 offsetT newval2;
25856 addressT immA, immB, immC;
25857
25858 immA = (value & 0x0001f000) >> 12;
25859 immB = (value & 0x00000ffc) >> 2;
25860 immC = (value & 0x00000002) >> 1;
25861
25862 newval = md_chars_to_number (buf, THUMB_SIZE);
25863 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25864 newval |= immA;
25865 newval2 |= (immC << 11) | (immB << 1);
25866 md_number_to_chars (buf, newval, THUMB_SIZE);
25867 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25868 }
25869 break;
25870
1caf72a5
AV
25871 case BFD_RELOC_ARM_THUMB_BF19:
25872 if (fixP->fx_addsy
25873 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25874 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25875 && ARM_IS_FUNC (fixP->fx_addsy)
25876 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25877 {
25878 /* Force a relocation for a branch 19 bits wide. */
25879 fixP->fx_done = 0;
25880 }
25881
25882 if (v8_1_branch_value_check (value, 19, TRUE) == FAIL)
25883 as_bad_where (fixP->fx_file, fixP->fx_line,
25884 BAD_BRANCH_OFF);
25885
25886 if (fixP->fx_done || !seg->use_rela_p)
25887 {
25888 offsetT newval2;
25889 addressT immA, immB, immC;
25890
25891 immA = (value & 0x0007f000) >> 12;
25892 immB = (value & 0x00000ffc) >> 2;
25893 immC = (value & 0x00000002) >> 1;
25894
25895 newval = md_chars_to_number (buf, THUMB_SIZE);
25896 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25897 newval |= immA;
25898 newval2 |= (immC << 11) | (immB << 1);
25899 md_number_to_chars (buf, newval, THUMB_SIZE);
25900 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25901 }
25902 break;
25903
1889da70
AV
25904 case BFD_RELOC_ARM_THUMB_BF13:
25905 if (fixP->fx_addsy
25906 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25907 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25908 && ARM_IS_FUNC (fixP->fx_addsy)
25909 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25910 {
25911 /* Force a relocation for a branch 13 bits wide. */
25912 fixP->fx_done = 0;
25913 }
25914
25915 if (v8_1_branch_value_check (value, 13, TRUE) == FAIL)
25916 as_bad_where (fixP->fx_file, fixP->fx_line,
25917 BAD_BRANCH_OFF);
25918
25919 if (fixP->fx_done || !seg->use_rela_p)
25920 {
25921 offsetT newval2;
25922 addressT immA, immB, immC;
25923
25924 immA = (value & 0x00001000) >> 12;
25925 immB = (value & 0x00000ffc) >> 2;
25926 immC = (value & 0x00000002) >> 1;
25927
25928 newval = md_chars_to_number (buf, THUMB_SIZE);
25929 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25930 newval |= immA;
25931 newval2 |= (immC << 11) | (immB << 1);
25932 md_number_to_chars (buf, newval, THUMB_SIZE);
25933 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25934 }
25935 break;
25936
60f993ce
AV
25937 case BFD_RELOC_ARM_THUMB_LOOP12:
25938 if (fixP->fx_addsy
25939 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25940 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25941 && ARM_IS_FUNC (fixP->fx_addsy)
25942 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25943 {
25944 /* Force a relocation for a branch 12 bits wide. */
25945 fixP->fx_done = 0;
25946 }
25947
25948 bfd_vma insn = get_thumb32_insn (buf);
25949 /* le lr, <label> or le <label> */
25950 if (((insn & 0xffffffff) == 0xf00fc001)
25951 || ((insn & 0xffffffff) == 0xf02fc001))
25952 value = -value;
25953
25954 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
25955 as_bad_where (fixP->fx_file, fixP->fx_line,
25956 BAD_BRANCH_OFF);
25957 if (fixP->fx_done || !seg->use_rela_p)
25958 {
25959 addressT imml, immh;
25960
25961 immh = (value & 0x00000ffc) >> 2;
25962 imml = (value & 0x00000002) >> 1;
25963
25964 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25965 newval |= (imml << 11) | (immh << 1);
25966 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
25967 }
25968 break;
25969
845b51d6
PB
25970 case BFD_RELOC_ARM_V4BX:
25971 /* This will need to go in the object file. */
25972 fixP->fx_done = 0;
25973 break;
25974
c19d1205
ZW
25975 case BFD_RELOC_UNUSED:
25976 default:
25977 as_bad_where (fixP->fx_file, fixP->fx_line,
25978 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
25979 }
6c43fab6
RE
25980}
25981
c19d1205
ZW
25982/* Translate internal representation of relocation info to BFD target
25983 format. */
a737bd4d 25984
c19d1205 25985arelent *
00a97672 25986tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 25987{
c19d1205
ZW
25988 arelent * reloc;
25989 bfd_reloc_code_real_type code;
a737bd4d 25990
325801bd 25991 reloc = XNEW (arelent);
a737bd4d 25992
325801bd 25993 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
25994 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
25995 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 25996
2fc8bdac 25997 if (fixp->fx_pcrel)
00a97672
RS
25998 {
25999 if (section->use_rela_p)
26000 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
26001 else
26002 fixp->fx_offset = reloc->address;
26003 }
c19d1205 26004 reloc->addend = fixp->fx_offset;
a737bd4d 26005
c19d1205 26006 switch (fixp->fx_r_type)
a737bd4d 26007 {
c19d1205
ZW
26008 case BFD_RELOC_8:
26009 if (fixp->fx_pcrel)
26010 {
26011 code = BFD_RELOC_8_PCREL;
26012 break;
26013 }
1a0670f3 26014 /* Fall through. */
a737bd4d 26015
c19d1205
ZW
26016 case BFD_RELOC_16:
26017 if (fixp->fx_pcrel)
26018 {
26019 code = BFD_RELOC_16_PCREL;
26020 break;
26021 }
1a0670f3 26022 /* Fall through. */
6c43fab6 26023
c19d1205
ZW
26024 case BFD_RELOC_32:
26025 if (fixp->fx_pcrel)
26026 {
26027 code = BFD_RELOC_32_PCREL;
26028 break;
26029 }
1a0670f3 26030 /* Fall through. */
a737bd4d 26031
b6895b4f
PB
26032 case BFD_RELOC_ARM_MOVW:
26033 if (fixp->fx_pcrel)
26034 {
26035 code = BFD_RELOC_ARM_MOVW_PCREL;
26036 break;
26037 }
1a0670f3 26038 /* Fall through. */
b6895b4f
PB
26039
26040 case BFD_RELOC_ARM_MOVT:
26041 if (fixp->fx_pcrel)
26042 {
26043 code = BFD_RELOC_ARM_MOVT_PCREL;
26044 break;
26045 }
1a0670f3 26046 /* Fall through. */
b6895b4f
PB
26047
26048 case BFD_RELOC_ARM_THUMB_MOVW:
26049 if (fixp->fx_pcrel)
26050 {
26051 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
26052 break;
26053 }
1a0670f3 26054 /* Fall through. */
b6895b4f
PB
26055
26056 case BFD_RELOC_ARM_THUMB_MOVT:
26057 if (fixp->fx_pcrel)
26058 {
26059 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
26060 break;
26061 }
1a0670f3 26062 /* Fall through. */
b6895b4f 26063
c19d1205
ZW
26064 case BFD_RELOC_NONE:
26065 case BFD_RELOC_ARM_PCREL_BRANCH:
26066 case BFD_RELOC_ARM_PCREL_BLX:
26067 case BFD_RELOC_RVA:
26068 case BFD_RELOC_THUMB_PCREL_BRANCH7:
26069 case BFD_RELOC_THUMB_PCREL_BRANCH9:
26070 case BFD_RELOC_THUMB_PCREL_BRANCH12:
26071 case BFD_RELOC_THUMB_PCREL_BRANCH20:
26072 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26073 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
26074 case BFD_RELOC_VTABLE_ENTRY:
26075 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
26076#ifdef TE_PE
26077 case BFD_RELOC_32_SECREL:
26078#endif
c19d1205
ZW
26079 code = fixp->fx_r_type;
26080 break;
a737bd4d 26081
00adf2d4
JB
26082 case BFD_RELOC_THUMB_PCREL_BLX:
26083#ifdef OBJ_ELF
26084 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
26085 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
26086 else
26087#endif
26088 code = BFD_RELOC_THUMB_PCREL_BLX;
26089 break;
26090
c19d1205
ZW
26091 case BFD_RELOC_ARM_LITERAL:
26092 case BFD_RELOC_ARM_HWLITERAL:
26093 /* If this is called then the a literal has
26094 been referenced across a section boundary. */
26095 as_bad_where (fixp->fx_file, fixp->fx_line,
26096 _("literal referenced across section boundary"));
26097 return NULL;
a737bd4d 26098
c19d1205 26099#ifdef OBJ_ELF
0855e32b
NS
26100 case BFD_RELOC_ARM_TLS_CALL:
26101 case BFD_RELOC_ARM_THM_TLS_CALL:
26102 case BFD_RELOC_ARM_TLS_DESCSEQ:
26103 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
26104 case BFD_RELOC_ARM_GOT32:
26105 case BFD_RELOC_ARM_GOTOFF:
b43420e6 26106 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
26107 case BFD_RELOC_ARM_PLT32:
26108 case BFD_RELOC_ARM_TARGET1:
26109 case BFD_RELOC_ARM_ROSEGREL32:
26110 case BFD_RELOC_ARM_SBREL32:
26111 case BFD_RELOC_ARM_PREL31:
26112 case BFD_RELOC_ARM_TARGET2:
c19d1205 26113 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
26114 case BFD_RELOC_ARM_PCREL_CALL:
26115 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
26116 case BFD_RELOC_ARM_ALU_PC_G0_NC:
26117 case BFD_RELOC_ARM_ALU_PC_G0:
26118 case BFD_RELOC_ARM_ALU_PC_G1_NC:
26119 case BFD_RELOC_ARM_ALU_PC_G1:
26120 case BFD_RELOC_ARM_ALU_PC_G2:
26121 case BFD_RELOC_ARM_LDR_PC_G0:
26122 case BFD_RELOC_ARM_LDR_PC_G1:
26123 case BFD_RELOC_ARM_LDR_PC_G2:
26124 case BFD_RELOC_ARM_LDRS_PC_G0:
26125 case BFD_RELOC_ARM_LDRS_PC_G1:
26126 case BFD_RELOC_ARM_LDRS_PC_G2:
26127 case BFD_RELOC_ARM_LDC_PC_G0:
26128 case BFD_RELOC_ARM_LDC_PC_G1:
26129 case BFD_RELOC_ARM_LDC_PC_G2:
26130 case BFD_RELOC_ARM_ALU_SB_G0_NC:
26131 case BFD_RELOC_ARM_ALU_SB_G0:
26132 case BFD_RELOC_ARM_ALU_SB_G1_NC:
26133 case BFD_RELOC_ARM_ALU_SB_G1:
26134 case BFD_RELOC_ARM_ALU_SB_G2:
26135 case BFD_RELOC_ARM_LDR_SB_G0:
26136 case BFD_RELOC_ARM_LDR_SB_G1:
26137 case BFD_RELOC_ARM_LDR_SB_G2:
26138 case BFD_RELOC_ARM_LDRS_SB_G0:
26139 case BFD_RELOC_ARM_LDRS_SB_G1:
26140 case BFD_RELOC_ARM_LDRS_SB_G2:
26141 case BFD_RELOC_ARM_LDC_SB_G0:
26142 case BFD_RELOC_ARM_LDC_SB_G1:
26143 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 26144 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
26145 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
26146 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
26147 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
26148 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
188fd7ae
CL
26149 case BFD_RELOC_ARM_GOTFUNCDESC:
26150 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
26151 case BFD_RELOC_ARM_FUNCDESC:
e5d6e09e 26152 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 26153 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 26154 case BFD_RELOC_ARM_THUMB_BF13:
c19d1205
ZW
26155 code = fixp->fx_r_type;
26156 break;
a737bd4d 26157
0855e32b 26158 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 26159 case BFD_RELOC_ARM_TLS_GD32:
5c5a4843 26160 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
75c11999 26161 case BFD_RELOC_ARM_TLS_LE32:
c19d1205 26162 case BFD_RELOC_ARM_TLS_IE32:
5c5a4843 26163 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
c19d1205 26164 case BFD_RELOC_ARM_TLS_LDM32:
5c5a4843 26165 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
c19d1205
ZW
26166 /* BFD will include the symbol's address in the addend.
26167 But we don't want that, so subtract it out again here. */
26168 if (!S_IS_COMMON (fixp->fx_addsy))
26169 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
26170 code = fixp->fx_r_type;
26171 break;
26172#endif
a737bd4d 26173
c19d1205
ZW
26174 case BFD_RELOC_ARM_IMMEDIATE:
26175 as_bad_where (fixp->fx_file, fixp->fx_line,
26176 _("internal relocation (type: IMMEDIATE) not fixed up"));
26177 return NULL;
a737bd4d 26178
c19d1205
ZW
26179 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
26180 as_bad_where (fixp->fx_file, fixp->fx_line,
26181 _("ADRL used for a symbol not defined in the same file"));
26182 return NULL;
a737bd4d 26183
e12437dc 26184 case BFD_RELOC_THUMB_PCREL_BRANCH5:
f6b2b12d 26185 case BFD_RELOC_THUMB_PCREL_BFCSEL:
60f993ce 26186 case BFD_RELOC_ARM_THUMB_LOOP12:
e12437dc
AV
26187 as_bad_where (fixp->fx_file, fixp->fx_line,
26188 _("%s used for a symbol not defined in the same file"),
26189 bfd_get_reloc_code_name (fixp->fx_r_type));
26190 return NULL;
26191
c19d1205 26192 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
26193 if (section->use_rela_p)
26194 {
26195 code = fixp->fx_r_type;
26196 break;
26197 }
26198
c19d1205
ZW
26199 if (fixp->fx_addsy != NULL
26200 && !S_IS_DEFINED (fixp->fx_addsy)
26201 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 26202 {
c19d1205
ZW
26203 as_bad_where (fixp->fx_file, fixp->fx_line,
26204 _("undefined local label `%s'"),
26205 S_GET_NAME (fixp->fx_addsy));
26206 return NULL;
a737bd4d
NC
26207 }
26208
c19d1205
ZW
26209 as_bad_where (fixp->fx_file, fixp->fx_line,
26210 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
26211 return NULL;
a737bd4d 26212
c19d1205
ZW
26213 default:
26214 {
e0471c16 26215 const char * type;
6c43fab6 26216
c19d1205
ZW
26217 switch (fixp->fx_r_type)
26218 {
26219 case BFD_RELOC_NONE: type = "NONE"; break;
26220 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
26221 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 26222 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
26223 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
26224 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
26225 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 26226 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 26227 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
26228 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
26229 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
26230 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
26231 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
26232 default: type = _("<unknown>"); break;
26233 }
26234 as_bad_where (fixp->fx_file, fixp->fx_line,
26235 _("cannot represent %s relocation in this object file format"),
26236 type);
26237 return NULL;
26238 }
a737bd4d 26239 }
6c43fab6 26240
c19d1205
ZW
26241#ifdef OBJ_ELF
26242 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
26243 && GOT_symbol
26244 && fixp->fx_addsy == GOT_symbol)
26245 {
26246 code = BFD_RELOC_ARM_GOTPC;
26247 reloc->addend = fixp->fx_offset = reloc->address;
26248 }
26249#endif
6c43fab6 26250
c19d1205 26251 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 26252
c19d1205
ZW
26253 if (reloc->howto == NULL)
26254 {
26255 as_bad_where (fixp->fx_file, fixp->fx_line,
26256 _("cannot represent %s relocation in this object file format"),
26257 bfd_get_reloc_code_name (code));
26258 return NULL;
26259 }
6c43fab6 26260
c19d1205
ZW
26261 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
26262 vtable entry to be used in the relocation's section offset. */
26263 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
26264 reloc->address = fixp->fx_offset;
6c43fab6 26265
c19d1205 26266 return reloc;
6c43fab6
RE
26267}
26268
c19d1205 26269/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 26270
c19d1205
ZW
26271void
26272cons_fix_new_arm (fragS * frag,
26273 int where,
26274 int size,
62ebcb5c
AM
26275 expressionS * exp,
26276 bfd_reloc_code_real_type reloc)
6c43fab6 26277{
c19d1205 26278 int pcrel = 0;
6c43fab6 26279
c19d1205
ZW
26280 /* Pick a reloc.
26281 FIXME: @@ Should look at CPU word size. */
26282 switch (size)
26283 {
26284 case 1:
62ebcb5c 26285 reloc = BFD_RELOC_8;
c19d1205
ZW
26286 break;
26287 case 2:
62ebcb5c 26288 reloc = BFD_RELOC_16;
c19d1205
ZW
26289 break;
26290 case 4:
26291 default:
62ebcb5c 26292 reloc = BFD_RELOC_32;
c19d1205
ZW
26293 break;
26294 case 8:
62ebcb5c 26295 reloc = BFD_RELOC_64;
c19d1205
ZW
26296 break;
26297 }
6c43fab6 26298
f0927246
NC
26299#ifdef TE_PE
26300 if (exp->X_op == O_secrel)
26301 {
26302 exp->X_op = O_symbol;
62ebcb5c 26303 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
26304 }
26305#endif
26306
62ebcb5c 26307 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 26308}
6c43fab6 26309
4343666d 26310#if defined (OBJ_COFF)
c19d1205
ZW
26311void
26312arm_validate_fix (fixS * fixP)
6c43fab6 26313{
c19d1205
ZW
26314 /* If the destination of the branch is a defined symbol which does not have
26315 the THUMB_FUNC attribute, then we must be calling a function which has
26316 the (interfacearm) attribute. We look for the Thumb entry point to that
26317 function and change the branch to refer to that function instead. */
26318 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
26319 && fixP->fx_addsy != NULL
26320 && S_IS_DEFINED (fixP->fx_addsy)
26321 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 26322 {
c19d1205 26323 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 26324 }
c19d1205
ZW
26325}
26326#endif
6c43fab6 26327
267bf995 26328
c19d1205
ZW
26329int
26330arm_force_relocation (struct fix * fixp)
26331{
26332#if defined (OBJ_COFF) && defined (TE_PE)
26333 if (fixp->fx_r_type == BFD_RELOC_RVA)
26334 return 1;
26335#endif
6c43fab6 26336
267bf995
RR
26337 /* In case we have a call or a branch to a function in ARM ISA mode from
26338 a thumb function or vice-versa force the relocation. These relocations
26339 are cleared off for some cores that might have blx and simple transformations
26340 are possible. */
26341
26342#ifdef OBJ_ELF
26343 switch (fixp->fx_r_type)
26344 {
26345 case BFD_RELOC_ARM_PCREL_JUMP:
26346 case BFD_RELOC_ARM_PCREL_CALL:
26347 case BFD_RELOC_THUMB_PCREL_BLX:
26348 if (THUMB_IS_FUNC (fixp->fx_addsy))
26349 return 1;
26350 break;
26351
26352 case BFD_RELOC_ARM_PCREL_BLX:
26353 case BFD_RELOC_THUMB_PCREL_BRANCH25:
26354 case BFD_RELOC_THUMB_PCREL_BRANCH20:
26355 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26356 if (ARM_IS_FUNC (fixp->fx_addsy))
26357 return 1;
26358 break;
26359
26360 default:
26361 break;
26362 }
26363#endif
26364
b5884301
PB
26365 /* Resolve these relocations even if the symbol is extern or weak.
26366 Technically this is probably wrong due to symbol preemption.
26367 In practice these relocations do not have enough range to be useful
26368 at dynamic link time, and some code (e.g. in the Linux kernel)
26369 expects these references to be resolved. */
c19d1205
ZW
26370 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
26371 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 26372 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 26373 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
26374 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
26375 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
26376 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 26377 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
26378 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
26379 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
26380 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
26381 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
26382 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
26383 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 26384 return 0;
a737bd4d 26385
4962c51a
MS
26386 /* Always leave these relocations for the linker. */
26387 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
26388 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
26389 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
26390 return 1;
26391
f0291e4c
PB
26392 /* Always generate relocations against function symbols. */
26393 if (fixp->fx_r_type == BFD_RELOC_32
26394 && fixp->fx_addsy
26395 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
26396 return 1;
26397
c19d1205 26398 return generic_force_reloc (fixp);
404ff6b5
AH
26399}
26400
0ffdc86c 26401#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
26402/* Relocations against function names must be left unadjusted,
26403 so that the linker can use this information to generate interworking
26404 stubs. The MIPS version of this function
c19d1205
ZW
26405 also prevents relocations that are mips-16 specific, but I do not
26406 know why it does this.
404ff6b5 26407
c19d1205
ZW
26408 FIXME:
26409 There is one other problem that ought to be addressed here, but
26410 which currently is not: Taking the address of a label (rather
26411 than a function) and then later jumping to that address. Such
26412 addresses also ought to have their bottom bit set (assuming that
26413 they reside in Thumb code), but at the moment they will not. */
404ff6b5 26414
c19d1205
ZW
26415bfd_boolean
26416arm_fix_adjustable (fixS * fixP)
404ff6b5 26417{
c19d1205
ZW
26418 if (fixP->fx_addsy == NULL)
26419 return 1;
404ff6b5 26420
e28387c3
PB
26421 /* Preserve relocations against symbols with function type. */
26422 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 26423 return FALSE;
e28387c3 26424
c19d1205
ZW
26425 if (THUMB_IS_FUNC (fixP->fx_addsy)
26426 && fixP->fx_subsy == NULL)
c921be7d 26427 return FALSE;
a737bd4d 26428
c19d1205
ZW
26429 /* We need the symbol name for the VTABLE entries. */
26430 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
26431 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 26432 return FALSE;
404ff6b5 26433
c19d1205
ZW
26434 /* Don't allow symbols to be discarded on GOT related relocs. */
26435 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
26436 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
26437 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
26438 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
5c5a4843 26439 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
c19d1205
ZW
26440 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
26441 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
5c5a4843 26442 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
c19d1205 26443 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
5c5a4843 26444 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
c19d1205 26445 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
26446 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
26447 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
26448 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
26449 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
26450 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 26451 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 26452 return FALSE;
a737bd4d 26453
4962c51a
MS
26454 /* Similarly for group relocations. */
26455 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
26456 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
26457 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 26458 return FALSE;
4962c51a 26459
79947c54
CD
26460 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
26461 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
26462 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
26463 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
26464 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
26465 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
26466 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
26467 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
26468 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 26469 return FALSE;
79947c54 26470
72d98d16
MG
26471 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
26472 offsets, so keep these symbols. */
26473 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
26474 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
26475 return FALSE;
26476
c921be7d 26477 return TRUE;
a737bd4d 26478}
0ffdc86c
NC
26479#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
26480
26481#ifdef OBJ_ELF
c19d1205
ZW
26482const char *
26483elf32_arm_target_format (void)
404ff6b5 26484{
c19d1205
ZW
26485#ifdef TE_SYMBIAN
26486 return (target_big_endian
26487 ? "elf32-bigarm-symbian"
26488 : "elf32-littlearm-symbian");
26489#elif defined (TE_VXWORKS)
26490 return (target_big_endian
26491 ? "elf32-bigarm-vxworks"
26492 : "elf32-littlearm-vxworks");
b38cadfb
NC
26493#elif defined (TE_NACL)
26494 return (target_big_endian
26495 ? "elf32-bigarm-nacl"
26496 : "elf32-littlearm-nacl");
c19d1205 26497#else
18a20338
CL
26498 if (arm_fdpic)
26499 {
26500 if (target_big_endian)
26501 return "elf32-bigarm-fdpic";
26502 else
26503 return "elf32-littlearm-fdpic";
26504 }
c19d1205 26505 else
18a20338
CL
26506 {
26507 if (target_big_endian)
26508 return "elf32-bigarm";
26509 else
26510 return "elf32-littlearm";
26511 }
c19d1205 26512#endif
404ff6b5
AH
26513}
26514
c19d1205
ZW
26515void
26516armelf_frob_symbol (symbolS * symp,
26517 int * puntp)
404ff6b5 26518{
c19d1205
ZW
26519 elf_frob_symbol (symp, puntp);
26520}
26521#endif
404ff6b5 26522
c19d1205 26523/* MD interface: Finalization. */
a737bd4d 26524
c19d1205
ZW
26525void
26526arm_cleanup (void)
26527{
26528 literal_pool * pool;
a737bd4d 26529
5ee91343
AV
26530 /* Ensure that all the predication blocks are properly closed. */
26531 check_pred_blocks_finished ();
e07e6e58 26532
c19d1205
ZW
26533 for (pool = list_of_pools; pool; pool = pool->next)
26534 {
5f4273c7 26535 /* Put it at the end of the relevant section. */
c19d1205
ZW
26536 subseg_set (pool->section, pool->sub_section);
26537#ifdef OBJ_ELF
26538 arm_elf_change_section ();
26539#endif
26540 s_ltorg (0);
26541 }
404ff6b5
AH
26542}
26543
cd000bff
DJ
26544#ifdef OBJ_ELF
26545/* Remove any excess mapping symbols generated for alignment frags in
26546 SEC. We may have created a mapping symbol before a zero byte
26547 alignment; remove it if there's a mapping symbol after the
26548 alignment. */
26549static void
26550check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
26551 void *dummy ATTRIBUTE_UNUSED)
26552{
26553 segment_info_type *seginfo = seg_info (sec);
26554 fragS *fragp;
26555
26556 if (seginfo == NULL || seginfo->frchainP == NULL)
26557 return;
26558
26559 for (fragp = seginfo->frchainP->frch_root;
26560 fragp != NULL;
26561 fragp = fragp->fr_next)
26562 {
26563 symbolS *sym = fragp->tc_frag_data.last_map;
26564 fragS *next = fragp->fr_next;
26565
26566 /* Variable-sized frags have been converted to fixed size by
26567 this point. But if this was variable-sized to start with,
26568 there will be a fixed-size frag after it. So don't handle
26569 next == NULL. */
26570 if (sym == NULL || next == NULL)
26571 continue;
26572
26573 if (S_GET_VALUE (sym) < next->fr_address)
26574 /* Not at the end of this frag. */
26575 continue;
26576 know (S_GET_VALUE (sym) == next->fr_address);
26577
26578 do
26579 {
26580 if (next->tc_frag_data.first_map != NULL)
26581 {
26582 /* Next frag starts with a mapping symbol. Discard this
26583 one. */
26584 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
26585 break;
26586 }
26587
26588 if (next->fr_next == NULL)
26589 {
26590 /* This mapping symbol is at the end of the section. Discard
26591 it. */
26592 know (next->fr_fix == 0 && next->fr_var == 0);
26593 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
26594 break;
26595 }
26596
26597 /* As long as we have empty frags without any mapping symbols,
26598 keep looking. */
26599 /* If the next frag is non-empty and does not start with a
26600 mapping symbol, then this mapping symbol is required. */
26601 if (next->fr_address != next->fr_next->fr_address)
26602 break;
26603
26604 next = next->fr_next;
26605 }
26606 while (next != NULL);
26607 }
26608}
26609#endif
26610
c19d1205
ZW
26611/* Adjust the symbol table. This marks Thumb symbols as distinct from
26612 ARM ones. */
404ff6b5 26613
c19d1205
ZW
26614void
26615arm_adjust_symtab (void)
404ff6b5 26616{
c19d1205
ZW
26617#ifdef OBJ_COFF
26618 symbolS * sym;
404ff6b5 26619
c19d1205
ZW
26620 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
26621 {
26622 if (ARM_IS_THUMB (sym))
26623 {
26624 if (THUMB_IS_FUNC (sym))
26625 {
26626 /* Mark the symbol as a Thumb function. */
26627 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
26628 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
26629 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 26630
c19d1205
ZW
26631 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
26632 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
26633 else
26634 as_bad (_("%s: unexpected function type: %d"),
26635 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
26636 }
26637 else switch (S_GET_STORAGE_CLASS (sym))
26638 {
26639 case C_EXT:
26640 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
26641 break;
26642 case C_STAT:
26643 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
26644 break;
26645 case C_LABEL:
26646 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
26647 break;
26648 default:
26649 /* Do nothing. */
26650 break;
26651 }
26652 }
a737bd4d 26653
c19d1205
ZW
26654 if (ARM_IS_INTERWORK (sym))
26655 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 26656 }
c19d1205
ZW
26657#endif
26658#ifdef OBJ_ELF
26659 symbolS * sym;
26660 char bind;
404ff6b5 26661
c19d1205 26662 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 26663 {
c19d1205
ZW
26664 if (ARM_IS_THUMB (sym))
26665 {
26666 elf_symbol_type * elf_sym;
404ff6b5 26667
c19d1205
ZW
26668 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
26669 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 26670
b0796911
PB
26671 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
26672 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
26673 {
26674 /* If it's a .thumb_func, declare it as so,
26675 otherwise tag label as .code 16. */
26676 if (THUMB_IS_FUNC (sym))
39d911fc
TP
26677 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
26678 ST_BRANCH_TO_THUMB);
3ba67470 26679 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
26680 elf_sym->internal_elf_sym.st_info =
26681 ELF_ST_INFO (bind, STT_ARM_16BIT);
26682 }
26683 }
26684 }
cd000bff
DJ
26685
26686 /* Remove any overlapping mapping symbols generated by alignment frags. */
26687 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
26688 /* Now do generic ELF adjustments. */
26689 elf_adjust_symtab ();
c19d1205 26690#endif
404ff6b5
AH
26691}
26692
c19d1205 26693/* MD interface: Initialization. */
404ff6b5 26694
a737bd4d 26695static void
c19d1205 26696set_constant_flonums (void)
a737bd4d 26697{
c19d1205 26698 int i;
404ff6b5 26699
c19d1205
ZW
26700 for (i = 0; i < NUM_FLOAT_VALS; i++)
26701 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
26702 abort ();
a737bd4d 26703}
404ff6b5 26704
3e9e4fcf
JB
26705/* Auto-select Thumb mode if it's the only available instruction set for the
26706 given architecture. */
26707
26708static void
26709autoselect_thumb_from_cpu_variant (void)
26710{
26711 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
26712 opcode_select (16);
26713}
26714
c19d1205
ZW
26715void
26716md_begin (void)
a737bd4d 26717{
c19d1205
ZW
26718 unsigned mach;
26719 unsigned int i;
404ff6b5 26720
c19d1205
ZW
26721 if ( (arm_ops_hsh = hash_new ()) == NULL
26722 || (arm_cond_hsh = hash_new ()) == NULL
5ee91343 26723 || (arm_vcond_hsh = hash_new ()) == NULL
c19d1205
ZW
26724 || (arm_shift_hsh = hash_new ()) == NULL
26725 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 26726 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 26727 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
26728 || (arm_reloc_hsh = hash_new ()) == NULL
26729 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
26730 as_fatal (_("virtual memory exhausted"));
26731
26732 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 26733 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 26734 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 26735 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
5ee91343
AV
26736 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
26737 hash_insert (arm_vcond_hsh, vconds[i].template_name, (void *) (vconds + i));
c19d1205 26738 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 26739 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 26740 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 26741 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 26742 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 26743 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 26744 (void *) (v7m_psrs + i));
c19d1205 26745 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 26746 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
26747 for (i = 0;
26748 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
26749 i++)
d3ce72d0 26750 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 26751 (void *) (barrier_opt_names + i));
c19d1205 26752#ifdef OBJ_ELF
3da1d841
NC
26753 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
26754 {
26755 struct reloc_entry * entry = reloc_names + i;
26756
26757 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
26758 /* This makes encode_branch() use the EABI versions of this relocation. */
26759 entry->reloc = BFD_RELOC_UNUSED;
26760
26761 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
26762 }
c19d1205
ZW
26763#endif
26764
26765 set_constant_flonums ();
404ff6b5 26766
c19d1205
ZW
26767 /* Set the cpu variant based on the command-line options. We prefer
26768 -mcpu= over -march= if both are set (as for GCC); and we prefer
26769 -mfpu= over any other way of setting the floating point unit.
26770 Use of legacy options with new options are faulted. */
e74cfd16 26771 if (legacy_cpu)
404ff6b5 26772 {
e74cfd16 26773 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
26774 as_bad (_("use of old and new-style options to set CPU type"));
26775
4d354d8b 26776 selected_arch = *legacy_cpu;
404ff6b5 26777 }
4d354d8b
TP
26778 else if (mcpu_cpu_opt)
26779 {
26780 selected_arch = *mcpu_cpu_opt;
26781 selected_ext = *mcpu_ext_opt;
26782 }
26783 else if (march_cpu_opt)
c168ce07 26784 {
4d354d8b
TP
26785 selected_arch = *march_cpu_opt;
26786 selected_ext = *march_ext_opt;
c168ce07 26787 }
4d354d8b 26788 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
404ff6b5 26789
e74cfd16 26790 if (legacy_fpu)
c19d1205 26791 {
e74cfd16 26792 if (mfpu_opt)
c19d1205 26793 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f 26794
4d354d8b 26795 selected_fpu = *legacy_fpu;
03b1477f 26796 }
4d354d8b
TP
26797 else if (mfpu_opt)
26798 selected_fpu = *mfpu_opt;
26799 else
03b1477f 26800 {
45eb4c1b
NS
26801#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
26802 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
26803 /* Some environments specify a default FPU. If they don't, infer it
26804 from the processor. */
e74cfd16 26805 if (mcpu_fpu_opt)
4d354d8b 26806 selected_fpu = *mcpu_fpu_opt;
e7da50fa 26807 else if (march_fpu_opt)
4d354d8b 26808 selected_fpu = *march_fpu_opt;
39c2da32 26809#else
4d354d8b 26810 selected_fpu = fpu_default;
39c2da32 26811#endif
03b1477f
RE
26812 }
26813
4d354d8b 26814 if (ARM_FEATURE_ZERO (selected_fpu))
03b1477f 26815 {
4d354d8b
TP
26816 if (!no_cpu_selected ())
26817 selected_fpu = fpu_default;
03b1477f 26818 else
4d354d8b 26819 selected_fpu = fpu_arch_fpa;
03b1477f
RE
26820 }
26821
ee065d83 26822#ifdef CPU_DEFAULT
4d354d8b 26823 if (ARM_FEATURE_ZERO (selected_arch))
ee065d83 26824 {
4d354d8b
TP
26825 selected_arch = cpu_default;
26826 selected_cpu = selected_arch;
ee065d83 26827 }
4d354d8b 26828 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
e74cfd16 26829#else
4d354d8b
TP
26830 /* Autodection of feature mode: allow all features in cpu_variant but leave
26831 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
26832 after all instruction have been processed and we can decide what CPU
26833 should be selected. */
26834 if (ARM_FEATURE_ZERO (selected_arch))
26835 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
ee065d83 26836 else
4d354d8b 26837 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83 26838#endif
03b1477f 26839
3e9e4fcf
JB
26840 autoselect_thumb_from_cpu_variant ();
26841
e74cfd16 26842 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 26843
f17c130b 26844#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 26845 {
7cc69913
NC
26846 unsigned int flags = 0;
26847
26848#if defined OBJ_ELF
26849 flags = meabi_flags;
d507cf36
PB
26850
26851 switch (meabi_flags)
33a392fb 26852 {
d507cf36 26853 case EF_ARM_EABI_UNKNOWN:
7cc69913 26854#endif
d507cf36
PB
26855 /* Set the flags in the private structure. */
26856 if (uses_apcs_26) flags |= F_APCS26;
26857 if (support_interwork) flags |= F_INTERWORK;
26858 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 26859 if (pic_code) flags |= F_PIC;
e74cfd16 26860 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
26861 flags |= F_SOFT_FLOAT;
26862
d507cf36
PB
26863 switch (mfloat_abi_opt)
26864 {
26865 case ARM_FLOAT_ABI_SOFT:
26866 case ARM_FLOAT_ABI_SOFTFP:
26867 flags |= F_SOFT_FLOAT;
26868 break;
33a392fb 26869
d507cf36
PB
26870 case ARM_FLOAT_ABI_HARD:
26871 if (flags & F_SOFT_FLOAT)
26872 as_bad (_("hard-float conflicts with specified fpu"));
26873 break;
26874 }
03b1477f 26875
e74cfd16
PB
26876 /* Using pure-endian doubles (even if soft-float). */
26877 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 26878 flags |= F_VFP_FLOAT;
f17c130b 26879
fde78edd 26880#if defined OBJ_ELF
e74cfd16 26881 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 26882 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
26883 break;
26884
8cb51566 26885 case EF_ARM_EABI_VER4:
3a4a14e9 26886 case EF_ARM_EABI_VER5:
c19d1205 26887 /* No additional flags to set. */
d507cf36
PB
26888 break;
26889
26890 default:
26891 abort ();
26892 }
7cc69913 26893#endif
b99bd4ef
NC
26894 bfd_set_private_flags (stdoutput, flags);
26895
26896 /* We have run out flags in the COFF header to encode the
26897 status of ATPCS support, so instead we create a dummy,
c19d1205 26898 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
26899 if (atpcs)
26900 {
26901 asection * sec;
26902
26903 sec = bfd_make_section (stdoutput, ".arm.atpcs");
26904
26905 if (sec != NULL)
26906 {
26907 bfd_set_section_flags
26908 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
26909 bfd_set_section_size (stdoutput, sec, 0);
26910 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
26911 }
26912 }
7cc69913 26913 }
f17c130b 26914#endif
b99bd4ef
NC
26915
26916 /* Record the CPU type as well. */
2d447fca
JM
26917 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
26918 mach = bfd_mach_arm_iWMMXt2;
26919 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 26920 mach = bfd_mach_arm_iWMMXt;
e74cfd16 26921 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 26922 mach = bfd_mach_arm_XScale;
e74cfd16 26923 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 26924 mach = bfd_mach_arm_ep9312;
e74cfd16 26925 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 26926 mach = bfd_mach_arm_5TE;
e74cfd16 26927 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 26928 {
e74cfd16 26929 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
26930 mach = bfd_mach_arm_5T;
26931 else
26932 mach = bfd_mach_arm_5;
26933 }
e74cfd16 26934 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 26935 {
e74cfd16 26936 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
26937 mach = bfd_mach_arm_4T;
26938 else
26939 mach = bfd_mach_arm_4;
26940 }
e74cfd16 26941 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 26942 mach = bfd_mach_arm_3M;
e74cfd16
PB
26943 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
26944 mach = bfd_mach_arm_3;
26945 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
26946 mach = bfd_mach_arm_2a;
26947 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
26948 mach = bfd_mach_arm_2;
26949 else
26950 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
26951
26952 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
26953}
26954
c19d1205 26955/* Command line processing. */
b99bd4ef 26956
c19d1205
ZW
26957/* md_parse_option
26958 Invocation line includes a switch not recognized by the base assembler.
26959 See if it's a processor-specific option.
b99bd4ef 26960
c19d1205
ZW
26961 This routine is somewhat complicated by the need for backwards
26962 compatibility (since older releases of gcc can't be changed).
26963 The new options try to make the interface as compatible as
26964 possible with GCC.
b99bd4ef 26965
c19d1205 26966 New options (supported) are:
b99bd4ef 26967
c19d1205
ZW
26968 -mcpu=<cpu name> Assemble for selected processor
26969 -march=<architecture name> Assemble for selected architecture
26970 -mfpu=<fpu architecture> Assemble for selected FPU.
26971 -EB/-mbig-endian Big-endian
26972 -EL/-mlittle-endian Little-endian
26973 -k Generate PIC code
26974 -mthumb Start in Thumb mode
26975 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 26976
278df34e 26977 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 26978 -m[no-]warn-syms Warn when symbols match instructions
267bf995 26979
c19d1205 26980 For now we will also provide support for:
b99bd4ef 26981
c19d1205
ZW
26982 -mapcs-32 32-bit Program counter
26983 -mapcs-26 26-bit Program counter
26984 -macps-float Floats passed in FP registers
26985 -mapcs-reentrant Reentrant code
26986 -matpcs
26987 (sometime these will probably be replaced with -mapcs=<list of options>
26988 and -matpcs=<list of options>)
b99bd4ef 26989
c19d1205
ZW
26990 The remaining options are only supported for back-wards compatibility.
26991 Cpu variants, the arm part is optional:
26992 -m[arm]1 Currently not supported.
26993 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
26994 -m[arm]3 Arm 3 processor
26995 -m[arm]6[xx], Arm 6 processors
26996 -m[arm]7[xx][t][[d]m] Arm 7 processors
26997 -m[arm]8[10] Arm 8 processors
26998 -m[arm]9[20][tdmi] Arm 9 processors
26999 -mstrongarm[110[0]] StrongARM processors
27000 -mxscale XScale processors
27001 -m[arm]v[2345[t[e]]] Arm architectures
27002 -mall All (except the ARM1)
27003 FP variants:
27004 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
27005 -mfpe-old (No float load/store multiples)
27006 -mvfpxd VFP Single precision
27007 -mvfp All VFP
27008 -mno-fpu Disable all floating point instructions
b99bd4ef 27009
c19d1205
ZW
27010 The following CPU names are recognized:
27011 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
27012 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
27013 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
27014 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
27015 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
27016 arm10t arm10e, arm1020t, arm1020e, arm10200e,
27017 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 27018
c19d1205 27019 */
b99bd4ef 27020
c19d1205 27021const char * md_shortopts = "m:k";
b99bd4ef 27022
c19d1205
ZW
27023#ifdef ARM_BI_ENDIAN
27024#define OPTION_EB (OPTION_MD_BASE + 0)
27025#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 27026#else
c19d1205
ZW
27027#if TARGET_BYTES_BIG_ENDIAN
27028#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 27029#else
c19d1205
ZW
27030#define OPTION_EL (OPTION_MD_BASE + 1)
27031#endif
b99bd4ef 27032#endif
845b51d6 27033#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
18a20338 27034#define OPTION_FDPIC (OPTION_MD_BASE + 3)
b99bd4ef 27035
c19d1205 27036struct option md_longopts[] =
b99bd4ef 27037{
c19d1205
ZW
27038#ifdef OPTION_EB
27039 {"EB", no_argument, NULL, OPTION_EB},
27040#endif
27041#ifdef OPTION_EL
27042 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 27043#endif
845b51d6 27044 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
18a20338
CL
27045#ifdef OBJ_ELF
27046 {"fdpic", no_argument, NULL, OPTION_FDPIC},
27047#endif
c19d1205
ZW
27048 {NULL, no_argument, NULL, 0}
27049};
b99bd4ef 27050
c19d1205 27051size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 27052
c19d1205 27053struct arm_option_table
b99bd4ef 27054{
0198d5e6
TC
27055 const char * option; /* Option name to match. */
27056 const char * help; /* Help information. */
27057 int * var; /* Variable to change. */
27058 int value; /* What to change it to. */
27059 const char * deprecated; /* If non-null, print this message. */
c19d1205 27060};
b99bd4ef 27061
c19d1205
ZW
27062struct arm_option_table arm_opts[] =
27063{
27064 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
27065 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
27066 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
27067 &support_interwork, 1, NULL},
27068 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
27069 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
27070 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
27071 1, NULL},
27072 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
27073 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
27074 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
27075 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
27076 NULL},
b99bd4ef 27077
c19d1205
ZW
27078 /* These are recognized by the assembler, but have no affect on code. */
27079 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
27080 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
27081
27082 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
27083 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
27084 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
27085 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
27086 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
27087 {NULL, NULL, NULL, 0, NULL}
27088};
27089
27090struct arm_legacy_option_table
27091{
0198d5e6
TC
27092 const char * option; /* Option name to match. */
27093 const arm_feature_set ** var; /* Variable to change. */
27094 const arm_feature_set value; /* What to change it to. */
27095 const char * deprecated; /* If non-null, print this message. */
e74cfd16 27096};
b99bd4ef 27097
e74cfd16
PB
27098const struct arm_legacy_option_table arm_legacy_opts[] =
27099{
c19d1205
ZW
27100 /* DON'T add any new processors to this list -- we want the whole list
27101 to go away... Add them to the processors table instead. */
e74cfd16
PB
27102 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
27103 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
27104 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
27105 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
27106 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
27107 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
27108 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
27109 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
27110 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
27111 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
27112 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
27113 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
27114 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
27115 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
27116 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
27117 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
27118 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
27119 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
27120 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
27121 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
27122 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
27123 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
27124 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
27125 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
27126 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
27127 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
27128 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
27129 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
27130 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
27131 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
27132 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
27133 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
27134 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
27135 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
27136 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
27137 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
27138 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
27139 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
27140 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
27141 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
27142 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
27143 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
27144 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
27145 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
27146 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
27147 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
27148 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
27149 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
27150 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
27151 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
27152 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
27153 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
27154 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
27155 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
27156 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
27157 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
27158 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
27159 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
27160 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
27161 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
27162 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
27163 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
27164 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
27165 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
27166 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
27167 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
27168 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
27169 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
27170 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
27171 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 27172 N_("use -mcpu=strongarm110")},
e74cfd16 27173 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 27174 N_("use -mcpu=strongarm1100")},
e74cfd16 27175 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 27176 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
27177 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
27178 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
27179 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 27180
c19d1205 27181 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
27182 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
27183 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
27184 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
27185 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
27186 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
27187 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
27188 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
27189 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
27190 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
27191 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
27192 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
27193 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
27194 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
27195 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
27196 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
27197 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
27198 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
27199 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 27200
c19d1205 27201 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
27202 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
27203 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
27204 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
27205 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 27206 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 27207
e74cfd16 27208 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 27209};
7ed4c4c5 27210
c19d1205 27211struct arm_cpu_option_table
7ed4c4c5 27212{
0198d5e6
TC
27213 const char * name;
27214 size_t name_len;
27215 const arm_feature_set value;
27216 const arm_feature_set ext;
c19d1205
ZW
27217 /* For some CPUs we assume an FPU unless the user explicitly sets
27218 -mfpu=... */
0198d5e6 27219 const arm_feature_set default_fpu;
ee065d83
PB
27220 /* The canonical name of the CPU, or NULL to use NAME converted to upper
27221 case. */
0198d5e6 27222 const char * canonical_name;
c19d1205 27223};
7ed4c4c5 27224
c19d1205
ZW
27225/* This list should, at a minimum, contain all the cpu names
27226 recognized by GCC. */
996b5569 27227#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 27228
e74cfd16 27229static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 27230{
996b5569
TP
27231 ARM_CPU_OPT ("all", NULL, ARM_ANY,
27232 ARM_ARCH_NONE,
27233 FPU_ARCH_FPA),
27234 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
27235 ARM_ARCH_NONE,
27236 FPU_ARCH_FPA),
27237 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
27238 ARM_ARCH_NONE,
27239 FPU_ARCH_FPA),
27240 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
27241 ARM_ARCH_NONE,
27242 FPU_ARCH_FPA),
27243 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
27244 ARM_ARCH_NONE,
27245 FPU_ARCH_FPA),
27246 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
27247 ARM_ARCH_NONE,
27248 FPU_ARCH_FPA),
27249 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
27250 ARM_ARCH_NONE,
27251 FPU_ARCH_FPA),
27252 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
27253 ARM_ARCH_NONE,
27254 FPU_ARCH_FPA),
27255 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
27256 ARM_ARCH_NONE,
27257 FPU_ARCH_FPA),
27258 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
27259 ARM_ARCH_NONE,
27260 FPU_ARCH_FPA),
27261 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
27262 ARM_ARCH_NONE,
27263 FPU_ARCH_FPA),
27264 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
27265 ARM_ARCH_NONE,
27266 FPU_ARCH_FPA),
27267 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
27268 ARM_ARCH_NONE,
27269 FPU_ARCH_FPA),
27270 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
27271 ARM_ARCH_NONE,
27272 FPU_ARCH_FPA),
27273 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
27274 ARM_ARCH_NONE,
27275 FPU_ARCH_FPA),
27276 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
27277 ARM_ARCH_NONE,
27278 FPU_ARCH_FPA),
27279 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
27280 ARM_ARCH_NONE,
27281 FPU_ARCH_FPA),
27282 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
27283 ARM_ARCH_NONE,
27284 FPU_ARCH_FPA),
27285 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
27286 ARM_ARCH_NONE,
27287 FPU_ARCH_FPA),
27288 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
27289 ARM_ARCH_NONE,
27290 FPU_ARCH_FPA),
27291 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
27292 ARM_ARCH_NONE,
27293 FPU_ARCH_FPA),
27294 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
27295 ARM_ARCH_NONE,
27296 FPU_ARCH_FPA),
27297 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
27298 ARM_ARCH_NONE,
27299 FPU_ARCH_FPA),
27300 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
27301 ARM_ARCH_NONE,
27302 FPU_ARCH_FPA),
27303 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
27304 ARM_ARCH_NONE,
27305 FPU_ARCH_FPA),
27306 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
27307 ARM_ARCH_NONE,
27308 FPU_ARCH_FPA),
27309 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
27310 ARM_ARCH_NONE,
27311 FPU_ARCH_FPA),
27312 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
27313 ARM_ARCH_NONE,
27314 FPU_ARCH_FPA),
27315 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
27316 ARM_ARCH_NONE,
27317 FPU_ARCH_FPA),
27318 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
27319 ARM_ARCH_NONE,
27320 FPU_ARCH_FPA),
27321 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
27322 ARM_ARCH_NONE,
27323 FPU_ARCH_FPA),
27324 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
27325 ARM_ARCH_NONE,
27326 FPU_ARCH_FPA),
27327 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
27328 ARM_ARCH_NONE,
27329 FPU_ARCH_FPA),
27330 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
27331 ARM_ARCH_NONE,
27332 FPU_ARCH_FPA),
27333 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
27334 ARM_ARCH_NONE,
27335 FPU_ARCH_FPA),
27336 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
27337 ARM_ARCH_NONE,
27338 FPU_ARCH_FPA),
27339 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
27340 ARM_ARCH_NONE,
27341 FPU_ARCH_FPA),
27342 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
27343 ARM_ARCH_NONE,
27344 FPU_ARCH_FPA),
27345 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
27346 ARM_ARCH_NONE,
27347 FPU_ARCH_FPA),
27348 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
27349 ARM_ARCH_NONE,
27350 FPU_ARCH_FPA),
27351 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
27352 ARM_ARCH_NONE,
27353 FPU_ARCH_FPA),
27354 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
27355 ARM_ARCH_NONE,
27356 FPU_ARCH_FPA),
27357 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
27358 ARM_ARCH_NONE,
27359 FPU_ARCH_FPA),
27360 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
27361 ARM_ARCH_NONE,
27362 FPU_ARCH_FPA),
27363 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
27364 ARM_ARCH_NONE,
27365 FPU_ARCH_FPA),
27366 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
27367 ARM_ARCH_NONE,
27368 FPU_ARCH_FPA),
27369
c19d1205
ZW
27370 /* For V5 or later processors we default to using VFP; but the user
27371 should really set the FPU type explicitly. */
996b5569
TP
27372 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
27373 ARM_ARCH_NONE,
27374 FPU_ARCH_VFP_V2),
27375 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
27376 ARM_ARCH_NONE,
27377 FPU_ARCH_VFP_V2),
27378 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
27379 ARM_ARCH_NONE,
27380 FPU_ARCH_VFP_V2),
27381 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
27382 ARM_ARCH_NONE,
27383 FPU_ARCH_VFP_V2),
27384 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
27385 ARM_ARCH_NONE,
27386 FPU_ARCH_VFP_V2),
27387 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
27388 ARM_ARCH_NONE,
27389 FPU_ARCH_VFP_V2),
27390 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
27391 ARM_ARCH_NONE,
27392 FPU_ARCH_VFP_V2),
27393 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
27394 ARM_ARCH_NONE,
27395 FPU_ARCH_VFP_V2),
27396 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
27397 ARM_ARCH_NONE,
27398 FPU_ARCH_VFP_V2),
27399 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
27400 ARM_ARCH_NONE,
27401 FPU_ARCH_VFP_V2),
27402 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
27403 ARM_ARCH_NONE,
27404 FPU_ARCH_VFP_V2),
27405 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
27406 ARM_ARCH_NONE,
27407 FPU_ARCH_VFP_V2),
27408 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
27409 ARM_ARCH_NONE,
27410 FPU_ARCH_VFP_V1),
27411 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
27412 ARM_ARCH_NONE,
27413 FPU_ARCH_VFP_V1),
27414 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
27415 ARM_ARCH_NONE,
27416 FPU_ARCH_VFP_V2),
27417 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
27418 ARM_ARCH_NONE,
27419 FPU_ARCH_VFP_V2),
27420 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
27421 ARM_ARCH_NONE,
27422 FPU_ARCH_VFP_V1),
27423 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
27424 ARM_ARCH_NONE,
27425 FPU_ARCH_VFP_V2),
27426 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
27427 ARM_ARCH_NONE,
27428 FPU_ARCH_VFP_V2),
27429 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
27430 ARM_ARCH_NONE,
27431 FPU_ARCH_VFP_V2),
27432 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
27433 ARM_ARCH_NONE,
27434 FPU_ARCH_VFP_V2),
27435 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
27436 ARM_ARCH_NONE,
27437 FPU_ARCH_VFP_V2),
27438 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
27439 ARM_ARCH_NONE,
27440 FPU_ARCH_VFP_V2),
27441 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
27442 ARM_ARCH_NONE,
27443 FPU_ARCH_VFP_V2),
27444 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
27445 ARM_ARCH_NONE,
27446 FPU_ARCH_VFP_V2),
27447 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
27448 ARM_ARCH_NONE,
27449 FPU_ARCH_VFP_V2),
27450 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
27451 ARM_ARCH_NONE,
27452 FPU_NONE),
27453 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
27454 ARM_ARCH_NONE,
27455 FPU_NONE),
27456 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
27457 ARM_ARCH_NONE,
27458 FPU_ARCH_VFP_V2),
27459 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
27460 ARM_ARCH_NONE,
27461 FPU_ARCH_VFP_V2),
27462 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
27463 ARM_ARCH_NONE,
27464 FPU_ARCH_VFP_V2),
27465 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
27466 ARM_ARCH_NONE,
27467 FPU_NONE),
27468 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
27469 ARM_ARCH_NONE,
27470 FPU_NONE),
27471 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
27472 ARM_ARCH_NONE,
27473 FPU_ARCH_VFP_V2),
27474 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
27475 ARM_ARCH_NONE,
27476 FPU_NONE),
27477 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
27478 ARM_ARCH_NONE,
27479 FPU_ARCH_VFP_V2),
27480 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
27481 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
27482 FPU_NONE),
27483 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
27484 ARM_ARCH_NONE,
27485 FPU_ARCH_NEON_VFP_V4),
27486 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
27487 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
27488 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
27489 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
27490 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
27491 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
27492 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
27493 ARM_ARCH_NONE,
27494 FPU_ARCH_NEON_VFP_V4),
27495 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
27496 ARM_ARCH_NONE,
27497 FPU_ARCH_NEON_VFP_V4),
27498 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
27499 ARM_ARCH_NONE,
27500 FPU_ARCH_NEON_VFP_V4),
27501 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
27502 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27503 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27504 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
27505 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27506 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27507 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
27508 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27509 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
27510 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
27511 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 27512 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
27513 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
27514 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27515 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27516 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
27517 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27518 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27519 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
27520 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27521 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
27522 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
27523 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 27524 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
7ebd1359 27525 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
27526 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27527 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
ef8df4ca
KT
27528 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
27529 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27530 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
27531 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
27532 ARM_ARCH_NONE,
27533 FPU_NONE),
27534 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
27535 ARM_ARCH_NONE,
27536 FPU_ARCH_VFP_V3D16),
27537 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
27538 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
27539 FPU_NONE),
27540 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
27541 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
27542 FPU_ARCH_VFP_V3D16),
27543 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
27544 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
27545 FPU_ARCH_VFP_V3D16),
0cda1e19
TP
27546 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
27547 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27548 FPU_ARCH_NEON_VFP_ARMV8),
996b5569
TP
27549 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
27550 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27551 FPU_NONE),
27552 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
27553 ARM_ARCH_NONE,
27554 FPU_NONE),
27555 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
27556 ARM_ARCH_NONE,
27557 FPU_NONE),
27558 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
27559 ARM_ARCH_NONE,
27560 FPU_NONE),
27561 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
27562 ARM_ARCH_NONE,
27563 FPU_NONE),
27564 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
27565 ARM_ARCH_NONE,
27566 FPU_NONE),
27567 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
27568 ARM_ARCH_NONE,
27569 FPU_NONE),
27570 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
27571 ARM_ARCH_NONE,
27572 FPU_NONE),
27573 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
27574 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27575 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
83f43c83
KT
27576 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
27577 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27578 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
c19d1205 27579 /* ??? XSCALE is really an architecture. */
996b5569
TP
27580 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
27581 ARM_ARCH_NONE,
27582 FPU_ARCH_VFP_V2),
27583
c19d1205 27584 /* ??? iwmmxt is not a processor. */
996b5569
TP
27585 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
27586 ARM_ARCH_NONE,
27587 FPU_ARCH_VFP_V2),
27588 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
27589 ARM_ARCH_NONE,
27590 FPU_ARCH_VFP_V2),
27591 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
27592 ARM_ARCH_NONE,
27593 FPU_ARCH_VFP_V2),
27594
0198d5e6 27595 /* Maverick. */
996b5569
TP
27596 ARM_CPU_OPT ("ep9312", "ARM920T",
27597 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
27598 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
27599
da4339ed 27600 /* Marvell processors. */
996b5569
TP
27601 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
27602 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
27603 FPU_ARCH_VFP_V3D16),
27604 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
27605 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
27606 FPU_ARCH_NEON_VFP_V4),
da4339ed 27607
996b5569
TP
27608 /* APM X-Gene family. */
27609 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
27610 ARM_ARCH_NONE,
27611 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27612 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
27613 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27614 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27615
27616 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 27617};
f3bad469 27618#undef ARM_CPU_OPT
7ed4c4c5 27619
34ef62f4
AV
27620struct arm_ext_table
27621{
27622 const char * name;
27623 size_t name_len;
27624 const arm_feature_set merge;
27625 const arm_feature_set clear;
27626};
27627
c19d1205 27628struct arm_arch_option_table
7ed4c4c5 27629{
34ef62f4
AV
27630 const char * name;
27631 size_t name_len;
27632 const arm_feature_set value;
27633 const arm_feature_set default_fpu;
27634 const struct arm_ext_table * ext_table;
27635};
27636
27637/* Used to add support for +E and +noE extension. */
27638#define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
27639/* Used to add support for a +E extension. */
27640#define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
27641/* Used to add support for a +noE extension. */
27642#define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
27643
27644#define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
27645 ~0 & ~FPU_ENDIAN_PURE)
27646
27647static const struct arm_ext_table armv5te_ext_table[] =
27648{
27649 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
27650 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27651};
27652
27653static const struct arm_ext_table armv7_ext_table[] =
27654{
27655 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
27656 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27657};
27658
27659static const struct arm_ext_table armv7ve_ext_table[] =
27660{
27661 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
27662 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
27663 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
27664 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
27665 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
27666 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
27667 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
27668
27669 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
27670 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
27671
27672 /* Aliases for +simd. */
27673 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
27674
27675 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
27676 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
27677 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
27678
27679 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27680};
27681
27682static const struct arm_ext_table armv7a_ext_table[] =
27683{
27684 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
27685 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
27686 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
27687 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
27688 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
27689 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
27690 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
27691
27692 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
27693 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
27694
27695 /* Aliases for +simd. */
27696 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
27697 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
27698
27699 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
27700 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
27701
27702 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
27703 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
27704 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27705};
27706
27707static const struct arm_ext_table armv7r_ext_table[] =
27708{
27709 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
27710 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
27711 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
27712 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
27713 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
27714 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
27715 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
27716 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
27717 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27718};
27719
27720static const struct arm_ext_table armv7em_ext_table[] =
27721{
27722 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
27723 /* Alias for +fp, used to be known as fpv4-sp-d16. */
27724 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
27725 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
27726 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
27727 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
27728 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27729};
27730
27731static const struct arm_ext_table armv8a_ext_table[] =
27732{
27733 ARM_ADD ("crc", ARCH_CRC_ARMV8),
27734 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
27735 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
27736 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27737
27738 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27739 should use the +simd option to turn on FP. */
27740 ARM_REMOVE ("fp", ALL_FP),
27741 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
27742 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
27743 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27744};
27745
27746
27747static const struct arm_ext_table armv81a_ext_table[] =
27748{
27749 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
27750 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
27751 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27752
27753 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27754 should use the +simd option to turn on FP. */
27755 ARM_REMOVE ("fp", ALL_FP),
27756 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
27757 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
27758 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27759};
27760
27761static const struct arm_ext_table armv82a_ext_table[] =
27762{
27763 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
27764 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
27765 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
27766 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
27767 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27768 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
27769
27770 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27771 should use the +simd option to turn on FP. */
27772 ARM_REMOVE ("fp", ALL_FP),
27773 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
27774 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
27775 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27776};
27777
27778static const struct arm_ext_table armv84a_ext_table[] =
27779{
27780 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
27781 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
27782 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
27783 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27784
27785 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27786 should use the +simd option to turn on FP. */
27787 ARM_REMOVE ("fp", ALL_FP),
27788 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
27789 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
27790 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27791};
27792
27793static const struct arm_ext_table armv85a_ext_table[] =
27794{
27795 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
27796 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
27797 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
27798 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27799
27800 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27801 should use the +simd option to turn on FP. */
27802 ARM_REMOVE ("fp", ALL_FP),
27803 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27804};
27805
27806static const struct arm_ext_table armv8m_main_ext_table[] =
27807{
27808 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27809 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
27810 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
27811 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
27812 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27813};
27814
e0991585
AV
27815static const struct arm_ext_table armv8_1m_main_ext_table[] =
27816{
27817 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27818 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
27819 ARM_EXT ("fp",
27820 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
27821 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
27822 ALL_FP),
27823 ARM_ADD ("fp.dp",
27824 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
27825 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
a7ad558c
AV
27826 ARM_EXT ("mve", ARM_FEATURE_COPROC (FPU_MVE),
27827 ARM_FEATURE_COPROC (FPU_MVE | FPU_MVE_FP)),
27828 ARM_ADD ("mve.fp",
27829 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
27830 FPU_MVE | FPU_MVE_FP | FPU_VFP_V5_SP_D16 |
27831 FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
e0991585
AV
27832 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27833};
27834
34ef62f4
AV
27835static const struct arm_ext_table armv8r_ext_table[] =
27836{
27837 ARM_ADD ("crc", ARCH_CRC_ARMV8),
27838 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
27839 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
27840 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27841 ARM_REMOVE ("fp", ALL_FP),
27842 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
27843 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 27844};
7ed4c4c5 27845
c19d1205
ZW
27846/* This list should, at a minimum, contain all the architecture names
27847 recognized by GCC. */
34ef62f4
AV
27848#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
27849#define ARM_ARCH_OPT2(N, V, DF, ext) \
27850 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
0198d5e6 27851
e74cfd16 27852static const struct arm_arch_option_table arm_archs[] =
c19d1205 27853{
497d849d
TP
27854 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
27855 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
27856 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
27857 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
27858 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
27859 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
27860 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
27861 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
27862 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
27863 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
27864 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
27865 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
27866 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
27867 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
34ef62f4
AV
27868 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
27869 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
27870 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
27871 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
27872 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
27873 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
27874 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
f33026a9
MW
27875 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
27876 kept to preserve existing behaviour. */
34ef62f4
AV
27877 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
27878 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
27879 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
27880 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
27881 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
f33026a9
MW
27882 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
27883 kept to preserve existing behaviour. */
34ef62f4
AV
27884 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
27885 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
497d849d
TP
27886 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
27887 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
34ef62f4 27888 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
c450d570
PB
27889 /* The official spelling of the ARMv7 profile variants is the dashed form.
27890 Accept the non-dashed form for compatibility with old toolchains. */
34ef62f4
AV
27891 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
27892 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
27893 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 27894 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4
AV
27895 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
27896 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 27897 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4 27898 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
497d849d 27899 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
34ef62f4
AV
27900 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
27901 armv8m_main),
e0991585
AV
27902 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
27903 armv8_1m_main),
34ef62f4
AV
27904 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
27905 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
27906 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
27907 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
27908 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
27909 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
27910 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
497d849d
TP
27911 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
27912 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
27913 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
34ef62f4 27914 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 27915};
f3bad469 27916#undef ARM_ARCH_OPT
7ed4c4c5 27917
69133863 27918/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 27919
69133863 27920struct arm_option_extension_value_table
c19d1205 27921{
0198d5e6
TC
27922 const char * name;
27923 size_t name_len;
27924 const arm_feature_set merge_value;
27925 const arm_feature_set clear_value;
d942732e
TP
27926 /* List of architectures for which an extension is available. ARM_ARCH_NONE
27927 indicates that an extension is available for all architectures while
27928 ARM_ANY marks an empty entry. */
0198d5e6 27929 const arm_feature_set allowed_archs[2];
c19d1205 27930};
7ed4c4c5 27931
0198d5e6
TC
27932/* The following table must be in alphabetical order with a NULL last entry. */
27933
d942732e
TP
27934#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
27935#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 27936
34ef62f4
AV
27937/* DEPRECATED: Refrain from using this table to add any new extensions, instead
27938 use the context sensitive approach using arm_ext_table's. */
69133863 27939static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 27940{
823d2571
TG
27941 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27942 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 27943 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
27944 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
27945 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
27946 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
27947 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
27948 ARM_ARCH_V8_2A),
15afaa63
TP
27949 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27950 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27951 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
27952 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
27953 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
27954 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27955 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27956 ARM_ARCH_V8_2A),
01f48020
TC
27957 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
27958 | ARM_EXT2_FP16_FML),
27959 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
27960 | ARM_EXT2_FP16_FML),
27961 ARM_ARCH_V8_2A),
d942732e 27962 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 27963 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
27964 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
27965 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
27966 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
27967 Thumb divide instruction. Due to this having the same name as the
27968 previous entry, this will be ignored when doing command-line parsing and
27969 only considered by build attribute selection code. */
27970 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
27971 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
27972 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 27973 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 27974 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 27975 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 27976 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 27977 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
27978 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
27979 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 27980 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
27981 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
27982 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
27983 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
27984 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
27985 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
27986 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
27987 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 27988 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
dad0c3bf
SD
27989 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
27990 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
27991 ARM_ARCH_V8A),
4d1464f2
MW
27992 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
27993 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 27994 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
27995 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
27996 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 27997 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
7fadb25d
SD
27998 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
27999 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
28000 ARM_ARCH_V8A),
d942732e 28001 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 28002 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
28003 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
28004 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
28005 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
28006 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
28007 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
28008 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
28009 | ARM_EXT_DIV),
28010 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
28011 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
28012 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
28013 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
28014 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 28015};
f3bad469 28016#undef ARM_EXT_OPT
69133863
MGD
28017
28018/* ISA floating-point and Advanced SIMD extensions. */
28019struct arm_option_fpu_value_table
28020{
0198d5e6
TC
28021 const char * name;
28022 const arm_feature_set value;
c19d1205 28023};
7ed4c4c5 28024
c19d1205
ZW
28025/* This list should, at a minimum, contain all the fpu names
28026 recognized by GCC. */
69133863 28027static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
28028{
28029 {"softfpa", FPU_NONE},
28030 {"fpe", FPU_ARCH_FPE},
28031 {"fpe2", FPU_ARCH_FPE},
28032 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
28033 {"fpa", FPU_ARCH_FPA},
28034 {"fpa10", FPU_ARCH_FPA},
28035 {"fpa11", FPU_ARCH_FPA},
28036 {"arm7500fe", FPU_ARCH_FPA},
28037 {"softvfp", FPU_ARCH_VFP},
28038 {"softvfp+vfp", FPU_ARCH_VFP_V2},
28039 {"vfp", FPU_ARCH_VFP_V2},
28040 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 28041 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
28042 {"vfp10", FPU_ARCH_VFP_V2},
28043 {"vfp10-r0", FPU_ARCH_VFP_V1},
28044 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
28045 {"vfpv2", FPU_ARCH_VFP_V2},
28046 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 28047 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 28048 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
28049 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
28050 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
28051 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
28052 {"arm1020t", FPU_ARCH_VFP_V1},
28053 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 28054 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
28055 {"arm1136jf-s", FPU_ARCH_VFP_V2},
28056 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 28057 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 28058 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 28059 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
28060 {"vfpv4", FPU_ARCH_VFP_V4},
28061 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 28062 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
28063 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
28064 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 28065 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
28066 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
28067 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
28068 {"crypto-neon-fp-armv8",
28069 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 28070 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
28071 {"crypto-neon-fp-armv8.1",
28072 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
28073 {NULL, ARM_ARCH_NONE}
28074};
28075
28076struct arm_option_value_table
28077{
e0471c16 28078 const char *name;
e74cfd16 28079 long value;
c19d1205 28080};
7ed4c4c5 28081
e74cfd16 28082static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
28083{
28084 {"hard", ARM_FLOAT_ABI_HARD},
28085 {"softfp", ARM_FLOAT_ABI_SOFTFP},
28086 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 28087 {NULL, 0}
c19d1205 28088};
7ed4c4c5 28089
c19d1205 28090#ifdef OBJ_ELF
3a4a14e9 28091/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 28092static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
28093{
28094 {"gnu", EF_ARM_EABI_UNKNOWN},
28095 {"4", EF_ARM_EABI_VER4},
3a4a14e9 28096 {"5", EF_ARM_EABI_VER5},
e74cfd16 28097 {NULL, 0}
c19d1205
ZW
28098};
28099#endif
7ed4c4c5 28100
c19d1205
ZW
28101struct arm_long_option_table
28102{
0198d5e6 28103 const char * option; /* Substring to match. */
e0471c16 28104 const char * help; /* Help information. */
17b9d67d 28105 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 28106 const char * deprecated; /* If non-null, print this message. */
c19d1205 28107};
7ed4c4c5 28108
c921be7d 28109static bfd_boolean
c168ce07 28110arm_parse_extension (const char *str, const arm_feature_set *opt_set,
34ef62f4
AV
28111 arm_feature_set *ext_set,
28112 const struct arm_ext_table *ext_table)
7ed4c4c5 28113{
69133863 28114 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
28115 extensions being added before being removed. We achieve this by having
28116 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 28117 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 28118 or removing it (0) and only allowing it to change in the order
69133863
MGD
28119 -1 -> 1 -> 0. */
28120 const struct arm_option_extension_value_table * opt = NULL;
d942732e 28121 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
28122 int adding_value = -1;
28123
c19d1205 28124 while (str != NULL && *str != 0)
7ed4c4c5 28125 {
82b8a785 28126 const char *ext;
f3bad469 28127 size_t len;
7ed4c4c5 28128
c19d1205
ZW
28129 if (*str != '+')
28130 {
28131 as_bad (_("invalid architectural extension"));
c921be7d 28132 return FALSE;
c19d1205 28133 }
7ed4c4c5 28134
c19d1205
ZW
28135 str++;
28136 ext = strchr (str, '+');
7ed4c4c5 28137
c19d1205 28138 if (ext != NULL)
f3bad469 28139 len = ext - str;
c19d1205 28140 else
f3bad469 28141 len = strlen (str);
7ed4c4c5 28142
f3bad469 28143 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
28144 {
28145 if (adding_value != 0)
28146 {
28147 adding_value = 0;
28148 opt = arm_extensions;
28149 }
28150
f3bad469 28151 len -= 2;
69133863
MGD
28152 str += 2;
28153 }
f3bad469 28154 else if (len > 0)
69133863
MGD
28155 {
28156 if (adding_value == -1)
28157 {
28158 adding_value = 1;
28159 opt = arm_extensions;
28160 }
28161 else if (adding_value != 1)
28162 {
28163 as_bad (_("must specify extensions to add before specifying "
28164 "those to remove"));
28165 return FALSE;
28166 }
28167 }
28168
f3bad469 28169 if (len == 0)
c19d1205
ZW
28170 {
28171 as_bad (_("missing architectural extension"));
c921be7d 28172 return FALSE;
c19d1205 28173 }
7ed4c4c5 28174
69133863
MGD
28175 gas_assert (adding_value != -1);
28176 gas_assert (opt != NULL);
28177
34ef62f4
AV
28178 if (ext_table != NULL)
28179 {
28180 const struct arm_ext_table * ext_opt = ext_table;
28181 bfd_boolean found = FALSE;
28182 for (; ext_opt->name != NULL; ext_opt++)
28183 if (ext_opt->name_len == len
28184 && strncmp (ext_opt->name, str, len) == 0)
28185 {
28186 if (adding_value)
28187 {
28188 if (ARM_FEATURE_ZERO (ext_opt->merge))
28189 /* TODO: Option not supported. When we remove the
28190 legacy table this case should error out. */
28191 continue;
28192
28193 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
28194 }
28195 else
28196 {
28197 if (ARM_FEATURE_ZERO (ext_opt->clear))
28198 /* TODO: Option not supported. When we remove the
28199 legacy table this case should error out. */
28200 continue;
28201 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
28202 }
28203 found = TRUE;
28204 break;
28205 }
28206 if (found)
28207 {
28208 str = ext;
28209 continue;
28210 }
28211 }
28212
69133863
MGD
28213 /* Scan over the options table trying to find an exact match. */
28214 for (; opt->name != NULL; opt++)
f3bad469 28215 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 28216 {
d942732e
TP
28217 int i, nb_allowed_archs =
28218 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 28219 /* Check we can apply the extension to this architecture. */
d942732e
TP
28220 for (i = 0; i < nb_allowed_archs; i++)
28221 {
28222 /* Empty entry. */
28223 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
28224 continue;
c168ce07 28225 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
28226 break;
28227 }
28228 if (i == nb_allowed_archs)
69133863
MGD
28229 {
28230 as_bad (_("extension does not apply to the base architecture"));
28231 return FALSE;
28232 }
28233
28234 /* Add or remove the extension. */
28235 if (adding_value)
4d354d8b 28236 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 28237 else
4d354d8b 28238 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 28239
3d030cdb
TP
28240 /* Allowing Thumb division instructions for ARMv7 in autodetection
28241 rely on this break so that duplicate extensions (extensions
28242 with the same name as a previous extension in the list) are not
28243 considered for command-line parsing. */
c19d1205
ZW
28244 break;
28245 }
7ed4c4c5 28246
c19d1205
ZW
28247 if (opt->name == NULL)
28248 {
69133863
MGD
28249 /* Did we fail to find an extension because it wasn't specified in
28250 alphabetical order, or because it does not exist? */
28251
28252 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 28253 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
28254 break;
28255
28256 if (opt->name == NULL)
28257 as_bad (_("unknown architectural extension `%s'"), str);
28258 else
28259 as_bad (_("architectural extensions must be specified in "
28260 "alphabetical order"));
28261
c921be7d 28262 return FALSE;
c19d1205 28263 }
69133863
MGD
28264 else
28265 {
28266 /* We should skip the extension we've just matched the next time
28267 round. */
28268 opt++;
28269 }
7ed4c4c5 28270
c19d1205
ZW
28271 str = ext;
28272 };
7ed4c4c5 28273
c921be7d 28274 return TRUE;
c19d1205 28275}
7ed4c4c5 28276
c921be7d 28277static bfd_boolean
17b9d67d 28278arm_parse_cpu (const char *str)
7ed4c4c5 28279{
f3bad469 28280 const struct arm_cpu_option_table *opt;
82b8a785 28281 const char *ext = strchr (str, '+');
f3bad469 28282 size_t len;
7ed4c4c5 28283
c19d1205 28284 if (ext != NULL)
f3bad469 28285 len = ext - str;
7ed4c4c5 28286 else
f3bad469 28287 len = strlen (str);
7ed4c4c5 28288
f3bad469 28289 if (len == 0)
7ed4c4c5 28290 {
c19d1205 28291 as_bad (_("missing cpu name `%s'"), str);
c921be7d 28292 return FALSE;
7ed4c4c5
NC
28293 }
28294
c19d1205 28295 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 28296 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 28297 {
c168ce07 28298 mcpu_cpu_opt = &opt->value;
4d354d8b
TP
28299 if (mcpu_ext_opt == NULL)
28300 mcpu_ext_opt = XNEW (arm_feature_set);
28301 *mcpu_ext_opt = opt->ext;
e74cfd16 28302 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 28303 if (opt->canonical_name)
ef8e6722
JW
28304 {
28305 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
28306 strcpy (selected_cpu_name, opt->canonical_name);
28307 }
ee065d83
PB
28308 else
28309 {
f3bad469 28310 size_t i;
c921be7d 28311
ef8e6722
JW
28312 if (len >= sizeof selected_cpu_name)
28313 len = (sizeof selected_cpu_name) - 1;
28314
f3bad469 28315 for (i = 0; i < len; i++)
ee065d83
PB
28316 selected_cpu_name[i] = TOUPPER (opt->name[i]);
28317 selected_cpu_name[i] = 0;
28318 }
7ed4c4c5 28319
c19d1205 28320 if (ext != NULL)
34ef62f4 28321 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
7ed4c4c5 28322
c921be7d 28323 return TRUE;
c19d1205 28324 }
7ed4c4c5 28325
c19d1205 28326 as_bad (_("unknown cpu `%s'"), str);
c921be7d 28327 return FALSE;
7ed4c4c5
NC
28328}
28329
c921be7d 28330static bfd_boolean
17b9d67d 28331arm_parse_arch (const char *str)
7ed4c4c5 28332{
e74cfd16 28333 const struct arm_arch_option_table *opt;
82b8a785 28334 const char *ext = strchr (str, '+');
f3bad469 28335 size_t len;
7ed4c4c5 28336
c19d1205 28337 if (ext != NULL)
f3bad469 28338 len = ext - str;
7ed4c4c5 28339 else
f3bad469 28340 len = strlen (str);
7ed4c4c5 28341
f3bad469 28342 if (len == 0)
7ed4c4c5 28343 {
c19d1205 28344 as_bad (_("missing architecture name `%s'"), str);
c921be7d 28345 return FALSE;
7ed4c4c5
NC
28346 }
28347
c19d1205 28348 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 28349 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 28350 {
e74cfd16 28351 march_cpu_opt = &opt->value;
4d354d8b
TP
28352 if (march_ext_opt == NULL)
28353 march_ext_opt = XNEW (arm_feature_set);
28354 *march_ext_opt = arm_arch_none;
e74cfd16 28355 march_fpu_opt = &opt->default_fpu;
5f4273c7 28356 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 28357
c19d1205 28358 if (ext != NULL)
34ef62f4
AV
28359 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
28360 opt->ext_table);
7ed4c4c5 28361
c921be7d 28362 return TRUE;
c19d1205
ZW
28363 }
28364
28365 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 28366 return FALSE;
7ed4c4c5 28367}
eb043451 28368
c921be7d 28369static bfd_boolean
17b9d67d 28370arm_parse_fpu (const char * str)
c19d1205 28371{
69133863 28372 const struct arm_option_fpu_value_table * opt;
b99bd4ef 28373
c19d1205
ZW
28374 for (opt = arm_fpus; opt->name != NULL; opt++)
28375 if (streq (opt->name, str))
28376 {
e74cfd16 28377 mfpu_opt = &opt->value;
c921be7d 28378 return TRUE;
c19d1205 28379 }
b99bd4ef 28380
c19d1205 28381 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 28382 return FALSE;
c19d1205
ZW
28383}
28384
c921be7d 28385static bfd_boolean
17b9d67d 28386arm_parse_float_abi (const char * str)
b99bd4ef 28387{
e74cfd16 28388 const struct arm_option_value_table * opt;
b99bd4ef 28389
c19d1205
ZW
28390 for (opt = arm_float_abis; opt->name != NULL; opt++)
28391 if (streq (opt->name, str))
28392 {
28393 mfloat_abi_opt = opt->value;
c921be7d 28394 return TRUE;
c19d1205 28395 }
cc8a6dd0 28396
c19d1205 28397 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 28398 return FALSE;
c19d1205 28399}
b99bd4ef 28400
c19d1205 28401#ifdef OBJ_ELF
c921be7d 28402static bfd_boolean
17b9d67d 28403arm_parse_eabi (const char * str)
c19d1205 28404{
e74cfd16 28405 const struct arm_option_value_table *opt;
cc8a6dd0 28406
c19d1205
ZW
28407 for (opt = arm_eabis; opt->name != NULL; opt++)
28408 if (streq (opt->name, str))
28409 {
28410 meabi_flags = opt->value;
c921be7d 28411 return TRUE;
c19d1205
ZW
28412 }
28413 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 28414 return FALSE;
c19d1205
ZW
28415}
28416#endif
cc8a6dd0 28417
c921be7d 28418static bfd_boolean
17b9d67d 28419arm_parse_it_mode (const char * str)
e07e6e58 28420{
c921be7d 28421 bfd_boolean ret = TRUE;
e07e6e58
NC
28422
28423 if (streq ("arm", str))
28424 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
28425 else if (streq ("thumb", str))
28426 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
28427 else if (streq ("always", str))
28428 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
28429 else if (streq ("never", str))
28430 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
28431 else
28432 {
28433 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 28434 "arm, thumb, always, or never."), str);
c921be7d 28435 ret = FALSE;
e07e6e58
NC
28436 }
28437
28438 return ret;
28439}
28440
2e6976a8 28441static bfd_boolean
17b9d67d 28442arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
28443{
28444 codecomposer_syntax = TRUE;
28445 arm_comment_chars[0] = ';';
28446 arm_line_separator_chars[0] = 0;
28447 return TRUE;
28448}
28449
c19d1205
ZW
28450struct arm_long_option_table arm_long_opts[] =
28451{
28452 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
28453 arm_parse_cpu, NULL},
28454 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
28455 arm_parse_arch, NULL},
28456 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
28457 arm_parse_fpu, NULL},
28458 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
28459 arm_parse_float_abi, NULL},
28460#ifdef OBJ_ELF
7fac0536 28461 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
28462 arm_parse_eabi, NULL},
28463#endif
e07e6e58
NC
28464 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
28465 arm_parse_it_mode, NULL},
2e6976a8
DG
28466 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
28467 arm_ccs_mode, NULL},
c19d1205
ZW
28468 {NULL, NULL, 0, NULL}
28469};
cc8a6dd0 28470
c19d1205 28471int
17b9d67d 28472md_parse_option (int c, const char * arg)
c19d1205
ZW
28473{
28474 struct arm_option_table *opt;
e74cfd16 28475 const struct arm_legacy_option_table *fopt;
c19d1205 28476 struct arm_long_option_table *lopt;
b99bd4ef 28477
c19d1205 28478 switch (c)
b99bd4ef 28479 {
c19d1205
ZW
28480#ifdef OPTION_EB
28481 case OPTION_EB:
28482 target_big_endian = 1;
28483 break;
28484#endif
cc8a6dd0 28485
c19d1205
ZW
28486#ifdef OPTION_EL
28487 case OPTION_EL:
28488 target_big_endian = 0;
28489 break;
28490#endif
b99bd4ef 28491
845b51d6
PB
28492 case OPTION_FIX_V4BX:
28493 fix_v4bx = TRUE;
28494 break;
28495
18a20338
CL
28496#ifdef OBJ_ELF
28497 case OPTION_FDPIC:
28498 arm_fdpic = TRUE;
28499 break;
28500#endif /* OBJ_ELF */
28501
c19d1205
ZW
28502 case 'a':
28503 /* Listing option. Just ignore these, we don't support additional
28504 ones. */
28505 return 0;
b99bd4ef 28506
c19d1205
ZW
28507 default:
28508 for (opt = arm_opts; opt->option != NULL; opt++)
28509 {
28510 if (c == opt->option[0]
28511 && ((arg == NULL && opt->option[1] == 0)
28512 || streq (arg, opt->option + 1)))
28513 {
c19d1205 28514 /* If the option is deprecated, tell the user. */
278df34e 28515 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
28516 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
28517 arg ? arg : "", _(opt->deprecated));
b99bd4ef 28518
c19d1205
ZW
28519 if (opt->var != NULL)
28520 *opt->var = opt->value;
cc8a6dd0 28521
c19d1205
ZW
28522 return 1;
28523 }
28524 }
b99bd4ef 28525
e74cfd16
PB
28526 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
28527 {
28528 if (c == fopt->option[0]
28529 && ((arg == NULL && fopt->option[1] == 0)
28530 || streq (arg, fopt->option + 1)))
28531 {
e74cfd16 28532 /* If the option is deprecated, tell the user. */
278df34e 28533 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
28534 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
28535 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
28536
28537 if (fopt->var != NULL)
28538 *fopt->var = &fopt->value;
28539
28540 return 1;
28541 }
28542 }
28543
c19d1205
ZW
28544 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
28545 {
28546 /* These options are expected to have an argument. */
28547 if (c == lopt->option[0]
28548 && arg != NULL
28549 && strncmp (arg, lopt->option + 1,
28550 strlen (lopt->option + 1)) == 0)
28551 {
c19d1205 28552 /* If the option is deprecated, tell the user. */
278df34e 28553 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
28554 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
28555 _(lopt->deprecated));
b99bd4ef 28556
c19d1205
ZW
28557 /* Call the sup-option parser. */
28558 return lopt->func (arg + strlen (lopt->option) - 1);
28559 }
28560 }
a737bd4d 28561
c19d1205
ZW
28562 return 0;
28563 }
a394c00f 28564
c19d1205
ZW
28565 return 1;
28566}
a394c00f 28567
c19d1205
ZW
28568void
28569md_show_usage (FILE * fp)
a394c00f 28570{
c19d1205
ZW
28571 struct arm_option_table *opt;
28572 struct arm_long_option_table *lopt;
a394c00f 28573
c19d1205 28574 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 28575
c19d1205
ZW
28576 for (opt = arm_opts; opt->option != NULL; opt++)
28577 if (opt->help != NULL)
28578 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 28579
c19d1205
ZW
28580 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
28581 if (lopt->help != NULL)
28582 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 28583
c19d1205
ZW
28584#ifdef OPTION_EB
28585 fprintf (fp, _("\
28586 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
28587#endif
28588
c19d1205
ZW
28589#ifdef OPTION_EL
28590 fprintf (fp, _("\
28591 -EL assemble code for a little-endian cpu\n"));
a737bd4d 28592#endif
845b51d6
PB
28593
28594 fprintf (fp, _("\
28595 --fix-v4bx Allow BX in ARMv4 code\n"));
18a20338
CL
28596
28597#ifdef OBJ_ELF
28598 fprintf (fp, _("\
28599 --fdpic generate an FDPIC object file\n"));
28600#endif /* OBJ_ELF */
c19d1205 28601}
ee065d83 28602
ee065d83 28603#ifdef OBJ_ELF
0198d5e6 28604
62b3e311
PB
28605typedef struct
28606{
28607 int val;
28608 arm_feature_set flags;
28609} cpu_arch_ver_table;
28610
2c6b98ea
TP
28611/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
28612 chronologically for architectures, with an exception for ARMv6-M and
28613 ARMv6S-M due to legacy reasons. No new architecture should have a
28614 special case. This allows for build attribute selection results to be
28615 stable when new architectures are added. */
62b3e311
PB
28616static const cpu_arch_ver_table cpu_arch_ver[] =
28617{
031254f2
AV
28618 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
28619 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
28620 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
28621 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
28622 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
28623 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
28624 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
28625 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
28626 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
28627 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
28628 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
28629 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
28630 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
28631 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
28632 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
28633 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
28634 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
28635 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
28636 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
28637 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
28638 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
28639 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
28640 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
28641 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
2c6b98ea
TP
28642
28643 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
28644 always selected build attributes to match those of ARMv6-M
28645 (resp. ARMv6S-M). However, due to these architectures being a strict
28646 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
28647 would be selected when fully respecting chronology of architectures.
28648 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
28649 move them before ARMv7 architectures. */
031254f2
AV
28650 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
28651 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
28652
28653 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
28654 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
28655 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
28656 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
28657 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
28658 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
28659 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
28660 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
28661 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
28662 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
28663 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
28664 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
28665 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
28666 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
28667 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
28668 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
28669 {-1, ARM_ARCH_NONE}
62b3e311
PB
28670};
28671
ee3c0378 28672/* Set an attribute if it has not already been set by the user. */
0198d5e6 28673
ee3c0378
AS
28674static void
28675aeabi_set_attribute_int (int tag, int value)
28676{
28677 if (tag < 1
28678 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
28679 || !attributes_set_explicitly[tag])
28680 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
28681}
28682
28683static void
28684aeabi_set_attribute_string (int tag, const char *value)
28685{
28686 if (tag < 1
28687 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
28688 || !attributes_set_explicitly[tag])
28689 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
28690}
28691
2c6b98ea
TP
28692/* Return whether features in the *NEEDED feature set are available via
28693 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 28694
2c6b98ea
TP
28695static bfd_boolean
28696have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
28697 const arm_feature_set *needed)
28698{
28699 int i, nb_allowed_archs;
28700 arm_feature_set ext_fset;
28701 const struct arm_option_extension_value_table *opt;
28702
28703 ext_fset = arm_arch_none;
28704 for (opt = arm_extensions; opt->name != NULL; opt++)
28705 {
28706 /* Extension does not provide any feature we need. */
28707 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
28708 continue;
28709
28710 nb_allowed_archs =
28711 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
28712 for (i = 0; i < nb_allowed_archs; i++)
28713 {
28714 /* Empty entry. */
28715 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
28716 break;
28717
28718 /* Extension is available, add it. */
28719 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
28720 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
28721 }
28722 }
28723
28724 /* Can we enable all features in *needed? */
28725 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
28726}
28727
28728/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
28729 a given architecture feature set *ARCH_EXT_FSET including extension feature
28730 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
28731 - if true, check for an exact match of the architecture modulo extensions;
28732 - otherwise, select build attribute value of the first superset
28733 architecture released so that results remains stable when new architectures
28734 are added.
28735 For -march/-mcpu=all the build attribute value of the most featureful
28736 architecture is returned. Tag_CPU_arch_profile result is returned in
28737 PROFILE. */
0198d5e6 28738
2c6b98ea
TP
28739static int
28740get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
28741 const arm_feature_set *ext_fset,
28742 char *profile, int exact_match)
28743{
28744 arm_feature_set arch_fset;
28745 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
28746
28747 /* Select most featureful architecture with all its extensions if building
28748 for -march=all as the feature sets used to set build attributes. */
28749 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
28750 {
28751 /* Force revisiting of decision for each new architecture. */
031254f2 28752 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
2c6b98ea
TP
28753 *profile = 'A';
28754 return TAG_CPU_ARCH_V8;
28755 }
28756
28757 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
28758
28759 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
28760 {
28761 arm_feature_set known_arch_fset;
28762
28763 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
28764 if (exact_match)
28765 {
28766 /* Base architecture match user-specified architecture and
28767 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
28768 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
28769 {
28770 p_ver_ret = p_ver;
28771 goto found;
28772 }
28773 /* Base architecture match user-specified architecture only
28774 (eg. ARMv6-M in the same case as above). Record it in case we
28775 find a match with above condition. */
28776 else if (p_ver_ret == NULL
28777 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
28778 p_ver_ret = p_ver;
28779 }
28780 else
28781 {
28782
28783 /* Architecture has all features wanted. */
28784 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
28785 {
28786 arm_feature_set added_fset;
28787
28788 /* Compute features added by this architecture over the one
28789 recorded in p_ver_ret. */
28790 if (p_ver_ret != NULL)
28791 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
28792 p_ver_ret->flags);
28793 /* First architecture that match incl. with extensions, or the
28794 only difference in features over the recorded match is
28795 features that were optional and are now mandatory. */
28796 if (p_ver_ret == NULL
28797 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
28798 {
28799 p_ver_ret = p_ver;
28800 goto found;
28801 }
28802 }
28803 else if (p_ver_ret == NULL)
28804 {
28805 arm_feature_set needed_ext_fset;
28806
28807 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
28808
28809 /* Architecture has all features needed when using some
28810 extensions. Record it and continue searching in case there
28811 exist an architecture providing all needed features without
28812 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
28813 OS extension). */
28814 if (have_ext_for_needed_feat_p (&known_arch_fset,
28815 &needed_ext_fset))
28816 p_ver_ret = p_ver;
28817 }
28818 }
28819 }
28820
28821 if (p_ver_ret == NULL)
28822 return -1;
28823
28824found:
28825 /* Tag_CPU_arch_profile. */
28826 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
28827 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
28828 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
28829 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
28830 *profile = 'A';
28831 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
28832 *profile = 'R';
28833 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
28834 *profile = 'M';
28835 else
28836 *profile = '\0';
28837 return p_ver_ret->val;
28838}
28839
ee065d83 28840/* Set the public EABI object attributes. */
0198d5e6 28841
c168ce07 28842static void
ee065d83
PB
28843aeabi_set_public_attributes (void)
28844{
b90d5ba0 28845 char profile = '\0';
2c6b98ea 28846 int arch = -1;
90ec0d68 28847 int virt_sec = 0;
bca38921 28848 int fp16_optional = 0;
2c6b98ea
TP
28849 int skip_exact_match = 0;
28850 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 28851
54bab281
TP
28852 /* Autodetection mode, choose the architecture based the instructions
28853 actually used. */
28854 if (no_cpu_selected ())
28855 {
28856 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 28857
54bab281
TP
28858 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
28859 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 28860
54bab281
TP
28861 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
28862 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 28863
54bab281 28864 /* Code run during relaxation relies on selected_cpu being set. */
4d354d8b
TP
28865 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
28866 flags_ext = arm_arch_none;
28867 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
28868 selected_ext = flags_ext;
54bab281
TP
28869 selected_cpu = flags;
28870 }
28871 /* Otherwise, choose the architecture based on the capabilities of the
28872 requested cpu. */
28873 else
4d354d8b
TP
28874 {
28875 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
28876 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
28877 flags_ext = selected_ext;
28878 flags = selected_cpu;
28879 }
28880 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
7f78eb34 28881
ddd7f988 28882 /* Allow the user to override the reported architecture. */
4d354d8b 28883 if (!ARM_FEATURE_ZERO (selected_object_arch))
7a1d4c38 28884 {
4d354d8b 28885 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
2c6b98ea 28886 flags_ext = arm_arch_none;
7a1d4c38 28887 }
2c6b98ea 28888 else
4d354d8b 28889 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
2c6b98ea
TP
28890
28891 /* When this function is run again after relaxation has happened there is no
28892 way to determine whether an architecture or CPU was specified by the user:
28893 - selected_cpu is set above for relaxation to work;
28894 - march_cpu_opt is not set if only -mcpu or .cpu is used;
28895 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
28896 Therefore, if not in -march=all case we first try an exact match and fall
28897 back to autodetection. */
28898 if (!skip_exact_match)
28899 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
28900 if (arch == -1)
28901 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
28902 if (arch == -1)
28903 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 28904
ee065d83
PB
28905 /* Tag_CPU_name. */
28906 if (selected_cpu_name[0])
28907 {
91d6fa6a 28908 char *q;
ee065d83 28909
91d6fa6a
NC
28910 q = selected_cpu_name;
28911 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
28912 {
28913 int i;
5f4273c7 28914
91d6fa6a
NC
28915 q += 4;
28916 for (i = 0; q[i]; i++)
28917 q[i] = TOUPPER (q[i]);
ee065d83 28918 }
91d6fa6a 28919 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 28920 }
62f3b8c8 28921
ee065d83 28922 /* Tag_CPU_arch. */
ee3c0378 28923 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 28924
62b3e311 28925 /* Tag_CPU_arch_profile. */
69239280
MGD
28926 if (profile != '\0')
28927 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 28928
15afaa63 28929 /* Tag_DSP_extension. */
4d354d8b 28930 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
6c290d53 28931 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 28932
2c6b98ea 28933 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 28934 /* Tag_ARM_ISA_use. */
ee3c0378 28935 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 28936 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 28937 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 28938
ee065d83 28939 /* Tag_THUMB_ISA_use. */
ee3c0378 28940 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 28941 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
28942 {
28943 int thumb_isa_use;
28944
28945 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 28946 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
28947 thumb_isa_use = 3;
28948 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
28949 thumb_isa_use = 2;
28950 else
28951 thumb_isa_use = 1;
28952 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
28953 }
62f3b8c8 28954
ee065d83 28955 /* Tag_VFP_arch. */
a715796b
TG
28956 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
28957 aeabi_set_attribute_int (Tag_VFP_arch,
28958 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
28959 ? 7 : 8);
bca38921 28960 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
28961 aeabi_set_attribute_int (Tag_VFP_arch,
28962 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
28963 ? 5 : 6);
28964 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
28965 {
28966 fp16_optional = 1;
28967 aeabi_set_attribute_int (Tag_VFP_arch, 3);
28968 }
ada65aa3 28969 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
28970 {
28971 aeabi_set_attribute_int (Tag_VFP_arch, 4);
28972 fp16_optional = 1;
28973 }
ee3c0378
AS
28974 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
28975 aeabi_set_attribute_int (Tag_VFP_arch, 2);
28976 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 28977 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 28978 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 28979
4547cb56
NC
28980 /* Tag_ABI_HardFP_use. */
28981 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
28982 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
28983 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
28984
ee065d83 28985 /* Tag_WMMX_arch. */
ee3c0378
AS
28986 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
28987 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
28988 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
28989 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 28990
ee3c0378 28991 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
28992 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
28993 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
28994 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
28995 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
28996 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
28997 {
28998 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
28999 {
29000 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
29001 }
29002 else
29003 {
29004 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
29005 fp16_optional = 1;
29006 }
29007 }
fa94de6b 29008
a7ad558c
AV
29009 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
29010 aeabi_set_attribute_int (Tag_MVE_arch, 2);
29011 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
29012 aeabi_set_attribute_int (Tag_MVE_arch, 1);
29013
ee3c0378 29014 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 29015 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 29016 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 29017
69239280
MGD
29018 /* Tag_DIV_use.
29019
29020 We set Tag_DIV_use to two when integer divide instructions have been used
29021 in ARM state, or when Thumb integer divide instructions have been used,
29022 but we have no architecture profile set, nor have we any ARM instructions.
29023
4ed7ed8d
TP
29024 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
29025 by the base architecture.
bca38921 29026
69239280 29027 For new architectures we will have to check these tests. */
031254f2 29028 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
4ed7ed8d
TP
29029 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
29030 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
29031 aeabi_set_attribute_int (Tag_DIV_use, 0);
29032 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
29033 || (profile == '\0'
29034 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
29035 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 29036 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
29037
29038 /* Tag_MP_extension_use. */
29039 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
29040 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
29041
29042 /* Tag Virtualization_use. */
29043 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
29044 virt_sec |= 1;
29045 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
29046 virt_sec |= 2;
29047 if (virt_sec != 0)
29048 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
29049}
29050
c168ce07
TP
29051/* Post relaxation hook. Recompute ARM attributes now that relaxation is
29052 finished and free extension feature bits which will not be used anymore. */
0198d5e6 29053
c168ce07
TP
29054void
29055arm_md_post_relax (void)
29056{
29057 aeabi_set_public_attributes ();
4d354d8b
TP
29058 XDELETE (mcpu_ext_opt);
29059 mcpu_ext_opt = NULL;
29060 XDELETE (march_ext_opt);
29061 march_ext_opt = NULL;
c168ce07
TP
29062}
29063
104d59d1 29064/* Add the default contents for the .ARM.attributes section. */
0198d5e6 29065
ee065d83
PB
29066void
29067arm_md_end (void)
29068{
ee065d83
PB
29069 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
29070 return;
29071
29072 aeabi_set_public_attributes ();
ee065d83 29073}
8463be01 29074#endif /* OBJ_ELF */
ee065d83 29075
ee065d83
PB
29076/* Parse a .cpu directive. */
29077
29078static void
29079s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
29080{
e74cfd16 29081 const struct arm_cpu_option_table *opt;
ee065d83
PB
29082 char *name;
29083 char saved_char;
29084
29085 name = input_line_pointer;
5f4273c7 29086 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
29087 input_line_pointer++;
29088 saved_char = *input_line_pointer;
29089 *input_line_pointer = 0;
29090
29091 /* Skip the first "all" entry. */
29092 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
29093 if (streq (opt->name, name))
29094 {
4d354d8b
TP
29095 selected_arch = opt->value;
29096 selected_ext = opt->ext;
29097 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
ee065d83 29098 if (opt->canonical_name)
5f4273c7 29099 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
29100 else
29101 {
29102 int i;
29103 for (i = 0; opt->name[i]; i++)
29104 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 29105
ee065d83
PB
29106 selected_cpu_name[i] = 0;
29107 }
4d354d8b
TP
29108 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
29109
ee065d83
PB
29110 *input_line_pointer = saved_char;
29111 demand_empty_rest_of_line ();
29112 return;
29113 }
29114 as_bad (_("unknown cpu `%s'"), name);
29115 *input_line_pointer = saved_char;
29116 ignore_rest_of_line ();
29117}
29118
ee065d83
PB
29119/* Parse a .arch directive. */
29120
29121static void
29122s_arm_arch (int ignored ATTRIBUTE_UNUSED)
29123{
e74cfd16 29124 const struct arm_arch_option_table *opt;
ee065d83
PB
29125 char saved_char;
29126 char *name;
29127
29128 name = input_line_pointer;
5f4273c7 29129 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
29130 input_line_pointer++;
29131 saved_char = *input_line_pointer;
29132 *input_line_pointer = 0;
29133
29134 /* Skip the first "all" entry. */
29135 for (opt = arm_archs + 1; opt->name != NULL; opt++)
29136 if (streq (opt->name, name))
29137 {
4d354d8b
TP
29138 selected_arch = opt->value;
29139 selected_ext = arm_arch_none;
29140 selected_cpu = selected_arch;
5f4273c7 29141 strcpy (selected_cpu_name, opt->name);
4d354d8b 29142 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
29143 *input_line_pointer = saved_char;
29144 demand_empty_rest_of_line ();
29145 return;
29146 }
29147
29148 as_bad (_("unknown architecture `%s'\n"), name);
29149 *input_line_pointer = saved_char;
29150 ignore_rest_of_line ();
29151}
29152
7a1d4c38
PB
29153/* Parse a .object_arch directive. */
29154
29155static void
29156s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
29157{
29158 const struct arm_arch_option_table *opt;
29159 char saved_char;
29160 char *name;
29161
29162 name = input_line_pointer;
5f4273c7 29163 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
29164 input_line_pointer++;
29165 saved_char = *input_line_pointer;
29166 *input_line_pointer = 0;
29167
29168 /* Skip the first "all" entry. */
29169 for (opt = arm_archs + 1; opt->name != NULL; opt++)
29170 if (streq (opt->name, name))
29171 {
4d354d8b 29172 selected_object_arch = opt->value;
7a1d4c38
PB
29173 *input_line_pointer = saved_char;
29174 demand_empty_rest_of_line ();
29175 return;
29176 }
29177
29178 as_bad (_("unknown architecture `%s'\n"), name);
29179 *input_line_pointer = saved_char;
29180 ignore_rest_of_line ();
29181}
29182
69133863
MGD
29183/* Parse a .arch_extension directive. */
29184
29185static void
29186s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
29187{
29188 const struct arm_option_extension_value_table *opt;
29189 char saved_char;
29190 char *name;
29191 int adding_value = 1;
29192
29193 name = input_line_pointer;
29194 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
29195 input_line_pointer++;
29196 saved_char = *input_line_pointer;
29197 *input_line_pointer = 0;
29198
29199 if (strlen (name) >= 2
29200 && strncmp (name, "no", 2) == 0)
29201 {
29202 adding_value = 0;
29203 name += 2;
29204 }
29205
29206 for (opt = arm_extensions; opt->name != NULL; opt++)
29207 if (streq (opt->name, name))
29208 {
d942732e
TP
29209 int i, nb_allowed_archs =
29210 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
29211 for (i = 0; i < nb_allowed_archs; i++)
29212 {
29213 /* Empty entry. */
4d354d8b 29214 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
d942732e 29215 continue;
4d354d8b 29216 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
d942732e
TP
29217 break;
29218 }
29219
29220 if (i == nb_allowed_archs)
69133863
MGD
29221 {
29222 as_bad (_("architectural extension `%s' is not allowed for the "
29223 "current base architecture"), name);
29224 break;
29225 }
29226
29227 if (adding_value)
4d354d8b 29228 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
5a70a223 29229 opt->merge_value);
69133863 29230 else
4d354d8b 29231 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
69133863 29232
4d354d8b
TP
29233 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
29234 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
69133863
MGD
29235 *input_line_pointer = saved_char;
29236 demand_empty_rest_of_line ();
3d030cdb
TP
29237 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
29238 on this return so that duplicate extensions (extensions with the
29239 same name as a previous extension in the list) are not considered
29240 for command-line parsing. */
69133863
MGD
29241 return;
29242 }
29243
29244 if (opt->name == NULL)
e673710a 29245 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
29246
29247 *input_line_pointer = saved_char;
29248 ignore_rest_of_line ();
29249}
29250
ee065d83
PB
29251/* Parse a .fpu directive. */
29252
29253static void
29254s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
29255{
69133863 29256 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
29257 char saved_char;
29258 char *name;
29259
29260 name = input_line_pointer;
5f4273c7 29261 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
29262 input_line_pointer++;
29263 saved_char = *input_line_pointer;
29264 *input_line_pointer = 0;
5f4273c7 29265
ee065d83
PB
29266 for (opt = arm_fpus; opt->name != NULL; opt++)
29267 if (streq (opt->name, name))
29268 {
4d354d8b
TP
29269 selected_fpu = opt->value;
29270#ifndef CPU_DEFAULT
29271 if (no_cpu_selected ())
29272 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
29273 else
29274#endif
29275 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
29276 *input_line_pointer = saved_char;
29277 demand_empty_rest_of_line ();
29278 return;
29279 }
29280
29281 as_bad (_("unknown floating point format `%s'\n"), name);
29282 *input_line_pointer = saved_char;
29283 ignore_rest_of_line ();
29284}
ee065d83 29285
794ba86a 29286/* Copy symbol information. */
f31fef98 29287
794ba86a
DJ
29288void
29289arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
29290{
29291 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
29292}
e04befd0 29293
f31fef98 29294#ifdef OBJ_ELF
e04befd0
AS
29295/* Given a symbolic attribute NAME, return the proper integer value.
29296 Returns -1 if the attribute is not known. */
f31fef98 29297
e04befd0
AS
29298int
29299arm_convert_symbolic_attribute (const char *name)
29300{
f31fef98
NC
29301 static const struct
29302 {
29303 const char * name;
29304 const int tag;
29305 }
29306 attribute_table[] =
29307 {
29308 /* When you modify this table you should
29309 also modify the list in doc/c-arm.texi. */
e04befd0 29310#define T(tag) {#tag, tag}
f31fef98
NC
29311 T (Tag_CPU_raw_name),
29312 T (Tag_CPU_name),
29313 T (Tag_CPU_arch),
29314 T (Tag_CPU_arch_profile),
29315 T (Tag_ARM_ISA_use),
29316 T (Tag_THUMB_ISA_use),
75375b3e 29317 T (Tag_FP_arch),
f31fef98
NC
29318 T (Tag_VFP_arch),
29319 T (Tag_WMMX_arch),
29320 T (Tag_Advanced_SIMD_arch),
29321 T (Tag_PCS_config),
29322 T (Tag_ABI_PCS_R9_use),
29323 T (Tag_ABI_PCS_RW_data),
29324 T (Tag_ABI_PCS_RO_data),
29325 T (Tag_ABI_PCS_GOT_use),
29326 T (Tag_ABI_PCS_wchar_t),
29327 T (Tag_ABI_FP_rounding),
29328 T (Tag_ABI_FP_denormal),
29329 T (Tag_ABI_FP_exceptions),
29330 T (Tag_ABI_FP_user_exceptions),
29331 T (Tag_ABI_FP_number_model),
75375b3e 29332 T (Tag_ABI_align_needed),
f31fef98 29333 T (Tag_ABI_align8_needed),
75375b3e 29334 T (Tag_ABI_align_preserved),
f31fef98
NC
29335 T (Tag_ABI_align8_preserved),
29336 T (Tag_ABI_enum_size),
29337 T (Tag_ABI_HardFP_use),
29338 T (Tag_ABI_VFP_args),
29339 T (Tag_ABI_WMMX_args),
29340 T (Tag_ABI_optimization_goals),
29341 T (Tag_ABI_FP_optimization_goals),
29342 T (Tag_compatibility),
29343 T (Tag_CPU_unaligned_access),
75375b3e 29344 T (Tag_FP_HP_extension),
f31fef98
NC
29345 T (Tag_VFP_HP_extension),
29346 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
29347 T (Tag_MPextension_use),
29348 T (Tag_DIV_use),
f31fef98
NC
29349 T (Tag_nodefaults),
29350 T (Tag_also_compatible_with),
29351 T (Tag_conformance),
29352 T (Tag_T2EE_use),
29353 T (Tag_Virtualization_use),
15afaa63 29354 T (Tag_DSP_extension),
a7ad558c 29355 T (Tag_MVE_arch),
cd21e546 29356 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 29357#undef T
f31fef98 29358 };
e04befd0
AS
29359 unsigned int i;
29360
29361 if (name == NULL)
29362 return -1;
29363
f31fef98 29364 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 29365 if (streq (name, attribute_table[i].name))
e04befd0
AS
29366 return attribute_table[i].tag;
29367
29368 return -1;
29369}
267bf995 29370
93ef582d
NC
29371/* Apply sym value for relocations only in the case that they are for
29372 local symbols in the same segment as the fixup and you have the
29373 respective architectural feature for blx and simple switches. */
0198d5e6 29374
267bf995 29375int
93ef582d 29376arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
29377{
29378 if (fixP->fx_addsy
29379 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
29380 /* PR 17444: If the local symbol is in a different section then a reloc
29381 will always be generated for it, so applying the symbol value now
29382 will result in a double offset being stored in the relocation. */
29383 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 29384 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
29385 {
29386 switch (fixP->fx_r_type)
29387 {
29388 case BFD_RELOC_ARM_PCREL_BLX:
29389 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29390 if (ARM_IS_FUNC (fixP->fx_addsy))
29391 return 1;
29392 break;
29393
29394 case BFD_RELOC_ARM_PCREL_CALL:
29395 case BFD_RELOC_THUMB_PCREL_BLX:
29396 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 29397 return 1;
267bf995
RR
29398 break;
29399
29400 default:
29401 break;
29402 }
29403
29404 }
29405 return 0;
29406}
f31fef98 29407#endif /* OBJ_ELF */