[PATCH 3/57][Arm][GAS] Add support for MVE instructions: vabs and vneg
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
82704155 2 Copyright (C) 1994-2019 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b
RE
34#include "opcode/arm.h"
35
b99bd4ef
NC
36#ifdef OBJ_ELF
37#include "elf/arm.h"
a394c00f 38#include "dw2gencfi.h"
b99bd4ef
NC
39#endif
40
f0927246
NC
41#include "dwarf2dbg.h"
42
7ed4c4c5
NC
43#ifdef OBJ_ELF
44/* Must be at least the size of the largest unwind opcode (currently two). */
45#define ARM_OPCODE_CHUNK_SIZE 8
46
47/* This structure holds the unwinding state. */
48
49static struct
50{
c19d1205
ZW
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
7ed4c4c5 55 /* The segment containing the function. */
c19d1205
ZW
56 segT saved_seg;
57 subsegT saved_subseg;
7ed4c4c5
NC
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
c19d1205
ZW
60 int opcode_count;
61 int opcode_alloc;
7ed4c4c5 62 /* The number of bytes pushed to the stack. */
c19d1205 63 offsetT frame_size;
7ed4c4c5
NC
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
c19d1205 67 offsetT pending_offset;
7ed4c4c5 68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
7ed4c4c5 72 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 73 unsigned fp_used:1;
7ed4c4c5 74 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 75 unsigned sp_restored:1;
7ed4c4c5
NC
76} unwind;
77
18a20338
CL
78/* Whether --fdpic was given. */
79static int arm_fdpic;
80
8b1ad454
NC
81#endif /* OBJ_ELF */
82
4962c51a
MS
83/* Results from operand parsing worker functions. */
84
85typedef enum
86{
87 PARSE_OPERAND_SUCCESS,
88 PARSE_OPERAND_FAIL,
89 PARSE_OPERAND_FAIL_NO_BACKTRACK
90} parse_operand_result;
91
33a392fb
PB
92enum arm_float_abi
93{
94 ARM_FLOAT_ABI_HARD,
95 ARM_FLOAT_ABI_SOFTFP,
96 ARM_FLOAT_ABI_SOFT
97};
98
c19d1205 99/* Types of processor to assemble for. */
b99bd4ef 100#ifndef CPU_DEFAULT
8a59fff3 101/* The code that was here used to select a default CPU depending on compiler
fa94de6b 102 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
103 changing gas' default behaviour depending upon the build host.
104
105 If you have a target that requires a default CPU option then the you
106 should define CPU_DEFAULT here. */
b99bd4ef
NC
107#endif
108
109#ifndef FPU_DEFAULT
c820d418
MM
110# ifdef TE_LINUX
111# define FPU_DEFAULT FPU_ARCH_FPA
112# elif defined (TE_NetBSD)
113# ifdef OBJ_ELF
114# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
115# else
116 /* Legacy a.out format. */
117# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
118# endif
4e7fd91e
PB
119# elif defined (TE_VXWORKS)
120# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
121# else
122 /* For backwards compatibility, default to FPA. */
123# define FPU_DEFAULT FPU_ARCH_FPA
124# endif
125#endif /* ifndef FPU_DEFAULT */
b99bd4ef 126
c19d1205 127#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 128
4d354d8b
TP
129/* Current set of feature bits available (CPU+FPU). Different from
130 selected_cpu + selected_fpu in case of autodetection since the CPU
131 feature bits are then all set. */
e74cfd16 132static arm_feature_set cpu_variant;
4d354d8b
TP
133/* Feature bits used in each execution state. Used to set build attribute
134 (in particular Tag_*_ISA_use) in CPU autodetection mode. */
e74cfd16
PB
135static arm_feature_set arm_arch_used;
136static arm_feature_set thumb_arch_used;
b99bd4ef 137
b99bd4ef 138/* Flags stored in private area of BFD structure. */
c19d1205
ZW
139static int uses_apcs_26 = FALSE;
140static int atpcs = FALSE;
b34976b6
AM
141static int support_interwork = FALSE;
142static int uses_apcs_float = FALSE;
c19d1205 143static int pic_code = FALSE;
845b51d6 144static int fix_v4bx = FALSE;
278df34e
NS
145/* Warn on using deprecated features. */
146static int warn_on_deprecated = TRUE;
147
2e6976a8
DG
148/* Understand CodeComposer Studio assembly syntax. */
149bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
150
151/* Variables that we set while parsing command-line options. Once all
152 options have been read we re-process these values to set the real
153 assembly flags. */
4d354d8b
TP
154
155/* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1
156 instead of -mcpu=arm1). */
157static const arm_feature_set *legacy_cpu = NULL;
158static const arm_feature_set *legacy_fpu = NULL;
159
160/* CPU, extension and FPU feature bits selected by -mcpu. */
161static const arm_feature_set *mcpu_cpu_opt = NULL;
162static arm_feature_set *mcpu_ext_opt = NULL;
163static const arm_feature_set *mcpu_fpu_opt = NULL;
164
165/* CPU, extension and FPU feature bits selected by -march. */
166static const arm_feature_set *march_cpu_opt = NULL;
167static arm_feature_set *march_ext_opt = NULL;
168static const arm_feature_set *march_fpu_opt = NULL;
169
170/* Feature bits selected by -mfpu. */
171static const arm_feature_set *mfpu_opt = NULL;
e74cfd16
PB
172
173/* Constants for known architecture features. */
174static const arm_feature_set fpu_default = FPU_DEFAULT;
f85d59c3 175static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 176static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
177static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
178static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
e74cfd16
PB
179static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
180static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
69c9e028 181#ifdef OBJ_ELF
e74cfd16 182static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
69c9e028 183#endif
e74cfd16
PB
184static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
185
186#ifdef CPU_DEFAULT
187static const arm_feature_set cpu_default = CPU_DEFAULT;
188#endif
189
823d2571 190static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
4070243b 191static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
823d2571
TG
192static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
193static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
194static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
195static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
196static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
197static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 198static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
199 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
200static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
201static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
202static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
203static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
204static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
205static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
206static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
55e8aae7
SP
207/* Only for compatability of hint instructions. */
208static const arm_feature_set arm_ext_v6k_v6t2 =
209 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2);
823d2571
TG
210static const arm_feature_set arm_ext_v6_notm =
211 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
212static const arm_feature_set arm_ext_v6_dsp =
213 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
214static const arm_feature_set arm_ext_barrier =
215 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
216static const arm_feature_set arm_ext_msr =
217 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
218static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
219static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
220static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
221static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 222#ifdef OBJ_ELF
e7d39ed3 223static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 224#endif
823d2571 225static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 226static const arm_feature_set arm_ext_m =
173205ca 227 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
16a1fa25 228 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
229static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
230static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
231static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
232static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
233static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 234static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 235static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
236static const arm_feature_set arm_ext_v8m_main =
237 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
e12437dc
AV
238static const arm_feature_set arm_ext_v8_1m_main =
239ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
16a1fa25
TP
240/* Instructions in ARMv8-M only found in M profile architectures. */
241static const arm_feature_set arm_ext_v8m_m_only =
242 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
243static const arm_feature_set arm_ext_v6t2_v8m =
244 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
245/* Instructions shared between ARMv8-A and ARMv8-M. */
246static const arm_feature_set arm_ext_atomics =
247 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 248#ifdef OBJ_ELF
15afaa63
TP
249/* DSP instructions Tag_DSP_extension refers to. */
250static const arm_feature_set arm_ext_dsp =
251 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 252#endif
4d1464f2
MW
253static const arm_feature_set arm_ext_ras =
254 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
255/* FP16 instructions. */
256static const arm_feature_set arm_ext_fp16 =
257 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
01f48020
TC
258static const arm_feature_set arm_ext_fp16_fml =
259 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
dec41383
JW
260static const arm_feature_set arm_ext_v8_2 =
261 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
49e8a725
SN
262static const arm_feature_set arm_ext_v8_3 =
263 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
7fadb25d
SD
264static const arm_feature_set arm_ext_sb =
265 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
dad0c3bf
SD
266static const arm_feature_set arm_ext_predres =
267 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
e74cfd16
PB
268
269static const arm_feature_set arm_arch_any = ARM_ANY;
49fa50ef 270#ifdef OBJ_ELF
2c6b98ea 271static const arm_feature_set fpu_any = FPU_ANY;
49fa50ef 272#endif
f85d59c3 273static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
274static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
275static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
276
2d447fca 277static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 278 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 279static const arm_feature_set arm_cext_iwmmxt =
823d2571 280 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 281static const arm_feature_set arm_cext_xscale =
823d2571 282 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 283static const arm_feature_set arm_cext_maverick =
823d2571
TG
284 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
285static const arm_feature_set fpu_fpa_ext_v1 =
286 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
287static const arm_feature_set fpu_fpa_ext_v2 =
288 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 289static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
290 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
291static const arm_feature_set fpu_vfp_ext_v1 =
292 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
293static const arm_feature_set fpu_vfp_ext_v2 =
294 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
295static const arm_feature_set fpu_vfp_ext_v3xd =
296 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
297static const arm_feature_set fpu_vfp_ext_v3 =
298 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 299static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
300 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
301static const arm_feature_set fpu_neon_ext_v1 =
302 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 303static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 304 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
a7ad558c
AV
305static const arm_feature_set mve_ext =
306 ARM_FEATURE_COPROC (FPU_MVE);
307static const arm_feature_set mve_fp_ext =
308 ARM_FEATURE_COPROC (FPU_MVE_FP);
69c9e028 309#ifdef OBJ_ELF
823d2571
TG
310static const arm_feature_set fpu_vfp_fp16 =
311 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
312static const arm_feature_set fpu_neon_ext_fma =
313 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 314#endif
823d2571
TG
315static const arm_feature_set fpu_vfp_ext_fma =
316 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 317static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 318 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 319static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 320 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 321static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 322 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 323static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 324 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 325static const arm_feature_set crc_ext_armv8 =
823d2571 326 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 327static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 328 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
329static const arm_feature_set fpu_neon_ext_dotprod =
330 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 331
33a392fb 332static int mfloat_abi_opt = -1;
4d354d8b
TP
333/* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
334 directive. */
335static arm_feature_set selected_arch = ARM_ARCH_NONE;
336/* Extension feature bits selected by the last -mcpu/-march or .arch_extension
337 directive. */
338static arm_feature_set selected_ext = ARM_ARCH_NONE;
339/* Feature bits selected by the last -mcpu/-march or by the combination of the
340 last .cpu/.arch directive .arch_extension directives since that
341 directive. */
e74cfd16 342static arm_feature_set selected_cpu = ARM_ARCH_NONE;
4d354d8b
TP
343/* FPU feature bits selected by the last -mfpu or .fpu directive. */
344static arm_feature_set selected_fpu = FPU_NONE;
345/* Feature bits selected by the last .object_arch directive. */
346static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
ee065d83 347/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 348static char selected_cpu_name[20];
8d67f500 349
aacf0b33
KT
350extern FLONUM_TYPE generic_floating_point_number;
351
8d67f500
NC
352/* Return if no cpu was selected on command-line. */
353static bfd_boolean
354no_cpu_selected (void)
355{
823d2571 356 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
357}
358
7cc69913 359#ifdef OBJ_ELF
deeaaff8
DJ
360# ifdef EABI_DEFAULT
361static int meabi_flags = EABI_DEFAULT;
362# else
d507cf36 363static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 364# endif
e1da3f5b 365
ee3c0378
AS
366static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
367
e1da3f5b 368bfd_boolean
5f4273c7 369arm_is_eabi (void)
e1da3f5b
PB
370{
371 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
372}
7cc69913 373#endif
b99bd4ef 374
b99bd4ef 375#ifdef OBJ_ELF
c19d1205 376/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
377symbolS * GOT_symbol;
378#endif
379
b99bd4ef
NC
380/* 0: assemble for ARM,
381 1: assemble for Thumb,
382 2: assemble for Thumb even though target CPU does not support thumb
383 instructions. */
384static int thumb_mode = 0;
8dc2430f
NC
385/* A value distinct from the possible values for thumb_mode that we
386 can use to record whether thumb_mode has been copied into the
387 tc_frag_data field of a frag. */
388#define MODE_RECORDED (1 << 4)
b99bd4ef 389
e07e6e58
NC
390/* Specifies the intrinsic IT insn behavior mode. */
391enum implicit_it_mode
392{
393 IMPLICIT_IT_MODE_NEVER = 0x00,
394 IMPLICIT_IT_MODE_ARM = 0x01,
395 IMPLICIT_IT_MODE_THUMB = 0x02,
396 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
397};
398static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
399
c19d1205
ZW
400/* If unified_syntax is true, we are processing the new unified
401 ARM/Thumb syntax. Important differences from the old ARM mode:
402
403 - Immediate operands do not require a # prefix.
404 - Conditional affixes always appear at the end of the
405 instruction. (For backward compatibility, those instructions
406 that formerly had them in the middle, continue to accept them
407 there.)
408 - The IT instruction may appear, and if it does is validated
409 against subsequent conditional affixes. It does not generate
410 machine code.
411
412 Important differences from the old Thumb mode:
413
414 - Immediate operands do not require a # prefix.
415 - Most of the V6T2 instructions are only available in unified mode.
416 - The .N and .W suffixes are recognized and honored (it is an error
417 if they cannot be honored).
418 - All instructions set the flags if and only if they have an 's' affix.
419 - Conditional affixes may be used. They are validated against
420 preceding IT instructions. Unlike ARM mode, you cannot use a
421 conditional affix except in the scope of an IT instruction. */
422
423static bfd_boolean unified_syntax = FALSE;
b99bd4ef 424
bacebabc
RM
425/* An immediate operand can start with #, and ld*, st*, pld operands
426 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
427 before a [, which can appear as the first operand for pld.
428 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
429const char arm_symbol_chars[] = "#[]{}";
bacebabc 430
5287ad62
JB
431enum neon_el_type
432{
dcbf9037 433 NT_invtype,
5287ad62
JB
434 NT_untyped,
435 NT_integer,
436 NT_float,
437 NT_poly,
438 NT_signed,
dcbf9037 439 NT_unsigned
5287ad62
JB
440};
441
442struct neon_type_el
443{
444 enum neon_el_type type;
445 unsigned size;
446};
447
448#define NEON_MAX_TYPE_ELS 4
449
450struct neon_type
451{
452 struct neon_type_el el[NEON_MAX_TYPE_ELS];
453 unsigned elems;
454};
455
5ee91343 456enum pred_instruction_type
e07e6e58 457{
5ee91343
AV
458 OUTSIDE_PRED_INSN,
459 INSIDE_VPT_INSN,
e07e6e58
NC
460 INSIDE_IT_INSN,
461 INSIDE_IT_LAST_INSN,
462 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 463 if inside, should be the last one. */
e07e6e58 464 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 465 i.e. BKPT and NOP. */
5ee91343
AV
466 IT_INSN, /* The IT insn has been parsed. */
467 VPT_INSN, /* The VPT/VPST insn has been parsed. */
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
037e8744 15953 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15954 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15955
485dee97
AV
15956 if (check_simd_pred_availability (et.type == NT_float,
15957 NEON_CHECK_ARCH | NEON_CHECK_CC))
15958 return;
15959
5287ad62
JB
15960 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15961 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15962 inst.instruction |= LOW4 (inst.operands[1].reg);
15963 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15964 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15965 inst.instruction |= (et.type == NT_float) << 10;
15966 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15967
88714cb8 15968 neon_dp_fixup (&inst);
5287ad62
JB
15969}
15970
15971static void
15972do_neon_sli (void)
15973{
037e8744 15974 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15975 struct neon_type_el et = neon_check_type (2, rs,
15976 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15977 int imm = inst.operands[2].imm;
15978 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15979 _("immediate out of range for insert"));
037e8744 15980 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15981}
15982
15983static void
15984do_neon_sri (void)
15985{
037e8744 15986 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15987 struct neon_type_el et = neon_check_type (2, rs,
15988 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15989 int imm = inst.operands[2].imm;
15990 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15991 _("immediate out of range for insert"));
037e8744 15992 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15993}
15994
15995static void
15996do_neon_qshlu_imm (void)
15997{
037e8744 15998 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15999 struct neon_type_el et = neon_check_type (2, rs,
16000 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
16001 int imm = inst.operands[2].imm;
16002 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 16003 _("immediate out of range for shift"));
5287ad62
JB
16004 /* Only encodes the 'U present' variant of the instruction.
16005 In this case, signed types have OP (bit 8) set to 0.
16006 Unsigned types have OP set to 1. */
16007 inst.instruction |= (et.type == NT_unsigned) << 8;
16008 /* The rest of the bits are the same as other immediate shifts. */
037e8744 16009 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
16010}
16011
16012static void
16013do_neon_qmovn (void)
16014{
16015 struct neon_type_el et = neon_check_type (2, NS_DQ,
16016 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
16017 /* Saturating move where operands can be signed or unsigned, and the
16018 destination has the same signedness. */
88714cb8 16019 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16020 if (et.type == NT_unsigned)
16021 inst.instruction |= 0xc0;
16022 else
16023 inst.instruction |= 0x80;
16024 neon_two_same (0, 1, et.size / 2);
16025}
16026
16027static void
16028do_neon_qmovun (void)
16029{
16030 struct neon_type_el et = neon_check_type (2, NS_DQ,
16031 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
16032 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 16033 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16034 neon_two_same (0, 1, et.size / 2);
16035}
16036
16037static void
16038do_neon_rshift_sat_narrow (void)
16039{
16040 /* FIXME: Types for narrowing. If operands are signed, results can be signed
16041 or unsigned. If operands are unsigned, results must also be unsigned. */
16042 struct neon_type_el et = neon_check_type (2, NS_DQI,
16043 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
16044 int imm = inst.operands[2].imm;
16045 /* This gets the bounds check, size encoding and immediate bits calculation
16046 right. */
16047 et.size /= 2;
5f4273c7 16048
5287ad62
JB
16049 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
16050 VQMOVN.I<size> <Dd>, <Qm>. */
16051 if (imm == 0)
16052 {
16053 inst.operands[2].present = 0;
16054 inst.instruction = N_MNEM_vqmovn;
16055 do_neon_qmovn ();
16056 return;
16057 }
5f4273c7 16058
5287ad62 16059 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16060 _("immediate out of range"));
5287ad62
JB
16061 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
16062}
16063
16064static void
16065do_neon_rshift_sat_narrow_u (void)
16066{
16067 /* FIXME: Types for narrowing. If operands are signed, results can be signed
16068 or unsigned. If operands are unsigned, results must also be unsigned. */
16069 struct neon_type_el et = neon_check_type (2, NS_DQI,
16070 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
16071 int imm = inst.operands[2].imm;
16072 /* This gets the bounds check, size encoding and immediate bits calculation
16073 right. */
16074 et.size /= 2;
16075
16076 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
16077 VQMOVUN.I<size> <Dd>, <Qm>. */
16078 if (imm == 0)
16079 {
16080 inst.operands[2].present = 0;
16081 inst.instruction = N_MNEM_vqmovun;
16082 do_neon_qmovun ();
16083 return;
16084 }
16085
16086 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16087 _("immediate out of range"));
5287ad62
JB
16088 /* FIXME: The manual is kind of unclear about what value U should have in
16089 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
16090 must be 1. */
16091 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
16092}
16093
16094static void
16095do_neon_movn (void)
16096{
16097 struct neon_type_el et = neon_check_type (2, NS_DQ,
16098 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 16099 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16100 neon_two_same (0, 1, et.size / 2);
16101}
16102
16103static void
16104do_neon_rshift_narrow (void)
16105{
16106 struct neon_type_el et = neon_check_type (2, NS_DQI,
16107 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
16108 int imm = inst.operands[2].imm;
16109 /* This gets the bounds check, size encoding and immediate bits calculation
16110 right. */
16111 et.size /= 2;
5f4273c7 16112
5287ad62
JB
16113 /* If immediate is zero then we are a pseudo-instruction for
16114 VMOVN.I<size> <Dd>, <Qm> */
16115 if (imm == 0)
16116 {
16117 inst.operands[2].present = 0;
16118 inst.instruction = N_MNEM_vmovn;
16119 do_neon_movn ();
16120 return;
16121 }
5f4273c7 16122
5287ad62 16123 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16124 _("immediate out of range for narrowing operation"));
5287ad62
JB
16125 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
16126}
16127
16128static void
16129do_neon_shll (void)
16130{
16131 /* FIXME: Type checking when lengthening. */
16132 struct neon_type_el et = neon_check_type (2, NS_QDI,
16133 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
16134 unsigned imm = inst.operands[2].imm;
16135
16136 if (imm == et.size)
16137 {
16138 /* Maximum shift variant. */
88714cb8 16139 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16140 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16141 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16142 inst.instruction |= LOW4 (inst.operands[1].reg);
16143 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16144 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 16145
88714cb8 16146 neon_dp_fixup (&inst);
5287ad62
JB
16147 }
16148 else
16149 {
16150 /* A more-specific type check for non-max versions. */
16151 et = neon_check_type (2, NS_QDI,
477330fc 16152 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 16153 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16154 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
16155 }
16156}
16157
037e8744 16158/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
16159 the current instruction is. */
16160
6b9a8b67
MGD
16161#define CVT_FLAVOUR_VAR \
16162 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
16163 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
16164 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
16165 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
16166 /* Half-precision conversions. */ \
cc933301
JW
16167 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
16168 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
16169 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
16170 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
16171 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
16172 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
16173 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
16174 Compared with single/double precision variants, only the co-processor \
16175 field is different, so the encoding flow is reused here. */ \
16176 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
16177 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
16178 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
16179 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
16180 /* VFP instructions. */ \
16181 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
16182 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
16183 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
16184 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
16185 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
16186 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
16187 /* VFP instructions with bitshift. */ \
16188 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
16189 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
16190 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
16191 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
16192 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
16193 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
16194 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
16195 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
16196
16197#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
16198 neon_cvt_flavour_##C,
16199
16200/* The different types of conversions we can do. */
16201enum neon_cvt_flavour
16202{
16203 CVT_FLAVOUR_VAR
16204 neon_cvt_flavour_invalid,
16205 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
16206};
16207
16208#undef CVT_VAR
16209
16210static enum neon_cvt_flavour
16211get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 16212{
6b9a8b67
MGD
16213#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
16214 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
16215 if (et.type != NT_invtype) \
16216 { \
16217 inst.error = NULL; \
16218 return (neon_cvt_flavour_##C); \
5287ad62 16219 }
6b9a8b67 16220
5287ad62 16221 struct neon_type_el et;
037e8744 16222 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 16223 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
16224 /* The instruction versions which take an immediate take one register
16225 argument, which is extended to the width of the full register. Thus the
16226 "source" and "destination" registers must have the same width. Hack that
16227 here by making the size equal to the key (wider, in this case) operand. */
16228 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 16229
6b9a8b67
MGD
16230 CVT_FLAVOUR_VAR;
16231
16232 return neon_cvt_flavour_invalid;
5287ad62
JB
16233#undef CVT_VAR
16234}
16235
7e8e6784
MGD
16236enum neon_cvt_mode
16237{
16238 neon_cvt_mode_a,
16239 neon_cvt_mode_n,
16240 neon_cvt_mode_p,
16241 neon_cvt_mode_m,
16242 neon_cvt_mode_z,
30bdf752
MGD
16243 neon_cvt_mode_x,
16244 neon_cvt_mode_r
7e8e6784
MGD
16245};
16246
037e8744
JB
16247/* Neon-syntax VFP conversions. */
16248
5287ad62 16249static void
6b9a8b67 16250do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 16251{
037e8744 16252 const char *opname = 0;
5f4273c7 16253
d54af2d0
RL
16254 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
16255 || rs == NS_FHI || rs == NS_HFI)
5287ad62 16256 {
037e8744
JB
16257 /* Conversions with immediate bitshift. */
16258 const char *enc[] =
477330fc 16259 {
6b9a8b67
MGD
16260#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
16261 CVT_FLAVOUR_VAR
16262 NULL
16263#undef CVT_VAR
477330fc 16264 };
037e8744 16265
6b9a8b67 16266 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
16267 {
16268 opname = enc[flavour];
16269 constraint (inst.operands[0].reg != inst.operands[1].reg,
16270 _("operands 0 and 1 must be the same register"));
16271 inst.operands[1] = inst.operands[2];
16272 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
16273 }
5287ad62
JB
16274 }
16275 else
16276 {
037e8744
JB
16277 /* Conversions without bitshift. */
16278 const char *enc[] =
477330fc 16279 {
6b9a8b67
MGD
16280#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
16281 CVT_FLAVOUR_VAR
16282 NULL
16283#undef CVT_VAR
477330fc 16284 };
037e8744 16285
6b9a8b67 16286 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 16287 opname = enc[flavour];
037e8744
JB
16288 }
16289
16290 if (opname)
16291 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
16292
16293 /* ARMv8.2 fp16 VCVT instruction. */
16294 if (flavour == neon_cvt_flavour_s32_f16
16295 || flavour == neon_cvt_flavour_u32_f16
16296 || flavour == neon_cvt_flavour_f16_u32
16297 || flavour == neon_cvt_flavour_f16_s32)
16298 do_scalar_fp16_v82_encode ();
037e8744
JB
16299}
16300
16301static void
16302do_vfp_nsyn_cvtz (void)
16303{
d54af2d0 16304 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 16305 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
16306 const char *enc[] =
16307 {
6b9a8b67
MGD
16308#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
16309 CVT_FLAVOUR_VAR
16310 NULL
16311#undef CVT_VAR
037e8744
JB
16312 };
16313
6b9a8b67 16314 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
16315 do_vfp_nsyn_opcode (enc[flavour]);
16316}
f31fef98 16317
037e8744 16318static void
bacebabc 16319do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
16320 enum neon_cvt_mode mode)
16321{
16322 int sz, op;
16323 int rm;
16324
a715796b
TG
16325 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16326 D register operands. */
16327 if (flavour == neon_cvt_flavour_s32_f64
16328 || flavour == neon_cvt_flavour_u32_f64)
16329 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16330 _(BAD_FPU));
16331
9db2f6b4
RL
16332 if (flavour == neon_cvt_flavour_s32_f16
16333 || flavour == neon_cvt_flavour_u32_f16)
16334 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
16335 _(BAD_FP16));
16336
5ee91343 16337 set_pred_insn_type (OUTSIDE_PRED_INSN);
7e8e6784
MGD
16338
16339 switch (flavour)
16340 {
16341 case neon_cvt_flavour_s32_f64:
16342 sz = 1;
827f64ff 16343 op = 1;
7e8e6784
MGD
16344 break;
16345 case neon_cvt_flavour_s32_f32:
16346 sz = 0;
16347 op = 1;
16348 break;
9db2f6b4
RL
16349 case neon_cvt_flavour_s32_f16:
16350 sz = 0;
16351 op = 1;
16352 break;
7e8e6784
MGD
16353 case neon_cvt_flavour_u32_f64:
16354 sz = 1;
16355 op = 0;
16356 break;
16357 case neon_cvt_flavour_u32_f32:
16358 sz = 0;
16359 op = 0;
16360 break;
9db2f6b4
RL
16361 case neon_cvt_flavour_u32_f16:
16362 sz = 0;
16363 op = 0;
16364 break;
7e8e6784
MGD
16365 default:
16366 first_error (_("invalid instruction shape"));
16367 return;
16368 }
16369
16370 switch (mode)
16371 {
16372 case neon_cvt_mode_a: rm = 0; break;
16373 case neon_cvt_mode_n: rm = 1; break;
16374 case neon_cvt_mode_p: rm = 2; break;
16375 case neon_cvt_mode_m: rm = 3; break;
16376 default: first_error (_("invalid rounding mode")); return;
16377 }
16378
16379 NEON_ENCODE (FPV8, inst);
16380 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
16381 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
16382 inst.instruction |= sz << 8;
9db2f6b4
RL
16383
16384 /* ARMv8.2 fp16 VCVT instruction. */
16385 if (flavour == neon_cvt_flavour_s32_f16
16386 ||flavour == neon_cvt_flavour_u32_f16)
16387 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
16388 inst.instruction |= op << 7;
16389 inst.instruction |= rm << 16;
16390 inst.instruction |= 0xf0000000;
16391 inst.is_neon = TRUE;
16392}
16393
16394static void
16395do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
16396{
16397 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
16398 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
16399 NS_FH, NS_HF, NS_FHI, NS_HFI,
16400 NS_NULL);
6b9a8b67 16401 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 16402
cc933301
JW
16403 if (flavour == neon_cvt_flavour_invalid)
16404 return;
16405
e3e535bc 16406 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 16407 if (mode == neon_cvt_mode_z
e3e535bc 16408 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
16409 && (flavour == neon_cvt_flavour_s16_f16
16410 || flavour == neon_cvt_flavour_u16_f16
16411 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
16412 || flavour == neon_cvt_flavour_u32_f32
16413 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 16414 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
16415 && (rs == NS_FD || rs == NS_FF))
16416 {
16417 do_vfp_nsyn_cvtz ();
16418 return;
16419 }
16420
9db2f6b4
RL
16421 /* ARMv8.2 fp16 VCVT conversions. */
16422 if (mode == neon_cvt_mode_z
16423 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
16424 && (flavour == neon_cvt_flavour_s32_f16
16425 || flavour == neon_cvt_flavour_u32_f16)
16426 && (rs == NS_FH))
16427 {
16428 do_vfp_nsyn_cvtz ();
16429 do_scalar_fp16_v82_encode ();
16430 return;
16431 }
16432
037e8744 16433 /* VFP rather than Neon conversions. */
6b9a8b67 16434 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 16435 {
7e8e6784
MGD
16436 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
16437 do_vfp_nsyn_cvt (rs, flavour);
16438 else
16439 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
16440
037e8744
JB
16441 return;
16442 }
16443
16444 switch (rs)
16445 {
16446 case NS_DDI:
16447 case NS_QQI:
16448 {
477330fc 16449 unsigned immbits;
cc933301
JW
16450 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
16451 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 16452
477330fc
RM
16453 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16454 return;
037e8744 16455
477330fc
RM
16456 /* Fixed-point conversion with #0 immediate is encoded as an
16457 integer conversion. */
16458 if (inst.operands[2].present && inst.operands[2].imm == 0)
16459 goto int_encode;
477330fc
RM
16460 NEON_ENCODE (IMMED, inst);
16461 if (flavour != neon_cvt_flavour_invalid)
16462 inst.instruction |= enctab[flavour];
16463 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16464 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16465 inst.instruction |= LOW4 (inst.operands[1].reg);
16466 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16467 inst.instruction |= neon_quad (rs) << 6;
16468 inst.instruction |= 1 << 21;
cc933301
JW
16469 if (flavour < neon_cvt_flavour_s16_f16)
16470 {
16471 inst.instruction |= 1 << 21;
16472 immbits = 32 - inst.operands[2].imm;
16473 inst.instruction |= immbits << 16;
16474 }
16475 else
16476 {
16477 inst.instruction |= 3 << 20;
16478 immbits = 16 - inst.operands[2].imm;
16479 inst.instruction |= immbits << 16;
16480 inst.instruction &= ~(1 << 9);
16481 }
477330fc
RM
16482
16483 neon_dp_fixup (&inst);
037e8744
JB
16484 }
16485 break;
16486
16487 case NS_DD:
16488 case NS_QQ:
7e8e6784
MGD
16489 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
16490 {
16491 NEON_ENCODE (FLOAT, inst);
5ee91343 16492 set_pred_insn_type (OUTSIDE_PRED_INSN);
7e8e6784
MGD
16493
16494 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16495 return;
16496
16497 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16498 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16499 inst.instruction |= LOW4 (inst.operands[1].reg);
16500 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16501 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
16502 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
16503 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 16504 inst.instruction |= mode << 8;
cc933301
JW
16505 if (flavour == neon_cvt_flavour_u16_f16
16506 || flavour == neon_cvt_flavour_s16_f16)
16507 /* Mask off the original size bits and reencode them. */
16508 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
16509
7e8e6784
MGD
16510 if (thumb_mode)
16511 inst.instruction |= 0xfc000000;
16512 else
16513 inst.instruction |= 0xf0000000;
16514 }
16515 else
16516 {
037e8744 16517 int_encode:
7e8e6784 16518 {
cc933301
JW
16519 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
16520 0x100, 0x180, 0x0, 0x080};
037e8744 16521
7e8e6784 16522 NEON_ENCODE (INTEGER, inst);
037e8744 16523
7e8e6784
MGD
16524 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16525 return;
037e8744 16526
7e8e6784
MGD
16527 if (flavour != neon_cvt_flavour_invalid)
16528 inst.instruction |= enctab[flavour];
037e8744 16529
7e8e6784
MGD
16530 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16531 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16532 inst.instruction |= LOW4 (inst.operands[1].reg);
16533 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16534 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
16535 if (flavour >= neon_cvt_flavour_s16_f16
16536 && flavour <= neon_cvt_flavour_f16_u16)
16537 /* Half precision. */
16538 inst.instruction |= 1 << 18;
16539 else
16540 inst.instruction |= 2 << 18;
037e8744 16541
7e8e6784
MGD
16542 neon_dp_fixup (&inst);
16543 }
16544 }
16545 break;
037e8744 16546
8e79c3df
CM
16547 /* Half-precision conversions for Advanced SIMD -- neon. */
16548 case NS_QD:
16549 case NS_DQ:
bc52d49c
MM
16550 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16551 return;
8e79c3df
CM
16552
16553 if ((rs == NS_DQ)
16554 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
16555 {
16556 as_bad (_("operand size must match register width"));
16557 break;
16558 }
16559
16560 if ((rs == NS_QD)
16561 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
16562 {
16563 as_bad (_("operand size must match register width"));
16564 break;
16565 }
16566
16567 if (rs == NS_DQ)
477330fc 16568 inst.instruction = 0x3b60600;
8e79c3df
CM
16569 else
16570 inst.instruction = 0x3b60700;
16571
16572 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16573 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16574 inst.instruction |= LOW4 (inst.operands[1].reg);
16575 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 16576 neon_dp_fixup (&inst);
8e79c3df
CM
16577 break;
16578
037e8744
JB
16579 default:
16580 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
16581 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
16582 do_vfp_nsyn_cvt (rs, flavour);
16583 else
16584 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 16585 }
5287ad62
JB
16586}
16587
e3e535bc
NC
16588static void
16589do_neon_cvtr (void)
16590{
7e8e6784 16591 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
16592}
16593
16594static void
16595do_neon_cvt (void)
16596{
7e8e6784
MGD
16597 do_neon_cvt_1 (neon_cvt_mode_z);
16598}
16599
16600static void
16601do_neon_cvta (void)
16602{
16603 do_neon_cvt_1 (neon_cvt_mode_a);
16604}
16605
16606static void
16607do_neon_cvtn (void)
16608{
16609 do_neon_cvt_1 (neon_cvt_mode_n);
16610}
16611
16612static void
16613do_neon_cvtp (void)
16614{
16615 do_neon_cvt_1 (neon_cvt_mode_p);
16616}
16617
16618static void
16619do_neon_cvtm (void)
16620{
16621 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
16622}
16623
8e79c3df 16624static void
c70a8987 16625do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 16626{
c70a8987
MGD
16627 if (is_double)
16628 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 16629
c70a8987
MGD
16630 encode_arm_vfp_reg (inst.operands[0].reg,
16631 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
16632 encode_arm_vfp_reg (inst.operands[1].reg,
16633 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
16634 inst.instruction |= to ? 0x10000 : 0;
16635 inst.instruction |= t ? 0x80 : 0;
16636 inst.instruction |= is_double ? 0x100 : 0;
16637 do_vfp_cond_or_thumb ();
16638}
8e79c3df 16639
c70a8987
MGD
16640static void
16641do_neon_cvttb_1 (bfd_boolean t)
16642{
d54af2d0
RL
16643 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
16644 NS_DF, NS_DH, NS_NULL);
8e79c3df 16645
c70a8987
MGD
16646 if (rs == NS_NULL)
16647 return;
16648 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
16649 {
16650 inst.error = NULL;
16651 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
16652 }
16653 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
16654 {
16655 inst.error = NULL;
16656 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
16657 }
16658 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
16659 {
a715796b
TG
16660 /* The VCVTB and VCVTT instructions with D-register operands
16661 don't work for SP only targets. */
16662 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16663 _(BAD_FPU));
16664
c70a8987
MGD
16665 inst.error = NULL;
16666 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
16667 }
16668 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
16669 {
a715796b
TG
16670 /* The VCVTB and VCVTT instructions with D-register operands
16671 don't work for SP only targets. */
16672 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16673 _(BAD_FPU));
16674
c70a8987
MGD
16675 inst.error = NULL;
16676 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
16677 }
16678 else
16679 return;
16680}
16681
16682static void
16683do_neon_cvtb (void)
16684{
16685 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
16686}
16687
16688
16689static void
16690do_neon_cvtt (void)
16691{
c70a8987 16692 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
16693}
16694
5287ad62
JB
16695static void
16696neon_move_immediate (void)
16697{
037e8744
JB
16698 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
16699 struct neon_type_el et = neon_check_type (2, rs,
16700 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 16701 unsigned immlo, immhi = 0, immbits;
c96612cc 16702 int op, cmode, float_p;
5287ad62 16703
037e8744 16704 constraint (et.type == NT_invtype,
477330fc 16705 _("operand size must be specified for immediate VMOV"));
037e8744 16706
5287ad62
JB
16707 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
16708 op = (inst.instruction & (1 << 5)) != 0;
16709
16710 immlo = inst.operands[1].imm;
16711 if (inst.operands[1].regisimm)
16712 immhi = inst.operands[1].reg;
16713
16714 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 16715 _("immediate has bits set outside the operand size"));
5287ad62 16716
c96612cc
JB
16717 float_p = inst.operands[1].immisfloat;
16718
16719 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 16720 et.size, et.type)) == FAIL)
5287ad62
JB
16721 {
16722 /* Invert relevant bits only. */
16723 neon_invert_size (&immlo, &immhi, et.size);
16724 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
16725 with one or the other; those cases are caught by
16726 neon_cmode_for_move_imm. */
5287ad62 16727 op = !op;
c96612cc
JB
16728 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16729 &op, et.size, et.type)) == FAIL)
477330fc
RM
16730 {
16731 first_error (_("immediate out of range"));
16732 return;
16733 }
5287ad62
JB
16734 }
16735
16736 inst.instruction &= ~(1 << 5);
16737 inst.instruction |= op << 5;
16738
16739 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16740 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 16741 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16742 inst.instruction |= cmode << 8;
16743
16744 neon_write_immbits (immbits);
16745}
16746
16747static void
16748do_neon_mvn (void)
16749{
16750 if (inst.operands[1].isreg)
16751 {
037e8744 16752 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16753
88714cb8 16754 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16755 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16756 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16757 inst.instruction |= LOW4 (inst.operands[1].reg);
16758 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16759 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16760 }
16761 else
16762 {
88714cb8 16763 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16764 neon_move_immediate ();
16765 }
16766
88714cb8 16767 neon_dp_fixup (&inst);
5287ad62
JB
16768}
16769
16770/* Encode instructions of form:
16771
16772 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16773 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16774
16775static void
16776neon_mixed_length (struct neon_type_el et, unsigned size)
16777{
16778 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16779 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16780 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16781 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16782 inst.instruction |= LOW4 (inst.operands[2].reg);
16783 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16784 inst.instruction |= (et.type == NT_unsigned) << 24;
16785 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16786
88714cb8 16787 neon_dp_fixup (&inst);
5287ad62
JB
16788}
16789
16790static void
16791do_neon_dyadic_long (void)
16792{
5ee91343
AV
16793 enum neon_shape rs = neon_select_shape (NS_QDD, NS_QQQ, NS_QQR, NS_NULL);
16794 if (rs == NS_QDD)
16795 {
16796 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL)
16797 return;
16798
16799 NEON_ENCODE (INTEGER, inst);
16800 /* FIXME: Type checking for lengthening op. */
16801 struct neon_type_el et = neon_check_type (3, NS_QDD,
16802 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16803 neon_mixed_length (et, et.size);
16804 }
16805 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
16806 && (inst.cond == 0xf || inst.cond == 0x10))
16807 {
16808 /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd
16809 in an IT block with le/lt conditions. */
16810
16811 if (inst.cond == 0xf)
16812 inst.cond = 0xb;
16813 else if (inst.cond == 0x10)
16814 inst.cond = 0xd;
16815
16816 inst.pred_insn_type = INSIDE_IT_INSN;
16817
16818 if (inst.instruction == N_MNEM_vaddl)
16819 {
16820 inst.instruction = N_MNEM_vadd;
16821 do_neon_addsub_if_i ();
16822 }
16823 else if (inst.instruction == N_MNEM_vsubl)
16824 {
16825 inst.instruction = N_MNEM_vsub;
16826 do_neon_addsub_if_i ();
16827 }
16828 else if (inst.instruction == N_MNEM_vabdl)
16829 {
16830 inst.instruction = N_MNEM_vabd;
16831 do_neon_dyadic_if_su ();
16832 }
16833 }
16834 else
16835 first_error (BAD_FPU);
5287ad62
JB
16836}
16837
16838static void
16839do_neon_abal (void)
16840{
16841 struct neon_type_el et = neon_check_type (3, NS_QDD,
16842 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16843 neon_mixed_length (et, et.size);
16844}
16845
16846static void
16847neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16848{
16849 if (inst.operands[2].isscalar)
16850 {
dcbf9037 16851 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16852 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16853 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16854 neon_mul_mac (et, et.type == NT_unsigned);
16855 }
16856 else
16857 {
16858 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16859 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16860 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16861 neon_mixed_length (et, et.size);
16862 }
16863}
16864
16865static void
16866do_neon_mac_maybe_scalar_long (void)
16867{
16868 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16869}
16870
dec41383
JW
16871/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
16872 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
16873
16874static unsigned
16875neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
16876{
16877 unsigned regno = NEON_SCALAR_REG (scalar);
16878 unsigned elno = NEON_SCALAR_INDEX (scalar);
16879
16880 if (quad_p)
16881 {
16882 if (regno > 7 || elno > 3)
16883 goto bad_scalar;
16884
16885 return ((regno & 0x7)
16886 | ((elno & 0x1) << 3)
16887 | (((elno >> 1) & 0x1) << 5));
16888 }
16889 else
16890 {
16891 if (regno > 15 || elno > 1)
16892 goto bad_scalar;
16893
16894 return (((regno & 0x1) << 5)
16895 | ((regno >> 1) & 0x7)
16896 | ((elno & 0x1) << 3));
16897 }
16898
16899bad_scalar:
16900 first_error (_("scalar out of range for multiply instruction"));
16901 return 0;
16902}
16903
16904static void
16905do_neon_fmac_maybe_scalar_long (int subtype)
16906{
16907 enum neon_shape rs;
16908 int high8;
16909 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
16910 field (bits[21:20]) has different meaning. For scalar index variant, it's
16911 used to differentiate add and subtract, otherwise it's with fixed value
16912 0x2. */
16913 int size = -1;
16914
16915 if (inst.cond != COND_ALWAYS)
16916 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
16917 "behaviour is UNPREDICTABLE"));
16918
01f48020 16919 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
dec41383
JW
16920 _(BAD_FP16));
16921
16922 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
16923 _(BAD_FPU));
16924
16925 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
16926 be a scalar index register. */
16927 if (inst.operands[2].isscalar)
16928 {
16929 high8 = 0xfe000000;
16930 if (subtype)
16931 size = 16;
16932 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
16933 }
16934 else
16935 {
16936 high8 = 0xfc000000;
16937 size = 32;
16938 if (subtype)
16939 inst.instruction |= (0x1 << 23);
16940 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
16941 }
16942
16943 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
16944
16945 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
16946 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
16947 so we simply pass -1 as size. */
16948 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
16949 neon_three_same (quad_p, 0, size);
16950
16951 /* Undo neon_dp_fixup. Redo the high eight bits. */
16952 inst.instruction &= 0x00ffffff;
16953 inst.instruction |= high8;
16954
16955#define LOW1(R) ((R) & 0x1)
16956#define HI4(R) (((R) >> 1) & 0xf)
16957 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
16958 whether the instruction is in Q form and whether Vm is a scalar indexed
16959 operand. */
16960 if (inst.operands[2].isscalar)
16961 {
16962 unsigned rm
16963 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
16964 inst.instruction &= 0xffffffd0;
16965 inst.instruction |= rm;
16966
16967 if (!quad_p)
16968 {
16969 /* Redo Rn as well. */
16970 inst.instruction &= 0xfff0ff7f;
16971 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16972 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16973 }
16974 }
16975 else if (!quad_p)
16976 {
16977 /* Redo Rn and Rm. */
16978 inst.instruction &= 0xfff0ff50;
16979 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16980 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16981 inst.instruction |= HI4 (inst.operands[2].reg);
16982 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
16983 }
16984}
16985
16986static void
16987do_neon_vfmal (void)
16988{
16989 return do_neon_fmac_maybe_scalar_long (0);
16990}
16991
16992static void
16993do_neon_vfmsl (void)
16994{
16995 return do_neon_fmac_maybe_scalar_long (1);
16996}
16997
5287ad62
JB
16998static void
16999do_neon_dyadic_wide (void)
17000{
17001 struct neon_type_el et = neon_check_type (3, NS_QQD,
17002 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
17003 neon_mixed_length (et, et.size);
17004}
17005
17006static void
17007do_neon_dyadic_narrow (void)
17008{
17009 struct neon_type_el et = neon_check_type (3, NS_QDD,
17010 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
17011 /* Operand sign is unimportant, and the U bit is part of the opcode,
17012 so force the operand type to integer. */
17013 et.type = NT_integer;
5287ad62
JB
17014 neon_mixed_length (et, et.size / 2);
17015}
17016
17017static void
17018do_neon_mul_sat_scalar_long (void)
17019{
17020 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
17021}
17022
17023static void
17024do_neon_vmull (void)
17025{
17026 if (inst.operands[2].isscalar)
17027 do_neon_mac_maybe_scalar_long ();
17028 else
17029 {
17030 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 17031 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 17032
5287ad62 17033 if (et.type == NT_poly)
477330fc 17034 NEON_ENCODE (POLY, inst);
5287ad62 17035 else
477330fc 17036 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
17037
17038 /* For polynomial encoding the U bit must be zero, and the size must
17039 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
17040 obviously, as 0b10). */
17041 if (et.size == 64)
17042 {
17043 /* Check we're on the correct architecture. */
17044 if (!mark_feature_used (&fpu_crypto_ext_armv8))
17045 inst.error =
17046 _("Instruction form not available on this architecture.");
17047
17048 et.size = 32;
17049 }
17050
5287ad62
JB
17051 neon_mixed_length (et, et.size);
17052 }
17053}
17054
17055static void
17056do_neon_ext (void)
17057{
037e8744 17058 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
17059 struct neon_type_el et = neon_check_type (3, rs,
17060 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
17061 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
17062
17063 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
17064 _("shift out of range"));
5287ad62
JB
17065 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17066 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17067 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17068 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17069 inst.instruction |= LOW4 (inst.operands[2].reg);
17070 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 17071 inst.instruction |= neon_quad (rs) << 6;
5287ad62 17072 inst.instruction |= imm << 8;
5f4273c7 17073
88714cb8 17074 neon_dp_fixup (&inst);
5287ad62
JB
17075}
17076
17077static void
17078do_neon_rev (void)
17079{
037e8744 17080 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17081 struct neon_type_el et = neon_check_type (2, rs,
17082 N_EQK, N_8 | N_16 | N_32 | N_KEY);
17083 unsigned op = (inst.instruction >> 7) & 3;
17084 /* N (width of reversed regions) is encoded as part of the bitmask. We
17085 extract it here to check the elements to be reversed are smaller.
17086 Otherwise we'd get a reserved instruction. */
17087 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 17088 gas_assert (elsize != 0);
5287ad62 17089 constraint (et.size >= elsize,
477330fc 17090 _("elements must be smaller than reversal region"));
037e8744 17091 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17092}
17093
17094static void
17095do_neon_dup (void)
17096{
17097 if (inst.operands[1].isscalar)
17098 {
037e8744 17099 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 17100 struct neon_type_el et = neon_check_type (2, rs,
477330fc 17101 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 17102 unsigned sizebits = et.size >> 3;
dcbf9037 17103 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 17104 int logsize = neon_logbits (et.size);
dcbf9037 17105 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
17106
17107 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 17108 return;
037e8744 17109
88714cb8 17110 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
17111 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17112 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17113 inst.instruction |= LOW4 (dm);
17114 inst.instruction |= HI1 (dm) << 5;
037e8744 17115 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17116 inst.instruction |= x << 17;
17117 inst.instruction |= sizebits << 16;
5f4273c7 17118
88714cb8 17119 neon_dp_fixup (&inst);
5287ad62
JB
17120 }
17121 else
17122 {
037e8744
JB
17123 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
17124 struct neon_type_el et = neon_check_type (2, rs,
477330fc 17125 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 17126 /* Duplicate ARM register to lanes of vector. */
88714cb8 17127 NEON_ENCODE (ARMREG, inst);
5287ad62 17128 switch (et.size)
477330fc
RM
17129 {
17130 case 8: inst.instruction |= 0x400000; break;
17131 case 16: inst.instruction |= 0x000020; break;
17132 case 32: inst.instruction |= 0x000000; break;
17133 default: break;
17134 }
5287ad62
JB
17135 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
17136 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
17137 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 17138 inst.instruction |= neon_quad (rs) << 21;
5287ad62 17139 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 17140 variants, except for the condition field. */
037e8744 17141 do_vfp_cond_or_thumb ();
5287ad62
JB
17142 }
17143}
17144
17145/* VMOV has particularly many variations. It can be one of:
17146 0. VMOV<c><q> <Qd>, <Qm>
17147 1. VMOV<c><q> <Dd>, <Dm>
17148 (Register operations, which are VORR with Rm = Rn.)
17149 2. VMOV<c><q>.<dt> <Qd>, #<imm>
17150 3. VMOV<c><q>.<dt> <Dd>, #<imm>
17151 (Immediate loads.)
17152 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
17153 (ARM register to scalar.)
17154 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
17155 (Two ARM registers to vector.)
17156 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
17157 (Scalar to ARM register.)
17158 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
17159 (Vector to two ARM registers.)
037e8744
JB
17160 8. VMOV.F32 <Sd>, <Sm>
17161 9. VMOV.F64 <Dd>, <Dm>
17162 (VFP register moves.)
17163 10. VMOV.F32 <Sd>, #imm
17164 11. VMOV.F64 <Dd>, #imm
17165 (VFP float immediate load.)
17166 12. VMOV <Rd>, <Sm>
17167 (VFP single to ARM reg.)
17168 13. VMOV <Sd>, <Rm>
17169 (ARM reg to VFP single.)
17170 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
17171 (Two ARM regs to two VFP singles.)
17172 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
17173 (Two VFP singles to two ARM regs.)
5f4273c7 17174
037e8744
JB
17175 These cases can be disambiguated using neon_select_shape, except cases 1/9
17176 and 3/11 which depend on the operand type too.
5f4273c7 17177
5287ad62 17178 All the encoded bits are hardcoded by this function.
5f4273c7 17179
b7fc2769
JB
17180 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
17181 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 17182
5287ad62 17183 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 17184 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
17185
17186static void
17187do_neon_mov (void)
17188{
037e8744 17189 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
17190 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
17191 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
17192 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
17193 struct neon_type_el et;
17194 const char *ldconst = 0;
5287ad62 17195
037e8744 17196 switch (rs)
5287ad62 17197 {
037e8744
JB
17198 case NS_DD: /* case 1/9. */
17199 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
17200 /* It is not an error here if no type is given. */
17201 inst.error = NULL;
17202 if (et.type == NT_float && et.size == 64)
477330fc
RM
17203 {
17204 do_vfp_nsyn_opcode ("fcpyd");
17205 break;
17206 }
037e8744 17207 /* fall through. */
5287ad62 17208
037e8744
JB
17209 case NS_QQ: /* case 0/1. */
17210 {
477330fc
RM
17211 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17212 return;
17213 /* The architecture manual I have doesn't explicitly state which
17214 value the U bit should have for register->register moves, but
17215 the equivalent VORR instruction has U = 0, so do that. */
17216 inst.instruction = 0x0200110;
17217 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17218 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17219 inst.instruction |= LOW4 (inst.operands[1].reg);
17220 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17221 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17222 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17223 inst.instruction |= neon_quad (rs) << 6;
17224
17225 neon_dp_fixup (&inst);
037e8744
JB
17226 }
17227 break;
5f4273c7 17228
037e8744
JB
17229 case NS_DI: /* case 3/11. */
17230 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
17231 inst.error = NULL;
17232 if (et.type == NT_float && et.size == 64)
477330fc
RM
17233 {
17234 /* case 11 (fconstd). */
17235 ldconst = "fconstd";
17236 goto encode_fconstd;
17237 }
037e8744
JB
17238 /* fall through. */
17239
17240 case NS_QI: /* case 2/3. */
17241 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 17242 return;
037e8744
JB
17243 inst.instruction = 0x0800010;
17244 neon_move_immediate ();
88714cb8 17245 neon_dp_fixup (&inst);
5287ad62 17246 break;
5f4273c7 17247
037e8744
JB
17248 case NS_SR: /* case 4. */
17249 {
477330fc
RM
17250 unsigned bcdebits = 0;
17251 int logsize;
17252 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
17253 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 17254
05ac0ffb
JB
17255 /* .<size> is optional here, defaulting to .32. */
17256 if (inst.vectype.elems == 0
17257 && inst.operands[0].vectype.type == NT_invtype
17258 && inst.operands[1].vectype.type == NT_invtype)
17259 {
17260 inst.vectype.el[0].type = NT_untyped;
17261 inst.vectype.el[0].size = 32;
17262 inst.vectype.elems = 1;
17263 }
17264
477330fc
RM
17265 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
17266 logsize = neon_logbits (et.size);
17267
17268 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
17269 _(BAD_FPU));
17270 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
17271 && et.size != 32, _(BAD_FPU));
17272 constraint (et.type == NT_invtype, _("bad type for scalar"));
17273 constraint (x >= 64 / et.size, _("scalar index out of range"));
17274
17275 switch (et.size)
17276 {
17277 case 8: bcdebits = 0x8; break;
17278 case 16: bcdebits = 0x1; break;
17279 case 32: bcdebits = 0x0; break;
17280 default: ;
17281 }
17282
17283 bcdebits |= x << logsize;
17284
17285 inst.instruction = 0xe000b10;
17286 do_vfp_cond_or_thumb ();
17287 inst.instruction |= LOW4 (dn) << 16;
17288 inst.instruction |= HI1 (dn) << 7;
17289 inst.instruction |= inst.operands[1].reg << 12;
17290 inst.instruction |= (bcdebits & 3) << 5;
17291 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
17292 }
17293 break;
5f4273c7 17294
037e8744 17295 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 17296 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 17297 _(BAD_FPU));
b7fc2769 17298
037e8744
JB
17299 inst.instruction = 0xc400b10;
17300 do_vfp_cond_or_thumb ();
17301 inst.instruction |= LOW4 (inst.operands[0].reg);
17302 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
17303 inst.instruction |= inst.operands[1].reg << 12;
17304 inst.instruction |= inst.operands[2].reg << 16;
17305 break;
5f4273c7 17306
037e8744
JB
17307 case NS_RS: /* case 6. */
17308 {
477330fc
RM
17309 unsigned logsize;
17310 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
17311 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
17312 unsigned abcdebits = 0;
037e8744 17313
05ac0ffb
JB
17314 /* .<dt> is optional here, defaulting to .32. */
17315 if (inst.vectype.elems == 0
17316 && inst.operands[0].vectype.type == NT_invtype
17317 && inst.operands[1].vectype.type == NT_invtype)
17318 {
17319 inst.vectype.el[0].type = NT_untyped;
17320 inst.vectype.el[0].size = 32;
17321 inst.vectype.elems = 1;
17322 }
17323
91d6fa6a
NC
17324 et = neon_check_type (2, NS_NULL,
17325 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
17326 logsize = neon_logbits (et.size);
17327
17328 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
17329 _(BAD_FPU));
17330 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
17331 && et.size != 32, _(BAD_FPU));
17332 constraint (et.type == NT_invtype, _("bad type for scalar"));
17333 constraint (x >= 64 / et.size, _("scalar index out of range"));
17334
17335 switch (et.size)
17336 {
17337 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
17338 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
17339 case 32: abcdebits = 0x00; break;
17340 default: ;
17341 }
17342
17343 abcdebits |= x << logsize;
17344 inst.instruction = 0xe100b10;
17345 do_vfp_cond_or_thumb ();
17346 inst.instruction |= LOW4 (dn) << 16;
17347 inst.instruction |= HI1 (dn) << 7;
17348 inst.instruction |= inst.operands[0].reg << 12;
17349 inst.instruction |= (abcdebits & 3) << 5;
17350 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
17351 }
17352 break;
5f4273c7 17353
037e8744
JB
17354 case NS_RRD: /* case 7 (fmrrd). */
17355 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 17356 _(BAD_FPU));
037e8744
JB
17357
17358 inst.instruction = 0xc500b10;
17359 do_vfp_cond_or_thumb ();
17360 inst.instruction |= inst.operands[0].reg << 12;
17361 inst.instruction |= inst.operands[1].reg << 16;
17362 inst.instruction |= LOW4 (inst.operands[2].reg);
17363 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
17364 break;
5f4273c7 17365
037e8744
JB
17366 case NS_FF: /* case 8 (fcpys). */
17367 do_vfp_nsyn_opcode ("fcpys");
17368 break;
5f4273c7 17369
9db2f6b4 17370 case NS_HI:
037e8744
JB
17371 case NS_FI: /* case 10 (fconsts). */
17372 ldconst = "fconsts";
4ef4710f 17373 encode_fconstd:
58ed5c38
TC
17374 if (!inst.operands[1].immisfloat)
17375 {
4ef4710f 17376 unsigned new_imm;
58ed5c38 17377 /* Immediate has to fit in 8 bits so float is enough. */
4ef4710f
NC
17378 float imm = (float) inst.operands[1].imm;
17379 memcpy (&new_imm, &imm, sizeof (float));
17380 /* But the assembly may have been written to provide an integer
17381 bit pattern that equates to a float, so check that the
17382 conversion has worked. */
17383 if (is_quarter_float (new_imm))
17384 {
17385 if (is_quarter_float (inst.operands[1].imm))
17386 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
17387
17388 inst.operands[1].imm = new_imm;
17389 inst.operands[1].immisfloat = 1;
17390 }
58ed5c38
TC
17391 }
17392
037e8744 17393 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
17394 {
17395 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
17396 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
17397
17398 /* ARMv8.2 fp16 vmov.f16 instruction. */
17399 if (rs == NS_HI)
17400 do_scalar_fp16_v82_encode ();
477330fc 17401 }
5287ad62 17402 else
477330fc 17403 first_error (_("immediate out of range"));
037e8744 17404 break;
5f4273c7 17405
9db2f6b4 17406 case NS_RH:
037e8744
JB
17407 case NS_RF: /* case 12 (fmrs). */
17408 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
17409 /* ARMv8.2 fp16 vmov.f16 instruction. */
17410 if (rs == NS_RH)
17411 do_scalar_fp16_v82_encode ();
037e8744 17412 break;
5f4273c7 17413
9db2f6b4 17414 case NS_HR:
037e8744
JB
17415 case NS_FR: /* case 13 (fmsr). */
17416 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
17417 /* ARMv8.2 fp16 vmov.f16 instruction. */
17418 if (rs == NS_HR)
17419 do_scalar_fp16_v82_encode ();
037e8744 17420 break;
5f4273c7 17421
037e8744
JB
17422 /* The encoders for the fmrrs and fmsrr instructions expect three operands
17423 (one of which is a list), but we have parsed four. Do some fiddling to
17424 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
17425 expect. */
17426 case NS_RRFF: /* case 14 (fmrrs). */
17427 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 17428 _("VFP registers must be adjacent"));
037e8744
JB
17429 inst.operands[2].imm = 2;
17430 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
17431 do_vfp_nsyn_opcode ("fmrrs");
17432 break;
5f4273c7 17433
037e8744
JB
17434 case NS_FFRR: /* case 15 (fmsrr). */
17435 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 17436 _("VFP registers must be adjacent"));
037e8744
JB
17437 inst.operands[1] = inst.operands[2];
17438 inst.operands[2] = inst.operands[3];
17439 inst.operands[0].imm = 2;
17440 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
17441 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 17442 break;
5f4273c7 17443
4c261dff
NC
17444 case NS_NULL:
17445 /* neon_select_shape has determined that the instruction
17446 shape is wrong and has already set the error message. */
17447 break;
17448
5287ad62
JB
17449 default:
17450 abort ();
17451 }
17452}
17453
17454static void
17455do_neon_rshift_round_imm (void)
17456{
037e8744 17457 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
17458 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
17459 int imm = inst.operands[2].imm;
17460
17461 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
17462 if (imm == 0)
17463 {
17464 inst.operands[2].present = 0;
17465 do_neon_mov ();
17466 return;
17467 }
17468
17469 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 17470 _("immediate out of range for shift"));
037e8744 17471 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 17472 et.size - imm);
5287ad62
JB
17473}
17474
9db2f6b4
RL
17475static void
17476do_neon_movhf (void)
17477{
17478 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
17479 constraint (rs != NS_HH, _("invalid suffix"));
17480
7bdf778b
ASDV
17481 if (inst.cond != COND_ALWAYS)
17482 {
17483 if (thumb_mode)
17484 {
17485 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
17486 " the behaviour is UNPREDICTABLE"));
17487 }
17488 else
17489 {
17490 inst.error = BAD_COND;
17491 return;
17492 }
17493 }
17494
9db2f6b4
RL
17495 do_vfp_sp_monadic ();
17496
17497 inst.is_neon = 1;
17498 inst.instruction |= 0xf0000000;
17499}
17500
5287ad62
JB
17501static void
17502do_neon_movl (void)
17503{
17504 struct neon_type_el et = neon_check_type (2, NS_QD,
17505 N_EQK | N_DBL, N_SU_32 | N_KEY);
17506 unsigned sizebits = et.size >> 3;
17507 inst.instruction |= sizebits << 19;
17508 neon_two_same (0, et.type == NT_unsigned, -1);
17509}
17510
17511static void
17512do_neon_trn (void)
17513{
037e8744 17514 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17515 struct neon_type_el et = neon_check_type (2, rs,
17516 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 17517 NEON_ENCODE (INTEGER, inst);
037e8744 17518 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17519}
17520
17521static void
17522do_neon_zip_uzp (void)
17523{
037e8744 17524 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17525 struct neon_type_el et = neon_check_type (2, rs,
17526 N_EQK, N_8 | N_16 | N_32 | N_KEY);
17527 if (rs == NS_DD && et.size == 32)
17528 {
17529 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
17530 inst.instruction = N_MNEM_vtrn;
17531 do_neon_trn ();
17532 return;
17533 }
037e8744 17534 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17535}
17536
17537static void
17538do_neon_sat_abs_neg (void)
17539{
037e8744 17540 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17541 struct neon_type_el et = neon_check_type (2, rs,
17542 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 17543 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17544}
17545
17546static void
17547do_neon_pair_long (void)
17548{
037e8744 17549 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17550 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
17551 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
17552 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 17553 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17554}
17555
17556static void
17557do_neon_recip_est (void)
17558{
037e8744 17559 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 17560 struct neon_type_el et = neon_check_type (2, rs,
cc933301 17561 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 17562 inst.instruction |= (et.type == NT_float) << 8;
037e8744 17563 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17564}
17565
17566static void
17567do_neon_cls (void)
17568{
037e8744 17569 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17570 struct neon_type_el et = neon_check_type (2, rs,
17571 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 17572 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17573}
17574
17575static void
17576do_neon_clz (void)
17577{
037e8744 17578 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17579 struct neon_type_el et = neon_check_type (2, rs,
17580 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 17581 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17582}
17583
17584static void
17585do_neon_cnt (void)
17586{
037e8744 17587 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17588 struct neon_type_el et = neon_check_type (2, rs,
17589 N_EQK | N_INT, N_8 | N_KEY);
037e8744 17590 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17591}
17592
17593static void
17594do_neon_swp (void)
17595{
037e8744
JB
17596 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
17597 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
17598}
17599
17600static void
17601do_neon_tbl_tbx (void)
17602{
17603 unsigned listlenbits;
dcbf9037 17604 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 17605
5287ad62
JB
17606 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
17607 {
dcbf9037 17608 first_error (_("bad list length for table lookup"));
5287ad62
JB
17609 return;
17610 }
5f4273c7 17611
5287ad62
JB
17612 listlenbits = inst.operands[1].imm - 1;
17613 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17614 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17615 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17616 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17617 inst.instruction |= LOW4 (inst.operands[2].reg);
17618 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
17619 inst.instruction |= listlenbits << 8;
5f4273c7 17620
88714cb8 17621 neon_dp_fixup (&inst);
5287ad62
JB
17622}
17623
17624static void
17625do_neon_ldm_stm (void)
17626{
17627 /* P, U and L bits are part of bitmask. */
17628 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
17629 unsigned offsetbits = inst.operands[1].imm * 2;
17630
037e8744
JB
17631 if (inst.operands[1].issingle)
17632 {
17633 do_vfp_nsyn_ldm_stm (is_dbmode);
17634 return;
17635 }
17636
5287ad62 17637 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 17638 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
17639
17640 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
17641 _("register list must contain at least 1 and at most 16 "
17642 "registers"));
5287ad62
JB
17643
17644 inst.instruction |= inst.operands[0].reg << 16;
17645 inst.instruction |= inst.operands[0].writeback << 21;
17646 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
17647 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
17648
17649 inst.instruction |= offsetbits;
5f4273c7 17650
037e8744 17651 do_vfp_cond_or_thumb ();
5287ad62
JB
17652}
17653
17654static void
17655do_neon_ldr_str (void)
17656{
5287ad62 17657 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 17658
6844b2c2
MGD
17659 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
17660 And is UNPREDICTABLE in thumb mode. */
fa94de6b 17661 if (!is_ldr
6844b2c2 17662 && inst.operands[1].reg == REG_PC
ba86b375 17663 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 17664 {
94dcf8bf 17665 if (thumb_mode)
6844b2c2 17666 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 17667 else if (warn_on_deprecated)
5c3696f8 17668 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
17669 }
17670
037e8744
JB
17671 if (inst.operands[0].issingle)
17672 {
cd2f129f 17673 if (is_ldr)
477330fc 17674 do_vfp_nsyn_opcode ("flds");
cd2f129f 17675 else
477330fc 17676 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
17677
17678 /* ARMv8.2 vldr.16/vstr.16 instruction. */
17679 if (inst.vectype.el[0].size == 16)
17680 do_scalar_fp16_v82_encode ();
5287ad62
JB
17681 }
17682 else
5287ad62 17683 {
cd2f129f 17684 if (is_ldr)
477330fc 17685 do_vfp_nsyn_opcode ("fldd");
5287ad62 17686 else
477330fc 17687 do_vfp_nsyn_opcode ("fstd");
5287ad62 17688 }
5287ad62
JB
17689}
17690
32c36c3c
AV
17691static void
17692do_t_vldr_vstr_sysreg (void)
17693{
17694 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
17695 bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
17696
17697 /* Use of PC is UNPREDICTABLE. */
17698 if (inst.operands[1].reg == REG_PC)
17699 inst.error = _("Use of PC here is UNPREDICTABLE");
17700
17701 if (inst.operands[1].immisreg)
17702 inst.error = _("instruction does not accept register index");
17703
17704 if (!inst.operands[1].isreg)
17705 inst.error = _("instruction does not accept PC-relative addressing");
17706
17707 if (abs (inst.operands[1].imm) >= (1 << 7))
17708 inst.error = _("immediate value out of range");
17709
17710 inst.instruction = 0xec000f80;
17711 if (is_vldr)
17712 inst.instruction |= 1 << sysreg_vldr_bitno;
17713 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
17714 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
17715 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
17716}
17717
17718static void
17719do_vldr_vstr (void)
17720{
17721 bfd_boolean sysreg_op = !inst.operands[0].isreg;
17722
17723 /* VLDR/VSTR (System Register). */
17724 if (sysreg_op)
17725 {
17726 if (!mark_feature_used (&arm_ext_v8_1m_main))
17727 as_bad (_("Instruction not permitted on this architecture"));
17728
17729 do_t_vldr_vstr_sysreg ();
17730 }
17731 /* VLDR/VSTR. */
17732 else
17733 {
17734 if (!mark_feature_used (&fpu_vfp_ext_v1xd))
17735 as_bad (_("Instruction not permitted on this architecture"));
17736 do_neon_ldr_str ();
17737 }
17738}
17739
5287ad62
JB
17740/* "interleave" version also handles non-interleaving register VLD1/VST1
17741 instructions. */
17742
17743static void
17744do_neon_ld_st_interleave (void)
17745{
037e8744 17746 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 17747 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
17748 unsigned alignbits = 0;
17749 unsigned idx;
17750 /* The bits in this table go:
17751 0: register stride of one (0) or two (1)
17752 1,2: register list length, minus one (1, 2, 3, 4).
17753 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
17754 We use -1 for invalid entries. */
17755 const int typetable[] =
17756 {
17757 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
17758 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
17759 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
17760 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
17761 };
17762 int typebits;
17763
dcbf9037
JB
17764 if (et.type == NT_invtype)
17765 return;
17766
5287ad62
JB
17767 if (inst.operands[1].immisalign)
17768 switch (inst.operands[1].imm >> 8)
17769 {
17770 case 64: alignbits = 1; break;
17771 case 128:
477330fc 17772 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 17773 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
17774 goto bad_alignment;
17775 alignbits = 2;
17776 break;
5287ad62 17777 case 256:
477330fc
RM
17778 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
17779 goto bad_alignment;
17780 alignbits = 3;
17781 break;
5287ad62
JB
17782 default:
17783 bad_alignment:
477330fc
RM
17784 first_error (_("bad alignment"));
17785 return;
5287ad62
JB
17786 }
17787
17788 inst.instruction |= alignbits << 4;
17789 inst.instruction |= neon_logbits (et.size) << 6;
17790
17791 /* Bits [4:6] of the immediate in a list specifier encode register stride
17792 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
17793 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
17794 up the right value for "type" in a table based on this value and the given
17795 list style, then stick it back. */
17796 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 17797 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
17798
17799 typebits = typetable[idx];
5f4273c7 17800
5287ad62 17801 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
17802 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
17803 _("bad element type for instruction"));
5287ad62
JB
17804
17805 inst.instruction &= ~0xf00;
17806 inst.instruction |= typebits << 8;
17807}
17808
17809/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
17810 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
17811 otherwise. The variable arguments are a list of pairs of legal (size, align)
17812 values, terminated with -1. */
17813
17814static int
aa8a0863 17815neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
17816{
17817 va_list ap;
17818 int result = FAIL, thissize, thisalign;
5f4273c7 17819
5287ad62
JB
17820 if (!inst.operands[1].immisalign)
17821 {
aa8a0863 17822 *do_alignment = 0;
5287ad62
JB
17823 return SUCCESS;
17824 }
5f4273c7 17825
aa8a0863 17826 va_start (ap, do_alignment);
5287ad62
JB
17827
17828 do
17829 {
17830 thissize = va_arg (ap, int);
17831 if (thissize == -1)
477330fc 17832 break;
5287ad62
JB
17833 thisalign = va_arg (ap, int);
17834
17835 if (size == thissize && align == thisalign)
477330fc 17836 result = SUCCESS;
5287ad62
JB
17837 }
17838 while (result != SUCCESS);
17839
17840 va_end (ap);
17841
17842 if (result == SUCCESS)
aa8a0863 17843 *do_alignment = 1;
5287ad62 17844 else
dcbf9037 17845 first_error (_("unsupported alignment for instruction"));
5f4273c7 17846
5287ad62
JB
17847 return result;
17848}
17849
17850static void
17851do_neon_ld_st_lane (void)
17852{
037e8744 17853 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17854 int align_good, do_alignment = 0;
5287ad62
JB
17855 int logsize = neon_logbits (et.size);
17856 int align = inst.operands[1].imm >> 8;
17857 int n = (inst.instruction >> 8) & 3;
17858 int max_el = 64 / et.size;
5f4273c7 17859
dcbf9037
JB
17860 if (et.type == NT_invtype)
17861 return;
5f4273c7 17862
5287ad62 17863 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 17864 _("bad list length"));
5287ad62 17865 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 17866 _("scalar index out of range"));
5287ad62 17867 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
17868 && et.size == 8,
17869 _("stride of 2 unavailable when element size is 8"));
5f4273c7 17870
5287ad62
JB
17871 switch (n)
17872 {
17873 case 0: /* VLD1 / VST1. */
aa8a0863 17874 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 17875 32, 32, -1);
5287ad62 17876 if (align_good == FAIL)
477330fc 17877 return;
aa8a0863 17878 if (do_alignment)
477330fc
RM
17879 {
17880 unsigned alignbits = 0;
17881 switch (et.size)
17882 {
17883 case 16: alignbits = 0x1; break;
17884 case 32: alignbits = 0x3; break;
17885 default: ;
17886 }
17887 inst.instruction |= alignbits << 4;
17888 }
5287ad62
JB
17889 break;
17890
17891 case 1: /* VLD2 / VST2. */
aa8a0863
TS
17892 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
17893 16, 32, 32, 64, -1);
5287ad62 17894 if (align_good == FAIL)
477330fc 17895 return;
aa8a0863 17896 if (do_alignment)
477330fc 17897 inst.instruction |= 1 << 4;
5287ad62
JB
17898 break;
17899
17900 case 2: /* VLD3 / VST3. */
17901 constraint (inst.operands[1].immisalign,
477330fc 17902 _("can't use alignment with this instruction"));
5287ad62
JB
17903 break;
17904
17905 case 3: /* VLD4 / VST4. */
aa8a0863 17906 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 17907 16, 64, 32, 64, 32, 128, -1);
5287ad62 17908 if (align_good == FAIL)
477330fc 17909 return;
aa8a0863 17910 if (do_alignment)
477330fc
RM
17911 {
17912 unsigned alignbits = 0;
17913 switch (et.size)
17914 {
17915 case 8: alignbits = 0x1; break;
17916 case 16: alignbits = 0x1; break;
17917 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
17918 default: ;
17919 }
17920 inst.instruction |= alignbits << 4;
17921 }
5287ad62
JB
17922 break;
17923
17924 default: ;
17925 }
17926
17927 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
17928 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17929 inst.instruction |= 1 << (4 + logsize);
5f4273c7 17930
5287ad62
JB
17931 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
17932 inst.instruction |= logsize << 10;
17933}
17934
17935/* Encode single n-element structure to all lanes VLD<n> instructions. */
17936
17937static void
17938do_neon_ld_dup (void)
17939{
037e8744 17940 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17941 int align_good, do_alignment = 0;
5287ad62 17942
dcbf9037
JB
17943 if (et.type == NT_invtype)
17944 return;
17945
5287ad62
JB
17946 switch ((inst.instruction >> 8) & 3)
17947 {
17948 case 0: /* VLD1. */
9c2799c2 17949 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 17950 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 17951 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 17952 if (align_good == FAIL)
477330fc 17953 return;
5287ad62 17954 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
17955 {
17956 case 1: break;
17957 case 2: inst.instruction |= 1 << 5; break;
17958 default: first_error (_("bad list length")); return;
17959 }
5287ad62
JB
17960 inst.instruction |= neon_logbits (et.size) << 6;
17961 break;
17962
17963 case 1: /* VLD2. */
17964 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
17965 &do_alignment, 8, 16, 16, 32, 32, 64,
17966 -1);
5287ad62 17967 if (align_good == FAIL)
477330fc 17968 return;
5287ad62 17969 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 17970 _("bad list length"));
5287ad62 17971 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17972 inst.instruction |= 1 << 5;
5287ad62
JB
17973 inst.instruction |= neon_logbits (et.size) << 6;
17974 break;
17975
17976 case 2: /* VLD3. */
17977 constraint (inst.operands[1].immisalign,
477330fc 17978 _("can't use alignment with this instruction"));
5287ad62 17979 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 17980 _("bad list length"));
5287ad62 17981 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17982 inst.instruction |= 1 << 5;
5287ad62
JB
17983 inst.instruction |= neon_logbits (et.size) << 6;
17984 break;
17985
17986 case 3: /* VLD4. */
17987 {
477330fc 17988 int align = inst.operands[1].imm >> 8;
aa8a0863 17989 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17990 16, 64, 32, 64, 32, 128, -1);
17991 if (align_good == FAIL)
17992 return;
17993 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17994 _("bad list length"));
17995 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17996 inst.instruction |= 1 << 5;
17997 if (et.size == 32 && align == 128)
17998 inst.instruction |= 0x3 << 6;
17999 else
18000 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
18001 }
18002 break;
18003
18004 default: ;
18005 }
18006
aa8a0863 18007 inst.instruction |= do_alignment << 4;
5287ad62
JB
18008}
18009
18010/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
18011 apart from bits [11:4]. */
18012
18013static void
18014do_neon_ldx_stx (void)
18015{
b1a769ed
DG
18016 if (inst.operands[1].isreg)
18017 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18018
5287ad62
JB
18019 switch (NEON_LANE (inst.operands[0].imm))
18020 {
18021 case NEON_INTERLEAVE_LANES:
88714cb8 18022 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
18023 do_neon_ld_st_interleave ();
18024 break;
5f4273c7 18025
5287ad62 18026 case NEON_ALL_LANES:
88714cb8 18027 NEON_ENCODE (DUP, inst);
2d51fb74
JB
18028 if (inst.instruction == N_INV)
18029 {
18030 first_error ("only loads support such operands");
18031 break;
18032 }
5287ad62
JB
18033 do_neon_ld_dup ();
18034 break;
5f4273c7 18035
5287ad62 18036 default:
88714cb8 18037 NEON_ENCODE (LANE, inst);
5287ad62
JB
18038 do_neon_ld_st_lane ();
18039 }
18040
18041 /* L bit comes from bit mask. */
18042 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18043 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18044 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 18045
5287ad62
JB
18046 if (inst.operands[1].postind)
18047 {
18048 int postreg = inst.operands[1].imm & 0xf;
18049 constraint (!inst.operands[1].immisreg,
477330fc 18050 _("post-index must be a register"));
5287ad62 18051 constraint (postreg == 0xd || postreg == 0xf,
477330fc 18052 _("bad register for post-index"));
5287ad62
JB
18053 inst.instruction |= postreg;
18054 }
4f2374c7 18055 else
5287ad62 18056 {
4f2374c7 18057 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
e2b0ab59
AV
18058 constraint (inst.relocs[0].exp.X_op != O_constant
18059 || inst.relocs[0].exp.X_add_number != 0,
4f2374c7
WN
18060 BAD_ADDR_MODE);
18061
18062 if (inst.operands[1].writeback)
18063 {
18064 inst.instruction |= 0xd;
18065 }
18066 else
18067 inst.instruction |= 0xf;
5287ad62 18068 }
5f4273c7 18069
5287ad62
JB
18070 if (thumb_mode)
18071 inst.instruction |= 0xf9000000;
18072 else
18073 inst.instruction |= 0xf4000000;
18074}
33399f07
MGD
18075
18076/* FP v8. */
18077static void
18078do_vfp_nsyn_fpv8 (enum neon_shape rs)
18079{
a715796b
TG
18080 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18081 D register operands. */
18082 if (neon_shape_class[rs] == SC_DOUBLE)
18083 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18084 _(BAD_FPU));
18085
33399f07
MGD
18086 NEON_ENCODE (FPV8, inst);
18087
9db2f6b4
RL
18088 if (rs == NS_FFF || rs == NS_HHH)
18089 {
18090 do_vfp_sp_dyadic ();
18091
18092 /* ARMv8.2 fp16 instruction. */
18093 if (rs == NS_HHH)
18094 do_scalar_fp16_v82_encode ();
18095 }
33399f07
MGD
18096 else
18097 do_vfp_dp_rd_rn_rm ();
18098
18099 if (rs == NS_DDD)
18100 inst.instruction |= 0x100;
18101
18102 inst.instruction |= 0xf0000000;
18103}
18104
18105static void
18106do_vsel (void)
18107{
5ee91343 18108 set_pred_insn_type (OUTSIDE_PRED_INSN);
33399f07
MGD
18109
18110 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
18111 first_error (_("invalid instruction shape"));
18112}
18113
73924fbc
MGD
18114static void
18115do_vmaxnm (void)
18116{
5ee91343 18117 set_pred_insn_type (OUTSIDE_PRED_INSN);
73924fbc
MGD
18118
18119 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
18120 return;
18121
18122 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
18123 return;
18124
cc933301 18125 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
18126}
18127
30bdf752
MGD
18128static void
18129do_vrint_1 (enum neon_cvt_mode mode)
18130{
9db2f6b4 18131 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
18132 struct neon_type_el et;
18133
18134 if (rs == NS_NULL)
18135 return;
18136
a715796b
TG
18137 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18138 D register operands. */
18139 if (neon_shape_class[rs] == SC_DOUBLE)
18140 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18141 _(BAD_FPU));
18142
9db2f6b4
RL
18143 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
18144 | N_VFP);
30bdf752
MGD
18145 if (et.type != NT_invtype)
18146 {
18147 /* VFP encodings. */
18148 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
18149 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
5ee91343 18150 set_pred_insn_type (OUTSIDE_PRED_INSN);
30bdf752
MGD
18151
18152 NEON_ENCODE (FPV8, inst);
9db2f6b4 18153 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
18154 do_vfp_sp_monadic ();
18155 else
18156 do_vfp_dp_rd_rm ();
18157
18158 switch (mode)
18159 {
18160 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
18161 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
18162 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
18163 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
18164 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
18165 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
18166 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
18167 default: abort ();
18168 }
18169
18170 inst.instruction |= (rs == NS_DD) << 8;
18171 do_vfp_cond_or_thumb ();
9db2f6b4
RL
18172
18173 /* ARMv8.2 fp16 vrint instruction. */
18174 if (rs == NS_HH)
18175 do_scalar_fp16_v82_encode ();
30bdf752
MGD
18176 }
18177 else
18178 {
18179 /* Neon encodings (or something broken...). */
18180 inst.error = NULL;
cc933301 18181 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
18182
18183 if (et.type == NT_invtype)
18184 return;
18185
5ee91343 18186 set_pred_insn_type (OUTSIDE_PRED_INSN);
30bdf752
MGD
18187 NEON_ENCODE (FLOAT, inst);
18188
18189 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
18190 return;
18191
18192 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18193 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18194 inst.instruction |= LOW4 (inst.operands[1].reg);
18195 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18196 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
18197 /* Mask off the original size bits and reencode them. */
18198 inst.instruction = ((inst.instruction & 0xfff3ffff)
18199 | neon_logbits (et.size) << 18);
18200
30bdf752
MGD
18201 switch (mode)
18202 {
18203 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
18204 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
18205 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
18206 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
18207 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
18208 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
18209 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
18210 default: abort ();
18211 }
18212
18213 if (thumb_mode)
18214 inst.instruction |= 0xfc000000;
18215 else
18216 inst.instruction |= 0xf0000000;
18217 }
18218}
18219
18220static void
18221do_vrintx (void)
18222{
18223 do_vrint_1 (neon_cvt_mode_x);
18224}
18225
18226static void
18227do_vrintz (void)
18228{
18229 do_vrint_1 (neon_cvt_mode_z);
18230}
18231
18232static void
18233do_vrintr (void)
18234{
18235 do_vrint_1 (neon_cvt_mode_r);
18236}
18237
18238static void
18239do_vrinta (void)
18240{
18241 do_vrint_1 (neon_cvt_mode_a);
18242}
18243
18244static void
18245do_vrintn (void)
18246{
18247 do_vrint_1 (neon_cvt_mode_n);
18248}
18249
18250static void
18251do_vrintp (void)
18252{
18253 do_vrint_1 (neon_cvt_mode_p);
18254}
18255
18256static void
18257do_vrintm (void)
18258{
18259 do_vrint_1 (neon_cvt_mode_m);
18260}
18261
c28eeff2
SN
18262static unsigned
18263neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
18264{
18265 unsigned regno = NEON_SCALAR_REG (opnd);
18266 unsigned elno = NEON_SCALAR_INDEX (opnd);
18267
18268 if (elsize == 16 && elno < 2 && regno < 16)
18269 return regno | (elno << 4);
18270 else if (elsize == 32 && elno == 0)
18271 return regno;
18272
18273 first_error (_("scalar out of range"));
18274 return 0;
18275}
18276
18277static void
18278do_vcmla (void)
18279{
18280 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
18281 _(BAD_FPU));
e2b0ab59
AV
18282 constraint (inst.relocs[0].exp.X_op != O_constant,
18283 _("expression too complex"));
18284 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
18285 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
18286 _("immediate out of range"));
18287 rot /= 90;
18288 if (inst.operands[2].isscalar)
18289 {
18290 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
18291 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
18292 N_KEY | N_F16 | N_F32).size;
18293 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
18294 inst.is_neon = 1;
18295 inst.instruction = 0xfe000800;
18296 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18297 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18298 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
18299 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
18300 inst.instruction |= LOW4 (m);
18301 inst.instruction |= HI1 (m) << 5;
18302 inst.instruction |= neon_quad (rs) << 6;
18303 inst.instruction |= rot << 20;
18304 inst.instruction |= (size == 32) << 23;
18305 }
18306 else
18307 {
18308 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
18309 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
18310 N_KEY | N_F16 | N_F32).size;
18311 neon_three_same (neon_quad (rs), 0, -1);
18312 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
18313 inst.instruction |= 0xfc200800;
18314 inst.instruction |= rot << 23;
18315 inst.instruction |= (size == 32) << 20;
18316 }
18317}
18318
18319static void
18320do_vcadd (void)
18321{
18322 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
18323 _(BAD_FPU));
e2b0ab59
AV
18324 constraint (inst.relocs[0].exp.X_op != O_constant,
18325 _("expression too complex"));
18326 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
18327 constraint (rot != 90 && rot != 270, _("immediate out of range"));
18328 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
18329 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
18330 N_KEY | N_F16 | N_F32).size;
18331 neon_three_same (neon_quad (rs), 0, -1);
18332 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
18333 inst.instruction |= 0xfc800800;
18334 inst.instruction |= (rot == 270) << 24;
18335 inst.instruction |= (size == 32) << 20;
18336}
18337
c604a79a
JW
18338/* Dot Product instructions encoding support. */
18339
18340static void
18341do_neon_dotproduct (int unsigned_p)
18342{
18343 enum neon_shape rs;
18344 unsigned scalar_oprd2 = 0;
18345 int high8;
18346
18347 if (inst.cond != COND_ALWAYS)
18348 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
18349 "is UNPREDICTABLE"));
18350
18351 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
18352 _(BAD_FPU));
18353
18354 /* Dot Product instructions are in three-same D/Q register format or the third
18355 operand can be a scalar index register. */
18356 if (inst.operands[2].isscalar)
18357 {
18358 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
18359 high8 = 0xfe000000;
18360 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18361 }
18362 else
18363 {
18364 high8 = 0xfc000000;
18365 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18366 }
18367
18368 if (unsigned_p)
18369 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
18370 else
18371 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
18372
18373 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
18374 Product instruction, so we pass 0 as the "ubit" parameter. And the
18375 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
18376 neon_three_same (neon_quad (rs), 0, 32);
18377
18378 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
18379 different NEON three-same encoding. */
18380 inst.instruction &= 0x00ffffff;
18381 inst.instruction |= high8;
18382 /* Encode 'U' bit which indicates signedness. */
18383 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
18384 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
18385 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
18386 the instruction encoding. */
18387 if (inst.operands[2].isscalar)
18388 {
18389 inst.instruction &= 0xffffffd0;
18390 inst.instruction |= LOW4 (scalar_oprd2);
18391 inst.instruction |= HI1 (scalar_oprd2) << 5;
18392 }
18393}
18394
18395/* Dot Product instructions for signed integer. */
18396
18397static void
18398do_neon_dotproduct_s (void)
18399{
18400 return do_neon_dotproduct (0);
18401}
18402
18403/* Dot Product instructions for unsigned integer. */
18404
18405static void
18406do_neon_dotproduct_u (void)
18407{
18408 return do_neon_dotproduct (1);
18409}
18410
91ff7894
MGD
18411/* Crypto v1 instructions. */
18412static void
18413do_crypto_2op_1 (unsigned elttype, int op)
18414{
5ee91343 18415 set_pred_insn_type (OUTSIDE_PRED_INSN);
91ff7894
MGD
18416
18417 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
18418 == NT_invtype)
18419 return;
18420
18421 inst.error = NULL;
18422
18423 NEON_ENCODE (INTEGER, inst);
18424 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18425 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18426 inst.instruction |= LOW4 (inst.operands[1].reg);
18427 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18428 if (op != -1)
18429 inst.instruction |= op << 6;
18430
18431 if (thumb_mode)
18432 inst.instruction |= 0xfc000000;
18433 else
18434 inst.instruction |= 0xf0000000;
18435}
18436
48adcd8e
MGD
18437static void
18438do_crypto_3op_1 (int u, int op)
18439{
5ee91343 18440 set_pred_insn_type (OUTSIDE_PRED_INSN);
48adcd8e
MGD
18441
18442 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
18443 N_32 | N_UNT | N_KEY).type == NT_invtype)
18444 return;
18445
18446 inst.error = NULL;
18447
18448 NEON_ENCODE (INTEGER, inst);
18449 neon_three_same (1, u, 8 << op);
18450}
18451
91ff7894
MGD
18452static void
18453do_aese (void)
18454{
18455 do_crypto_2op_1 (N_8, 0);
18456}
18457
18458static void
18459do_aesd (void)
18460{
18461 do_crypto_2op_1 (N_8, 1);
18462}
18463
18464static void
18465do_aesmc (void)
18466{
18467 do_crypto_2op_1 (N_8, 2);
18468}
18469
18470static void
18471do_aesimc (void)
18472{
18473 do_crypto_2op_1 (N_8, 3);
18474}
18475
48adcd8e
MGD
18476static void
18477do_sha1c (void)
18478{
18479 do_crypto_3op_1 (0, 0);
18480}
18481
18482static void
18483do_sha1p (void)
18484{
18485 do_crypto_3op_1 (0, 1);
18486}
18487
18488static void
18489do_sha1m (void)
18490{
18491 do_crypto_3op_1 (0, 2);
18492}
18493
18494static void
18495do_sha1su0 (void)
18496{
18497 do_crypto_3op_1 (0, 3);
18498}
91ff7894 18499
48adcd8e
MGD
18500static void
18501do_sha256h (void)
18502{
18503 do_crypto_3op_1 (1, 0);
18504}
18505
18506static void
18507do_sha256h2 (void)
18508{
18509 do_crypto_3op_1 (1, 1);
18510}
18511
18512static void
18513do_sha256su1 (void)
18514{
18515 do_crypto_3op_1 (1, 2);
18516}
3c9017d2
MGD
18517
18518static void
18519do_sha1h (void)
18520{
18521 do_crypto_2op_1 (N_32, -1);
18522}
18523
18524static void
18525do_sha1su1 (void)
18526{
18527 do_crypto_2op_1 (N_32, 0);
18528}
18529
18530static void
18531do_sha256su0 (void)
18532{
18533 do_crypto_2op_1 (N_32, 1);
18534}
dd5181d5
KT
18535
18536static void
18537do_crc32_1 (unsigned int poly, unsigned int sz)
18538{
18539 unsigned int Rd = inst.operands[0].reg;
18540 unsigned int Rn = inst.operands[1].reg;
18541 unsigned int Rm = inst.operands[2].reg;
18542
5ee91343 18543 set_pred_insn_type (OUTSIDE_PRED_INSN);
dd5181d5
KT
18544 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
18545 inst.instruction |= LOW4 (Rn) << 16;
18546 inst.instruction |= LOW4 (Rm);
18547 inst.instruction |= sz << (thumb_mode ? 4 : 21);
18548 inst.instruction |= poly << (thumb_mode ? 20 : 9);
18549
18550 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
18551 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
18552}
18553
18554static void
18555do_crc32b (void)
18556{
18557 do_crc32_1 (0, 0);
18558}
18559
18560static void
18561do_crc32h (void)
18562{
18563 do_crc32_1 (0, 1);
18564}
18565
18566static void
18567do_crc32w (void)
18568{
18569 do_crc32_1 (0, 2);
18570}
18571
18572static void
18573do_crc32cb (void)
18574{
18575 do_crc32_1 (1, 0);
18576}
18577
18578static void
18579do_crc32ch (void)
18580{
18581 do_crc32_1 (1, 1);
18582}
18583
18584static void
18585do_crc32cw (void)
18586{
18587 do_crc32_1 (1, 2);
18588}
18589
49e8a725
SN
18590static void
18591do_vjcvt (void)
18592{
18593 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18594 _(BAD_FPU));
18595 neon_check_type (2, NS_FD, N_S32, N_F64);
18596 do_vfp_sp_dp_cvt ();
18597 do_vfp_cond_or_thumb ();
18598}
18599
5287ad62
JB
18600\f
18601/* Overall per-instruction processing. */
18602
18603/* We need to be able to fix up arbitrary expressions in some statements.
18604 This is so that we can handle symbols that are an arbitrary distance from
18605 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
18606 which returns part of an address in a form which will be valid for
18607 a data instruction. We do this by pushing the expression into a symbol
18608 in the expr_section, and creating a fix for that. */
18609
18610static void
18611fix_new_arm (fragS * frag,
18612 int where,
18613 short int size,
18614 expressionS * exp,
18615 int pc_rel,
18616 int reloc)
18617{
18618 fixS * new_fix;
18619
18620 switch (exp->X_op)
18621 {
18622 case O_constant:
6e7ce2cd
PB
18623 if (pc_rel)
18624 {
18625 /* Create an absolute valued symbol, so we have something to
477330fc
RM
18626 refer to in the object file. Unfortunately for us, gas's
18627 generic expression parsing will already have folded out
18628 any use of .set foo/.type foo %function that may have
18629 been used to set type information of the target location,
18630 that's being specified symbolically. We have to presume
18631 the user knows what they are doing. */
6e7ce2cd
PB
18632 char name[16 + 8];
18633 symbolS *symbol;
18634
18635 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
18636
18637 symbol = symbol_find_or_make (name);
18638 S_SET_SEGMENT (symbol, absolute_section);
18639 symbol_set_frag (symbol, &zero_address_frag);
18640 S_SET_VALUE (symbol, exp->X_add_number);
18641 exp->X_op = O_symbol;
18642 exp->X_add_symbol = symbol;
18643 exp->X_add_number = 0;
18644 }
18645 /* FALLTHROUGH */
5287ad62
JB
18646 case O_symbol:
18647 case O_add:
18648 case O_subtract:
21d799b5 18649 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 18650 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
18651 break;
18652
18653 default:
21d799b5 18654 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 18655 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
18656 break;
18657 }
18658
18659 /* Mark whether the fix is to a THUMB instruction, or an ARM
18660 instruction. */
18661 new_fix->tc_fix_data = thumb_mode;
18662}
18663
18664/* Create a frg for an instruction requiring relaxation. */
18665static void
18666output_relax_insn (void)
18667{
18668 char * to;
18669 symbolS *sym;
0110f2b8
PB
18670 int offset;
18671
6e1cb1a6
PB
18672 /* The size of the instruction is unknown, so tie the debug info to the
18673 start of the instruction. */
18674 dwarf2_emit_insn (0);
6e1cb1a6 18675
e2b0ab59 18676 switch (inst.relocs[0].exp.X_op)
0110f2b8
PB
18677 {
18678 case O_symbol:
e2b0ab59
AV
18679 sym = inst.relocs[0].exp.X_add_symbol;
18680 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
18681 break;
18682 case O_constant:
18683 sym = NULL;
e2b0ab59 18684 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
18685 break;
18686 default:
e2b0ab59 18687 sym = make_expr_symbol (&inst.relocs[0].exp);
0110f2b8
PB
18688 offset = 0;
18689 break;
18690 }
18691 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
18692 inst.relax, sym, offset, NULL/*offset, opcode*/);
18693 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
18694}
18695
18696/* Write a 32-bit thumb instruction to buf. */
18697static void
18698put_thumb32_insn (char * buf, unsigned long insn)
18699{
18700 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
18701 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
18702}
18703
b99bd4ef 18704static void
c19d1205 18705output_inst (const char * str)
b99bd4ef 18706{
c19d1205 18707 char * to = NULL;
b99bd4ef 18708
c19d1205 18709 if (inst.error)
b99bd4ef 18710 {
c19d1205 18711 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
18712 return;
18713 }
5f4273c7
NC
18714 if (inst.relax)
18715 {
18716 output_relax_insn ();
0110f2b8 18717 return;
5f4273c7 18718 }
c19d1205
ZW
18719 if (inst.size == 0)
18720 return;
b99bd4ef 18721
c19d1205 18722 to = frag_more (inst.size);
8dc2430f
NC
18723 /* PR 9814: Record the thumb mode into the current frag so that we know
18724 what type of NOP padding to use, if necessary. We override any previous
18725 setting so that if the mode has changed then the NOPS that we use will
18726 match the encoding of the last instruction in the frag. */
cd000bff 18727 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
18728
18729 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 18730 {
9c2799c2 18731 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 18732 put_thumb32_insn (to, inst.instruction);
b99bd4ef 18733 }
c19d1205 18734 else if (inst.size > INSN_SIZE)
b99bd4ef 18735 {
9c2799c2 18736 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
18737 md_number_to_chars (to, inst.instruction, INSN_SIZE);
18738 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 18739 }
c19d1205
ZW
18740 else
18741 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 18742
e2b0ab59
AV
18743 int r;
18744 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
18745 {
18746 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
18747 fix_new_arm (frag_now, to - frag_now->fr_literal,
18748 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
18749 inst.relocs[r].type);
18750 }
b99bd4ef 18751
c19d1205 18752 dwarf2_emit_insn (inst.size);
c19d1205 18753}
b99bd4ef 18754
e07e6e58
NC
18755static char *
18756output_it_inst (int cond, int mask, char * to)
18757{
18758 unsigned long instruction = 0xbf00;
18759
18760 mask &= 0xf;
18761 instruction |= mask;
18762 instruction |= cond << 4;
18763
18764 if (to == NULL)
18765 {
18766 to = frag_more (2);
18767#ifdef OBJ_ELF
18768 dwarf2_emit_insn (2);
18769#endif
18770 }
18771
18772 md_number_to_chars (to, instruction, 2);
18773
18774 return to;
18775}
18776
c19d1205
ZW
18777/* Tag values used in struct asm_opcode's tag field. */
18778enum opcode_tag
18779{
18780 OT_unconditional, /* Instruction cannot be conditionalized.
18781 The ARM condition field is still 0xE. */
18782 OT_unconditionalF, /* Instruction cannot be conditionalized
18783 and carries 0xF in its ARM condition field. */
18784 OT_csuffix, /* Instruction takes a conditional suffix. */
5ee91343
AV
18785 OT_csuffixF, /* Some forms of the instruction take a scalar
18786 conditional suffix, others place 0xF where the
18787 condition field would be, others take a vector
18788 conditional suffix. */
c19d1205
ZW
18789 OT_cinfix3, /* Instruction takes a conditional infix,
18790 beginning at character index 3. (In
18791 unified mode, it becomes a suffix.) */
088fa78e
KH
18792 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
18793 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
18794 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
18795 character index 3, even in unified mode. Used for
18796 legacy instructions where suffix and infix forms
18797 may be ambiguous. */
c19d1205 18798 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 18799 suffix or an infix at character index 3. */
c19d1205
ZW
18800 OT_odd_infix_unc, /* This is the unconditional variant of an
18801 instruction that takes a conditional infix
18802 at an unusual position. In unified mode,
18803 this variant will accept a suffix. */
18804 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
18805 are the conditional variants of instructions that
18806 take conditional infixes in unusual positions.
18807 The infix appears at character index
18808 (tag - OT_odd_infix_0). These are not accepted
18809 in unified mode. */
18810};
b99bd4ef 18811
c19d1205
ZW
18812/* Subroutine of md_assemble, responsible for looking up the primary
18813 opcode from the mnemonic the user wrote. STR points to the
18814 beginning of the mnemonic.
18815
18816 This is not simply a hash table lookup, because of conditional
18817 variants. Most instructions have conditional variants, which are
18818 expressed with a _conditional affix_ to the mnemonic. If we were
18819 to encode each conditional variant as a literal string in the opcode
18820 table, it would have approximately 20,000 entries.
18821
18822 Most mnemonics take this affix as a suffix, and in unified syntax,
18823 'most' is upgraded to 'all'. However, in the divided syntax, some
18824 instructions take the affix as an infix, notably the s-variants of
18825 the arithmetic instructions. Of those instructions, all but six
18826 have the infix appear after the third character of the mnemonic.
18827
18828 Accordingly, the algorithm for looking up primary opcodes given
18829 an identifier is:
18830
18831 1. Look up the identifier in the opcode table.
18832 If we find a match, go to step U.
18833
18834 2. Look up the last two characters of the identifier in the
18835 conditions table. If we find a match, look up the first N-2
18836 characters of the identifier in the opcode table. If we
18837 find a match, go to step CE.
18838
18839 3. Look up the fourth and fifth characters of the identifier in
18840 the conditions table. If we find a match, extract those
18841 characters from the identifier, and look up the remaining
18842 characters in the opcode table. If we find a match, go
18843 to step CM.
18844
18845 4. Fail.
18846
18847 U. Examine the tag field of the opcode structure, in case this is
18848 one of the six instructions with its conditional infix in an
18849 unusual place. If it is, the tag tells us where to find the
18850 infix; look it up in the conditions table and set inst.cond
18851 accordingly. Otherwise, this is an unconditional instruction.
18852 Again set inst.cond accordingly. Return the opcode structure.
18853
18854 CE. Examine the tag field to make sure this is an instruction that
18855 should receive a conditional suffix. If it is not, fail.
18856 Otherwise, set inst.cond from the suffix we already looked up,
18857 and return the opcode structure.
18858
18859 CM. Examine the tag field to make sure this is an instruction that
18860 should receive a conditional infix after the third character.
18861 If it is not, fail. Otherwise, undo the edits to the current
18862 line of input and proceed as for case CE. */
18863
18864static const struct asm_opcode *
18865opcode_lookup (char **str)
18866{
18867 char *end, *base;
18868 char *affix;
18869 const struct asm_opcode *opcode;
18870 const struct asm_cond *cond;
e3cb604e 18871 char save[2];
c19d1205
ZW
18872
18873 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 18874 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 18875 for (base = end = *str; *end != '\0'; end++)
721a8186 18876 if (*end == ' ' || *end == '.')
c19d1205 18877 break;
b99bd4ef 18878
c19d1205 18879 if (end == base)
c921be7d 18880 return NULL;
b99bd4ef 18881
5287ad62 18882 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 18883 if (end[0] == '.')
b99bd4ef 18884 {
5287ad62 18885 int offset = 2;
5f4273c7 18886
267d2029 18887 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 18888 use. */
267d2029 18889 if (unified_syntax && end[1] == 'w')
c19d1205 18890 inst.size_req = 4;
267d2029 18891 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
18892 inst.size_req = 2;
18893 else
477330fc 18894 offset = 0;
5287ad62
JB
18895
18896 inst.vectype.elems = 0;
18897
18898 *str = end + offset;
b99bd4ef 18899
5f4273c7 18900 if (end[offset] == '.')
5287ad62 18901 {
267d2029 18902 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
18903 non-unified ARM syntax mode). */
18904 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 18905 return NULL;
477330fc 18906 }
5287ad62 18907 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 18908 return NULL;
b99bd4ef 18909 }
c19d1205
ZW
18910 else
18911 *str = end;
b99bd4ef 18912
c19d1205 18913 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 18914 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18915 end - base);
c19d1205 18916 if (opcode)
b99bd4ef 18917 {
c19d1205
ZW
18918 /* step U */
18919 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 18920 {
c19d1205
ZW
18921 inst.cond = COND_ALWAYS;
18922 return opcode;
b99bd4ef 18923 }
b99bd4ef 18924
278df34e 18925 if (warn_on_deprecated && unified_syntax)
5c3696f8 18926 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 18927 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 18928 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 18929 gas_assert (cond);
b99bd4ef 18930
c19d1205
ZW
18931 inst.cond = cond->value;
18932 return opcode;
18933 }
5ee91343
AV
18934 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18935 {
18936 /* Cannot have a conditional suffix on a mnemonic of less than a character.
18937 */
18938 if (end - base < 2)
18939 return NULL;
18940 affix = end - 1;
18941 cond = (const struct asm_cond *) hash_find_n (arm_vcond_hsh, affix, 1);
18942 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
18943 affix - base);
18944 /* If this opcode can not be vector predicated then don't accept it with a
18945 vector predication code. */
18946 if (opcode && !opcode->mayBeVecPred)
18947 opcode = NULL;
18948 }
18949 if (!opcode || !cond)
18950 {
18951 /* Cannot have a conditional suffix on a mnemonic of less than two
18952 characters. */
18953 if (end - base < 3)
18954 return NULL;
b99bd4ef 18955
5ee91343
AV
18956 /* Look for suffixed mnemonic. */
18957 affix = end - 2;
18958 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18959 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
18960 affix - base);
18961 }
b99bd4ef 18962
c19d1205
ZW
18963 if (opcode && cond)
18964 {
18965 /* step CE */
18966 switch (opcode->tag)
18967 {
e3cb604e
PB
18968 case OT_cinfix3_legacy:
18969 /* Ignore conditional suffixes matched on infix only mnemonics. */
18970 break;
18971
c19d1205 18972 case OT_cinfix3:
088fa78e 18973 case OT_cinfix3_deprecated:
c19d1205
ZW
18974 case OT_odd_infix_unc:
18975 if (!unified_syntax)
0198d5e6 18976 return NULL;
1a0670f3 18977 /* Fall through. */
c19d1205
ZW
18978
18979 case OT_csuffix:
477330fc 18980 case OT_csuffixF:
c19d1205
ZW
18981 case OT_csuf_or_in3:
18982 inst.cond = cond->value;
18983 return opcode;
18984
18985 case OT_unconditional:
18986 case OT_unconditionalF:
dfa9f0d5 18987 if (thumb_mode)
c921be7d 18988 inst.cond = cond->value;
dfa9f0d5
PB
18989 else
18990 {
c921be7d 18991 /* Delayed diagnostic. */
dfa9f0d5
PB
18992 inst.error = BAD_COND;
18993 inst.cond = COND_ALWAYS;
18994 }
c19d1205 18995 return opcode;
b99bd4ef 18996
c19d1205 18997 default:
c921be7d 18998 return NULL;
c19d1205
ZW
18999 }
19000 }
b99bd4ef 19001
c19d1205
ZW
19002 /* Cannot have a usual-position infix on a mnemonic of less than
19003 six characters (five would be a suffix). */
19004 if (end - base < 6)
c921be7d 19005 return NULL;
b99bd4ef 19006
c19d1205
ZW
19007 /* Look for infixed mnemonic in the usual position. */
19008 affix = base + 3;
21d799b5 19009 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 19010 if (!cond)
c921be7d 19011 return NULL;
e3cb604e
PB
19012
19013 memcpy (save, affix, 2);
19014 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 19015 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 19016 (end - base) - 2);
e3cb604e
PB
19017 memmove (affix + 2, affix, (end - affix) - 2);
19018 memcpy (affix, save, 2);
19019
088fa78e
KH
19020 if (opcode
19021 && (opcode->tag == OT_cinfix3
19022 || opcode->tag == OT_cinfix3_deprecated
19023 || opcode->tag == OT_csuf_or_in3
19024 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 19025 {
c921be7d 19026 /* Step CM. */
278df34e 19027 if (warn_on_deprecated && unified_syntax
088fa78e
KH
19028 && (opcode->tag == OT_cinfix3
19029 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 19030 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
19031
19032 inst.cond = cond->value;
19033 return opcode;
b99bd4ef
NC
19034 }
19035
c921be7d 19036 return NULL;
b99bd4ef
NC
19037}
19038
e07e6e58
NC
19039/* This function generates an initial IT instruction, leaving its block
19040 virtually open for the new instructions. Eventually,
5ee91343 19041 the mask will be updated by now_pred_add_mask () each time
e07e6e58
NC
19042 a new instruction needs to be included in the IT block.
19043 Finally, the block is closed with close_automatic_it_block ().
19044 The block closure can be requested either from md_assemble (),
19045 a tencode (), or due to a label hook. */
19046
19047static void
19048new_automatic_it_block (int cond)
19049{
5ee91343
AV
19050 now_pred.state = AUTOMATIC_PRED_BLOCK;
19051 now_pred.mask = 0x18;
19052 now_pred.cc = cond;
19053 now_pred.block_length = 1;
cd000bff 19054 mapping_state (MAP_THUMB);
5ee91343
AV
19055 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
19056 now_pred.warn_deprecated = FALSE;
19057 now_pred.insn_cond = TRUE;
e07e6e58
NC
19058}
19059
19060/* Close an automatic IT block.
19061 See comments in new_automatic_it_block (). */
19062
19063static void
19064close_automatic_it_block (void)
19065{
5ee91343
AV
19066 now_pred.mask = 0x10;
19067 now_pred.block_length = 0;
e07e6e58
NC
19068}
19069
19070/* Update the mask of the current automatically-generated IT
19071 instruction. See comments in new_automatic_it_block (). */
19072
19073static void
5ee91343 19074now_pred_add_mask (int cond)
e07e6e58
NC
19075{
19076#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
19077#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 19078 | ((bitvalue) << (nbit)))
e07e6e58 19079 const int resulting_bit = (cond & 1);
c921be7d 19080
5ee91343
AV
19081 now_pred.mask &= 0xf;
19082 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 19083 resulting_bit,
5ee91343
AV
19084 (5 - now_pred.block_length));
19085 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 19086 1,
5ee91343
AV
19087 ((5 - now_pred.block_length) - 1));
19088 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
e07e6e58
NC
19089
19090#undef CLEAR_BIT
19091#undef SET_BIT_VALUE
e07e6e58
NC
19092}
19093
19094/* The IT blocks handling machinery is accessed through the these functions:
19095 it_fsm_pre_encode () from md_assemble ()
5ee91343
AV
19096 set_pred_insn_type () optional, from the tencode functions
19097 set_pred_insn_type_last () ditto
19098 in_pred_block () ditto
e07e6e58 19099 it_fsm_post_encode () from md_assemble ()
33eaf5de 19100 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
19101
19102 Rationale:
19103 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
19104 initializing the IT insn type with a generic initial value depending
19105 on the inst.condition.
e07e6e58 19106 2) During the tencode function, two things may happen:
477330fc 19107 a) The tencode function overrides the IT insn type by
5ee91343
AV
19108 calling either set_pred_insn_type (type) or
19109 set_pred_insn_type_last ().
477330fc 19110 b) The tencode function queries the IT block state by
5ee91343 19111 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
477330fc 19112
5ee91343
AV
19113 Both set_pred_insn_type and in_pred_block run the internal FSM state
19114 handling function (handle_pred_state), because: a) setting the IT insn
477330fc
RM
19115 type may incur in an invalid state (exiting the function),
19116 and b) querying the state requires the FSM to be updated.
19117 Specifically we want to avoid creating an IT block for conditional
19118 branches, so it_fsm_pre_encode is actually a guess and we can't
19119 determine whether an IT block is required until the tencode () routine
19120 has decided what type of instruction this actually it.
5ee91343
AV
19121 Because of this, if set_pred_insn_type and in_pred_block have to be
19122 used, set_pred_insn_type has to be called first.
477330fc 19123
5ee91343
AV
19124 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
19125 that determines the insn IT type depending on the inst.cond code.
477330fc
RM
19126 When a tencode () routine encodes an instruction that can be
19127 either outside an IT block, or, in the case of being inside, has to be
5ee91343 19128 the last one, set_pred_insn_type_last () will determine the proper
477330fc 19129 IT instruction type based on the inst.cond code. Otherwise,
5ee91343 19130 set_pred_insn_type can be called for overriding that logic or
477330fc
RM
19131 for covering other cases.
19132
5ee91343
AV
19133 Calling handle_pred_state () may not transition the IT block state to
19134 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
477330fc 19135 still queried. Instead, if the FSM determines that the state should
5ee91343 19136 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
477330fc
RM
19137 after the tencode () function: that's what it_fsm_post_encode () does.
19138
5ee91343 19139 Since in_pred_block () calls the state handling function to get an
477330fc
RM
19140 updated state, an error may occur (due to invalid insns combination).
19141 In that case, inst.error is set.
19142 Therefore, inst.error has to be checked after the execution of
19143 the tencode () routine.
e07e6e58
NC
19144
19145 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc 19146 any pending state change (if any) that didn't take place in
5ee91343 19147 handle_pred_state () as explained above. */
e07e6e58
NC
19148
19149static void
19150it_fsm_pre_encode (void)
19151{
19152 if (inst.cond != COND_ALWAYS)
5ee91343 19153 inst.pred_insn_type = INSIDE_IT_INSN;
e07e6e58 19154 else
5ee91343 19155 inst.pred_insn_type = OUTSIDE_PRED_INSN;
e07e6e58 19156
5ee91343 19157 now_pred.state_handled = 0;
e07e6e58
NC
19158}
19159
19160/* IT state FSM handling function. */
5ee91343
AV
19161/* MVE instructions and non-MVE instructions are handled differently because of
19162 the introduction of VPT blocks.
19163 Specifications say that any non-MVE instruction inside a VPT block is
19164 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
19165 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
19166 few exceptions this will be handled at their respective handler functions.
19167 The error messages provided depending on the different combinations possible
19168 are described in the cases below:
19169 For 'most' MVE instructions:
19170 1) In an IT block, with an IT code: syntax error
19171 2) In an IT block, with a VPT code: error: must be in a VPT block
19172 3) In an IT block, with no code: warning: UNPREDICTABLE
19173 4) In a VPT block, with an IT code: syntax error
19174 5) In a VPT block, with a VPT code: OK!
19175 6) In a VPT block, with no code: error: missing code
19176 7) Outside a pred block, with an IT code: error: syntax error
19177 8) Outside a pred block, with a VPT code: error: should be in a VPT block
19178 9) Outside a pred block, with no code: OK!
19179 For non-MVE instructions:
19180 10) In an IT block, with an IT code: OK!
19181 11) In an IT block, with a VPT code: syntax error
19182 12) In an IT block, with no code: error: missing code
19183 13) In a VPT block, with an IT code: error: should be in an IT block
19184 14) In a VPT block, with a VPT code: syntax error
19185 15) In a VPT block, with no code: UNPREDICTABLE
19186 16) Outside a pred block, with an IT code: error: should be in an IT block
19187 17) Outside a pred block, with a VPT code: syntax error
19188 18) Outside a pred block, with no code: OK!
19189 */
19190
e07e6e58
NC
19191
19192static int
5ee91343 19193handle_pred_state (void)
e07e6e58 19194{
5ee91343
AV
19195 now_pred.state_handled = 1;
19196 now_pred.insn_cond = FALSE;
e07e6e58 19197
5ee91343 19198 switch (now_pred.state)
e07e6e58 19199 {
5ee91343
AV
19200 case OUTSIDE_PRED_BLOCK:
19201 switch (inst.pred_insn_type)
e07e6e58 19202 {
5ee91343
AV
19203 case MVE_OUTSIDE_PRED_INSN:
19204 if (inst.cond < COND_ALWAYS)
19205 {
19206 /* Case 7: Outside a pred block, with an IT code: error: syntax
19207 error. */
19208 inst.error = BAD_SYNTAX;
19209 return FAIL;
19210 }
19211 /* Case 9: Outside a pred block, with no code: OK! */
19212 break;
19213 case OUTSIDE_PRED_INSN:
19214 if (inst.cond > COND_ALWAYS)
19215 {
19216 /* Case 17: Outside a pred block, with a VPT code: syntax error.
19217 */
19218 inst.error = BAD_SYNTAX;
19219 return FAIL;
19220 }
19221 /* Case 18: Outside a pred block, with no code: OK! */
e07e6e58
NC
19222 break;
19223
5ee91343
AV
19224 case INSIDE_VPT_INSN:
19225 /* Case 8: Outside a pred block, with a VPT code: error: should be in
19226 a VPT block. */
19227 inst.error = BAD_OUT_VPT;
19228 return FAIL;
19229
e07e6e58
NC
19230 case INSIDE_IT_INSN:
19231 case INSIDE_IT_LAST_INSN:
5ee91343 19232 if (inst.cond < COND_ALWAYS)
e07e6e58 19233 {
5ee91343
AV
19234 /* Case 16: Outside a pred block, with an IT code: error: should
19235 be in an IT block. */
19236 if (thumb_mode == 0)
e07e6e58 19237 {
5ee91343
AV
19238 if (unified_syntax
19239 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
19240 as_tsktsk (_("Warning: conditional outside an IT block"\
19241 " for Thumb."));
e07e6e58
NC
19242 }
19243 else
19244 {
5ee91343
AV
19245 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
19246 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
19247 {
19248 /* Automatically generate the IT instruction. */
19249 new_automatic_it_block (inst.cond);
19250 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
19251 close_automatic_it_block ();
19252 }
19253 else
19254 {
19255 inst.error = BAD_OUT_IT;
19256 return FAIL;
19257 }
e07e6e58 19258 }
5ee91343 19259 break;
e07e6e58 19260 }
5ee91343
AV
19261 else if (inst.cond > COND_ALWAYS)
19262 {
19263 /* Case 17: Outside a pred block, with a VPT code: syntax error.
19264 */
19265 inst.error = BAD_SYNTAX;
19266 return FAIL;
19267 }
19268 else
19269 gas_assert (0);
e07e6e58
NC
19270 case IF_INSIDE_IT_LAST_INSN:
19271 case NEUTRAL_IT_INSN:
19272 break;
19273
5ee91343
AV
19274 case VPT_INSN:
19275 if (inst.cond != COND_ALWAYS)
19276 first_error (BAD_SYNTAX);
19277 now_pred.state = MANUAL_PRED_BLOCK;
19278 now_pred.block_length = 0;
19279 now_pred.type = VECTOR_PRED;
19280 now_pred.cc = 0;
19281 break;
e07e6e58 19282 case IT_INSN:
5ee91343
AV
19283 now_pred.state = MANUAL_PRED_BLOCK;
19284 now_pred.block_length = 0;
19285 now_pred.type = SCALAR_PRED;
e07e6e58
NC
19286 break;
19287 }
19288 break;
19289
5ee91343 19290 case AUTOMATIC_PRED_BLOCK:
e07e6e58
NC
19291 /* Three things may happen now:
19292 a) We should increment current it block size;
19293 b) We should close current it block (closing insn or 4 insns);
19294 c) We should close current it block and start a new one (due
19295 to incompatible conditions or
19296 4 insns-length block reached). */
19297
5ee91343 19298 switch (inst.pred_insn_type)
e07e6e58 19299 {
5ee91343
AV
19300 case INSIDE_VPT_INSN:
19301 case VPT_INSN:
19302 case MVE_OUTSIDE_PRED_INSN:
19303 gas_assert (0);
19304 case OUTSIDE_PRED_INSN:
2b0f3761 19305 /* The closure of the block shall happen immediately,
5ee91343 19306 so any in_pred_block () call reports the block as closed. */
e07e6e58
NC
19307 force_automatic_it_block_close ();
19308 break;
19309
19310 case INSIDE_IT_INSN:
19311 case INSIDE_IT_LAST_INSN:
19312 case IF_INSIDE_IT_LAST_INSN:
5ee91343 19313 now_pred.block_length++;
e07e6e58 19314
5ee91343
AV
19315 if (now_pred.block_length > 4
19316 || !now_pred_compatible (inst.cond))
e07e6e58
NC
19317 {
19318 force_automatic_it_block_close ();
5ee91343 19319 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
e07e6e58
NC
19320 new_automatic_it_block (inst.cond);
19321 }
19322 else
19323 {
5ee91343
AV
19324 now_pred.insn_cond = TRUE;
19325 now_pred_add_mask (inst.cond);
e07e6e58
NC
19326 }
19327
5ee91343
AV
19328 if (now_pred.state == AUTOMATIC_PRED_BLOCK
19329 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
19330 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
e07e6e58
NC
19331 close_automatic_it_block ();
19332 break;
19333
19334 case NEUTRAL_IT_INSN:
5ee91343
AV
19335 now_pred.block_length++;
19336 now_pred.insn_cond = TRUE;
e07e6e58 19337
5ee91343 19338 if (now_pred.block_length > 4)
e07e6e58
NC
19339 force_automatic_it_block_close ();
19340 else
5ee91343 19341 now_pred_add_mask (now_pred.cc & 1);
e07e6e58
NC
19342 break;
19343
19344 case IT_INSN:
19345 close_automatic_it_block ();
5ee91343 19346 now_pred.state = MANUAL_PRED_BLOCK;
e07e6e58
NC
19347 break;
19348 }
19349 break;
19350
5ee91343 19351 case MANUAL_PRED_BLOCK:
e07e6e58 19352 {
5ee91343
AV
19353 int cond, is_last;
19354 if (now_pred.type == SCALAR_PRED)
e07e6e58 19355 {
5ee91343
AV
19356 /* Check conditional suffixes. */
19357 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
19358 now_pred.mask <<= 1;
19359 now_pred.mask &= 0x1f;
19360 is_last = (now_pred.mask == 0x10);
19361 }
19362 else
19363 {
19364 now_pred.cc ^= (now_pred.mask >> 4);
19365 cond = now_pred.cc + 0xf;
19366 now_pred.mask <<= 1;
19367 now_pred.mask &= 0x1f;
19368 is_last = now_pred.mask == 0x10;
19369 }
19370 now_pred.insn_cond = TRUE;
e07e6e58 19371
5ee91343
AV
19372 switch (inst.pred_insn_type)
19373 {
19374 case OUTSIDE_PRED_INSN:
19375 if (now_pred.type == SCALAR_PRED)
19376 {
19377 if (inst.cond == COND_ALWAYS)
19378 {
19379 /* Case 12: In an IT block, with no code: error: missing
19380 code. */
19381 inst.error = BAD_NOT_IT;
19382 return FAIL;
19383 }
19384 else if (inst.cond > COND_ALWAYS)
19385 {
19386 /* Case 11: In an IT block, with a VPT code: syntax error.
19387 */
19388 inst.error = BAD_SYNTAX;
19389 return FAIL;
19390 }
19391 else if (thumb_mode)
19392 {
19393 /* This is for some special cases where a non-MVE
19394 instruction is not allowed in an IT block, such as cbz,
19395 but are put into one with a condition code.
19396 You could argue this should be a syntax error, but we
19397 gave the 'not allowed in IT block' diagnostic in the
19398 past so we will keep doing so. */
19399 inst.error = BAD_NOT_IT;
19400 return FAIL;
19401 }
19402 break;
19403 }
19404 else
19405 {
19406 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
19407 as_tsktsk (MVE_NOT_VPT);
19408 return SUCCESS;
19409 }
19410 case MVE_OUTSIDE_PRED_INSN:
19411 if (now_pred.type == SCALAR_PRED)
19412 {
19413 if (inst.cond == COND_ALWAYS)
19414 {
19415 /* Case 3: In an IT block, with no code: warning:
19416 UNPREDICTABLE. */
19417 as_tsktsk (MVE_NOT_IT);
19418 return SUCCESS;
19419 }
19420 else if (inst.cond < COND_ALWAYS)
19421 {
19422 /* Case 1: In an IT block, with an IT code: syntax error.
19423 */
19424 inst.error = BAD_SYNTAX;
19425 return FAIL;
19426 }
19427 else
19428 gas_assert (0);
19429 }
19430 else
19431 {
19432 if (inst.cond < COND_ALWAYS)
19433 {
19434 /* Case 4: In a VPT block, with an IT code: syntax error.
19435 */
19436 inst.error = BAD_SYNTAX;
19437 return FAIL;
19438 }
19439 else if (inst.cond == COND_ALWAYS)
19440 {
19441 /* Case 6: In a VPT block, with no code: error: missing
19442 code. */
19443 inst.error = BAD_NOT_VPT;
19444 return FAIL;
19445 }
19446 else
19447 {
19448 gas_assert (0);
19449 }
19450 }
e07e6e58 19451 case INSIDE_IT_INSN:
5ee91343 19452 if (inst.cond > COND_ALWAYS)
e07e6e58 19453 {
5ee91343
AV
19454 /* Case 11: In an IT block, with a VPT code: syntax error. */
19455 /* Case 14: In a VPT block, with a VPT code: syntax error. */
19456 inst.error = BAD_SYNTAX;
19457 return FAIL;
19458 }
19459 else if (now_pred.type == SCALAR_PRED)
19460 {
19461 /* Case 10: In an IT block, with an IT code: OK! */
19462 if (cond != inst.cond)
19463 {
19464 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
19465 BAD_VPT_COND;
19466 return FAIL;
19467 }
19468 }
19469 else
19470 {
19471 /* Case 13: In a VPT block, with an IT code: error: should be
19472 in an IT block. */
19473 inst.error = BAD_OUT_IT;
e07e6e58
NC
19474 return FAIL;
19475 }
19476 break;
19477
5ee91343
AV
19478 case INSIDE_VPT_INSN:
19479 if (now_pred.type == SCALAR_PRED)
19480 {
19481 /* Case 2: In an IT block, with a VPT code: error: must be in a
19482 VPT block. */
19483 inst.error = BAD_OUT_VPT;
19484 return FAIL;
19485 }
19486 /* Case 5: In a VPT block, with a VPT code: OK! */
19487 else if (cond != inst.cond)
19488 {
19489 inst.error = BAD_VPT_COND;
19490 return FAIL;
19491 }
19492 break;
e07e6e58
NC
19493 case INSIDE_IT_LAST_INSN:
19494 case IF_INSIDE_IT_LAST_INSN:
5ee91343
AV
19495 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
19496 {
19497 /* Case 4: In a VPT block, with an IT code: syntax error. */
19498 /* Case 11: In an IT block, with a VPT code: syntax error. */
19499 inst.error = BAD_SYNTAX;
19500 return FAIL;
19501 }
19502 else if (cond != inst.cond)
e07e6e58
NC
19503 {
19504 inst.error = BAD_IT_COND;
19505 return FAIL;
19506 }
19507 if (!is_last)
19508 {
19509 inst.error = BAD_BRANCH;
19510 return FAIL;
19511 }
19512 break;
19513
19514 case NEUTRAL_IT_INSN:
5ee91343
AV
19515 /* The BKPT instruction is unconditional even in a IT or VPT
19516 block. */
e07e6e58
NC
19517 break;
19518
19519 case IT_INSN:
5ee91343
AV
19520 if (now_pred.type == SCALAR_PRED)
19521 {
19522 inst.error = BAD_IT_IT;
19523 return FAIL;
19524 }
19525 /* fall through. */
19526 case VPT_INSN:
19527 if (inst.cond == COND_ALWAYS)
19528 {
19529 /* Executing a VPT/VPST instruction inside an IT block or a
19530 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
19531 */
19532 if (now_pred.type == SCALAR_PRED)
19533 as_tsktsk (MVE_NOT_IT);
19534 else
19535 as_tsktsk (MVE_NOT_VPT);
19536 return SUCCESS;
19537 }
19538 else
19539 {
19540 /* VPT/VPST do not accept condition codes. */
19541 inst.error = BAD_SYNTAX;
19542 return FAIL;
19543 }
e07e6e58 19544 }
5ee91343 19545 }
e07e6e58
NC
19546 break;
19547 }
19548
19549 return SUCCESS;
19550}
19551
5a01bb1d
MGD
19552struct depr_insn_mask
19553{
19554 unsigned long pattern;
19555 unsigned long mask;
19556 const char* description;
19557};
19558
19559/* List of 16-bit instruction patterns deprecated in an IT block in
19560 ARMv8. */
19561static const struct depr_insn_mask depr_it_insns[] = {
19562 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
19563 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
19564 { 0xa000, 0xb800, N_("ADR") },
19565 { 0x4800, 0xf800, N_("Literal loads") },
19566 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
19567 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
19568 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
19569 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
19570 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
19571 { 0, 0, NULL }
19572};
19573
e07e6e58
NC
19574static void
19575it_fsm_post_encode (void)
19576{
19577 int is_last;
19578
5ee91343
AV
19579 if (!now_pred.state_handled)
19580 handle_pred_state ();
e07e6e58 19581
5ee91343
AV
19582 if (now_pred.insn_cond
19583 && !now_pred.warn_deprecated
5a01bb1d 19584 && warn_on_deprecated
df9909b8
TP
19585 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
19586 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
5a01bb1d
MGD
19587 {
19588 if (inst.instruction >= 0x10000)
19589 {
5c3696f8 19590 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
df9909b8 19591 "performance deprecated in ARMv8-A and ARMv8-R"));
5ee91343 19592 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
19593 }
19594 else
19595 {
19596 const struct depr_insn_mask *p = depr_it_insns;
19597
19598 while (p->mask != 0)
19599 {
19600 if ((inst.instruction & p->mask) == p->pattern)
19601 {
df9909b8
TP
19602 as_tsktsk (_("IT blocks containing 16-bit Thumb "
19603 "instructions of the following class are "
19604 "performance deprecated in ARMv8-A and "
19605 "ARMv8-R: %s"), p->description);
5ee91343 19606 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
19607 break;
19608 }
19609
19610 ++p;
19611 }
19612 }
19613
5ee91343 19614 if (now_pred.block_length > 1)
5a01bb1d 19615 {
5c3696f8 19616 as_tsktsk (_("IT blocks containing more than one conditional "
df9909b8
TP
19617 "instruction are performance deprecated in ARMv8-A and "
19618 "ARMv8-R"));
5ee91343 19619 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
19620 }
19621 }
19622
5ee91343
AV
19623 is_last = (now_pred.mask == 0x10);
19624 if (is_last)
19625 {
19626 now_pred.state = OUTSIDE_PRED_BLOCK;
19627 now_pred.mask = 0;
19628 }
e07e6e58
NC
19629}
19630
19631static void
19632force_automatic_it_block_close (void)
19633{
5ee91343 19634 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
e07e6e58
NC
19635 {
19636 close_automatic_it_block ();
5ee91343
AV
19637 now_pred.state = OUTSIDE_PRED_BLOCK;
19638 now_pred.mask = 0;
e07e6e58
NC
19639 }
19640}
19641
19642static int
5ee91343 19643in_pred_block (void)
e07e6e58 19644{
5ee91343
AV
19645 if (!now_pred.state_handled)
19646 handle_pred_state ();
e07e6e58 19647
5ee91343 19648 return now_pred.state != OUTSIDE_PRED_BLOCK;
e07e6e58
NC
19649}
19650
ff8646ee
TP
19651/* Whether OPCODE only has T32 encoding. Since this function is only used by
19652 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
19653 here, hence the "known" in the function name. */
fc289b0a
TP
19654
19655static bfd_boolean
ff8646ee 19656known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
19657{
19658 /* Original Thumb-1 wide instruction. */
19659 if (opcode->tencode == do_t_blx
19660 || opcode->tencode == do_t_branch23
19661 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
19662 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
19663 return TRUE;
19664
16a1fa25
TP
19665 /* Wide-only instruction added to ARMv8-M Baseline. */
19666 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
19667 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
19668 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
19669 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
19670 return TRUE;
19671
19672 return FALSE;
19673}
19674
19675/* Whether wide instruction variant can be used if available for a valid OPCODE
19676 in ARCH. */
19677
19678static bfd_boolean
19679t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
19680{
19681 if (known_t32_only_insn (opcode))
19682 return TRUE;
19683
19684 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
19685 of variant T3 of B.W is checked in do_t_branch. */
19686 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
19687 && opcode->tencode == do_t_branch)
19688 return TRUE;
19689
bada4342
JW
19690 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
19691 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
19692 && opcode->tencode == do_t_mov_cmp
19693 /* Make sure CMP instruction is not affected. */
19694 && opcode->aencode == do_mov)
19695 return TRUE;
19696
ff8646ee
TP
19697 /* Wide instruction variants of all instructions with narrow *and* wide
19698 variants become available with ARMv6t2. Other opcodes are either
19699 narrow-only or wide-only and are thus available if OPCODE is valid. */
19700 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
19701 return TRUE;
19702
19703 /* OPCODE with narrow only instruction variant or wide variant not
19704 available. */
fc289b0a
TP
19705 return FALSE;
19706}
19707
c19d1205
ZW
19708void
19709md_assemble (char *str)
b99bd4ef 19710{
c19d1205
ZW
19711 char *p = str;
19712 const struct asm_opcode * opcode;
b99bd4ef 19713
c19d1205
ZW
19714 /* Align the previous label if needed. */
19715 if (last_label_seen != NULL)
b99bd4ef 19716 {
c19d1205
ZW
19717 symbol_set_frag (last_label_seen, frag_now);
19718 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
19719 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
19720 }
19721
c19d1205 19722 memset (&inst, '\0', sizeof (inst));
e2b0ab59
AV
19723 int r;
19724 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
19725 inst.relocs[r].type = BFD_RELOC_UNUSED;
b99bd4ef 19726
c19d1205
ZW
19727 opcode = opcode_lookup (&p);
19728 if (!opcode)
b99bd4ef 19729 {
c19d1205 19730 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 19731 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 19732 if (! create_register_alias (str, p)
477330fc 19733 && ! create_neon_reg_alias (str, p))
c19d1205 19734 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 19735
b99bd4ef
NC
19736 return;
19737 }
19738
278df34e 19739 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 19740 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 19741
037e8744
JB
19742 /* The value which unconditional instructions should have in place of the
19743 condition field. */
19744 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
19745
c19d1205 19746 if (thumb_mode)
b99bd4ef 19747 {
e74cfd16 19748 arm_feature_set variant;
8f06b2d8
PB
19749
19750 variant = cpu_variant;
19751 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
19752 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
19753 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 19754 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
19755 if (!opcode->tvariant
19756 || (thumb_mode == 1
19757 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 19758 {
173205ca
TP
19759 if (opcode->tencode == do_t_swi)
19760 as_bad (_("SVC is not permitted on this architecture"));
19761 else
19762 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
19763 return;
19764 }
c19d1205
ZW
19765 if (inst.cond != COND_ALWAYS && !unified_syntax
19766 && opcode->tencode != do_t_branch)
b99bd4ef 19767 {
c19d1205 19768 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
19769 return;
19770 }
19771
fc289b0a
TP
19772 /* Two things are addressed here:
19773 1) Implicit require narrow instructions on Thumb-1.
19774 This avoids relaxation accidentally introducing Thumb-2
19775 instructions.
19776 2) Reject wide instructions in non Thumb-2 cores.
19777
19778 Only instructions with narrow and wide variants need to be handled
19779 but selecting all non wide-only instructions is easier. */
19780 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 19781 && !t32_insn_ok (variant, opcode))
076d447c 19782 {
fc289b0a
TP
19783 if (inst.size_req == 0)
19784 inst.size_req = 2;
19785 else if (inst.size_req == 4)
752d5da4 19786 {
ff8646ee
TP
19787 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
19788 as_bad (_("selected processor does not support 32bit wide "
19789 "variant of instruction `%s'"), str);
19790 else
19791 as_bad (_("selected processor does not support `%s' in "
19792 "Thumb-2 mode"), str);
fc289b0a 19793 return;
752d5da4 19794 }
076d447c
PB
19795 }
19796
c19d1205
ZW
19797 inst.instruction = opcode->tvalue;
19798
5be8be5d 19799 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc 19800 {
5ee91343 19801 /* Prepare the pred_insn_type for those encodings that don't set
477330fc
RM
19802 it. */
19803 it_fsm_pre_encode ();
c19d1205 19804
477330fc 19805 opcode->tencode ();
e07e6e58 19806
477330fc
RM
19807 it_fsm_post_encode ();
19808 }
e27ec89e 19809
0110f2b8 19810 if (!(inst.error || inst.relax))
b99bd4ef 19811 {
9c2799c2 19812 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
19813 inst.size = (inst.instruction > 0xffff ? 4 : 2);
19814 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 19815 {
c19d1205 19816 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
19817 return;
19818 }
19819 }
076d447c
PB
19820
19821 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 19822 instruction. */
9c2799c2 19823 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 19824
e74cfd16
PB
19825 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
19826 *opcode->tvariant);
ee065d83 19827 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
19828 set those bits when Thumb-2 32-bit instructions are seen. The impact
19829 of relaxable instructions will be considered later after we finish all
19830 relaxation. */
ff8646ee
TP
19831 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
19832 variant = arm_arch_none;
19833 else
19834 variant = cpu_variant;
19835 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
19836 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
19837 arm_ext_v6t2);
cd000bff 19838
88714cb8
DG
19839 check_neon_suffixes;
19840
cd000bff 19841 if (!inst.error)
c877a2f2
NC
19842 {
19843 mapping_state (MAP_THUMB);
19844 }
c19d1205 19845 }
3e9e4fcf 19846 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 19847 {
845b51d6
PB
19848 bfd_boolean is_bx;
19849
19850 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
19851 is_bx = (opcode->aencode == do_bx);
19852
c19d1205 19853 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
19854 if (!(is_bx && fix_v4bx)
19855 && !(opcode->avariant &&
19856 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 19857 {
84b52b66 19858 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 19859 return;
b99bd4ef 19860 }
c19d1205 19861 if (inst.size_req)
b99bd4ef 19862 {
c19d1205
ZW
19863 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
19864 return;
b99bd4ef
NC
19865 }
19866
c19d1205
ZW
19867 inst.instruction = opcode->avalue;
19868 if (opcode->tag == OT_unconditionalF)
eff0bc54 19869 inst.instruction |= 0xFU << 28;
c19d1205
ZW
19870 else
19871 inst.instruction |= inst.cond << 28;
19872 inst.size = INSN_SIZE;
5be8be5d 19873 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
19874 {
19875 it_fsm_pre_encode ();
19876 opcode->aencode ();
19877 it_fsm_post_encode ();
19878 }
ee065d83 19879 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 19880 on a hypothetical non-thumb v5 core. */
845b51d6 19881 if (is_bx)
e74cfd16 19882 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 19883 else
e74cfd16
PB
19884 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
19885 *opcode->avariant);
88714cb8
DG
19886
19887 check_neon_suffixes;
19888
cd000bff 19889 if (!inst.error)
c877a2f2
NC
19890 {
19891 mapping_state (MAP_ARM);
19892 }
b99bd4ef 19893 }
3e9e4fcf
JB
19894 else
19895 {
19896 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
19897 "-- `%s'"), str);
19898 return;
19899 }
c19d1205
ZW
19900 output_inst (str);
19901}
b99bd4ef 19902
e07e6e58 19903static void
5ee91343 19904check_pred_blocks_finished (void)
e07e6e58
NC
19905{
19906#ifdef OBJ_ELF
19907 asection *sect;
19908
19909 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
5ee91343
AV
19910 if (seg_info (sect)->tc_segment_info_data.current_pred.state
19911 == MANUAL_PRED_BLOCK)
e07e6e58 19912 {
5ee91343
AV
19913 if (now_pred.type == SCALAR_PRED)
19914 as_warn (_("section '%s' finished with an open IT block."),
19915 sect->name);
19916 else
19917 as_warn (_("section '%s' finished with an open VPT/VPST block."),
19918 sect->name);
e07e6e58
NC
19919 }
19920#else
5ee91343
AV
19921 if (now_pred.state == MANUAL_PRED_BLOCK)
19922 {
19923 if (now_pred.type == SCALAR_PRED)
19924 as_warn (_("file finished with an open IT block."));
19925 else
19926 as_warn (_("file finished with an open VPT/VPST block."));
19927 }
e07e6e58
NC
19928#endif
19929}
19930
c19d1205
ZW
19931/* Various frobbings of labels and their addresses. */
19932
19933void
19934arm_start_line_hook (void)
19935{
19936 last_label_seen = NULL;
b99bd4ef
NC
19937}
19938
c19d1205
ZW
19939void
19940arm_frob_label (symbolS * sym)
b99bd4ef 19941{
c19d1205 19942 last_label_seen = sym;
b99bd4ef 19943
c19d1205 19944 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 19945
c19d1205
ZW
19946#if defined OBJ_COFF || defined OBJ_ELF
19947 ARM_SET_INTERWORK (sym, support_interwork);
19948#endif
b99bd4ef 19949
e07e6e58
NC
19950 force_automatic_it_block_close ();
19951
5f4273c7 19952 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
19953 as Thumb functions. This is because these labels, whilst
19954 they exist inside Thumb code, are not the entry points for
19955 possible ARM->Thumb calls. Also, these labels can be used
19956 as part of a computed goto or switch statement. eg gcc
19957 can generate code that looks like this:
b99bd4ef 19958
c19d1205
ZW
19959 ldr r2, [pc, .Laaa]
19960 lsl r3, r3, #2
19961 ldr r2, [r3, r2]
19962 mov pc, r2
b99bd4ef 19963
c19d1205
ZW
19964 .Lbbb: .word .Lxxx
19965 .Lccc: .word .Lyyy
19966 ..etc...
19967 .Laaa: .word Lbbb
b99bd4ef 19968
c19d1205
ZW
19969 The first instruction loads the address of the jump table.
19970 The second instruction converts a table index into a byte offset.
19971 The third instruction gets the jump address out of the table.
19972 The fourth instruction performs the jump.
b99bd4ef 19973
c19d1205
ZW
19974 If the address stored at .Laaa is that of a symbol which has the
19975 Thumb_Func bit set, then the linker will arrange for this address
19976 to have the bottom bit set, which in turn would mean that the
19977 address computation performed by the third instruction would end
19978 up with the bottom bit set. Since the ARM is capable of unaligned
19979 word loads, the instruction would then load the incorrect address
19980 out of the jump table, and chaos would ensue. */
19981 if (label_is_thumb_function_name
19982 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
19983 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 19984 {
c19d1205
ZW
19985 /* When the address of a Thumb function is taken the bottom
19986 bit of that address should be set. This will allow
19987 interworking between Arm and Thumb functions to work
19988 correctly. */
b99bd4ef 19989
c19d1205 19990 THUMB_SET_FUNC (sym, 1);
b99bd4ef 19991
c19d1205 19992 label_is_thumb_function_name = FALSE;
b99bd4ef 19993 }
07a53e5c 19994
07a53e5c 19995 dwarf2_emit_label (sym);
b99bd4ef
NC
19996}
19997
c921be7d 19998bfd_boolean
c19d1205 19999arm_data_in_code (void)
b99bd4ef 20000{
c19d1205 20001 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 20002 {
c19d1205
ZW
20003 *input_line_pointer = '/';
20004 input_line_pointer += 5;
20005 *input_line_pointer = 0;
c921be7d 20006 return TRUE;
b99bd4ef
NC
20007 }
20008
c921be7d 20009 return FALSE;
b99bd4ef
NC
20010}
20011
c19d1205
ZW
20012char *
20013arm_canonicalize_symbol_name (char * name)
b99bd4ef 20014{
c19d1205 20015 int len;
b99bd4ef 20016
c19d1205
ZW
20017 if (thumb_mode && (len = strlen (name)) > 5
20018 && streq (name + len - 5, "/data"))
20019 *(name + len - 5) = 0;
b99bd4ef 20020
c19d1205 20021 return name;
b99bd4ef 20022}
c19d1205
ZW
20023\f
20024/* Table of all register names defined by default. The user can
20025 define additional names with .req. Note that all register names
20026 should appear in both upper and lowercase variants. Some registers
20027 also have mixed-case names. */
b99bd4ef 20028
dcbf9037 20029#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 20030#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 20031#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
20032#define REGSET(p,t) \
20033 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
20034 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
20035 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
20036 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
20037#define REGSETH(p,t) \
20038 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
20039 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
20040 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
20041 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
20042#define REGSET2(p,t) \
20043 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
20044 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
20045 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
20046 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
20047#define SPLRBANK(base,bank,t) \
20048 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
20049 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
20050 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
20051 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
20052 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
20053 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 20054
c19d1205 20055static const struct reg_entry reg_names[] =
7ed4c4c5 20056{
c19d1205
ZW
20057 /* ARM integer registers. */
20058 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 20059
c19d1205
ZW
20060 /* ATPCS synonyms. */
20061 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
20062 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
20063 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 20064
c19d1205
ZW
20065 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
20066 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
20067 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 20068
c19d1205
ZW
20069 /* Well-known aliases. */
20070 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
20071 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
20072
20073 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
20074 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
20075
20076 /* Coprocessor numbers. */
20077 REGSET(p, CP), REGSET(P, CP),
20078
20079 /* Coprocessor register numbers. The "cr" variants are for backward
20080 compatibility. */
20081 REGSET(c, CN), REGSET(C, CN),
20082 REGSET(cr, CN), REGSET(CR, CN),
20083
90ec0d68
MGD
20084 /* ARM banked registers. */
20085 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
20086 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
20087 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
20088 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
20089 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
20090 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
20091 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
20092
20093 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
20094 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
20095 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
20096 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
20097 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 20098 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
20099 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
20100 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
20101
20102 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
20103 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
20104 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
20105 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
20106 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
20107 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
20108 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 20109 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
20110 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
20111
c19d1205
ZW
20112 /* FPA registers. */
20113 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
20114 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
20115
20116 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
20117 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
20118
20119 /* VFP SP registers. */
5287ad62
JB
20120 REGSET(s,VFS), REGSET(S,VFS),
20121 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
20122
20123 /* VFP DP Registers. */
5287ad62
JB
20124 REGSET(d,VFD), REGSET(D,VFD),
20125 /* Extra Neon DP registers. */
20126 REGSETH(d,VFD), REGSETH(D,VFD),
20127
20128 /* Neon QP registers. */
20129 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
20130
20131 /* VFP control registers. */
20132 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
20133 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
20134 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
20135 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
20136 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
20137 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 20138 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
c19d1205
ZW
20139
20140 /* Maverick DSP coprocessor registers. */
20141 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
20142 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
20143
20144 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
20145 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
20146 REGDEF(dspsc,0,DSPSC),
20147
20148 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
20149 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
20150 REGDEF(DSPSC,0,DSPSC),
20151
20152 /* iWMMXt data registers - p0, c0-15. */
20153 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
20154
20155 /* iWMMXt control registers - p1, c0-3. */
20156 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
20157 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
20158 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
20159 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
20160
20161 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
20162 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
20163 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
20164 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
20165 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
20166
20167 /* XScale accumulator registers. */
20168 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
20169};
20170#undef REGDEF
20171#undef REGNUM
20172#undef REGSET
7ed4c4c5 20173
c19d1205
ZW
20174/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
20175 within psr_required_here. */
20176static const struct asm_psr psrs[] =
20177{
20178 /* Backward compatibility notation. Note that "all" is no longer
20179 truly all possible PSR bits. */
20180 {"all", PSR_c | PSR_f},
20181 {"flg", PSR_f},
20182 {"ctl", PSR_c},
20183
20184 /* Individual flags. */
20185 {"f", PSR_f},
20186 {"c", PSR_c},
20187 {"x", PSR_x},
20188 {"s", PSR_s},
59b42a0d 20189
c19d1205
ZW
20190 /* Combinations of flags. */
20191 {"fs", PSR_f | PSR_s},
20192 {"fx", PSR_f | PSR_x},
20193 {"fc", PSR_f | PSR_c},
20194 {"sf", PSR_s | PSR_f},
20195 {"sx", PSR_s | PSR_x},
20196 {"sc", PSR_s | PSR_c},
20197 {"xf", PSR_x | PSR_f},
20198 {"xs", PSR_x | PSR_s},
20199 {"xc", PSR_x | PSR_c},
20200 {"cf", PSR_c | PSR_f},
20201 {"cs", PSR_c | PSR_s},
20202 {"cx", PSR_c | PSR_x},
20203 {"fsx", PSR_f | PSR_s | PSR_x},
20204 {"fsc", PSR_f | PSR_s | PSR_c},
20205 {"fxs", PSR_f | PSR_x | PSR_s},
20206 {"fxc", PSR_f | PSR_x | PSR_c},
20207 {"fcs", PSR_f | PSR_c | PSR_s},
20208 {"fcx", PSR_f | PSR_c | PSR_x},
20209 {"sfx", PSR_s | PSR_f | PSR_x},
20210 {"sfc", PSR_s | PSR_f | PSR_c},
20211 {"sxf", PSR_s | PSR_x | PSR_f},
20212 {"sxc", PSR_s | PSR_x | PSR_c},
20213 {"scf", PSR_s | PSR_c | PSR_f},
20214 {"scx", PSR_s | PSR_c | PSR_x},
20215 {"xfs", PSR_x | PSR_f | PSR_s},
20216 {"xfc", PSR_x | PSR_f | PSR_c},
20217 {"xsf", PSR_x | PSR_s | PSR_f},
20218 {"xsc", PSR_x | PSR_s | PSR_c},
20219 {"xcf", PSR_x | PSR_c | PSR_f},
20220 {"xcs", PSR_x | PSR_c | PSR_s},
20221 {"cfs", PSR_c | PSR_f | PSR_s},
20222 {"cfx", PSR_c | PSR_f | PSR_x},
20223 {"csf", PSR_c | PSR_s | PSR_f},
20224 {"csx", PSR_c | PSR_s | PSR_x},
20225 {"cxf", PSR_c | PSR_x | PSR_f},
20226 {"cxs", PSR_c | PSR_x | PSR_s},
20227 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
20228 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
20229 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
20230 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
20231 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
20232 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
20233 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
20234 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
20235 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
20236 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
20237 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
20238 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
20239 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
20240 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
20241 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
20242 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
20243 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
20244 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
20245 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
20246 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
20247 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
20248 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
20249 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
20250 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
20251};
20252
62b3e311
PB
20253/* Table of V7M psr names. */
20254static const struct asm_psr v7m_psrs[] =
20255{
1a336194
TP
20256 {"apsr", 0x0 }, {"APSR", 0x0 },
20257 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
20258 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
20259 {"psr", 0x3 }, {"PSR", 0x3 },
20260 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
20261 {"ipsr", 0x5 }, {"IPSR", 0x5 },
20262 {"epsr", 0x6 }, {"EPSR", 0x6 },
20263 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
20264 {"msp", 0x8 }, {"MSP", 0x8 },
20265 {"psp", 0x9 }, {"PSP", 0x9 },
20266 {"msplim", 0xa }, {"MSPLIM", 0xa },
20267 {"psplim", 0xb }, {"PSPLIM", 0xb },
20268 {"primask", 0x10}, {"PRIMASK", 0x10},
20269 {"basepri", 0x11}, {"BASEPRI", 0x11},
20270 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
20271 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
20272 {"control", 0x14}, {"CONTROL", 0x14},
20273 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
20274 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
20275 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
20276 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
20277 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
20278 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
20279 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
20280 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
20281 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
20282};
20283
c19d1205
ZW
20284/* Table of all shift-in-operand names. */
20285static const struct asm_shift_name shift_names [] =
b99bd4ef 20286{
c19d1205
ZW
20287 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
20288 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
20289 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
20290 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
20291 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
20292 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
20293};
b99bd4ef 20294
c19d1205
ZW
20295/* Table of all explicit relocation names. */
20296#ifdef OBJ_ELF
20297static struct reloc_entry reloc_names[] =
20298{
20299 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
20300 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
20301 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
20302 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
20303 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
20304 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
20305 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
20306 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
20307 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
20308 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 20309 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
20310 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
20311 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 20312 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 20313 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 20314 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 20315 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
188fd7ae
CL
20316 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
20317 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
20318 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
20319 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
20320 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
20321 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
5c5a4843
CL
20322 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
20323 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
20324 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
20325 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
c19d1205
ZW
20326};
20327#endif
b99bd4ef 20328
5ee91343 20329/* Table of all conditional affixes. */
c19d1205
ZW
20330static const struct asm_cond conds[] =
20331{
20332 {"eq", 0x0},
20333 {"ne", 0x1},
20334 {"cs", 0x2}, {"hs", 0x2},
20335 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
20336 {"mi", 0x4},
20337 {"pl", 0x5},
20338 {"vs", 0x6},
20339 {"vc", 0x7},
20340 {"hi", 0x8},
20341 {"ls", 0x9},
20342 {"ge", 0xa},
20343 {"lt", 0xb},
20344 {"gt", 0xc},
20345 {"le", 0xd},
20346 {"al", 0xe}
20347};
5ee91343
AV
20348static const struct asm_cond vconds[] =
20349{
20350 {"t", 0xf},
20351 {"e", 0x10}
20352};
bfae80f2 20353
e797f7e0 20354#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
20355 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
20356 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 20357
62b3e311
PB
20358static struct asm_barrier_opt barrier_opt_names[] =
20359{
e797f7e0
MGD
20360 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
20361 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
20362 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
20363 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
20364 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
20365 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
20366 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
20367 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
20368 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
20369 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
20370 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
20371 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
20372 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
20373 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
20374 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
20375 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
20376};
20377
e797f7e0
MGD
20378#undef UL_BARRIER
20379
c19d1205
ZW
20380/* Table of ARM-format instructions. */
20381
20382/* Macros for gluing together operand strings. N.B. In all cases
20383 other than OPS0, the trailing OP_stop comes from default
20384 zero-initialization of the unspecified elements of the array. */
20385#define OPS0() { OP_stop, }
20386#define OPS1(a) { OP_##a, }
20387#define OPS2(a,b) { OP_##a,OP_##b, }
20388#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
20389#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
20390#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
20391#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
20392
5be8be5d
DG
20393/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
20394 This is useful when mixing operands for ARM and THUMB, i.e. using the
20395 MIX_ARM_THUMB_OPERANDS macro.
20396 In order to use these macros, prefix the number of operands with _
20397 e.g. _3. */
20398#define OPS_1(a) { a, }
20399#define OPS_2(a,b) { a,b, }
20400#define OPS_3(a,b,c) { a,b,c, }
20401#define OPS_4(a,b,c,d) { a,b,c,d, }
20402#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
20403#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
20404
c19d1205
ZW
20405/* These macros abstract out the exact format of the mnemonic table and
20406 save some repeated characters. */
20407
20408/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
20409#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 20410 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
5ee91343 20411 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
20412
20413/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
20414 a T_MNEM_xyz enumerator. */
20415#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 20416 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 20417#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 20418 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
20419
20420/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
20421 infix after the third character. */
20422#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 20423 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
5ee91343 20424 THUMB_VARIANT, do_##ae, do_##te, 0 }
088fa78e 20425#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 20426 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
5ee91343 20427 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 20428#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 20429 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 20430#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 20431 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 20432#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 20433 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 20434#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 20435 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 20436
c19d1205 20437/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
20438 field is still 0xE. Many of the Thumb variants can be executed
20439 conditionally, so this is checked separately. */
c19d1205 20440#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 20441 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 20442 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 20443
dd5181d5
KT
20444/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
20445 Used by mnemonics that have very minimal differences in the encoding for
20446 ARM and Thumb variants and can be handled in a common function. */
20447#define TUEc(mnem, op, top, nops, ops, en) \
20448 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 20449 THUMB_VARIANT, do_##en, do_##en, 0 }
dd5181d5 20450
c19d1205
ZW
20451/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
20452 condition code field. */
20453#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 20454 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 20455 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
20456
20457/* ARM-only variants of all the above. */
6a86118a 20458#define CE(mnem, op, nops, ops, ae) \
5ee91343 20459 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
20460
20461#define C3(mnem, op, nops, ops, ae) \
5ee91343 20462 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 20463
cf3cf39d
TP
20464/* Thumb-only variants of TCE and TUE. */
20465#define ToC(mnem, top, nops, ops, te) \
20466 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
5ee91343 20467 do_##te, 0 }
cf3cf39d
TP
20468
20469#define ToU(mnem, top, nops, ops, te) \
20470 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
5ee91343 20471 NULL, do_##te, 0 }
cf3cf39d 20472
4389b29a
AV
20473/* T_MNEM_xyz enumerator variants of ToC. */
20474#define toC(mnem, top, nops, ops, te) \
20475 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
5ee91343 20476 do_##te, 0 }
4389b29a 20477
f6b2b12d
AV
20478/* T_MNEM_xyz enumerator variants of ToU. */
20479#define toU(mnem, top, nops, ops, te) \
20480 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
5ee91343 20481 NULL, do_##te, 0 }
f6b2b12d 20482
e3cb604e
PB
20483/* Legacy mnemonics that always have conditional infix after the third
20484 character. */
20485#define CL(mnem, op, nops, ops, ae) \
21d799b5 20486 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 20487 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
e3cb604e 20488
8f06b2d8
PB
20489/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
20490#define cCE(mnem, op, nops, ops, ae) \
5ee91343 20491 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 20492
e3cb604e
PB
20493/* Legacy coprocessor instructions where conditional infix and conditional
20494 suffix are ambiguous. For consistency this includes all FPA instructions,
20495 not just the potentially ambiguous ones. */
20496#define cCL(mnem, op, nops, ops, ae) \
21d799b5 20497 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 20498 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
e3cb604e
PB
20499
20500/* Coprocessor, takes either a suffix or a position-3 infix
20501 (for an FPA corner case). */
20502#define C3E(mnem, op, nops, ops, ae) \
21d799b5 20503 { mnem, OPS##nops ops, OT_csuf_or_in3, \
5ee91343 20504 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 20505
6a86118a 20506#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
20507 { m1 #m2 m3, OPS##nops ops, \
20508 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
5ee91343 20509 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
20510
20511#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
20512 xCM_ (m1, , m2, op, nops, ops, ae), \
20513 xCM_ (m1, eq, m2, op, nops, ops, ae), \
20514 xCM_ (m1, ne, m2, op, nops, ops, ae), \
20515 xCM_ (m1, cs, m2, op, nops, ops, ae), \
20516 xCM_ (m1, hs, m2, op, nops, ops, ae), \
20517 xCM_ (m1, cc, m2, op, nops, ops, ae), \
20518 xCM_ (m1, ul, m2, op, nops, ops, ae), \
20519 xCM_ (m1, lo, m2, op, nops, ops, ae), \
20520 xCM_ (m1, mi, m2, op, nops, ops, ae), \
20521 xCM_ (m1, pl, m2, op, nops, ops, ae), \
20522 xCM_ (m1, vs, m2, op, nops, ops, ae), \
20523 xCM_ (m1, vc, m2, op, nops, ops, ae), \
20524 xCM_ (m1, hi, m2, op, nops, ops, ae), \
20525 xCM_ (m1, ls, m2, op, nops, ops, ae), \
20526 xCM_ (m1, ge, m2, op, nops, ops, ae), \
20527 xCM_ (m1, lt, m2, op, nops, ops, ae), \
20528 xCM_ (m1, gt, m2, op, nops, ops, ae), \
20529 xCM_ (m1, le, m2, op, nops, ops, ae), \
20530 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
20531
20532#define UE(mnem, op, nops, ops, ae) \
5ee91343 20533 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
20534
20535#define UF(mnem, op, nops, ops, ae) \
5ee91343 20536 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 20537
5287ad62
JB
20538/* Neon data-processing. ARM versions are unconditional with cond=0xf.
20539 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
20540 use the same encoding function for each. */
20541#define NUF(mnem, op, nops, ops, enc) \
20542 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
5ee91343 20543 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
20544
20545/* Neon data processing, version which indirects through neon_enc_tab for
20546 the various overloaded versions of opcodes. */
20547#define nUF(mnem, op, nops, ops, enc) \
21d799b5 20548 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5ee91343 20549 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
20550
20551/* Neon insn with conditional suffix for the ARM version, non-overloaded
20552 version. */
5ee91343 20553#define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
037e8744 20554 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5ee91343 20555 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 20556
037e8744 20557#define NCE(mnem, op, nops, ops, enc) \
5ee91343 20558 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
20559
20560#define NCEF(mnem, op, nops, ops, enc) \
5ee91343 20561 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
037e8744 20562
5287ad62 20563/* Neon insn with conditional suffix for the ARM version, overloaded types. */
5ee91343 20564#define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
21d799b5 20565 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5ee91343 20566 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 20567
037e8744 20568#define nCE(mnem, op, nops, ops, enc) \
5ee91343 20569 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
20570
20571#define nCEF(mnem, op, nops, ops, enc) \
5ee91343
AV
20572 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
20573
20574/* */
20575#define mCEF(mnem, op, nops, ops, enc) \
20576 { #mnem, OPS##nops ops, OT_csuffixF, 0, M_MNEM##op, \
20577 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
20578
20579
20580/* nCEF but for MVE predicated instructions. */
20581#define mnCEF(mnem, op, nops, ops, enc) \
20582 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
20583
20584/* nCE but for MVE predicated instructions. */
20585#define mnCE(mnem, op, nops, ops, enc) \
20586 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
037e8744 20587
5ee91343
AV
20588/* NUF but for potentially MVE predicated instructions. */
20589#define MNUF(mnem, op, nops, ops, enc) \
20590 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
20591 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
20592
20593/* nUF but for potentially MVE predicated instructions. */
20594#define mnUF(mnem, op, nops, ops, enc) \
20595 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
20596 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
20597
20598/* ToC but for potentially MVE predicated instructions. */
20599#define mToC(mnem, top, nops, ops, te) \
20600 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
20601 do_##te, 1 }
20602
20603/* NCE but for MVE predicated instructions. */
20604#define MNCE(mnem, op, nops, ops, enc) \
20605 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
20606
20607/* NCEF but for MVE predicated instructions. */
20608#define MNCEF(mnem, op, nops, ops, enc) \
20609 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
c19d1205
ZW
20610#define do_0 0
20611
c19d1205 20612static const struct asm_opcode insns[] =
bfae80f2 20613{
74db7efb
NC
20614#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
20615#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
20616 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
20617 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
20618 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
20619 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
20620 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
20621 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
20622 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
20623 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
20624 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
20625 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
20626 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
20627 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
20628 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
20629 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
20630 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
20631 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
20632
20633 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
20634 for setting PSR flag bits. They are obsolete in V6 and do not
20635 have Thumb equivalents. */
21d799b5
NC
20636 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
20637 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
20638 CL("tstp", 110f000, 2, (RR, SH), cmp),
20639 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
20640 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
20641 CL("cmpp", 150f000, 2, (RR, SH), cmp),
20642 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
20643 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
20644 CL("cmnp", 170f000, 2, (RR, SH), cmp),
20645
20646 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 20647 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
20648 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
20649 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
20650
20651 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
20652 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
20653 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
20654 OP_RRnpc),
20655 OP_ADDRGLDR),ldst, t_ldst),
20656 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
20657
20658 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20659 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20660 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20661 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20662 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20663 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20664
21d799b5
NC
20665 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
20666 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 20667
c19d1205 20668 /* Pseudo ops. */
21d799b5 20669 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 20670 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 20671 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 20672 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
20673
20674 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
20675 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
20676 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
20677 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
20678 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
20679 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
20680 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
20681 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
20682 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
20683 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
20684 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
20685 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
20686 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 20687
16a4cf17 20688 /* These may simplify to neg. */
21d799b5
NC
20689 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
20690 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 20691
173205ca
TP
20692#undef THUMB_VARIANT
20693#define THUMB_VARIANT & arm_ext_os
20694
20695 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
20696 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
20697
c921be7d
NC
20698#undef THUMB_VARIANT
20699#define THUMB_VARIANT & arm_ext_v6
20700
21d799b5 20701 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
20702
20703 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
20704#undef THUMB_VARIANT
20705#define THUMB_VARIANT & arm_ext_v6t2
20706
21d799b5
NC
20707 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
20708 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
20709 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 20710
5be8be5d
DG
20711 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
20712 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
20713 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
20714 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 20715
21d799b5
NC
20716 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20717 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 20718
21d799b5
NC
20719 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20720 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
20721
20722 /* V1 instructions with no Thumb analogue at all. */
21d799b5 20723 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
20724 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
20725
20726 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
20727 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
20728 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
20729 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
20730 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
20731 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
20732 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
20733 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
20734
c921be7d
NC
20735#undef ARM_VARIANT
20736#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
20737#undef THUMB_VARIANT
20738#define THUMB_VARIANT & arm_ext_v4t
20739
21d799b5
NC
20740 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
20741 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 20742
c921be7d
NC
20743#undef THUMB_VARIANT
20744#define THUMB_VARIANT & arm_ext_v6t2
20745
21d799b5 20746 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
20747 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
20748
20749 /* Generic coprocessor instructions. */
21d799b5
NC
20750 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
20751 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20752 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20753 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20754 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20755 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 20756 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 20757
c921be7d
NC
20758#undef ARM_VARIANT
20759#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
20760
21d799b5 20761 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
20762 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
20763
c921be7d
NC
20764#undef ARM_VARIANT
20765#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
20766#undef THUMB_VARIANT
20767#define THUMB_VARIANT & arm_ext_msr
20768
d2cd1205
JB
20769 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
20770 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 20771
c921be7d
NC
20772#undef ARM_VARIANT
20773#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
20774#undef THUMB_VARIANT
20775#define THUMB_VARIANT & arm_ext_v6t2
20776
21d799b5
NC
20777 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20778 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
20779 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20780 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
20781 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20782 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
20783 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20784 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 20785
c921be7d
NC
20786#undef ARM_VARIANT
20787#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
20788#undef THUMB_VARIANT
20789#define THUMB_VARIANT & arm_ext_v4t
20790
5be8be5d
DG
20791 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20792 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20793 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20794 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
20795 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20796 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 20797
c921be7d
NC
20798#undef ARM_VARIANT
20799#define ARM_VARIANT & arm_ext_v4t_5
20800
c19d1205
ZW
20801 /* ARM Architecture 4T. */
20802 /* Note: bx (and blx) are required on V5, even if the processor does
20803 not support Thumb. */
21d799b5 20804 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 20805
c921be7d
NC
20806#undef ARM_VARIANT
20807#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
20808#undef THUMB_VARIANT
20809#define THUMB_VARIANT & arm_ext_v5t
20810
c19d1205
ZW
20811 /* Note: blx has 2 variants; the .value coded here is for
20812 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
20813 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
20814 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 20815
c921be7d
NC
20816#undef THUMB_VARIANT
20817#define THUMB_VARIANT & arm_ext_v6t2
20818
21d799b5
NC
20819 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
20820 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20821 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20822 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20823 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20824 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
20825 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
20826 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 20827
c921be7d 20828#undef ARM_VARIANT
74db7efb
NC
20829#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
20830#undef THUMB_VARIANT
20831#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 20832
21d799b5
NC
20833 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20834 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20835 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20836 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 20837
21d799b5
NC
20838 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20839 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 20840
21d799b5
NC
20841 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
20842 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
20843 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
20844 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 20845
21d799b5
NC
20846 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20847 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20848 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20849 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 20850
21d799b5
NC
20851 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20852 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 20853
03ee1b7f
NC
20854 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
20855 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
20856 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
20857 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 20858
c921be7d 20859#undef ARM_VARIANT
74db7efb
NC
20860#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
20861#undef THUMB_VARIANT
20862#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 20863
21d799b5 20864 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
20865 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
20866 ldrd, t_ldstd),
20867 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
20868 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 20869
21d799b5
NC
20870 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
20871 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 20872
c921be7d
NC
20873#undef ARM_VARIANT
20874#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
20875
21d799b5 20876 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 20877
c921be7d
NC
20878#undef ARM_VARIANT
20879#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
20880#undef THUMB_VARIANT
20881#define THUMB_VARIANT & arm_ext_v6
20882
21d799b5
NC
20883 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
20884 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
20885 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
20886 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
20887 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
20888 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20889 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20890 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20891 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20892 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 20893
c921be7d 20894#undef THUMB_VARIANT
ff8646ee 20895#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 20896
5be8be5d
DG
20897 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
20898 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
20899 strex, t_strex),
ff8646ee
TP
20900#undef THUMB_VARIANT
20901#define THUMB_VARIANT & arm_ext_v6t2
20902
21d799b5
NC
20903 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
20904 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 20905
21d799b5
NC
20906 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
20907 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 20908
9e3c6df6 20909/* ARM V6 not included in V7M. */
c921be7d
NC
20910#undef THUMB_VARIANT
20911#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 20912 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 20913 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
20914 UF(rfeib, 9900a00, 1, (RRw), rfe),
20915 UF(rfeda, 8100a00, 1, (RRw), rfe),
20916 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
20917 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
20918 UF(rfefa, 8100a00, 1, (RRw), rfe),
20919 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
20920 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 20921 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
20922 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
20923 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 20924 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 20925 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 20926 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 20927 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 20928 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 20929 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 20930 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 20931
9e3c6df6
PB
20932/* ARM V6 not included in V7M (eg. integer SIMD). */
20933#undef THUMB_VARIANT
20934#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
20935 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
20936 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
20937 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20938 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20939 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20940 /* Old name for QASX. */
74db7efb 20941 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 20942 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20943 /* Old name for QSAX. */
74db7efb 20944 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20945 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20946 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20947 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20948 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20949 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20950 /* Old name for SASX. */
74db7efb 20951 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20952 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20953 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20954 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20955 /* Old name for SHASX. */
21d799b5 20956 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20957 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20958 /* Old name for SHSAX. */
21d799b5
NC
20959 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20960 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20961 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20962 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20963 /* Old name for SSAX. */
74db7efb 20964 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20965 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20966 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20967 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20968 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20969 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20970 /* Old name for UASX. */
74db7efb 20971 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20972 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20973 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20974 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20975 /* Old name for UHASX. */
21d799b5
NC
20976 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20977 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20978 /* Old name for UHSAX. */
21d799b5
NC
20979 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20980 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20981 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20982 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20983 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20984 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20985 /* Old name for UQASX. */
21d799b5
NC
20986 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20987 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20988 /* Old name for UQSAX. */
21d799b5
NC
20989 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20990 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20991 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20992 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20993 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20994 /* Old name for USAX. */
74db7efb 20995 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 20996 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20997 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20998 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20999 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
21000 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
21001 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
21002 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
21003 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
21004 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
21005 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21006 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21007 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21008 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
21009 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
21010 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21011 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21012 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
21013 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
21014 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21015 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21016 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21017 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21018 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21019 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21020 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21021 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21022 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21023 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
21024 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
21025 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
21026 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21027 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21028 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 21029
c921be7d 21030#undef ARM_VARIANT
55e8aae7 21031#define ARM_VARIANT & arm_ext_v6k_v6t2
c921be7d 21032#undef THUMB_VARIANT
55e8aae7 21033#define THUMB_VARIANT & arm_ext_v6k_v6t2
c921be7d 21034
21d799b5
NC
21035 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
21036 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
21037 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
21038 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 21039
c921be7d
NC
21040#undef THUMB_VARIANT
21041#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
21042 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
21043 ldrexd, t_ldrexd),
21044 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
21045 RRnpcb), strexd, t_strexd),
ebdca51a 21046
c921be7d 21047#undef THUMB_VARIANT
ff8646ee 21048#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
21049 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
21050 rd_rn, rd_rn),
21051 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
21052 rd_rn, rd_rn),
21053 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 21054 strex, t_strexbh),
5be8be5d 21055 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 21056 strex, t_strexbh),
21d799b5 21057 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 21058
c921be7d 21059#undef ARM_VARIANT
f4c65163 21060#define ARM_VARIANT & arm_ext_sec
74db7efb 21061#undef THUMB_VARIANT
f4c65163 21062#define THUMB_VARIANT & arm_ext_sec
c921be7d 21063
21d799b5 21064 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 21065
90ec0d68
MGD
21066#undef ARM_VARIANT
21067#define ARM_VARIANT & arm_ext_virt
21068#undef THUMB_VARIANT
21069#define THUMB_VARIANT & arm_ext_virt
21070
21071 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
21072 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
21073
ddfded2f
MW
21074#undef ARM_VARIANT
21075#define ARM_VARIANT & arm_ext_pan
21076#undef THUMB_VARIANT
21077#define THUMB_VARIANT & arm_ext_pan
21078
21079 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
21080
c921be7d 21081#undef ARM_VARIANT
74db7efb 21082#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
21083#undef THUMB_VARIANT
21084#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 21085
21d799b5
NC
21086 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
21087 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
21088 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
21089 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 21090
21d799b5 21091 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 21092 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 21093
5be8be5d
DG
21094 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
21095 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
21096 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
21097 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 21098
91d8b670
JG
21099#undef ARM_VARIANT
21100#define ARM_VARIANT & arm_ext_v3
21101#undef THUMB_VARIANT
21102#define THUMB_VARIANT & arm_ext_v6t2
21103
21104 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
c597cc3d
SD
21105 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
21106 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
91d8b670
JG
21107
21108#undef ARM_VARIANT
21109#define ARM_VARIANT & arm_ext_v6t2
ff8646ee
TP
21110#undef THUMB_VARIANT
21111#define THUMB_VARIANT & arm_ext_v6t2_v8m
21112 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
21113 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
21114
bf3eeda7 21115 /* Thumb-only instructions. */
74db7efb 21116#undef ARM_VARIANT
bf3eeda7
NS
21117#define ARM_VARIANT NULL
21118 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
21119 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
21120
21121 /* ARM does not really have an IT instruction, so always allow it.
21122 The opcode is copied from Thumb in order to allow warnings in
21123 -mimplicit-it=[never | arm] modes. */
21124#undef ARM_VARIANT
21125#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
21126#undef THUMB_VARIANT
21127#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 21128
21d799b5
NC
21129 TUE("it", bf08, bf08, 1, (COND), it, t_it),
21130 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
21131 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
21132 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
21133 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
21134 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
21135 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
21136 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
21137 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
21138 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
21139 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
21140 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
21141 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
21142 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
21143 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 21144 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
21145 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
21146 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 21147
92e90b6e 21148 /* Thumb2 only instructions. */
c921be7d
NC
21149#undef ARM_VARIANT
21150#define ARM_VARIANT NULL
92e90b6e 21151
21d799b5
NC
21152 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
21153 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
21154 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
21155 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
21156 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
21157 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 21158
eea54501
MGD
21159 /* Hardware division instructions. */
21160#undef ARM_VARIANT
21161#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
21162#undef THUMB_VARIANT
21163#define THUMB_VARIANT & arm_ext_div
21164
eea54501
MGD
21165 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
21166 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 21167
7e806470 21168 /* ARM V6M/V7 instructions. */
c921be7d
NC
21169#undef ARM_VARIANT
21170#define ARM_VARIANT & arm_ext_barrier
21171#undef THUMB_VARIANT
21172#define THUMB_VARIANT & arm_ext_barrier
21173
ccb84d65
JB
21174 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
21175 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
21176 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 21177
62b3e311 21178 /* ARM V7 instructions. */
c921be7d
NC
21179#undef ARM_VARIANT
21180#define ARM_VARIANT & arm_ext_v7
21181#undef THUMB_VARIANT
21182#define THUMB_VARIANT & arm_ext_v7
21183
21d799b5
NC
21184 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
21185 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 21186
74db7efb 21187#undef ARM_VARIANT
60e5ef9f 21188#define ARM_VARIANT & arm_ext_mp
74db7efb 21189#undef THUMB_VARIANT
60e5ef9f
MGD
21190#define THUMB_VARIANT & arm_ext_mp
21191
21192 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
21193
53c4b28b
MGD
21194 /* AArchv8 instructions. */
21195#undef ARM_VARIANT
21196#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
21197
21198/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 21199#undef THUMB_VARIANT
4ed7ed8d 21200#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 21201
4ed7ed8d
TP
21202 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
21203 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
21204 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
21205 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
21206 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
21207 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 21208 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
21209 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
21210 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
21211 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
21212 stlex, t_stlex),
4b8c8c02
RE
21213 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
21214 stlex, t_stlex),
21215 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
21216 stlex, t_stlex),
4ed7ed8d
TP
21217#undef THUMB_VARIANT
21218#define THUMB_VARIANT & arm_ext_v8
53c4b28b 21219
4ed7ed8d 21220 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
4ed7ed8d
TP
21221 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
21222 ldrexd, t_ldrexd),
21223 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
21224 strexd, t_strexd),
f7dd2fb2
TC
21225
21226/* Defined in V8 but is in undefined encoding space for earlier
21227 architectures. However earlier architectures are required to treat
21228 this instuction as a semihosting trap as well. Hence while not explicitly
21229 defined as such, it is in fact correct to define the instruction for all
21230 architectures. */
21231#undef THUMB_VARIANT
21232#define THUMB_VARIANT & arm_ext_v1
21233#undef ARM_VARIANT
21234#define ARM_VARIANT & arm_ext_v1
21235 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
21236
8884b720 21237 /* ARMv8 T32 only. */
74db7efb 21238#undef ARM_VARIANT
b79f7053
MGD
21239#define ARM_VARIANT NULL
21240 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
21241 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
21242 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
21243
33399f07
MGD
21244 /* FP for ARMv8. */
21245#undef ARM_VARIANT
a715796b 21246#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 21247#undef THUMB_VARIANT
a715796b 21248#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
21249
21250 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
21251 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
21252 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
21253 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
21254 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
21255 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
21256 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
21257 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
21258 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
21259 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
21260 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
21261 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
21262 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
21263 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
21264 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
21265 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
21266 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 21267
91ff7894
MGD
21268 /* Crypto v1 extensions. */
21269#undef ARM_VARIANT
21270#define ARM_VARIANT & fpu_crypto_ext_armv8
21271#undef THUMB_VARIANT
21272#define THUMB_VARIANT & fpu_crypto_ext_armv8
21273
21274 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
21275 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
21276 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
21277 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
21278 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
21279 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
21280 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
21281 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
21282 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
21283 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
21284 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
21285 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
21286 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
21287 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 21288
dd5181d5 21289#undef ARM_VARIANT
74db7efb 21290#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
21291#undef THUMB_VARIANT
21292#define THUMB_VARIANT & crc_ext_armv8
21293 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
21294 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
21295 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
21296 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
21297 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
21298 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
21299
105bde57
MW
21300 /* ARMv8.2 RAS extension. */
21301#undef ARM_VARIANT
4d1464f2 21302#define ARM_VARIANT & arm_ext_ras
105bde57 21303#undef THUMB_VARIANT
4d1464f2 21304#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
21305 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
21306
49e8a725
SN
21307#undef ARM_VARIANT
21308#define ARM_VARIANT & arm_ext_v8_3
21309#undef THUMB_VARIANT
21310#define THUMB_VARIANT & arm_ext_v8_3
21311 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
21312 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
21313 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 21314
c604a79a
JW
21315#undef ARM_VARIANT
21316#define ARM_VARIANT & fpu_neon_ext_dotprod
21317#undef THUMB_VARIANT
21318#define THUMB_VARIANT & fpu_neon_ext_dotprod
21319 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
21320 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
21321
c921be7d
NC
21322#undef ARM_VARIANT
21323#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
21324#undef THUMB_VARIANT
21325#define THUMB_VARIANT NULL
c921be7d 21326
21d799b5
NC
21327 cCE("wfs", e200110, 1, (RR), rd),
21328 cCE("rfs", e300110, 1, (RR), rd),
21329 cCE("wfc", e400110, 1, (RR), rd),
21330 cCE("rfc", e500110, 1, (RR), rd),
21331
21332 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
21333 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
21334 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
21335 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
21336
21337 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
21338 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
21339 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
21340 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
21341
21342 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
21343 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
21344 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
21345 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
21346 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
21347 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
21348 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
21349 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
21350 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
21351 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
21352 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
21353 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
21354
21355 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
21356 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
21357 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
21358 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
21359 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
21360 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
21361 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
21362 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
21363 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
21364 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
21365 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
21366 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
21367
21368 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
21369 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
21370 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
21371 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
21372 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
21373 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
21374 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
21375 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
21376 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
21377 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
21378 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
21379 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
21380
21381 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
21382 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
21383 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
21384 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
21385 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
21386 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
21387 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
21388 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
21389 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
21390 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
21391 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
21392 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
21393
21394 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
21395 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
21396 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
21397 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
21398 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
21399 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
21400 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
21401 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
21402 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
21403 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
21404 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
21405 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
21406
21407 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
21408 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
21409 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
21410 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
21411 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
21412 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
21413 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
21414 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
21415 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
21416 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
21417 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
21418 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
21419
21420 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
21421 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
21422 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
21423 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
21424 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
21425 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
21426 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
21427 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
21428 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
21429 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
21430 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
21431 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
21432
21433 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
21434 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
21435 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
21436 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
21437 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
21438 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
21439 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
21440 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
21441 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
21442 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
21443 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
21444 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
21445
21446 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
21447 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
21448 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
21449 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
21450 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
21451 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
21452 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
21453 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
21454 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
21455 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
21456 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
21457 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
21458
21459 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
21460 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
21461 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
21462 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
21463 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
21464 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
21465 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
21466 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
21467 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
21468 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
21469 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
21470 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
21471
21472 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
21473 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
21474 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
21475 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
21476 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
21477 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
21478 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
21479 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
21480 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
21481 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
21482 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
21483 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
21484
21485 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
21486 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
21487 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
21488 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
21489 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
21490 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
21491 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
21492 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
21493 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
21494 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
21495 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
21496 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
21497
21498 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
21499 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
21500 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
21501 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
21502 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
21503 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
21504 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
21505 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
21506 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
21507 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
21508 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
21509 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
21510
21511 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
21512 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
21513 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
21514 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
21515 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
21516 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
21517 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
21518 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
21519 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
21520 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
21521 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
21522 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
21523
21524 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
21525 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
21526 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
21527 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
21528 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
21529 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
21530 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
21531 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
21532 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
21533 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
21534 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
21535 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
21536
21537 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
21538 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
21539 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
21540 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
21541 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
21542 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
21543 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
21544 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
21545 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
21546 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
21547 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
21548 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
21549
21550 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
21551 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
21552 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
21553 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
21554 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
21555 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21556 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21557 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21558 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
21559 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
21560 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
21561 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
21562
21563 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
21564 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
21565 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
21566 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
21567 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
21568 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21569 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21570 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21571 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
21572 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
21573 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
21574 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
21575
21576 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
21577 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
21578 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
21579 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
21580 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
21581 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21582 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21583 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21584 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
21585 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
21586 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
21587 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
21588
21589 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
21590 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
21591 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
21592 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
21593 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
21594 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21595 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21596 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21597 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
21598 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
21599 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
21600 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
21601
21602 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
21603 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
21604 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
21605 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
21606 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
21607 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21608 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21609 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21610 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
21611 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
21612 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
21613 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
21614
21615 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
21616 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
21617 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
21618 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
21619 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
21620 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21621 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21622 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21623 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
21624 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
21625 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
21626 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
21627
21628 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
21629 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
21630 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
21631 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
21632 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
21633 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21634 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21635 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21636 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
21637 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
21638 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
21639 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
21640
21641 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
21642 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
21643 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
21644 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
21645 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
21646 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21647 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21648 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21649 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
21650 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
21651 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
21652 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
21653
21654 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
21655 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
21656 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
21657 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
21658 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
21659 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21660 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21661 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21662 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
21663 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
21664 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
21665 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
21666
21667 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
21668 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
21669 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
21670 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
21671 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
21672 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21673 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21674 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21675 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
21676 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
21677 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
21678 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
21679
21680 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
21681 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
21682 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
21683 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
21684 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
21685 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21686 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21687 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21688 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
21689 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
21690 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
21691 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
21692
21693 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
21694 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
21695 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
21696 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
21697 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
21698 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21699 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21700 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21701 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
21702 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
21703 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
21704 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
21705
21706 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
21707 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
21708 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
21709 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
21710 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
21711 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21712 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21713 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21714 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
21715 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
21716 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
21717 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
21718
21719 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
21720 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
21721 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
21722 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
21723
21724 cCL("flts", e000110, 2, (RF, RR), rn_rd),
21725 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
21726 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
21727 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
21728 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
21729 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
21730 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
21731 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
21732 cCL("flte", e080110, 2, (RF, RR), rn_rd),
21733 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
21734 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
21735 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 21736
c19d1205
ZW
21737 /* The implementation of the FIX instruction is broken on some
21738 assemblers, in that it accepts a precision specifier as well as a
21739 rounding specifier, despite the fact that this is meaningless.
21740 To be more compatible, we accept it as well, though of course it
21741 does not set any bits. */
21d799b5
NC
21742 cCE("fix", e100110, 2, (RR, RF), rd_rm),
21743 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
21744 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
21745 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
21746 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
21747 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
21748 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
21749 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
21750 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
21751 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
21752 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
21753 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
21754 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 21755
c19d1205 21756 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
21757#undef ARM_VARIANT
21758#define ARM_VARIANT & fpu_fpa_ext_v2
21759
21d799b5
NC
21760 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21761 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21762 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21763 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21764 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21765 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 21766
c921be7d
NC
21767#undef ARM_VARIANT
21768#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
21769
c19d1205 21770 /* Moves and type conversions. */
21d799b5
NC
21771 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
21772 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
21773 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
21774 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
21775 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
21776 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
21777 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
21778 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
21779 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
21780 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
21781 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
21782 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
21783 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
21784 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
21785
21786 /* Memory operations. */
21d799b5
NC
21787 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
21788 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
21789 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21790 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21791 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21792 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21793 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21794 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21795 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
21796 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
21797 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21798 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21799 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21800 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21801 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21802 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21803 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
21804 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 21805
c19d1205 21806 /* Monadic operations. */
21d799b5
NC
21807 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
21808 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
21809 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
21810
21811 /* Dyadic operations. */
21d799b5
NC
21812 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21813 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21814 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21815 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21816 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21817 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21818 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21819 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21820 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 21821
c19d1205 21822 /* Comparisons. */
21d799b5
NC
21823 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
21824 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
21825 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
21826 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 21827
62f3b8c8
PB
21828 /* Double precision load/store are still present on single precision
21829 implementations. */
21830 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
21831 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
21832 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21833 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21834 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
21835 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
21836 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21837 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21838 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
21839 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 21840
c921be7d
NC
21841#undef ARM_VARIANT
21842#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
21843
c19d1205 21844 /* Moves and type conversions. */
21d799b5
NC
21845 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
21846 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
21847 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
21848 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
21849 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
21850 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
21851 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
21852 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
21853 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
21854 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
21855 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
21856 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
21857 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 21858
c19d1205 21859 /* Monadic operations. */
21d799b5
NC
21860 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
21861 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
21862 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
21863
21864 /* Dyadic operations. */
21d799b5
NC
21865 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21866 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21867 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21868 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21869 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21870 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21871 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21872 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21873 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 21874
c19d1205 21875 /* Comparisons. */
21d799b5
NC
21876 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
21877 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
21878 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
21879 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 21880
c921be7d
NC
21881#undef ARM_VARIANT
21882#define ARM_VARIANT & fpu_vfp_ext_v2
21883
21d799b5
NC
21884 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
21885 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
21886 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
21887 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 21888
037e8744
JB
21889/* Instructions which may belong to either the Neon or VFP instruction sets.
21890 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
21891#undef ARM_VARIANT
21892#define ARM_VARIANT & fpu_vfp_ext_v1xd
21893#undef THUMB_VARIANT
21894#define THUMB_VARIANT & fpu_vfp_ext_v1xd
21895
037e8744
JB
21896 /* These mnemonics are unique to VFP. */
21897 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
21898 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
21899 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21900 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21901 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
21902 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
21903 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
21904 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
21905 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
21906 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
21907
21908 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
21909 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
21910 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
21911 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 21912
55881a11
MGD
21913 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21914 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21915 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21916 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21917 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21918 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
037e8744 21919
5f1af56b 21920 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 21921 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
21922 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
21923 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 21924
037e8744
JB
21925
21926 /* NOTE: All VMOV encoding is special-cased! */
21927 NCE(vmov, 0, 1, (VMOV), neon_mov),
21928 NCE(vmovq, 0, 1, (VMOV), neon_mov),
21929
32c36c3c
AV
21930#undef THUMB_VARIANT
21931/* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
21932 by different feature bits. Since we are setting the Thumb guard, we can
21933 require Thumb-1 which makes it a nop guard and set the right feature bit in
21934 do_vldr_vstr (). */
21935#define THUMB_VARIANT & arm_ext_v4t
21936 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
21937 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
21938
9db2f6b4
RL
21939#undef ARM_VARIANT
21940#define ARM_VARIANT & arm_ext_fp16
21941#undef THUMB_VARIANT
21942#define THUMB_VARIANT & arm_ext_fp16
21943 /* New instructions added from v8.2, allowing the extraction and insertion of
21944 the upper 16 bits of a 32-bit vector register. */
21945 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
21946 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
21947
dec41383
JW
21948 /* New backported fma/fms instructions optional in v8.2. */
21949 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
21950 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
21951
c921be7d
NC
21952#undef THUMB_VARIANT
21953#define THUMB_VARIANT & fpu_neon_ext_v1
21954#undef ARM_VARIANT
21955#define ARM_VARIANT & fpu_neon_ext_v1
21956
5287ad62
JB
21957 /* Data processing with three registers of the same length. */
21958 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
21959 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
21960 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
21961 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21962 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21963 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21964 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21965 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21966 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21967 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
21968 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
21969 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
21970 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
21971 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
21972 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
21973 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
21974 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
21975 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
21976 /* If not immediate, fall back to neon_dyadic_i64_su.
21977 shl_imm should accept I8 I16 I32 I64,
21978 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
21979 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
21980 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
21981 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
21982 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 21983 /* Logic ops, types optional & ignored. */
4316f0d2
DG
21984 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21985 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21986 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21987 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21988 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21989 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21990 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21991 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21992 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
21993 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
21994 /* Bitfield ops, untyped. */
21995 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
21996 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
21997 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
21998 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
21999 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
22000 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 22001 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
22002 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
22003 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
22004 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
22005 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
22006 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
22007 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
22008 back to neon_dyadic_if_su. */
21d799b5
NC
22009 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
22010 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
22011 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
22012 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
22013 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
22014 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
22015 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
22016 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 22017 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
22018 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
22019 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 22020 /* As above, D registers only. */
21d799b5
NC
22021 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
22022 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 22023 /* Int and float variants, signedness unimportant. */
21d799b5
NC
22024 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
22025 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
22026 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 22027 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
22028 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
22029 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
22030 /* vtst takes sizes 8, 16, 32. */
22031 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
22032 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
22033 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 22034 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 22035 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
22036 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
22037 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
22038 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
22039 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
22040 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
22041 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
22042 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
22043 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
22044 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
22045 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
22046 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
22047 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
22048 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
22049 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
22050 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
22051 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 22052 /* ARM v8.1 extension. */
643afb90
MW
22053 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
22054 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
22055 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
22056 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
22057
22058 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 22059 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
22060 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
22061
22062 /* Data processing with two registers and a shift amount. */
22063 /* Right shifts, and variants with rounding.
22064 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
22065 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
22066 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
22067 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
22068 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
22069 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
22070 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
22071 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
22072 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
22073 /* Shift and insert. Sizes accepted 8 16 32 64. */
22074 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
22075 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
22076 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
22077 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
22078 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
22079 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
22080 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
22081 /* Right shift immediate, saturating & narrowing, with rounding variants.
22082 Types accepted S16 S32 S64 U16 U32 U64. */
22083 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
22084 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
22085 /* As above, unsigned. Types accepted S16 S32 S64. */
22086 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
22087 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
22088 /* Right shift narrowing. Types accepted I16 I32 I64. */
22089 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
22090 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
22091 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 22092 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 22093 /* CVT with optional immediate for fixed-point variant. */
21d799b5 22094 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 22095
4316f0d2
DG
22096 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
22097 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
22098
22099 /* Data processing, three registers of different lengths. */
22100 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
22101 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
5287ad62
JB
22102 /* If not scalar, fall back to neon_dyadic_long.
22103 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
22104 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
22105 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
22106 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
22107 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
22108 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
22109 /* Dyadic, narrowing insns. Types I16 I32 I64. */
22110 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
22111 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
22112 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
22113 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
22114 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
22115 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
22116 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
22117 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
22118 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
22119 S16 S32 U16 U32. */
21d799b5 22120 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
22121
22122 /* Extract. Size 8. */
3b8d421e
PB
22123 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
22124 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
22125
22126 /* Two registers, miscellaneous. */
22127 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
22128 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
22129 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
22130 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
22131 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
22132 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
22133 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
22134 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
22135 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
22136 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
22137 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
22138 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
22139 /* VMOVN. Types I16 I32 I64. */
21d799b5 22140 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 22141 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 22142 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 22143 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 22144 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
22145 /* VZIP / VUZP. Sizes 8 16 32. */
22146 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
22147 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
22148 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
22149 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
22150 /* VQABS / VQNEG. Types S8 S16 S32. */
22151 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
22152 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
22153 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
22154 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
22155 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
22156 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
22157 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
22158 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
22159 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 22160 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
22161 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
22162 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
22163 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
22164 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
22165 /* VCLS. Types S8 S16 S32. */
22166 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
22167 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
22168 /* VCLZ. Types I8 I16 I32. */
22169 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
22170 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
22171 /* VCNT. Size 8. */
22172 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
22173 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
22174 /* Two address, untyped. */
22175 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
22176 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
22177 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
22178 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
22179 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
22180
22181 /* Table lookup. Size 8. */
22182 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
22183 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
22184
c921be7d
NC
22185#undef THUMB_VARIANT
22186#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
22187#undef ARM_VARIANT
22188#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
22189
5287ad62 22190 /* Neon element/structure load/store. */
21d799b5
NC
22191 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
22192 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
22193 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
22194 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
22195 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
22196 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
22197 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
22198 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 22199
c921be7d 22200#undef THUMB_VARIANT
74db7efb
NC
22201#define THUMB_VARIANT & fpu_vfp_ext_v3xd
22202#undef ARM_VARIANT
22203#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
22204 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
22205 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
22206 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
22207 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
22208 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
22209 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
22210 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
22211 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
22212 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
22213
74db7efb 22214#undef THUMB_VARIANT
c921be7d
NC
22215#define THUMB_VARIANT & fpu_vfp_ext_v3
22216#undef ARM_VARIANT
22217#define ARM_VARIANT & fpu_vfp_ext_v3
22218
21d799b5 22219 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 22220 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 22221 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 22222 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 22223 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 22224 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 22225 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 22226 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 22227 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 22228
74db7efb
NC
22229#undef ARM_VARIANT
22230#define ARM_VARIANT & fpu_vfp_ext_fma
22231#undef THUMB_VARIANT
22232#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
22233 /* Mnemonics shared by Neon and VFP. These are included in the
22234 VFP FMA variant; NEON and VFP FMA always includes the NEON
22235 FMA instructions. */
22236 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
22237 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
22238 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
22239 the v form should always be used. */
22240 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
22241 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
22242 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
22243 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
22244 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
22245 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
22246
5287ad62 22247#undef THUMB_VARIANT
c921be7d
NC
22248#undef ARM_VARIANT
22249#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
22250
21d799b5
NC
22251 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22252 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22253 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22254 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22255 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22256 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22257 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
22258 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 22259
c921be7d
NC
22260#undef ARM_VARIANT
22261#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
22262
21d799b5
NC
22263 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
22264 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
22265 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
22266 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
22267 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
22268 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
22269 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
22270 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
22271 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
22272 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
22273 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
22274 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
22275 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
22276 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
22277 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
22278 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
22279 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
22280 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
22281 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
22282 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
22283 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22284 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22285 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22286 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22287 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22288 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
22289 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
22290 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
22291 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
22292 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
22293 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
22294 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
22295 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
22296 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
22297 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
22298 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
22299 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
22300 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22301 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22302 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22303 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22304 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22305 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22306 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22307 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22308 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22309 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
22310 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22311 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22312 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22313 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
22314 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22315 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22316 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22317 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22318 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22319 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22320 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22321 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22322 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
22323 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22324 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22325 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22326 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22327 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22328 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
22329 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
22330 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
22331 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
22332 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
22333 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22334 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22335 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22336 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22337 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22338 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22339 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22340 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22341 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22342 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22343 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22344 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22345 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22346 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22347 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22348 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22349 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22350 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22351 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
22352 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22353 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22354 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22355 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22356 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
22357 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22358 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22359 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22360 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22361 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22362 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
22363 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22364 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22365 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22366 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22367 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22368 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22369 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22370 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22371 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22372 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22373 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
22374 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22375 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22376 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22377 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22378 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22379 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22380 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22381 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22382 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22383 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22384 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22385 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22386 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22387 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22388 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22389 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22390 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22391 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22392 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
22393 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
22394 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
22395 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
22396 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22397 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22398 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22399 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22400 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22401 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22402 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22403 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22404 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22405 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
22406 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
22407 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
22408 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
22409 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
22410 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
22411 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22412 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22413 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22414 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
22415 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
22416 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
22417 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
22418 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
22419 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
22420 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22421 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22422 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22423 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22424 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 22425
c921be7d
NC
22426#undef ARM_VARIANT
22427#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
22428
21d799b5
NC
22429 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
22430 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
22431 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
22432 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
22433 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
22434 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
22435 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22436 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22437 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22438 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22439 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22440 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22441 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22442 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22443 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22444 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22445 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22446 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22447 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22448 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22449 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
22450 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22451 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22452 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22453 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22454 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22455 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22456 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22457 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22458 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22459 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22460 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22461 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22462 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22463 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22464 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22465 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22466 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22467 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22468 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22469 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22470 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22471 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22472 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22473 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22474 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22475 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22476 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22477 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22478 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22479 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22480 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22481 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22482 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22483 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22484 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22485 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 22486
c921be7d
NC
22487#undef ARM_VARIANT
22488#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
22489
21d799b5
NC
22490 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
22491 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
22492 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
22493 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
22494 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
22495 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
22496 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
22497 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
22498 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
22499 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
22500 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
22501 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
22502 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
22503 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
22504 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
22505 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
22506 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
22507 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
22508 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
22509 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
22510 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
22511 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
22512 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
22513 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
22514 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
22515 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
22516 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
22517 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
22518 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
22519 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
22520 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
22521 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
22522 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
22523 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
22524 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
22525 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
22526 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
22527 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
22528 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
22529 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
22530 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
22531 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
22532 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
22533 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
22534 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
22535 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
22536 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
22537 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
22538 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
22539 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
22540 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
22541 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
22542 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
22543 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
22544 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
22545 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
22546 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
22547 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
22548 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
22549 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
22550 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
22551 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
22552 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
22553 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
22554 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
22555 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
22556 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
22557 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
22558 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
22559 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
22560 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
22561 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
22562 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
22563 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
22564 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
22565 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 22566
7fadb25d
SD
22567 /* ARMv8.5-A instructions. */
22568#undef ARM_VARIANT
22569#define ARM_VARIANT & arm_ext_sb
22570#undef THUMB_VARIANT
22571#define THUMB_VARIANT & arm_ext_sb
22572 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
22573
dad0c3bf
SD
22574#undef ARM_VARIANT
22575#define ARM_VARIANT & arm_ext_predres
22576#undef THUMB_VARIANT
22577#define THUMB_VARIANT & arm_ext_predres
22578 CE("cfprctx", e070f93, 1, (RRnpc), rd),
22579 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
22580 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
22581
16a1fa25 22582 /* ARMv8-M instructions. */
4ed7ed8d
TP
22583#undef ARM_VARIANT
22584#define ARM_VARIANT NULL
22585#undef THUMB_VARIANT
22586#define THUMB_VARIANT & arm_ext_v8m
cf3cf39d
TP
22587 ToU("sg", e97fe97f, 0, (), noargs),
22588 ToC("blxns", 4784, 1, (RRnpc), t_blx),
22589 ToC("bxns", 4704, 1, (RRnpc), t_bx),
22590 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
22591 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
22592 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
22593 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
16a1fa25
TP
22594
22595 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
22596 instructions behave as nop if no VFP is present. */
22597#undef THUMB_VARIANT
22598#define THUMB_VARIANT & arm_ext_v8m_main
cf3cf39d
TP
22599 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
22600 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
4389b29a
AV
22601
22602 /* Armv8.1-M Mainline instructions. */
22603#undef THUMB_VARIANT
22604#define THUMB_VARIANT & arm_ext_v8_1m_main
22605 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
f6b2b12d 22606 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
f1c7f421 22607 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
65d1bc05 22608 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
f1c7f421 22609 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
60f993ce
AV
22610
22611 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
22612 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
22613 toU("le", _le, 2, (oLR, EXP), t_loloop),
4b5a202f 22614
efd6b359 22615 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
5ee91343
AV
22616 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
22617
22618#undef THUMB_VARIANT
22619#define THUMB_VARIANT & mve_ext
22620 ToC("vpst", fe710f4d, 0, (), mve_vpt),
22621 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
22622 ToC("vpste", fe718f4d, 0, (), mve_vpt),
22623 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
22624 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
22625 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
22626 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
22627 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
22628 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
22629 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
22630 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
22631 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
22632 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
22633 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
22634 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
22635
22636#undef ARM_VARIANT
22637#define ARM_VARIANT & fpu_vfp_ext_v1xd
22638#undef THUMB_VARIANT
22639#define THUMB_VARIANT & arm_ext_v6t2
22640
22641 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
22642 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
22643
485dee97
AV
22644 MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
22645 MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
22646
5ee91343
AV
22647#undef ARM_VARIANT
22648#define ARM_VARIANT & fpu_neon_ext_v1
22649 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
22650 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
22651 mnUF(vaddl, _vaddl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
22652 mnUF(vsubl, _vsubl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
c19d1205
ZW
22653};
22654#undef ARM_VARIANT
22655#undef THUMB_VARIANT
22656#undef TCE
c19d1205
ZW
22657#undef TUE
22658#undef TUF
22659#undef TCC
8f06b2d8 22660#undef cCE
e3cb604e
PB
22661#undef cCL
22662#undef C3E
4389b29a 22663#undef C3
c19d1205
ZW
22664#undef CE
22665#undef CM
4389b29a 22666#undef CL
c19d1205
ZW
22667#undef UE
22668#undef UF
22669#undef UT
5287ad62
JB
22670#undef NUF
22671#undef nUF
22672#undef NCE
22673#undef nCE
c19d1205
ZW
22674#undef OPS0
22675#undef OPS1
22676#undef OPS2
22677#undef OPS3
22678#undef OPS4
22679#undef OPS5
22680#undef OPS6
22681#undef do_0
4389b29a
AV
22682#undef ToC
22683#undef toC
22684#undef ToU
f6b2b12d 22685#undef toU
c19d1205
ZW
22686\f
22687/* MD interface: bits in the object file. */
bfae80f2 22688
c19d1205
ZW
22689/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
22690 for use in the a.out file, and stores them in the array pointed to by buf.
22691 This knows about the endian-ness of the target machine and does
22692 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
22693 2 (short) and 4 (long) Floating numbers are put out as a series of
22694 LITTLENUMS (shorts, here at least). */
b99bd4ef 22695
c19d1205
ZW
22696void
22697md_number_to_chars (char * buf, valueT val, int n)
22698{
22699 if (target_big_endian)
22700 number_to_chars_bigendian (buf, val, n);
22701 else
22702 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
22703}
22704
c19d1205
ZW
22705static valueT
22706md_chars_to_number (char * buf, int n)
bfae80f2 22707{
c19d1205
ZW
22708 valueT result = 0;
22709 unsigned char * where = (unsigned char *) buf;
bfae80f2 22710
c19d1205 22711 if (target_big_endian)
b99bd4ef 22712 {
c19d1205
ZW
22713 while (n--)
22714 {
22715 result <<= 8;
22716 result |= (*where++ & 255);
22717 }
b99bd4ef 22718 }
c19d1205 22719 else
b99bd4ef 22720 {
c19d1205
ZW
22721 while (n--)
22722 {
22723 result <<= 8;
22724 result |= (where[n] & 255);
22725 }
bfae80f2 22726 }
b99bd4ef 22727
c19d1205 22728 return result;
bfae80f2 22729}
b99bd4ef 22730
c19d1205 22731/* MD interface: Sections. */
b99bd4ef 22732
fa94de6b
RM
22733/* Calculate the maximum variable size (i.e., excluding fr_fix)
22734 that an rs_machine_dependent frag may reach. */
22735
22736unsigned int
22737arm_frag_max_var (fragS *fragp)
22738{
22739 /* We only use rs_machine_dependent for variable-size Thumb instructions,
22740 which are either THUMB_SIZE (2) or INSN_SIZE (4).
22741
22742 Note that we generate relaxable instructions even for cases that don't
22743 really need it, like an immediate that's a trivial constant. So we're
22744 overestimating the instruction size for some of those cases. Rather
22745 than putting more intelligence here, it would probably be better to
22746 avoid generating a relaxation frag in the first place when it can be
22747 determined up front that a short instruction will suffice. */
22748
22749 gas_assert (fragp->fr_type == rs_machine_dependent);
22750 return INSN_SIZE;
22751}
22752
0110f2b8
PB
22753/* Estimate the size of a frag before relaxing. Assume everything fits in
22754 2 bytes. */
22755
c19d1205 22756int
0110f2b8 22757md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
22758 segT segtype ATTRIBUTE_UNUSED)
22759{
0110f2b8
PB
22760 fragp->fr_var = 2;
22761 return 2;
22762}
22763
22764/* Convert a machine dependent frag. */
22765
22766void
22767md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
22768{
22769 unsigned long insn;
22770 unsigned long old_op;
22771 char *buf;
22772 expressionS exp;
22773 fixS *fixp;
22774 int reloc_type;
22775 int pc_rel;
22776 int opcode;
22777
22778 buf = fragp->fr_literal + fragp->fr_fix;
22779
22780 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
22781 if (fragp->fr_symbol)
22782 {
0110f2b8
PB
22783 exp.X_op = O_symbol;
22784 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
22785 }
22786 else
22787 {
0110f2b8 22788 exp.X_op = O_constant;
5f4273c7 22789 }
0110f2b8
PB
22790 exp.X_add_number = fragp->fr_offset;
22791 opcode = fragp->fr_subtype;
22792 switch (opcode)
22793 {
22794 case T_MNEM_ldr_pc:
22795 case T_MNEM_ldr_pc2:
22796 case T_MNEM_ldr_sp:
22797 case T_MNEM_str_sp:
22798 case T_MNEM_ldr:
22799 case T_MNEM_ldrb:
22800 case T_MNEM_ldrh:
22801 case T_MNEM_str:
22802 case T_MNEM_strb:
22803 case T_MNEM_strh:
22804 if (fragp->fr_var == 4)
22805 {
5f4273c7 22806 insn = THUMB_OP32 (opcode);
0110f2b8
PB
22807 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
22808 {
22809 insn |= (old_op & 0x700) << 4;
22810 }
22811 else
22812 {
22813 insn |= (old_op & 7) << 12;
22814 insn |= (old_op & 0x38) << 13;
22815 }
22816 insn |= 0x00000c00;
22817 put_thumb32_insn (buf, insn);
22818 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
22819 }
22820 else
22821 {
22822 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
22823 }
22824 pc_rel = (opcode == T_MNEM_ldr_pc2);
22825 break;
22826 case T_MNEM_adr:
22827 if (fragp->fr_var == 4)
22828 {
22829 insn = THUMB_OP32 (opcode);
22830 insn |= (old_op & 0xf0) << 4;
22831 put_thumb32_insn (buf, insn);
22832 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
22833 }
22834 else
22835 {
22836 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
22837 exp.X_add_number -= 4;
22838 }
22839 pc_rel = 1;
22840 break;
22841 case T_MNEM_mov:
22842 case T_MNEM_movs:
22843 case T_MNEM_cmp:
22844 case T_MNEM_cmn:
22845 if (fragp->fr_var == 4)
22846 {
22847 int r0off = (opcode == T_MNEM_mov
22848 || opcode == T_MNEM_movs) ? 0 : 8;
22849 insn = THUMB_OP32 (opcode);
22850 insn = (insn & 0xe1ffffff) | 0x10000000;
22851 insn |= (old_op & 0x700) << r0off;
22852 put_thumb32_insn (buf, insn);
22853 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
22854 }
22855 else
22856 {
22857 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
22858 }
22859 pc_rel = 0;
22860 break;
22861 case T_MNEM_b:
22862 if (fragp->fr_var == 4)
22863 {
22864 insn = THUMB_OP32(opcode);
22865 put_thumb32_insn (buf, insn);
22866 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
22867 }
22868 else
22869 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
22870 pc_rel = 1;
22871 break;
22872 case T_MNEM_bcond:
22873 if (fragp->fr_var == 4)
22874 {
22875 insn = THUMB_OP32(opcode);
22876 insn |= (old_op & 0xf00) << 14;
22877 put_thumb32_insn (buf, insn);
22878 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
22879 }
22880 else
22881 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
22882 pc_rel = 1;
22883 break;
22884 case T_MNEM_add_sp:
22885 case T_MNEM_add_pc:
22886 case T_MNEM_inc_sp:
22887 case T_MNEM_dec_sp:
22888 if (fragp->fr_var == 4)
22889 {
22890 /* ??? Choose between add and addw. */
22891 insn = THUMB_OP32 (opcode);
22892 insn |= (old_op & 0xf0) << 4;
22893 put_thumb32_insn (buf, insn);
16805f35
PB
22894 if (opcode == T_MNEM_add_pc)
22895 reloc_type = BFD_RELOC_ARM_T32_IMM12;
22896 else
22897 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
22898 }
22899 else
22900 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
22901 pc_rel = 0;
22902 break;
22903
22904 case T_MNEM_addi:
22905 case T_MNEM_addis:
22906 case T_MNEM_subi:
22907 case T_MNEM_subis:
22908 if (fragp->fr_var == 4)
22909 {
22910 insn = THUMB_OP32 (opcode);
22911 insn |= (old_op & 0xf0) << 4;
22912 insn |= (old_op & 0xf) << 16;
22913 put_thumb32_insn (buf, insn);
16805f35
PB
22914 if (insn & (1 << 20))
22915 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
22916 else
22917 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
22918 }
22919 else
22920 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
22921 pc_rel = 0;
22922 break;
22923 default:
5f4273c7 22924 abort ();
0110f2b8
PB
22925 }
22926 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 22927 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
22928 fixp->fx_file = fragp->fr_file;
22929 fixp->fx_line = fragp->fr_line;
22930 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
22931
22932 /* Set whether we use thumb-2 ISA based on final relaxation results. */
22933 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
22934 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
22935 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
22936}
22937
22938/* Return the size of a relaxable immediate operand instruction.
22939 SHIFT and SIZE specify the form of the allowable immediate. */
22940static int
22941relax_immediate (fragS *fragp, int size, int shift)
22942{
22943 offsetT offset;
22944 offsetT mask;
22945 offsetT low;
22946
22947 /* ??? Should be able to do better than this. */
22948 if (fragp->fr_symbol)
22949 return 4;
22950
22951 low = (1 << shift) - 1;
22952 mask = (1 << (shift + size)) - (1 << shift);
22953 offset = fragp->fr_offset;
22954 /* Force misaligned offsets to 32-bit variant. */
22955 if (offset & low)
5e77afaa 22956 return 4;
0110f2b8
PB
22957 if (offset & ~mask)
22958 return 4;
22959 return 2;
22960}
22961
5e77afaa
PB
22962/* Get the address of a symbol during relaxation. */
22963static addressT
5f4273c7 22964relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
22965{
22966 fragS *sym_frag;
22967 addressT addr;
22968 symbolS *sym;
22969
22970 sym = fragp->fr_symbol;
22971 sym_frag = symbol_get_frag (sym);
22972 know (S_GET_SEGMENT (sym) != absolute_section
22973 || sym_frag == &zero_address_frag);
22974 addr = S_GET_VALUE (sym) + fragp->fr_offset;
22975
22976 /* If frag has yet to be reached on this pass, assume it will
22977 move by STRETCH just as we did. If this is not so, it will
22978 be because some frag between grows, and that will force
22979 another pass. */
22980
22981 if (stretch != 0
22982 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
22983 {
22984 fragS *f;
22985
22986 /* Adjust stretch for any alignment frag. Note that if have
22987 been expanding the earlier code, the symbol may be
22988 defined in what appears to be an earlier frag. FIXME:
22989 This doesn't handle the fr_subtype field, which specifies
22990 a maximum number of bytes to skip when doing an
22991 alignment. */
22992 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
22993 {
22994 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
22995 {
22996 if (stretch < 0)
22997 stretch = - ((- stretch)
22998 & ~ ((1 << (int) f->fr_offset) - 1));
22999 else
23000 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
23001 if (stretch == 0)
23002 break;
23003 }
23004 }
23005 if (f != NULL)
23006 addr += stretch;
23007 }
5e77afaa
PB
23008
23009 return addr;
23010}
23011
0110f2b8
PB
23012/* Return the size of a relaxable adr pseudo-instruction or PC-relative
23013 load. */
23014static int
5e77afaa 23015relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
23016{
23017 addressT addr;
23018 offsetT val;
23019
23020 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
23021 if (fragp->fr_symbol == NULL
23022 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
23023 || sec != S_GET_SEGMENT (fragp->fr_symbol)
23024 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
23025 return 4;
23026
5f4273c7 23027 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
23028 addr = fragp->fr_address + fragp->fr_fix;
23029 addr = (addr + 4) & ~3;
5e77afaa 23030 /* Force misaligned targets to 32-bit variant. */
0110f2b8 23031 if (val & 3)
5e77afaa 23032 return 4;
0110f2b8
PB
23033 val -= addr;
23034 if (val < 0 || val > 1020)
23035 return 4;
23036 return 2;
23037}
23038
23039/* Return the size of a relaxable add/sub immediate instruction. */
23040static int
23041relax_addsub (fragS *fragp, asection *sec)
23042{
23043 char *buf;
23044 int op;
23045
23046 buf = fragp->fr_literal + fragp->fr_fix;
23047 op = bfd_get_16(sec->owner, buf);
23048 if ((op & 0xf) == ((op >> 4) & 0xf))
23049 return relax_immediate (fragp, 8, 0);
23050 else
23051 return relax_immediate (fragp, 3, 0);
23052}
23053
e83a675f
RE
23054/* Return TRUE iff the definition of symbol S could be pre-empted
23055 (overridden) at link or load time. */
23056static bfd_boolean
23057symbol_preemptible (symbolS *s)
23058{
23059 /* Weak symbols can always be pre-empted. */
23060 if (S_IS_WEAK (s))
23061 return TRUE;
23062
23063 /* Non-global symbols cannot be pre-empted. */
23064 if (! S_IS_EXTERNAL (s))
23065 return FALSE;
23066
23067#ifdef OBJ_ELF
23068 /* In ELF, a global symbol can be marked protected, or private. In that
23069 case it can't be pre-empted (other definitions in the same link unit
23070 would violate the ODR). */
23071 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
23072 return FALSE;
23073#endif
23074
23075 /* Other global symbols might be pre-empted. */
23076 return TRUE;
23077}
0110f2b8
PB
23078
23079/* Return the size of a relaxable branch instruction. BITS is the
23080 size of the offset field in the narrow instruction. */
23081
23082static int
5e77afaa 23083relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
23084{
23085 addressT addr;
23086 offsetT val;
23087 offsetT limit;
23088
23089 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 23090 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
23091 || sec != S_GET_SEGMENT (fragp->fr_symbol)
23092 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
23093 return 4;
23094
267bf995 23095#ifdef OBJ_ELF
e83a675f 23096 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
23097 if (S_IS_DEFINED (fragp->fr_symbol)
23098 && ARM_IS_FUNC (fragp->fr_symbol))
23099 return 4;
e83a675f 23100#endif
0d9b4b55 23101
e83a675f 23102 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 23103 return 4;
267bf995 23104
5f4273c7 23105 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
23106 addr = fragp->fr_address + fragp->fr_fix + 4;
23107 val -= addr;
23108
23109 /* Offset is a signed value *2 */
23110 limit = 1 << bits;
23111 if (val >= limit || val < -limit)
23112 return 4;
23113 return 2;
23114}
23115
23116
23117/* Relax a machine dependent frag. This returns the amount by which
23118 the current size of the frag should change. */
23119
23120int
5e77afaa 23121arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
23122{
23123 int oldsize;
23124 int newsize;
23125
23126 oldsize = fragp->fr_var;
23127 switch (fragp->fr_subtype)
23128 {
23129 case T_MNEM_ldr_pc2:
5f4273c7 23130 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
23131 break;
23132 case T_MNEM_ldr_pc:
23133 case T_MNEM_ldr_sp:
23134 case T_MNEM_str_sp:
5f4273c7 23135 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
23136 break;
23137 case T_MNEM_ldr:
23138 case T_MNEM_str:
5f4273c7 23139 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
23140 break;
23141 case T_MNEM_ldrh:
23142 case T_MNEM_strh:
5f4273c7 23143 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
23144 break;
23145 case T_MNEM_ldrb:
23146 case T_MNEM_strb:
5f4273c7 23147 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
23148 break;
23149 case T_MNEM_adr:
5f4273c7 23150 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
23151 break;
23152 case T_MNEM_mov:
23153 case T_MNEM_movs:
23154 case T_MNEM_cmp:
23155 case T_MNEM_cmn:
5f4273c7 23156 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
23157 break;
23158 case T_MNEM_b:
5f4273c7 23159 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
23160 break;
23161 case T_MNEM_bcond:
5f4273c7 23162 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
23163 break;
23164 case T_MNEM_add_sp:
23165 case T_MNEM_add_pc:
23166 newsize = relax_immediate (fragp, 8, 2);
23167 break;
23168 case T_MNEM_inc_sp:
23169 case T_MNEM_dec_sp:
23170 newsize = relax_immediate (fragp, 7, 2);
23171 break;
23172 case T_MNEM_addi:
23173 case T_MNEM_addis:
23174 case T_MNEM_subi:
23175 case T_MNEM_subis:
23176 newsize = relax_addsub (fragp, sec);
23177 break;
23178 default:
5f4273c7 23179 abort ();
0110f2b8 23180 }
5e77afaa
PB
23181
23182 fragp->fr_var = newsize;
23183 /* Freeze wide instructions that are at or before the same location as
23184 in the previous pass. This avoids infinite loops.
5f4273c7
NC
23185 Don't freeze them unconditionally because targets may be artificially
23186 misaligned by the expansion of preceding frags. */
5e77afaa 23187 if (stretch <= 0 && newsize > 2)
0110f2b8 23188 {
0110f2b8 23189 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 23190 frag_wane (fragp);
0110f2b8 23191 }
5e77afaa 23192
0110f2b8 23193 return newsize - oldsize;
c19d1205 23194}
b99bd4ef 23195
c19d1205 23196/* Round up a section size to the appropriate boundary. */
b99bd4ef 23197
c19d1205
ZW
23198valueT
23199md_section_align (segT segment ATTRIBUTE_UNUSED,
23200 valueT size)
23201{
6844c0cc 23202 return size;
bfae80f2 23203}
b99bd4ef 23204
c19d1205
ZW
23205/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
23206 of an rs_align_code fragment. */
23207
23208void
23209arm_handle_align (fragS * fragP)
bfae80f2 23210{
d9235011 23211 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
23212 {
23213 { /* ARMv1 */
23214 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
23215 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
23216 },
23217 { /* ARMv6k */
23218 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
23219 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
23220 },
23221 };
d9235011 23222 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
23223 {
23224 { /* Thumb-1 */
23225 {0xc0, 0x46}, /* LE */
23226 {0x46, 0xc0}, /* BE */
23227 },
23228 { /* Thumb-2 */
23229 {0x00, 0xbf}, /* LE */
23230 {0xbf, 0x00} /* BE */
23231 }
23232 };
d9235011 23233 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
23234 { /* Wide Thumb-2 */
23235 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
23236 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
23237 };
c921be7d 23238
e7495e45 23239 unsigned bytes, fix, noop_size;
c19d1205 23240 char * p;
d9235011
TS
23241 const unsigned char * noop;
23242 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
23243#ifdef OBJ_ELF
23244 enum mstate state;
23245#endif
bfae80f2 23246
c19d1205 23247 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
23248 return;
23249
c19d1205
ZW
23250 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
23251 p = fragP->fr_literal + fragP->fr_fix;
23252 fix = 0;
bfae80f2 23253
c19d1205
ZW
23254 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
23255 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 23256
cd000bff 23257 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 23258
cd000bff 23259 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 23260 {
7f78eb34
JW
23261 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
23262 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
23263 {
23264 narrow_noop = thumb_noop[1][target_big_endian];
23265 noop = wide_thumb_noop[target_big_endian];
23266 }
c19d1205 23267 else
e7495e45
NS
23268 noop = thumb_noop[0][target_big_endian];
23269 noop_size = 2;
cd000bff
DJ
23270#ifdef OBJ_ELF
23271 state = MAP_THUMB;
23272#endif
7ed4c4c5
NC
23273 }
23274 else
23275 {
7f78eb34
JW
23276 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
23277 ? selected_cpu : arm_arch_none,
23278 arm_ext_v6k) != 0]
e7495e45
NS
23279 [target_big_endian];
23280 noop_size = 4;
cd000bff
DJ
23281#ifdef OBJ_ELF
23282 state = MAP_ARM;
23283#endif
7ed4c4c5 23284 }
c921be7d 23285
e7495e45 23286 fragP->fr_var = noop_size;
c921be7d 23287
c19d1205 23288 if (bytes & (noop_size - 1))
7ed4c4c5 23289 {
c19d1205 23290 fix = bytes & (noop_size - 1);
cd000bff
DJ
23291#ifdef OBJ_ELF
23292 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
23293#endif
c19d1205
ZW
23294 memset (p, 0, fix);
23295 p += fix;
23296 bytes -= fix;
a737bd4d 23297 }
a737bd4d 23298
e7495e45
NS
23299 if (narrow_noop)
23300 {
23301 if (bytes & noop_size)
23302 {
23303 /* Insert a narrow noop. */
23304 memcpy (p, narrow_noop, noop_size);
23305 p += noop_size;
23306 bytes -= noop_size;
23307 fix += noop_size;
23308 }
23309
23310 /* Use wide noops for the remainder */
23311 noop_size = 4;
23312 }
23313
c19d1205 23314 while (bytes >= noop_size)
a737bd4d 23315 {
c19d1205
ZW
23316 memcpy (p, noop, noop_size);
23317 p += noop_size;
23318 bytes -= noop_size;
23319 fix += noop_size;
a737bd4d
NC
23320 }
23321
c19d1205 23322 fragP->fr_fix += fix;
a737bd4d
NC
23323}
23324
c19d1205
ZW
23325/* Called from md_do_align. Used to create an alignment
23326 frag in a code section. */
23327
23328void
23329arm_frag_align_code (int n, int max)
bfae80f2 23330{
c19d1205 23331 char * p;
7ed4c4c5 23332
c19d1205 23333 /* We assume that there will never be a requirement
6ec8e702 23334 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 23335 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
23336 {
23337 char err_msg[128];
23338
fa94de6b 23339 sprintf (err_msg,
477330fc
RM
23340 _("alignments greater than %d bytes not supported in .text sections."),
23341 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 23342 as_fatal ("%s", err_msg);
6ec8e702 23343 }
bfae80f2 23344
c19d1205
ZW
23345 p = frag_var (rs_align_code,
23346 MAX_MEM_FOR_RS_ALIGN_CODE,
23347 1,
23348 (relax_substateT) max,
23349 (symbolS *) NULL,
23350 (offsetT) n,
23351 (char *) NULL);
23352 *p = 0;
23353}
bfae80f2 23354
8dc2430f
NC
23355/* Perform target specific initialisation of a frag.
23356 Note - despite the name this initialisation is not done when the frag
23357 is created, but only when its type is assigned. A frag can be created
23358 and used a long time before its type is set, so beware of assuming that
33eaf5de 23359 this initialisation is performed first. */
bfae80f2 23360
cd000bff
DJ
23361#ifndef OBJ_ELF
23362void
23363arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
23364{
23365 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 23366 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
23367}
23368
23369#else /* OBJ_ELF is defined. */
c19d1205 23370void
cd000bff 23371arm_init_frag (fragS * fragP, int max_chars)
c19d1205 23372{
e8d84ca1 23373 bfd_boolean frag_thumb_mode;
b968d18a 23374
8dc2430f
NC
23375 /* If the current ARM vs THUMB mode has not already
23376 been recorded into this frag then do so now. */
cd000bff 23377 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
23378 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
23379
e8d84ca1
NC
23380 /* PR 21809: Do not set a mapping state for debug sections
23381 - it just confuses other tools. */
23382 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
23383 return;
23384
b968d18a 23385 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 23386
f9c1b181
RL
23387 /* Record a mapping symbol for alignment frags. We will delete this
23388 later if the alignment ends up empty. */
23389 switch (fragP->fr_type)
23390 {
23391 case rs_align:
23392 case rs_align_test:
23393 case rs_fill:
23394 mapping_state_2 (MAP_DATA, max_chars);
23395 break;
23396 case rs_align_code:
b968d18a 23397 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
23398 break;
23399 default:
23400 break;
cd000bff 23401 }
bfae80f2
RE
23402}
23403
c19d1205
ZW
23404/* When we change sections we need to issue a new mapping symbol. */
23405
23406void
23407arm_elf_change_section (void)
bfae80f2 23408{
c19d1205
ZW
23409 /* Link an unlinked unwind index table section to the .text section. */
23410 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
23411 && elf_linked_to_section (now_seg) == NULL)
23412 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
23413}
23414
c19d1205
ZW
23415int
23416arm_elf_section_type (const char * str, size_t len)
e45d0630 23417{
c19d1205
ZW
23418 if (len == 5 && strncmp (str, "exidx", 5) == 0)
23419 return SHT_ARM_EXIDX;
e45d0630 23420
c19d1205
ZW
23421 return -1;
23422}
23423\f
23424/* Code to deal with unwinding tables. */
e45d0630 23425
c19d1205 23426static void add_unwind_adjustsp (offsetT);
e45d0630 23427
5f4273c7 23428/* Generate any deferred unwind frame offset. */
e45d0630 23429
bfae80f2 23430static void
c19d1205 23431flush_pending_unwind (void)
bfae80f2 23432{
c19d1205 23433 offsetT offset;
bfae80f2 23434
c19d1205
ZW
23435 offset = unwind.pending_offset;
23436 unwind.pending_offset = 0;
23437 if (offset != 0)
23438 add_unwind_adjustsp (offset);
bfae80f2
RE
23439}
23440
c19d1205
ZW
23441/* Add an opcode to this list for this function. Two-byte opcodes should
23442 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
23443 order. */
23444
bfae80f2 23445static void
c19d1205 23446add_unwind_opcode (valueT op, int length)
bfae80f2 23447{
c19d1205
ZW
23448 /* Add any deferred stack adjustment. */
23449 if (unwind.pending_offset)
23450 flush_pending_unwind ();
bfae80f2 23451
c19d1205 23452 unwind.sp_restored = 0;
bfae80f2 23453
c19d1205 23454 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 23455 {
c19d1205
ZW
23456 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
23457 if (unwind.opcodes)
325801bd
TS
23458 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
23459 unwind.opcode_alloc);
c19d1205 23460 else
325801bd 23461 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 23462 }
c19d1205 23463 while (length > 0)
bfae80f2 23464 {
c19d1205
ZW
23465 length--;
23466 unwind.opcodes[unwind.opcode_count] = op & 0xff;
23467 op >>= 8;
23468 unwind.opcode_count++;
bfae80f2 23469 }
bfae80f2
RE
23470}
23471
c19d1205
ZW
23472/* Add unwind opcodes to adjust the stack pointer. */
23473
bfae80f2 23474static void
c19d1205 23475add_unwind_adjustsp (offsetT offset)
bfae80f2 23476{
c19d1205 23477 valueT op;
bfae80f2 23478
c19d1205 23479 if (offset > 0x200)
bfae80f2 23480 {
c19d1205
ZW
23481 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
23482 char bytes[5];
23483 int n;
23484 valueT o;
bfae80f2 23485
c19d1205
ZW
23486 /* Long form: 0xb2, uleb128. */
23487 /* This might not fit in a word so add the individual bytes,
23488 remembering the list is built in reverse order. */
23489 o = (valueT) ((offset - 0x204) >> 2);
23490 if (o == 0)
23491 add_unwind_opcode (0, 1);
bfae80f2 23492
c19d1205
ZW
23493 /* Calculate the uleb128 encoding of the offset. */
23494 n = 0;
23495 while (o)
23496 {
23497 bytes[n] = o & 0x7f;
23498 o >>= 7;
23499 if (o)
23500 bytes[n] |= 0x80;
23501 n++;
23502 }
23503 /* Add the insn. */
23504 for (; n; n--)
23505 add_unwind_opcode (bytes[n - 1], 1);
23506 add_unwind_opcode (0xb2, 1);
23507 }
23508 else if (offset > 0x100)
bfae80f2 23509 {
c19d1205
ZW
23510 /* Two short opcodes. */
23511 add_unwind_opcode (0x3f, 1);
23512 op = (offset - 0x104) >> 2;
23513 add_unwind_opcode (op, 1);
bfae80f2 23514 }
c19d1205
ZW
23515 else if (offset > 0)
23516 {
23517 /* Short opcode. */
23518 op = (offset - 4) >> 2;
23519 add_unwind_opcode (op, 1);
23520 }
23521 else if (offset < 0)
bfae80f2 23522 {
c19d1205
ZW
23523 offset = -offset;
23524 while (offset > 0x100)
bfae80f2 23525 {
c19d1205
ZW
23526 add_unwind_opcode (0x7f, 1);
23527 offset -= 0x100;
bfae80f2 23528 }
c19d1205
ZW
23529 op = ((offset - 4) >> 2) | 0x40;
23530 add_unwind_opcode (op, 1);
bfae80f2 23531 }
bfae80f2
RE
23532}
23533
c19d1205 23534/* Finish the list of unwind opcodes for this function. */
0198d5e6 23535
c19d1205
ZW
23536static void
23537finish_unwind_opcodes (void)
bfae80f2 23538{
c19d1205 23539 valueT op;
bfae80f2 23540
c19d1205 23541 if (unwind.fp_used)
bfae80f2 23542 {
708587a4 23543 /* Adjust sp as necessary. */
c19d1205
ZW
23544 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
23545 flush_pending_unwind ();
bfae80f2 23546
c19d1205
ZW
23547 /* After restoring sp from the frame pointer. */
23548 op = 0x90 | unwind.fp_reg;
23549 add_unwind_opcode (op, 1);
23550 }
23551 else
23552 flush_pending_unwind ();
bfae80f2
RE
23553}
23554
bfae80f2 23555
c19d1205
ZW
23556/* Start an exception table entry. If idx is nonzero this is an index table
23557 entry. */
bfae80f2
RE
23558
23559static void
c19d1205 23560start_unwind_section (const segT text_seg, int idx)
bfae80f2 23561{
c19d1205
ZW
23562 const char * text_name;
23563 const char * prefix;
23564 const char * prefix_once;
23565 const char * group_name;
c19d1205 23566 char * sec_name;
c19d1205
ZW
23567 int type;
23568 int flags;
23569 int linkonce;
bfae80f2 23570
c19d1205 23571 if (idx)
bfae80f2 23572 {
c19d1205
ZW
23573 prefix = ELF_STRING_ARM_unwind;
23574 prefix_once = ELF_STRING_ARM_unwind_once;
23575 type = SHT_ARM_EXIDX;
bfae80f2 23576 }
c19d1205 23577 else
bfae80f2 23578 {
c19d1205
ZW
23579 prefix = ELF_STRING_ARM_unwind_info;
23580 prefix_once = ELF_STRING_ARM_unwind_info_once;
23581 type = SHT_PROGBITS;
bfae80f2
RE
23582 }
23583
c19d1205
ZW
23584 text_name = segment_name (text_seg);
23585 if (streq (text_name, ".text"))
23586 text_name = "";
23587
23588 if (strncmp (text_name, ".gnu.linkonce.t.",
23589 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 23590 {
c19d1205
ZW
23591 prefix = prefix_once;
23592 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
23593 }
23594
29a2809e 23595 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 23596
c19d1205
ZW
23597 flags = SHF_ALLOC;
23598 linkonce = 0;
23599 group_name = 0;
bfae80f2 23600
c19d1205
ZW
23601 /* Handle COMDAT group. */
23602 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 23603 {
c19d1205
ZW
23604 group_name = elf_group_name (text_seg);
23605 if (group_name == NULL)
23606 {
bd3ba5d1 23607 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
23608 segment_name (text_seg));
23609 ignore_rest_of_line ();
23610 return;
23611 }
23612 flags |= SHF_GROUP;
23613 linkonce = 1;
bfae80f2
RE
23614 }
23615
a91e1603
L
23616 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
23617 linkonce, 0);
bfae80f2 23618
5f4273c7 23619 /* Set the section link for index tables. */
c19d1205
ZW
23620 if (idx)
23621 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
23622}
23623
bfae80f2 23624
c19d1205
ZW
23625/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
23626 personality routine data. Returns zero, or the index table value for
cad0da33 23627 an inline entry. */
c19d1205
ZW
23628
23629static valueT
23630create_unwind_entry (int have_data)
bfae80f2 23631{
c19d1205
ZW
23632 int size;
23633 addressT where;
23634 char *ptr;
23635 /* The current word of data. */
23636 valueT data;
23637 /* The number of bytes left in this word. */
23638 int n;
bfae80f2 23639
c19d1205 23640 finish_unwind_opcodes ();
bfae80f2 23641
c19d1205
ZW
23642 /* Remember the current text section. */
23643 unwind.saved_seg = now_seg;
23644 unwind.saved_subseg = now_subseg;
bfae80f2 23645
c19d1205 23646 start_unwind_section (now_seg, 0);
bfae80f2 23647
c19d1205 23648 if (unwind.personality_routine == NULL)
bfae80f2 23649 {
c19d1205
ZW
23650 if (unwind.personality_index == -2)
23651 {
23652 if (have_data)
5f4273c7 23653 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
23654 return 1; /* EXIDX_CANTUNWIND. */
23655 }
bfae80f2 23656
c19d1205
ZW
23657 /* Use a default personality routine if none is specified. */
23658 if (unwind.personality_index == -1)
23659 {
23660 if (unwind.opcode_count > 3)
23661 unwind.personality_index = 1;
23662 else
23663 unwind.personality_index = 0;
23664 }
bfae80f2 23665
c19d1205
ZW
23666 /* Space for the personality routine entry. */
23667 if (unwind.personality_index == 0)
23668 {
23669 if (unwind.opcode_count > 3)
23670 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 23671
c19d1205
ZW
23672 if (!have_data)
23673 {
23674 /* All the data is inline in the index table. */
23675 data = 0x80;
23676 n = 3;
23677 while (unwind.opcode_count > 0)
23678 {
23679 unwind.opcode_count--;
23680 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
23681 n--;
23682 }
bfae80f2 23683
c19d1205
ZW
23684 /* Pad with "finish" opcodes. */
23685 while (n--)
23686 data = (data << 8) | 0xb0;
bfae80f2 23687
c19d1205
ZW
23688 return data;
23689 }
23690 size = 0;
23691 }
23692 else
23693 /* We get two opcodes "free" in the first word. */
23694 size = unwind.opcode_count - 2;
23695 }
23696 else
5011093d 23697 {
cad0da33
NC
23698 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
23699 if (unwind.personality_index != -1)
23700 {
23701 as_bad (_("attempt to recreate an unwind entry"));
23702 return 1;
23703 }
5011093d
NC
23704
23705 /* An extra byte is required for the opcode count. */
23706 size = unwind.opcode_count + 1;
23707 }
bfae80f2 23708
c19d1205
ZW
23709 size = (size + 3) >> 2;
23710 if (size > 0xff)
23711 as_bad (_("too many unwind opcodes"));
bfae80f2 23712
c19d1205
ZW
23713 frag_align (2, 0, 0);
23714 record_alignment (now_seg, 2);
23715 unwind.table_entry = expr_build_dot ();
23716
23717 /* Allocate the table entry. */
23718 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
23719 /* PR 13449: Zero the table entries in case some of them are not used. */
23720 memset (ptr, 0, (size << 2) + 4);
c19d1205 23721 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 23722
c19d1205 23723 switch (unwind.personality_index)
bfae80f2 23724 {
c19d1205
ZW
23725 case -1:
23726 /* ??? Should this be a PLT generating relocation? */
23727 /* Custom personality routine. */
23728 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
23729 BFD_RELOC_ARM_PREL31);
bfae80f2 23730
c19d1205
ZW
23731 where += 4;
23732 ptr += 4;
bfae80f2 23733
c19d1205 23734 /* Set the first byte to the number of additional words. */
5011093d 23735 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
23736 n = 3;
23737 break;
bfae80f2 23738
c19d1205
ZW
23739 /* ABI defined personality routines. */
23740 case 0:
23741 /* Three opcodes bytes are packed into the first word. */
23742 data = 0x80;
23743 n = 3;
23744 break;
bfae80f2 23745
c19d1205
ZW
23746 case 1:
23747 case 2:
23748 /* The size and first two opcode bytes go in the first word. */
23749 data = ((0x80 + unwind.personality_index) << 8) | size;
23750 n = 2;
23751 break;
bfae80f2 23752
c19d1205
ZW
23753 default:
23754 /* Should never happen. */
23755 abort ();
23756 }
bfae80f2 23757
c19d1205
ZW
23758 /* Pack the opcodes into words (MSB first), reversing the list at the same
23759 time. */
23760 while (unwind.opcode_count > 0)
23761 {
23762 if (n == 0)
23763 {
23764 md_number_to_chars (ptr, data, 4);
23765 ptr += 4;
23766 n = 4;
23767 data = 0;
23768 }
23769 unwind.opcode_count--;
23770 n--;
23771 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
23772 }
23773
23774 /* Finish off the last word. */
23775 if (n < 4)
23776 {
23777 /* Pad with "finish" opcodes. */
23778 while (n--)
23779 data = (data << 8) | 0xb0;
23780
23781 md_number_to_chars (ptr, data, 4);
23782 }
23783
23784 if (!have_data)
23785 {
23786 /* Add an empty descriptor if there is no user-specified data. */
23787 ptr = frag_more (4);
23788 md_number_to_chars (ptr, 0, 4);
23789 }
23790
23791 return 0;
bfae80f2
RE
23792}
23793
f0927246
NC
23794
23795/* Initialize the DWARF-2 unwind information for this procedure. */
23796
23797void
23798tc_arm_frame_initial_instructions (void)
23799{
23800 cfi_add_CFA_def_cfa (REG_SP, 0);
23801}
23802#endif /* OBJ_ELF */
23803
c19d1205
ZW
23804/* Convert REGNAME to a DWARF-2 register number. */
23805
23806int
1df69f4f 23807tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 23808{
1df69f4f 23809 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
23810 if (reg != FAIL)
23811 return reg;
c19d1205 23812
1f5afe1c
NC
23813 /* PR 16694: Allow VFP registers as well. */
23814 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
23815 if (reg != FAIL)
23816 return 64 + reg;
c19d1205 23817
1f5afe1c
NC
23818 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
23819 if (reg != FAIL)
23820 return reg + 256;
23821
0198d5e6 23822 return FAIL;
bfae80f2
RE
23823}
23824
f0927246 23825#ifdef TE_PE
c19d1205 23826void
f0927246 23827tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 23828{
91d6fa6a 23829 expressionS exp;
bfae80f2 23830
91d6fa6a
NC
23831 exp.X_op = O_secrel;
23832 exp.X_add_symbol = symbol;
23833 exp.X_add_number = 0;
23834 emit_expr (&exp, size);
f0927246
NC
23835}
23836#endif
bfae80f2 23837
c19d1205 23838/* MD interface: Symbol and relocation handling. */
bfae80f2 23839
2fc8bdac
ZW
23840/* Return the address within the segment that a PC-relative fixup is
23841 relative to. For ARM, PC-relative fixups applied to instructions
23842 are generally relative to the location of the fixup plus 8 bytes.
23843 Thumb branches are offset by 4, and Thumb loads relative to PC
23844 require special handling. */
bfae80f2 23845
c19d1205 23846long
2fc8bdac 23847md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 23848{
2fc8bdac
ZW
23849 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
23850
23851 /* If this is pc-relative and we are going to emit a relocation
23852 then we just want to put out any pipeline compensation that the linker
53baae48
NC
23853 will need. Otherwise we want to use the calculated base.
23854 For WinCE we skip the bias for externals as well, since this
23855 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 23856 if (fixP->fx_pcrel
2fc8bdac 23857 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
23858 || (arm_force_relocation (fixP)
23859#ifdef TE_WINCE
23860 && !S_IS_EXTERNAL (fixP->fx_addsy)
23861#endif
23862 )))
2fc8bdac 23863 base = 0;
bfae80f2 23864
267bf995 23865
c19d1205 23866 switch (fixP->fx_r_type)
bfae80f2 23867 {
2fc8bdac
ZW
23868 /* PC relative addressing on the Thumb is slightly odd as the
23869 bottom two bits of the PC are forced to zero for the
23870 calculation. This happens *after* application of the
23871 pipeline offset. However, Thumb adrl already adjusts for
23872 this, so we need not do it again. */
c19d1205 23873 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 23874 return base & ~3;
c19d1205
ZW
23875
23876 case BFD_RELOC_ARM_THUMB_OFFSET:
23877 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 23878 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 23879 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 23880 return (base + 4) & ~3;
c19d1205 23881
2fc8bdac 23882 /* Thumb branches are simply offset by +4. */
e12437dc 23883 case BFD_RELOC_THUMB_PCREL_BRANCH5:
2fc8bdac
ZW
23884 case BFD_RELOC_THUMB_PCREL_BRANCH7:
23885 case BFD_RELOC_THUMB_PCREL_BRANCH9:
23886 case BFD_RELOC_THUMB_PCREL_BRANCH12:
23887 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 23888 case BFD_RELOC_THUMB_PCREL_BRANCH25:
f6b2b12d 23889 case BFD_RELOC_THUMB_PCREL_BFCSEL:
e5d6e09e 23890 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 23891 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 23892 case BFD_RELOC_ARM_THUMB_BF13:
60f993ce 23893 case BFD_RELOC_ARM_THUMB_LOOP12:
2fc8bdac 23894 return base + 4;
bfae80f2 23895
267bf995 23896 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
23897 if (fixP->fx_addsy
23898 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23899 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 23900 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
23901 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23902 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
23903 return base + 4;
23904
00adf2d4
JB
23905 /* BLX is like branches above, but forces the low two bits of PC to
23906 zero. */
486499d0
CL
23907 case BFD_RELOC_THUMB_PCREL_BLX:
23908 if (fixP->fx_addsy
23909 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23910 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
23911 && THUMB_IS_FUNC (fixP->fx_addsy)
23912 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23913 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
23914 return (base + 4) & ~3;
23915
2fc8bdac
ZW
23916 /* ARM mode branches are offset by +8. However, the Windows CE
23917 loader expects the relocation not to take this into account. */
267bf995 23918 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
23919 if (fixP->fx_addsy
23920 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23921 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
23922 && ARM_IS_FUNC (fixP->fx_addsy)
23923 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23924 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 23925 return base + 8;
267bf995 23926
486499d0
CL
23927 case BFD_RELOC_ARM_PCREL_CALL:
23928 if (fixP->fx_addsy
23929 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23930 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
23931 && THUMB_IS_FUNC (fixP->fx_addsy)
23932 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23933 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 23934 return base + 8;
267bf995 23935
2fc8bdac 23936 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 23937 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 23938 case BFD_RELOC_ARM_PLT32:
c19d1205 23939#ifdef TE_WINCE
5f4273c7 23940 /* When handling fixups immediately, because we have already
477330fc 23941 discovered the value of a symbol, or the address of the frag involved
53baae48 23942 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
23943 see fixup_segment() in write.c
23944 The S_IS_EXTERNAL test handles the case of global symbols.
23945 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
23946 if (fixP->fx_pcrel
23947 && fixP->fx_addsy != NULL
23948 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23949 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
23950 return base + 8;
2fc8bdac 23951 return base;
c19d1205 23952#else
2fc8bdac 23953 return base + 8;
c19d1205 23954#endif
2fc8bdac 23955
267bf995 23956
2fc8bdac
ZW
23957 /* ARM mode loads relative to PC are also offset by +8. Unlike
23958 branches, the Windows CE loader *does* expect the relocation
23959 to take this into account. */
23960 case BFD_RELOC_ARM_OFFSET_IMM:
23961 case BFD_RELOC_ARM_OFFSET_IMM8:
23962 case BFD_RELOC_ARM_HWLITERAL:
23963 case BFD_RELOC_ARM_LITERAL:
23964 case BFD_RELOC_ARM_CP_OFF_IMM:
23965 return base + 8;
23966
23967
23968 /* Other PC-relative relocations are un-offset. */
23969 default:
23970 return base;
23971 }
bfae80f2
RE
23972}
23973
8b2d793c
NC
23974static bfd_boolean flag_warn_syms = TRUE;
23975
ae8714c2
NC
23976bfd_boolean
23977arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 23978{
8b2d793c
NC
23979 /* PR 18347 - Warn if the user attempts to create a symbol with the same
23980 name as an ARM instruction. Whilst strictly speaking it is allowed, it
23981 does mean that the resulting code might be very confusing to the reader.
23982 Also this warning can be triggered if the user omits an operand before
23983 an immediate address, eg:
23984
23985 LDR =foo
23986
23987 GAS treats this as an assignment of the value of the symbol foo to a
23988 symbol LDR, and so (without this code) it will not issue any kind of
23989 warning or error message.
23990
23991 Note - ARM instructions are case-insensitive but the strings in the hash
23992 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
23993 lower case too. */
23994 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
23995 {
23996 char * nbuf = strdup (name);
23997 char * p;
23998
23999 for (p = nbuf; *p; p++)
24000 *p = TOLOWER (*p);
24001 if (hash_find (arm_ops_hsh, nbuf) != NULL)
24002 {
24003 static struct hash_control * already_warned = NULL;
24004
24005 if (already_warned == NULL)
24006 already_warned = hash_new ();
24007 /* Only warn about the symbol once. To keep the code
24008 simple we let hash_insert do the lookup for us. */
3076e594 24009 if (hash_insert (already_warned, nbuf, NULL) == NULL)
ae8714c2 24010 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
24011 }
24012 else
24013 free (nbuf);
24014 }
3739860c 24015
ae8714c2
NC
24016 return FALSE;
24017}
24018
24019/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
24020 Otherwise we have no need to default values of symbols. */
24021
24022symbolS *
24023md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
24024{
24025#ifdef OBJ_ELF
24026 if (name[0] == '_' && name[1] == 'G'
24027 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
24028 {
24029 if (!GOT_symbol)
24030 {
24031 if (symbol_find (name))
24032 as_bad (_("GOT already in the symbol table"));
24033
24034 GOT_symbol = symbol_new (name, undefined_section,
24035 (valueT) 0, & zero_address_frag);
24036 }
24037
24038 return GOT_symbol;
24039 }
24040#endif
24041
c921be7d 24042 return NULL;
bfae80f2
RE
24043}
24044
55cf6793 24045/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
24046 computed as two separate immediate values, added together. We
24047 already know that this value cannot be computed by just one ARM
24048 instruction. */
24049
24050static unsigned int
24051validate_immediate_twopart (unsigned int val,
24052 unsigned int * highpart)
bfae80f2 24053{
c19d1205
ZW
24054 unsigned int a;
24055 unsigned int i;
bfae80f2 24056
c19d1205
ZW
24057 for (i = 0; i < 32; i += 2)
24058 if (((a = rotate_left (val, i)) & 0xff) != 0)
24059 {
24060 if (a & 0xff00)
24061 {
24062 if (a & ~ 0xffff)
24063 continue;
24064 * highpart = (a >> 8) | ((i + 24) << 7);
24065 }
24066 else if (a & 0xff0000)
24067 {
24068 if (a & 0xff000000)
24069 continue;
24070 * highpart = (a >> 16) | ((i + 16) << 7);
24071 }
24072 else
24073 {
9c2799c2 24074 gas_assert (a & 0xff000000);
c19d1205
ZW
24075 * highpart = (a >> 24) | ((i + 8) << 7);
24076 }
bfae80f2 24077
c19d1205
ZW
24078 return (a & 0xff) | (i << 7);
24079 }
bfae80f2 24080
c19d1205 24081 return FAIL;
bfae80f2
RE
24082}
24083
c19d1205
ZW
24084static int
24085validate_offset_imm (unsigned int val, int hwse)
24086{
24087 if ((hwse && val > 255) || val > 4095)
24088 return FAIL;
24089 return val;
24090}
bfae80f2 24091
55cf6793 24092/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
24093 negative immediate constant by altering the instruction. A bit of
24094 a hack really.
24095 MOV <-> MVN
24096 AND <-> BIC
24097 ADC <-> SBC
24098 by inverting the second operand, and
24099 ADD <-> SUB
24100 CMP <-> CMN
24101 by negating the second operand. */
bfae80f2 24102
c19d1205
ZW
24103static int
24104negate_data_op (unsigned long * instruction,
24105 unsigned long value)
bfae80f2 24106{
c19d1205
ZW
24107 int op, new_inst;
24108 unsigned long negated, inverted;
bfae80f2 24109
c19d1205
ZW
24110 negated = encode_arm_immediate (-value);
24111 inverted = encode_arm_immediate (~value);
bfae80f2 24112
c19d1205
ZW
24113 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
24114 switch (op)
bfae80f2 24115 {
c19d1205
ZW
24116 /* First negates. */
24117 case OPCODE_SUB: /* ADD <-> SUB */
24118 new_inst = OPCODE_ADD;
24119 value = negated;
24120 break;
bfae80f2 24121
c19d1205
ZW
24122 case OPCODE_ADD:
24123 new_inst = OPCODE_SUB;
24124 value = negated;
24125 break;
bfae80f2 24126
c19d1205
ZW
24127 case OPCODE_CMP: /* CMP <-> CMN */
24128 new_inst = OPCODE_CMN;
24129 value = negated;
24130 break;
bfae80f2 24131
c19d1205
ZW
24132 case OPCODE_CMN:
24133 new_inst = OPCODE_CMP;
24134 value = negated;
24135 break;
bfae80f2 24136
c19d1205
ZW
24137 /* Now Inverted ops. */
24138 case OPCODE_MOV: /* MOV <-> MVN */
24139 new_inst = OPCODE_MVN;
24140 value = inverted;
24141 break;
bfae80f2 24142
c19d1205
ZW
24143 case OPCODE_MVN:
24144 new_inst = OPCODE_MOV;
24145 value = inverted;
24146 break;
bfae80f2 24147
c19d1205
ZW
24148 case OPCODE_AND: /* AND <-> BIC */
24149 new_inst = OPCODE_BIC;
24150 value = inverted;
24151 break;
bfae80f2 24152
c19d1205
ZW
24153 case OPCODE_BIC:
24154 new_inst = OPCODE_AND;
24155 value = inverted;
24156 break;
bfae80f2 24157
c19d1205
ZW
24158 case OPCODE_ADC: /* ADC <-> SBC */
24159 new_inst = OPCODE_SBC;
24160 value = inverted;
24161 break;
bfae80f2 24162
c19d1205
ZW
24163 case OPCODE_SBC:
24164 new_inst = OPCODE_ADC;
24165 value = inverted;
24166 break;
bfae80f2 24167
c19d1205
ZW
24168 /* We cannot do anything. */
24169 default:
24170 return FAIL;
b99bd4ef
NC
24171 }
24172
c19d1205
ZW
24173 if (value == (unsigned) FAIL)
24174 return FAIL;
24175
24176 *instruction &= OPCODE_MASK;
24177 *instruction |= new_inst << DATA_OP_SHIFT;
24178 return value;
b99bd4ef
NC
24179}
24180
ef8d22e6
PB
24181/* Like negate_data_op, but for Thumb-2. */
24182
24183static unsigned int
16dd5e42 24184thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
24185{
24186 int op, new_inst;
24187 int rd;
16dd5e42 24188 unsigned int negated, inverted;
ef8d22e6
PB
24189
24190 negated = encode_thumb32_immediate (-value);
24191 inverted = encode_thumb32_immediate (~value);
24192
24193 rd = (*instruction >> 8) & 0xf;
24194 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
24195 switch (op)
24196 {
24197 /* ADD <-> SUB. Includes CMP <-> CMN. */
24198 case T2_OPCODE_SUB:
24199 new_inst = T2_OPCODE_ADD;
24200 value = negated;
24201 break;
24202
24203 case T2_OPCODE_ADD:
24204 new_inst = T2_OPCODE_SUB;
24205 value = negated;
24206 break;
24207
24208 /* ORR <-> ORN. Includes MOV <-> MVN. */
24209 case T2_OPCODE_ORR:
24210 new_inst = T2_OPCODE_ORN;
24211 value = inverted;
24212 break;
24213
24214 case T2_OPCODE_ORN:
24215 new_inst = T2_OPCODE_ORR;
24216 value = inverted;
24217 break;
24218
24219 /* AND <-> BIC. TST has no inverted equivalent. */
24220 case T2_OPCODE_AND:
24221 new_inst = T2_OPCODE_BIC;
24222 if (rd == 15)
24223 value = FAIL;
24224 else
24225 value = inverted;
24226 break;
24227
24228 case T2_OPCODE_BIC:
24229 new_inst = T2_OPCODE_AND;
24230 value = inverted;
24231 break;
24232
24233 /* ADC <-> SBC */
24234 case T2_OPCODE_ADC:
24235 new_inst = T2_OPCODE_SBC;
24236 value = inverted;
24237 break;
24238
24239 case T2_OPCODE_SBC:
24240 new_inst = T2_OPCODE_ADC;
24241 value = inverted;
24242 break;
24243
24244 /* We cannot do anything. */
24245 default:
24246 return FAIL;
24247 }
24248
16dd5e42 24249 if (value == (unsigned int)FAIL)
ef8d22e6
PB
24250 return FAIL;
24251
24252 *instruction &= T2_OPCODE_MASK;
24253 *instruction |= new_inst << T2_DATA_OP_SHIFT;
24254 return value;
24255}
24256
8f06b2d8 24257/* Read a 32-bit thumb instruction from buf. */
0198d5e6 24258
8f06b2d8
PB
24259static unsigned long
24260get_thumb32_insn (char * buf)
24261{
24262 unsigned long insn;
24263 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
24264 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24265
24266 return insn;
24267}
24268
a8bc6c78
PB
24269/* We usually want to set the low bit on the address of thumb function
24270 symbols. In particular .word foo - . should have the low bit set.
24271 Generic code tries to fold the difference of two symbols to
24272 a constant. Prevent this and force a relocation when the first symbols
24273 is a thumb function. */
c921be7d
NC
24274
24275bfd_boolean
a8bc6c78
PB
24276arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
24277{
24278 if (op == O_subtract
24279 && l->X_op == O_symbol
24280 && r->X_op == O_symbol
24281 && THUMB_IS_FUNC (l->X_add_symbol))
24282 {
24283 l->X_op = O_subtract;
24284 l->X_op_symbol = r->X_add_symbol;
24285 l->X_add_number -= r->X_add_number;
c921be7d 24286 return TRUE;
a8bc6c78 24287 }
c921be7d 24288
a8bc6c78 24289 /* Process as normal. */
c921be7d 24290 return FALSE;
a8bc6c78
PB
24291}
24292
4a42ebbc
RR
24293/* Encode Thumb2 unconditional branches and calls. The encoding
24294 for the 2 are identical for the immediate values. */
24295
24296static void
24297encode_thumb2_b_bl_offset (char * buf, offsetT value)
24298{
24299#define T2I1I2MASK ((1 << 13) | (1 << 11))
24300 offsetT newval;
24301 offsetT newval2;
24302 addressT S, I1, I2, lo, hi;
24303
24304 S = (value >> 24) & 0x01;
24305 I1 = (value >> 23) & 0x01;
24306 I2 = (value >> 22) & 0x01;
24307 hi = (value >> 12) & 0x3ff;
fa94de6b 24308 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
24309 newval = md_chars_to_number (buf, THUMB_SIZE);
24310 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24311 newval |= (S << 10) | hi;
24312 newval2 &= ~T2I1I2MASK;
24313 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
24314 md_number_to_chars (buf, newval, THUMB_SIZE);
24315 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
24316}
24317
c19d1205 24318void
55cf6793 24319md_apply_fix (fixS * fixP,
c19d1205
ZW
24320 valueT * valP,
24321 segT seg)
24322{
24323 offsetT value = * valP;
24324 offsetT newval;
24325 unsigned int newimm;
24326 unsigned long temp;
24327 int sign;
24328 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 24329
9c2799c2 24330 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 24331
c19d1205 24332 /* Note whether this will delete the relocation. */
4962c51a 24333
c19d1205
ZW
24334 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
24335 fixP->fx_done = 1;
b99bd4ef 24336
adbaf948 24337 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 24338 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
24339 for emit_reloc. */
24340 value &= 0xffffffff;
24341 value ^= 0x80000000;
5f4273c7 24342 value -= 0x80000000;
adbaf948
ZW
24343
24344 *valP = value;
c19d1205 24345 fixP->fx_addnumber = value;
b99bd4ef 24346
adbaf948
ZW
24347 /* Same treatment for fixP->fx_offset. */
24348 fixP->fx_offset &= 0xffffffff;
24349 fixP->fx_offset ^= 0x80000000;
24350 fixP->fx_offset -= 0x80000000;
24351
c19d1205 24352 switch (fixP->fx_r_type)
b99bd4ef 24353 {
c19d1205
ZW
24354 case BFD_RELOC_NONE:
24355 /* This will need to go in the object file. */
24356 fixP->fx_done = 0;
24357 break;
b99bd4ef 24358
c19d1205
ZW
24359 case BFD_RELOC_ARM_IMMEDIATE:
24360 /* We claim that this fixup has been processed here,
24361 even if in fact we generate an error because we do
24362 not have a reloc for it, so tc_gen_reloc will reject it. */
24363 fixP->fx_done = 1;
b99bd4ef 24364
77db8e2e 24365 if (fixP->fx_addsy)
b99bd4ef 24366 {
77db8e2e 24367 const char *msg = 0;
b99bd4ef 24368
77db8e2e
NC
24369 if (! S_IS_DEFINED (fixP->fx_addsy))
24370 msg = _("undefined symbol %s used as an immediate value");
24371 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
24372 msg = _("symbol %s is in a different section");
24373 else if (S_IS_WEAK (fixP->fx_addsy))
24374 msg = _("symbol %s is weak and may be overridden later");
24375
24376 if (msg)
24377 {
24378 as_bad_where (fixP->fx_file, fixP->fx_line,
24379 msg, S_GET_NAME (fixP->fx_addsy));
24380 break;
24381 }
42e5fcbf
AS
24382 }
24383
c19d1205
ZW
24384 temp = md_chars_to_number (buf, INSN_SIZE);
24385
5e73442d
SL
24386 /* If the offset is negative, we should use encoding A2 for ADR. */
24387 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
24388 newimm = negate_data_op (&temp, value);
24389 else
24390 {
24391 newimm = encode_arm_immediate (value);
24392
24393 /* If the instruction will fail, see if we can fix things up by
24394 changing the opcode. */
24395 if (newimm == (unsigned int) FAIL)
24396 newimm = negate_data_op (&temp, value);
bada4342
JW
24397 /* MOV accepts both ARM modified immediate (A1 encoding) and
24398 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
24399 When disassembling, MOV is preferred when there is no encoding
24400 overlap. */
24401 if (newimm == (unsigned int) FAIL
24402 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
24403 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
24404 && !((temp >> SBIT_SHIFT) & 0x1)
24405 && value >= 0 && value <= 0xffff)
24406 {
24407 /* Clear bits[23:20] to change encoding from A1 to A2. */
24408 temp &= 0xff0fffff;
24409 /* Encoding high 4bits imm. Code below will encode the remaining
24410 low 12bits. */
24411 temp |= (value & 0x0000f000) << 4;
24412 newimm = value & 0x00000fff;
24413 }
5e73442d
SL
24414 }
24415
24416 if (newimm == (unsigned int) FAIL)
b99bd4ef 24417 {
c19d1205
ZW
24418 as_bad_where (fixP->fx_file, fixP->fx_line,
24419 _("invalid constant (%lx) after fixup"),
24420 (unsigned long) value);
24421 break;
b99bd4ef 24422 }
b99bd4ef 24423
c19d1205
ZW
24424 newimm |= (temp & 0xfffff000);
24425 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
24426 break;
b99bd4ef 24427
c19d1205
ZW
24428 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24429 {
24430 unsigned int highpart = 0;
24431 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 24432
77db8e2e 24433 if (fixP->fx_addsy)
42e5fcbf 24434 {
77db8e2e 24435 const char *msg = 0;
42e5fcbf 24436
77db8e2e
NC
24437 if (! S_IS_DEFINED (fixP->fx_addsy))
24438 msg = _("undefined symbol %s used as an immediate value");
24439 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
24440 msg = _("symbol %s is in a different section");
24441 else if (S_IS_WEAK (fixP->fx_addsy))
24442 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 24443
77db8e2e
NC
24444 if (msg)
24445 {
24446 as_bad_where (fixP->fx_file, fixP->fx_line,
24447 msg, S_GET_NAME (fixP->fx_addsy));
24448 break;
24449 }
24450 }
fa94de6b 24451
c19d1205
ZW
24452 newimm = encode_arm_immediate (value);
24453 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 24454
c19d1205
ZW
24455 /* If the instruction will fail, see if we can fix things up by
24456 changing the opcode. */
24457 if (newimm == (unsigned int) FAIL
24458 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
24459 {
24460 /* No ? OK - try using two ADD instructions to generate
24461 the value. */
24462 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 24463
c19d1205
ZW
24464 /* Yes - then make sure that the second instruction is
24465 also an add. */
24466 if (newimm != (unsigned int) FAIL)
24467 newinsn = temp;
24468 /* Still No ? Try using a negated value. */
24469 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
24470 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
24471 /* Otherwise - give up. */
24472 else
24473 {
24474 as_bad_where (fixP->fx_file, fixP->fx_line,
24475 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
24476 (long) value);
24477 break;
24478 }
b99bd4ef 24479
c19d1205
ZW
24480 /* Replace the first operand in the 2nd instruction (which
24481 is the PC) with the destination register. We have
24482 already added in the PC in the first instruction and we
24483 do not want to do it again. */
24484 newinsn &= ~ 0xf0000;
24485 newinsn |= ((newinsn & 0x0f000) << 4);
24486 }
b99bd4ef 24487
c19d1205
ZW
24488 newimm |= (temp & 0xfffff000);
24489 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 24490
c19d1205
ZW
24491 highpart |= (newinsn & 0xfffff000);
24492 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
24493 }
24494 break;
b99bd4ef 24495
c19d1205 24496 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24497 if (!fixP->fx_done && seg->use_rela_p)
24498 value = 0;
1a0670f3 24499 /* Fall through. */
00a97672 24500
c19d1205 24501 case BFD_RELOC_ARM_LITERAL:
26d97720 24502 sign = value > 0;
b99bd4ef 24503
c19d1205
ZW
24504 if (value < 0)
24505 value = - value;
b99bd4ef 24506
c19d1205 24507 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 24508 {
c19d1205
ZW
24509 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
24510 as_bad_where (fixP->fx_file, fixP->fx_line,
24511 _("invalid literal constant: pool needs to be closer"));
24512 else
24513 as_bad_where (fixP->fx_file, fixP->fx_line,
24514 _("bad immediate value for offset (%ld)"),
24515 (long) value);
24516 break;
f03698e6
RE
24517 }
24518
c19d1205 24519 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
24520 if (value == 0)
24521 newval &= 0xfffff000;
24522 else
24523 {
24524 newval &= 0xff7ff000;
24525 newval |= value | (sign ? INDEX_UP : 0);
24526 }
c19d1205
ZW
24527 md_number_to_chars (buf, newval, INSN_SIZE);
24528 break;
b99bd4ef 24529
c19d1205
ZW
24530 case BFD_RELOC_ARM_OFFSET_IMM8:
24531 case BFD_RELOC_ARM_HWLITERAL:
26d97720 24532 sign = value > 0;
b99bd4ef 24533
c19d1205
ZW
24534 if (value < 0)
24535 value = - value;
b99bd4ef 24536
c19d1205 24537 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 24538 {
c19d1205
ZW
24539 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
24540 as_bad_where (fixP->fx_file, fixP->fx_line,
24541 _("invalid literal constant: pool needs to be closer"));
24542 else
427d0db6
RM
24543 as_bad_where (fixP->fx_file, fixP->fx_line,
24544 _("bad immediate value for 8-bit offset (%ld)"),
24545 (long) value);
c19d1205 24546 break;
b99bd4ef
NC
24547 }
24548
c19d1205 24549 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
24550 if (value == 0)
24551 newval &= 0xfffff0f0;
24552 else
24553 {
24554 newval &= 0xff7ff0f0;
24555 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
24556 }
c19d1205
ZW
24557 md_number_to_chars (buf, newval, INSN_SIZE);
24558 break;
b99bd4ef 24559
c19d1205
ZW
24560 case BFD_RELOC_ARM_T32_OFFSET_U8:
24561 if (value < 0 || value > 1020 || value % 4 != 0)
24562 as_bad_where (fixP->fx_file, fixP->fx_line,
24563 _("bad immediate value for offset (%ld)"), (long) value);
24564 value /= 4;
b99bd4ef 24565
c19d1205 24566 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
24567 newval |= value;
24568 md_number_to_chars (buf+2, newval, THUMB_SIZE);
24569 break;
b99bd4ef 24570
c19d1205
ZW
24571 case BFD_RELOC_ARM_T32_OFFSET_IMM:
24572 /* This is a complicated relocation used for all varieties of Thumb32
24573 load/store instruction with immediate offset:
24574
24575 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 24576 *4, optional writeback(W)
c19d1205
ZW
24577 (doubleword load/store)
24578
24579 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
24580 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
24581 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
24582 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
24583 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
24584
24585 Uppercase letters indicate bits that are already encoded at
24586 this point. Lowercase letters are our problem. For the
24587 second block of instructions, the secondary opcode nybble
24588 (bits 8..11) is present, and bit 23 is zero, even if this is
24589 a PC-relative operation. */
24590 newval = md_chars_to_number (buf, THUMB_SIZE);
24591 newval <<= 16;
24592 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 24593
c19d1205 24594 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 24595 {
c19d1205
ZW
24596 /* Doubleword load/store: 8-bit offset, scaled by 4. */
24597 if (value >= 0)
24598 newval |= (1 << 23);
24599 else
24600 value = -value;
24601 if (value % 4 != 0)
24602 {
24603 as_bad_where (fixP->fx_file, fixP->fx_line,
24604 _("offset not a multiple of 4"));
24605 break;
24606 }
24607 value /= 4;
216d22bc 24608 if (value > 0xff)
c19d1205
ZW
24609 {
24610 as_bad_where (fixP->fx_file, fixP->fx_line,
24611 _("offset out of range"));
24612 break;
24613 }
24614 newval &= ~0xff;
b99bd4ef 24615 }
c19d1205 24616 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 24617 {
c19d1205
ZW
24618 /* PC-relative, 12-bit offset. */
24619 if (value >= 0)
24620 newval |= (1 << 23);
24621 else
24622 value = -value;
216d22bc 24623 if (value > 0xfff)
c19d1205
ZW
24624 {
24625 as_bad_where (fixP->fx_file, fixP->fx_line,
24626 _("offset out of range"));
24627 break;
24628 }
24629 newval &= ~0xfff;
b99bd4ef 24630 }
c19d1205 24631 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 24632 {
c19d1205
ZW
24633 /* Writeback: 8-bit, +/- offset. */
24634 if (value >= 0)
24635 newval |= (1 << 9);
24636 else
24637 value = -value;
216d22bc 24638 if (value > 0xff)
c19d1205
ZW
24639 {
24640 as_bad_where (fixP->fx_file, fixP->fx_line,
24641 _("offset out of range"));
24642 break;
24643 }
24644 newval &= ~0xff;
b99bd4ef 24645 }
c19d1205 24646 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 24647 {
c19d1205 24648 /* T-instruction: positive 8-bit offset. */
216d22bc 24649 if (value < 0 || value > 0xff)
b99bd4ef 24650 {
c19d1205
ZW
24651 as_bad_where (fixP->fx_file, fixP->fx_line,
24652 _("offset out of range"));
24653 break;
b99bd4ef 24654 }
c19d1205
ZW
24655 newval &= ~0xff;
24656 newval |= value;
b99bd4ef
NC
24657 }
24658 else
b99bd4ef 24659 {
c19d1205
ZW
24660 /* Positive 12-bit or negative 8-bit offset. */
24661 int limit;
24662 if (value >= 0)
b99bd4ef 24663 {
c19d1205
ZW
24664 newval |= (1 << 23);
24665 limit = 0xfff;
24666 }
24667 else
24668 {
24669 value = -value;
24670 limit = 0xff;
24671 }
24672 if (value > limit)
24673 {
24674 as_bad_where (fixP->fx_file, fixP->fx_line,
24675 _("offset out of range"));
24676 break;
b99bd4ef 24677 }
c19d1205 24678 newval &= ~limit;
b99bd4ef 24679 }
b99bd4ef 24680
c19d1205
ZW
24681 newval |= value;
24682 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
24683 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
24684 break;
404ff6b5 24685
c19d1205
ZW
24686 case BFD_RELOC_ARM_SHIFT_IMM:
24687 newval = md_chars_to_number (buf, INSN_SIZE);
24688 if (((unsigned long) value) > 32
24689 || (value == 32
24690 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
24691 {
24692 as_bad_where (fixP->fx_file, fixP->fx_line,
24693 _("shift expression is too large"));
24694 break;
24695 }
404ff6b5 24696
c19d1205
ZW
24697 if (value == 0)
24698 /* Shifts of zero must be done as lsl. */
24699 newval &= ~0x60;
24700 else if (value == 32)
24701 value = 0;
24702 newval &= 0xfffff07f;
24703 newval |= (value & 0x1f) << 7;
24704 md_number_to_chars (buf, newval, INSN_SIZE);
24705 break;
404ff6b5 24706
c19d1205 24707 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 24708 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 24709 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 24710 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
24711 /* We claim that this fixup has been processed here,
24712 even if in fact we generate an error because we do
24713 not have a reloc for it, so tc_gen_reloc will reject it. */
24714 fixP->fx_done = 1;
404ff6b5 24715
c19d1205
ZW
24716 if (fixP->fx_addsy
24717 && ! S_IS_DEFINED (fixP->fx_addsy))
24718 {
24719 as_bad_where (fixP->fx_file, fixP->fx_line,
24720 _("undefined symbol %s used as an immediate value"),
24721 S_GET_NAME (fixP->fx_addsy));
24722 break;
24723 }
404ff6b5 24724
c19d1205
ZW
24725 newval = md_chars_to_number (buf, THUMB_SIZE);
24726 newval <<= 16;
24727 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 24728
16805f35 24729 newimm = FAIL;
bada4342
JW
24730 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24731 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
24732 Thumb2 modified immediate encoding (T2). */
24733 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 24734 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
24735 {
24736 newimm = encode_thumb32_immediate (value);
24737 if (newimm == (unsigned int) FAIL)
24738 newimm = thumb32_negate_data_op (&newval, value);
24739 }
bada4342 24740 if (newimm == (unsigned int) FAIL)
92e90b6e 24741 {
bada4342 24742 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 24743 {
bada4342
JW
24744 /* Turn add/sum into addw/subw. */
24745 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
24746 newval = (newval & 0xfeffffff) | 0x02000000;
24747 /* No flat 12-bit imm encoding for addsw/subsw. */
24748 if ((newval & 0x00100000) == 0)
40f246e3 24749 {
bada4342
JW
24750 /* 12 bit immediate for addw/subw. */
24751 if (value < 0)
24752 {
24753 value = -value;
24754 newval ^= 0x00a00000;
24755 }
24756 if (value > 0xfff)
24757 newimm = (unsigned int) FAIL;
24758 else
24759 newimm = value;
24760 }
24761 }
24762 else
24763 {
24764 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
24765 UINT16 (T3 encoding), MOVW only accepts UINT16. When
24766 disassembling, MOV is preferred when there is no encoding
db7bf105 24767 overlap. */
bada4342 24768 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
db7bf105
NC
24769 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
24770 but with the Rn field [19:16] set to 1111. */
24771 && (((newval >> 16) & 0xf) == 0xf)
bada4342
JW
24772 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
24773 && !((newval >> T2_SBIT_SHIFT) & 0x1)
db7bf105 24774 && value >= 0 && value <= 0xffff)
bada4342
JW
24775 {
24776 /* Toggle bit[25] to change encoding from T2 to T3. */
24777 newval ^= 1 << 25;
24778 /* Clear bits[19:16]. */
24779 newval &= 0xfff0ffff;
24780 /* Encoding high 4bits imm. Code below will encode the
24781 remaining low 12bits. */
24782 newval |= (value & 0x0000f000) << 4;
24783 newimm = value & 0x00000fff;
40f246e3 24784 }
e9f89963 24785 }
92e90b6e 24786 }
cc8a6dd0 24787
c19d1205 24788 if (newimm == (unsigned int)FAIL)
3631a3c8 24789 {
c19d1205
ZW
24790 as_bad_where (fixP->fx_file, fixP->fx_line,
24791 _("invalid constant (%lx) after fixup"),
24792 (unsigned long) value);
24793 break;
3631a3c8
NC
24794 }
24795
c19d1205
ZW
24796 newval |= (newimm & 0x800) << 15;
24797 newval |= (newimm & 0x700) << 4;
24798 newval |= (newimm & 0x0ff);
cc8a6dd0 24799
c19d1205
ZW
24800 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
24801 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
24802 break;
a737bd4d 24803
3eb17e6b 24804 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
24805 if (((unsigned long) value) > 0xffff)
24806 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 24807 _("invalid smc expression"));
2fc8bdac 24808 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
24809 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
24810 md_number_to_chars (buf, newval, INSN_SIZE);
24811 break;
a737bd4d 24812
90ec0d68
MGD
24813 case BFD_RELOC_ARM_HVC:
24814 if (((unsigned long) value) > 0xffff)
24815 as_bad_where (fixP->fx_file, fixP->fx_line,
24816 _("invalid hvc expression"));
24817 newval = md_chars_to_number (buf, INSN_SIZE);
24818 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
24819 md_number_to_chars (buf, newval, INSN_SIZE);
24820 break;
24821
c19d1205 24822 case BFD_RELOC_ARM_SWI:
adbaf948 24823 if (fixP->tc_fix_data != 0)
c19d1205
ZW
24824 {
24825 if (((unsigned long) value) > 0xff)
24826 as_bad_where (fixP->fx_file, fixP->fx_line,
24827 _("invalid swi expression"));
2fc8bdac 24828 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
24829 newval |= value;
24830 md_number_to_chars (buf, newval, THUMB_SIZE);
24831 }
24832 else
24833 {
24834 if (((unsigned long) value) > 0x00ffffff)
24835 as_bad_where (fixP->fx_file, fixP->fx_line,
24836 _("invalid swi expression"));
2fc8bdac 24837 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
24838 newval |= value;
24839 md_number_to_chars (buf, newval, INSN_SIZE);
24840 }
24841 break;
a737bd4d 24842
c19d1205
ZW
24843 case BFD_RELOC_ARM_MULTI:
24844 if (((unsigned long) value) > 0xffff)
24845 as_bad_where (fixP->fx_file, fixP->fx_line,
24846 _("invalid expression in load/store multiple"));
24847 newval = value | md_chars_to_number (buf, INSN_SIZE);
24848 md_number_to_chars (buf, newval, INSN_SIZE);
24849 break;
a737bd4d 24850
c19d1205 24851#ifdef OBJ_ELF
39b41c9c 24852 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
24853
24854 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
24855 && fixP->fx_addsy
34e77a92 24856 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24857 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24858 && THUMB_IS_FUNC (fixP->fx_addsy))
24859 /* Flip the bl to blx. This is a simple flip
24860 bit here because we generate PCREL_CALL for
24861 unconditional bls. */
24862 {
24863 newval = md_chars_to_number (buf, INSN_SIZE);
24864 newval = newval | 0x10000000;
24865 md_number_to_chars (buf, newval, INSN_SIZE);
24866 temp = 1;
24867 fixP->fx_done = 1;
24868 }
39b41c9c
PB
24869 else
24870 temp = 3;
24871 goto arm_branch_common;
24872
24873 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
24874 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
24875 && fixP->fx_addsy
34e77a92 24876 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24877 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24878 && THUMB_IS_FUNC (fixP->fx_addsy))
24879 {
24880 /* This would map to a bl<cond>, b<cond>,
24881 b<always> to a Thumb function. We
24882 need to force a relocation for this particular
24883 case. */
24884 newval = md_chars_to_number (buf, INSN_SIZE);
24885 fixP->fx_done = 0;
24886 }
1a0670f3 24887 /* Fall through. */
267bf995 24888
2fc8bdac 24889 case BFD_RELOC_ARM_PLT32:
c19d1205 24890#endif
39b41c9c
PB
24891 case BFD_RELOC_ARM_PCREL_BRANCH:
24892 temp = 3;
24893 goto arm_branch_common;
a737bd4d 24894
39b41c9c 24895 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 24896
39b41c9c 24897 temp = 1;
267bf995
RR
24898 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
24899 && fixP->fx_addsy
34e77a92 24900 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24901 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24902 && ARM_IS_FUNC (fixP->fx_addsy))
24903 {
24904 /* Flip the blx to a bl and warn. */
24905 const char *name = S_GET_NAME (fixP->fx_addsy);
24906 newval = 0xeb000000;
24907 as_warn_where (fixP->fx_file, fixP->fx_line,
24908 _("blx to '%s' an ARM ISA state function changed to bl"),
24909 name);
24910 md_number_to_chars (buf, newval, INSN_SIZE);
24911 temp = 3;
24912 fixP->fx_done = 1;
24913 }
24914
24915#ifdef OBJ_ELF
24916 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 24917 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
24918#endif
24919
39b41c9c 24920 arm_branch_common:
c19d1205 24921 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
24922 instruction, in a 24 bit, signed field. Bits 26 through 32 either
24923 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 24924 also be clear. */
39b41c9c 24925 if (value & temp)
c19d1205 24926 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
24927 _("misaligned branch destination"));
24928 if ((value & (offsetT)0xfe000000) != (offsetT)0
24929 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 24930 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 24931
2fc8bdac 24932 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 24933 {
2fc8bdac
ZW
24934 newval = md_chars_to_number (buf, INSN_SIZE);
24935 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
24936 /* Set the H bit on BLX instructions. */
24937 if (temp == 1)
24938 {
24939 if (value & 2)
24940 newval |= 0x01000000;
24941 else
24942 newval &= ~0x01000000;
24943 }
2fc8bdac 24944 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 24945 }
c19d1205 24946 break;
a737bd4d 24947
25fe350b
MS
24948 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
24949 /* CBZ can only branch forward. */
a737bd4d 24950
738755b0 24951 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
24952 (which, strictly speaking, are prohibited) will be turned into
24953 no-ops.
738755b0
MS
24954
24955 FIXME: It may be better to remove the instruction completely and
24956 perform relaxation. */
24957 if (value == -2)
2fc8bdac
ZW
24958 {
24959 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 24960 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
24961 md_number_to_chars (buf, newval, THUMB_SIZE);
24962 }
738755b0
MS
24963 else
24964 {
24965 if (value & ~0x7e)
08f10d51 24966 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 24967
477330fc 24968 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
24969 {
24970 newval = md_chars_to_number (buf, THUMB_SIZE);
24971 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
24972 md_number_to_chars (buf, newval, THUMB_SIZE);
24973 }
24974 }
c19d1205 24975 break;
a737bd4d 24976
c19d1205 24977 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 24978 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 24979 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 24980
2fc8bdac
ZW
24981 if (fixP->fx_done || !seg->use_rela_p)
24982 {
24983 newval = md_chars_to_number (buf, THUMB_SIZE);
24984 newval |= (value & 0x1ff) >> 1;
24985 md_number_to_chars (buf, newval, THUMB_SIZE);
24986 }
c19d1205 24987 break;
a737bd4d 24988
c19d1205 24989 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 24990 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 24991 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 24992
2fc8bdac
ZW
24993 if (fixP->fx_done || !seg->use_rela_p)
24994 {
24995 newval = md_chars_to_number (buf, THUMB_SIZE);
24996 newval |= (value & 0xfff) >> 1;
24997 md_number_to_chars (buf, newval, THUMB_SIZE);
24998 }
c19d1205 24999 break;
a737bd4d 25000
c19d1205 25001 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
25002 if (fixP->fx_addsy
25003 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 25004 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
25005 && ARM_IS_FUNC (fixP->fx_addsy)
25006 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
25007 {
25008 /* Force a relocation for a branch 20 bits wide. */
25009 fixP->fx_done = 0;
25010 }
08f10d51 25011 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
25012 as_bad_where (fixP->fx_file, fixP->fx_line,
25013 _("conditional branch out of range"));
404ff6b5 25014
2fc8bdac
ZW
25015 if (fixP->fx_done || !seg->use_rela_p)
25016 {
25017 offsetT newval2;
25018 addressT S, J1, J2, lo, hi;
404ff6b5 25019
2fc8bdac
ZW
25020 S = (value & 0x00100000) >> 20;
25021 J2 = (value & 0x00080000) >> 19;
25022 J1 = (value & 0x00040000) >> 18;
25023 hi = (value & 0x0003f000) >> 12;
25024 lo = (value & 0x00000ffe) >> 1;
6c43fab6 25025
2fc8bdac
ZW
25026 newval = md_chars_to_number (buf, THUMB_SIZE);
25027 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25028 newval |= (S << 10) | hi;
25029 newval2 |= (J1 << 13) | (J2 << 11) | lo;
25030 md_number_to_chars (buf, newval, THUMB_SIZE);
25031 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25032 }
c19d1205 25033 break;
6c43fab6 25034
c19d1205 25035 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
25036 /* If there is a blx from a thumb state function to
25037 another thumb function flip this to a bl and warn
25038 about it. */
25039
25040 if (fixP->fx_addsy
34e77a92 25041 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
25042 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25043 && THUMB_IS_FUNC (fixP->fx_addsy))
25044 {
25045 const char *name = S_GET_NAME (fixP->fx_addsy);
25046 as_warn_where (fixP->fx_file, fixP->fx_line,
25047 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
25048 name);
25049 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25050 newval = newval | 0x1000;
25051 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
25052 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
25053 fixP->fx_done = 1;
25054 }
25055
25056
25057 goto thumb_bl_common;
25058
c19d1205 25059 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
25060 /* A bl from Thumb state ISA to an internal ARM state function
25061 is converted to a blx. */
25062 if (fixP->fx_addsy
25063 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 25064 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
25065 && ARM_IS_FUNC (fixP->fx_addsy)
25066 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
25067 {
25068 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25069 newval = newval & ~0x1000;
25070 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
25071 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
25072 fixP->fx_done = 1;
25073 }
25074
25075 thumb_bl_common:
25076
2fc8bdac
ZW
25077 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
25078 /* For a BLX instruction, make sure that the relocation is rounded up
25079 to a word boundary. This follows the semantics of the instruction
25080 which specifies that bit 1 of the target address will come from bit
25081 1 of the base address. */
d406f3e4
JB
25082 value = (value + 3) & ~ 3;
25083
25084#ifdef OBJ_ELF
25085 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
25086 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
25087 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
25088#endif
404ff6b5 25089
2b2f5df9
NC
25090 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
25091 {
fc289b0a 25092 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
25093 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
25094 else if ((value & ~0x1ffffff)
25095 && ((value & ~0x1ffffff) != ~0x1ffffff))
25096 as_bad_where (fixP->fx_file, fixP->fx_line,
25097 _("Thumb2 branch out of range"));
25098 }
4a42ebbc
RR
25099
25100 if (fixP->fx_done || !seg->use_rela_p)
25101 encode_thumb2_b_bl_offset (buf, value);
25102
c19d1205 25103 break;
404ff6b5 25104
c19d1205 25105 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
25106 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
25107 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 25108
2fc8bdac 25109 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 25110 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 25111
2fc8bdac 25112 break;
a737bd4d 25113
2fc8bdac
ZW
25114 case BFD_RELOC_8:
25115 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 25116 *buf = value;
c19d1205 25117 break;
a737bd4d 25118
c19d1205 25119 case BFD_RELOC_16:
2fc8bdac 25120 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 25121 md_number_to_chars (buf, value, 2);
c19d1205 25122 break;
a737bd4d 25123
c19d1205 25124#ifdef OBJ_ELF
0855e32b
NS
25125 case BFD_RELOC_ARM_TLS_CALL:
25126 case BFD_RELOC_ARM_THM_TLS_CALL:
25127 case BFD_RELOC_ARM_TLS_DESCSEQ:
25128 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 25129 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
25130 case BFD_RELOC_ARM_TLS_GD32:
25131 case BFD_RELOC_ARM_TLS_LE32:
25132 case BFD_RELOC_ARM_TLS_IE32:
25133 case BFD_RELOC_ARM_TLS_LDM32:
25134 case BFD_RELOC_ARM_TLS_LDO32:
25135 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 25136 break;
6c43fab6 25137
5c5a4843
CL
25138 /* Same handling as above, but with the arm_fdpic guard. */
25139 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
25140 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
25141 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
25142 if (arm_fdpic)
25143 {
25144 S_SET_THREAD_LOCAL (fixP->fx_addsy);
25145 }
25146 else
25147 {
25148 as_bad_where (fixP->fx_file, fixP->fx_line,
25149 _("Relocation supported only in FDPIC mode"));
25150 }
25151 break;
25152
c19d1205
ZW
25153 case BFD_RELOC_ARM_GOT32:
25154 case BFD_RELOC_ARM_GOTOFF:
c19d1205 25155 break;
b43420e6
NC
25156
25157 case BFD_RELOC_ARM_GOT_PREL:
25158 if (fixP->fx_done || !seg->use_rela_p)
477330fc 25159 md_number_to_chars (buf, value, 4);
b43420e6
NC
25160 break;
25161
9a6f4e97
NS
25162 case BFD_RELOC_ARM_TARGET2:
25163 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
25164 addend here for REL targets, because it won't be written out
25165 during reloc processing later. */
9a6f4e97
NS
25166 if (fixP->fx_done || !seg->use_rela_p)
25167 md_number_to_chars (buf, fixP->fx_offset, 4);
25168 break;
188fd7ae
CL
25169
25170 /* Relocations for FDPIC. */
25171 case BFD_RELOC_ARM_GOTFUNCDESC:
25172 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
25173 case BFD_RELOC_ARM_FUNCDESC:
25174 if (arm_fdpic)
25175 {
25176 if (fixP->fx_done || !seg->use_rela_p)
25177 md_number_to_chars (buf, 0, 4);
25178 }
25179 else
25180 {
25181 as_bad_where (fixP->fx_file, fixP->fx_line,
25182 _("Relocation supported only in FDPIC mode"));
25183 }
25184 break;
c19d1205 25185#endif
6c43fab6 25186
c19d1205
ZW
25187 case BFD_RELOC_RVA:
25188 case BFD_RELOC_32:
25189 case BFD_RELOC_ARM_TARGET1:
25190 case BFD_RELOC_ARM_ROSEGREL32:
25191 case BFD_RELOC_ARM_SBREL32:
25192 case BFD_RELOC_32_PCREL:
f0927246
NC
25193#ifdef TE_PE
25194 case BFD_RELOC_32_SECREL:
25195#endif
2fc8bdac 25196 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
25197#ifdef TE_WINCE
25198 /* For WinCE we only do this for pcrel fixups. */
25199 if (fixP->fx_done || fixP->fx_pcrel)
25200#endif
25201 md_number_to_chars (buf, value, 4);
c19d1205 25202 break;
6c43fab6 25203
c19d1205
ZW
25204#ifdef OBJ_ELF
25205 case BFD_RELOC_ARM_PREL31:
2fc8bdac 25206 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
25207 {
25208 newval = md_chars_to_number (buf, 4) & 0x80000000;
25209 if ((value ^ (value >> 1)) & 0x40000000)
25210 {
25211 as_bad_where (fixP->fx_file, fixP->fx_line,
25212 _("rel31 relocation overflow"));
25213 }
25214 newval |= value & 0x7fffffff;
25215 md_number_to_chars (buf, newval, 4);
25216 }
25217 break;
c19d1205 25218#endif
a737bd4d 25219
c19d1205 25220 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 25221 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
32c36c3c 25222 case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM:
9db2f6b4
RL
25223 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
25224 newval = md_chars_to_number (buf, INSN_SIZE);
25225 else
25226 newval = get_thumb32_insn (buf);
25227 if ((newval & 0x0f200f00) == 0x0d000900)
25228 {
25229 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
25230 has permitted values that are multiples of 2, in the range 0
25231 to 510. */
25232 if (value < -510 || value > 510 || (value & 1))
25233 as_bad_where (fixP->fx_file, fixP->fx_line,
25234 _("co-processor offset out of range"));
25235 }
32c36c3c
AV
25236 else if ((newval & 0xfe001f80) == 0xec000f80)
25237 {
25238 if (value < -511 || value > 512 || (value & 3))
25239 as_bad_where (fixP->fx_file, fixP->fx_line,
25240 _("co-processor offset out of range"));
25241 }
9db2f6b4 25242 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
25243 as_bad_where (fixP->fx_file, fixP->fx_line,
25244 _("co-processor offset out of range"));
25245 cp_off_common:
26d97720 25246 sign = value > 0;
c19d1205
ZW
25247 if (value < 0)
25248 value = -value;
8f06b2d8
PB
25249 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
25250 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
25251 newval = md_chars_to_number (buf, INSN_SIZE);
25252 else
25253 newval = get_thumb32_insn (buf);
26d97720 25254 if (value == 0)
32c36c3c
AV
25255 {
25256 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
25257 newval &= 0xffffff80;
25258 else
25259 newval &= 0xffffff00;
25260 }
26d97720
NS
25261 else
25262 {
32c36c3c
AV
25263 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
25264 newval &= 0xff7fff80;
25265 else
25266 newval &= 0xff7fff00;
9db2f6b4
RL
25267 if ((newval & 0x0f200f00) == 0x0d000900)
25268 {
25269 /* This is a fp16 vstr/vldr.
25270
25271 It requires the immediate offset in the instruction is shifted
25272 left by 1 to be a half-word offset.
25273
25274 Here, left shift by 1 first, and later right shift by 2
25275 should get the right offset. */
25276 value <<= 1;
25277 }
26d97720
NS
25278 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
25279 }
8f06b2d8
PB
25280 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
25281 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
25282 md_number_to_chars (buf, newval, INSN_SIZE);
25283 else
25284 put_thumb32_insn (buf, newval);
c19d1205 25285 break;
a737bd4d 25286
c19d1205 25287 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 25288 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
25289 if (value < -255 || value > 255)
25290 as_bad_where (fixP->fx_file, fixP->fx_line,
25291 _("co-processor offset out of range"));
df7849c5 25292 value *= 4;
c19d1205 25293 goto cp_off_common;
6c43fab6 25294
c19d1205
ZW
25295 case BFD_RELOC_ARM_THUMB_OFFSET:
25296 newval = md_chars_to_number (buf, THUMB_SIZE);
25297 /* Exactly what ranges, and where the offset is inserted depends
25298 on the type of instruction, we can establish this from the
25299 top 4 bits. */
25300 switch (newval >> 12)
25301 {
25302 case 4: /* PC load. */
25303 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
25304 forced to zero for these loads; md_pcrel_from has already
25305 compensated for this. */
25306 if (value & 3)
25307 as_bad_where (fixP->fx_file, fixP->fx_line,
25308 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
25309 (((unsigned long) fixP->fx_frag->fr_address
25310 + (unsigned long) fixP->fx_where) & ~3)
25311 + (unsigned long) value);
a737bd4d 25312
c19d1205
ZW
25313 if (value & ~0x3fc)
25314 as_bad_where (fixP->fx_file, fixP->fx_line,
25315 _("invalid offset, value too big (0x%08lX)"),
25316 (long) value);
a737bd4d 25317
c19d1205
ZW
25318 newval |= value >> 2;
25319 break;
a737bd4d 25320
c19d1205
ZW
25321 case 9: /* SP load/store. */
25322 if (value & ~0x3fc)
25323 as_bad_where (fixP->fx_file, fixP->fx_line,
25324 _("invalid offset, value too big (0x%08lX)"),
25325 (long) value);
25326 newval |= value >> 2;
25327 break;
6c43fab6 25328
c19d1205
ZW
25329 case 6: /* Word load/store. */
25330 if (value & ~0x7c)
25331 as_bad_where (fixP->fx_file, fixP->fx_line,
25332 _("invalid offset, value too big (0x%08lX)"),
25333 (long) value);
25334 newval |= value << 4; /* 6 - 2. */
25335 break;
a737bd4d 25336
c19d1205
ZW
25337 case 7: /* Byte load/store. */
25338 if (value & ~0x1f)
25339 as_bad_where (fixP->fx_file, fixP->fx_line,
25340 _("invalid offset, value too big (0x%08lX)"),
25341 (long) value);
25342 newval |= value << 6;
25343 break;
a737bd4d 25344
c19d1205
ZW
25345 case 8: /* Halfword load/store. */
25346 if (value & ~0x3e)
25347 as_bad_where (fixP->fx_file, fixP->fx_line,
25348 _("invalid offset, value too big (0x%08lX)"),
25349 (long) value);
25350 newval |= value << 5; /* 6 - 1. */
25351 break;
a737bd4d 25352
c19d1205
ZW
25353 default:
25354 as_bad_where (fixP->fx_file, fixP->fx_line,
25355 "Unable to process relocation for thumb opcode: %lx",
25356 (unsigned long) newval);
25357 break;
25358 }
25359 md_number_to_chars (buf, newval, THUMB_SIZE);
25360 break;
a737bd4d 25361
c19d1205
ZW
25362 case BFD_RELOC_ARM_THUMB_ADD:
25363 /* This is a complicated relocation, since we use it for all of
25364 the following immediate relocations:
a737bd4d 25365
c19d1205
ZW
25366 3bit ADD/SUB
25367 8bit ADD/SUB
25368 9bit ADD/SUB SP word-aligned
25369 10bit ADD PC/SP word-aligned
a737bd4d 25370
c19d1205
ZW
25371 The type of instruction being processed is encoded in the
25372 instruction field:
a737bd4d 25373
c19d1205
ZW
25374 0x8000 SUB
25375 0x00F0 Rd
25376 0x000F Rs
25377 */
25378 newval = md_chars_to_number (buf, THUMB_SIZE);
25379 {
25380 int rd = (newval >> 4) & 0xf;
25381 int rs = newval & 0xf;
25382 int subtract = !!(newval & 0x8000);
a737bd4d 25383
c19d1205
ZW
25384 /* Check for HI regs, only very restricted cases allowed:
25385 Adjusting SP, and using PC or SP to get an address. */
25386 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
25387 || (rs > 7 && rs != REG_SP && rs != REG_PC))
25388 as_bad_where (fixP->fx_file, fixP->fx_line,
25389 _("invalid Hi register with immediate"));
a737bd4d 25390
c19d1205
ZW
25391 /* If value is negative, choose the opposite instruction. */
25392 if (value < 0)
25393 {
25394 value = -value;
25395 subtract = !subtract;
25396 if (value < 0)
25397 as_bad_where (fixP->fx_file, fixP->fx_line,
25398 _("immediate value out of range"));
25399 }
a737bd4d 25400
c19d1205
ZW
25401 if (rd == REG_SP)
25402 {
75c11999 25403 if (value & ~0x1fc)
c19d1205
ZW
25404 as_bad_where (fixP->fx_file, fixP->fx_line,
25405 _("invalid immediate for stack address calculation"));
25406 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
25407 newval |= value >> 2;
25408 }
25409 else if (rs == REG_PC || rs == REG_SP)
25410 {
c12d2c9d
NC
25411 /* PR gas/18541. If the addition is for a defined symbol
25412 within range of an ADR instruction then accept it. */
25413 if (subtract
25414 && value == 4
25415 && fixP->fx_addsy != NULL)
25416 {
25417 subtract = 0;
25418
25419 if (! S_IS_DEFINED (fixP->fx_addsy)
25420 || S_GET_SEGMENT (fixP->fx_addsy) != seg
25421 || S_IS_WEAK (fixP->fx_addsy))
25422 {
25423 as_bad_where (fixP->fx_file, fixP->fx_line,
25424 _("address calculation needs a strongly defined nearby symbol"));
25425 }
25426 else
25427 {
25428 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
25429
25430 /* Round up to the next 4-byte boundary. */
25431 if (v & 3)
25432 v = (v + 3) & ~ 3;
25433 else
25434 v += 4;
25435 v = S_GET_VALUE (fixP->fx_addsy) - v;
25436
25437 if (v & ~0x3fc)
25438 {
25439 as_bad_where (fixP->fx_file, fixP->fx_line,
25440 _("symbol too far away"));
25441 }
25442 else
25443 {
25444 fixP->fx_done = 1;
25445 value = v;
25446 }
25447 }
25448 }
25449
c19d1205
ZW
25450 if (subtract || value & ~0x3fc)
25451 as_bad_where (fixP->fx_file, fixP->fx_line,
25452 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 25453 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
25454 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
25455 newval |= rd << 8;
25456 newval |= value >> 2;
25457 }
25458 else if (rs == rd)
25459 {
25460 if (value & ~0xff)
25461 as_bad_where (fixP->fx_file, fixP->fx_line,
25462 _("immediate value out of range"));
25463 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
25464 newval |= (rd << 8) | value;
25465 }
25466 else
25467 {
25468 if (value & ~0x7)
25469 as_bad_where (fixP->fx_file, fixP->fx_line,
25470 _("immediate value out of range"));
25471 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
25472 newval |= rd | (rs << 3) | (value << 6);
25473 }
25474 }
25475 md_number_to_chars (buf, newval, THUMB_SIZE);
25476 break;
a737bd4d 25477
c19d1205
ZW
25478 case BFD_RELOC_ARM_THUMB_IMM:
25479 newval = md_chars_to_number (buf, THUMB_SIZE);
25480 if (value < 0 || value > 255)
25481 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 25482 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
25483 (long) value);
25484 newval |= value;
25485 md_number_to_chars (buf, newval, THUMB_SIZE);
25486 break;
a737bd4d 25487
c19d1205
ZW
25488 case BFD_RELOC_ARM_THUMB_SHIFT:
25489 /* 5bit shift value (0..32). LSL cannot take 32. */
25490 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
25491 temp = newval & 0xf800;
25492 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
25493 as_bad_where (fixP->fx_file, fixP->fx_line,
25494 _("invalid shift value: %ld"), (long) value);
25495 /* Shifts of zero must be encoded as LSL. */
25496 if (value == 0)
25497 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
25498 /* Shifts of 32 are encoded as zero. */
25499 else if (value == 32)
25500 value = 0;
25501 newval |= value << 6;
25502 md_number_to_chars (buf, newval, THUMB_SIZE);
25503 break;
a737bd4d 25504
c19d1205
ZW
25505 case BFD_RELOC_VTABLE_INHERIT:
25506 case BFD_RELOC_VTABLE_ENTRY:
25507 fixP->fx_done = 0;
25508 return;
6c43fab6 25509
b6895b4f
PB
25510 case BFD_RELOC_ARM_MOVW:
25511 case BFD_RELOC_ARM_MOVT:
25512 case BFD_RELOC_ARM_THUMB_MOVW:
25513 case BFD_RELOC_ARM_THUMB_MOVT:
25514 if (fixP->fx_done || !seg->use_rela_p)
25515 {
25516 /* REL format relocations are limited to a 16-bit addend. */
25517 if (!fixP->fx_done)
25518 {
39623e12 25519 if (value < -0x8000 || value > 0x7fff)
b6895b4f 25520 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 25521 _("offset out of range"));
b6895b4f
PB
25522 }
25523 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
25524 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
25525 {
25526 value >>= 16;
25527 }
25528
25529 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
25530 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
25531 {
25532 newval = get_thumb32_insn (buf);
25533 newval &= 0xfbf08f00;
25534 newval |= (value & 0xf000) << 4;
25535 newval |= (value & 0x0800) << 15;
25536 newval |= (value & 0x0700) << 4;
25537 newval |= (value & 0x00ff);
25538 put_thumb32_insn (buf, newval);
25539 }
25540 else
25541 {
25542 newval = md_chars_to_number (buf, 4);
25543 newval &= 0xfff0f000;
25544 newval |= value & 0x0fff;
25545 newval |= (value & 0xf000) << 4;
25546 md_number_to_chars (buf, newval, 4);
25547 }
25548 }
25549 return;
25550
72d98d16
MG
25551 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
25552 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
25553 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
25554 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
25555 gas_assert (!fixP->fx_done);
25556 {
25557 bfd_vma insn;
25558 bfd_boolean is_mov;
25559 bfd_vma encoded_addend = value;
25560
25561 /* Check that addend can be encoded in instruction. */
25562 if (!seg->use_rela_p && (value < 0 || value > 255))
25563 as_bad_where (fixP->fx_file, fixP->fx_line,
25564 _("the offset 0x%08lX is not representable"),
25565 (unsigned long) encoded_addend);
25566
25567 /* Extract the instruction. */
25568 insn = md_chars_to_number (buf, THUMB_SIZE);
25569 is_mov = (insn & 0xf800) == 0x2000;
25570
25571 /* Encode insn. */
25572 if (is_mov)
25573 {
25574 if (!seg->use_rela_p)
25575 insn |= encoded_addend;
25576 }
25577 else
25578 {
25579 int rd, rs;
25580
25581 /* Extract the instruction. */
25582 /* Encoding is the following
25583 0x8000 SUB
25584 0x00F0 Rd
25585 0x000F Rs
25586 */
25587 /* The following conditions must be true :
25588 - ADD
25589 - Rd == Rs
25590 - Rd <= 7
25591 */
25592 rd = (insn >> 4) & 0xf;
25593 rs = insn & 0xf;
25594 if ((insn & 0x8000) || (rd != rs) || rd > 7)
25595 as_bad_where (fixP->fx_file, fixP->fx_line,
25596 _("Unable to process relocation for thumb opcode: %lx"),
25597 (unsigned long) insn);
25598
25599 /* Encode as ADD immediate8 thumb 1 code. */
25600 insn = 0x3000 | (rd << 8);
25601
25602 /* Place the encoded addend into the first 8 bits of the
25603 instruction. */
25604 if (!seg->use_rela_p)
25605 insn |= encoded_addend;
25606 }
25607
25608 /* Update the instruction. */
25609 md_number_to_chars (buf, insn, THUMB_SIZE);
25610 }
25611 break;
25612
4962c51a
MS
25613 case BFD_RELOC_ARM_ALU_PC_G0_NC:
25614 case BFD_RELOC_ARM_ALU_PC_G0:
25615 case BFD_RELOC_ARM_ALU_PC_G1_NC:
25616 case BFD_RELOC_ARM_ALU_PC_G1:
25617 case BFD_RELOC_ARM_ALU_PC_G2:
25618 case BFD_RELOC_ARM_ALU_SB_G0_NC:
25619 case BFD_RELOC_ARM_ALU_SB_G0:
25620 case BFD_RELOC_ARM_ALU_SB_G1_NC:
25621 case BFD_RELOC_ARM_ALU_SB_G1:
25622 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 25623 gas_assert (!fixP->fx_done);
4962c51a
MS
25624 if (!seg->use_rela_p)
25625 {
477330fc
RM
25626 bfd_vma insn;
25627 bfd_vma encoded_addend;
3ca4a8ec 25628 bfd_vma addend_abs = llabs (value);
477330fc
RM
25629
25630 /* Check that the absolute value of the addend can be
25631 expressed as an 8-bit constant plus a rotation. */
25632 encoded_addend = encode_arm_immediate (addend_abs);
25633 if (encoded_addend == (unsigned int) FAIL)
4962c51a 25634 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
25635 _("the offset 0x%08lX is not representable"),
25636 (unsigned long) addend_abs);
25637
25638 /* Extract the instruction. */
25639 insn = md_chars_to_number (buf, INSN_SIZE);
25640
25641 /* If the addend is positive, use an ADD instruction.
25642 Otherwise use a SUB. Take care not to destroy the S bit. */
25643 insn &= 0xff1fffff;
25644 if (value < 0)
25645 insn |= 1 << 22;
25646 else
25647 insn |= 1 << 23;
25648
25649 /* Place the encoded addend into the first 12 bits of the
25650 instruction. */
25651 insn &= 0xfffff000;
25652 insn |= encoded_addend;
25653
25654 /* Update the instruction. */
25655 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
25656 }
25657 break;
25658
25659 case BFD_RELOC_ARM_LDR_PC_G0:
25660 case BFD_RELOC_ARM_LDR_PC_G1:
25661 case BFD_RELOC_ARM_LDR_PC_G2:
25662 case BFD_RELOC_ARM_LDR_SB_G0:
25663 case BFD_RELOC_ARM_LDR_SB_G1:
25664 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 25665 gas_assert (!fixP->fx_done);
4962c51a 25666 if (!seg->use_rela_p)
477330fc
RM
25667 {
25668 bfd_vma insn;
3ca4a8ec 25669 bfd_vma addend_abs = llabs (value);
4962c51a 25670
477330fc
RM
25671 /* Check that the absolute value of the addend can be
25672 encoded in 12 bits. */
25673 if (addend_abs >= 0x1000)
4962c51a 25674 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
25675 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
25676 (unsigned long) addend_abs);
25677
25678 /* Extract the instruction. */
25679 insn = md_chars_to_number (buf, INSN_SIZE);
25680
25681 /* If the addend is negative, clear bit 23 of the instruction.
25682 Otherwise set it. */
25683 if (value < 0)
25684 insn &= ~(1 << 23);
25685 else
25686 insn |= 1 << 23;
25687
25688 /* Place the absolute value of the addend into the first 12 bits
25689 of the instruction. */
25690 insn &= 0xfffff000;
25691 insn |= addend_abs;
25692
25693 /* Update the instruction. */
25694 md_number_to_chars (buf, insn, INSN_SIZE);
25695 }
4962c51a
MS
25696 break;
25697
25698 case BFD_RELOC_ARM_LDRS_PC_G0:
25699 case BFD_RELOC_ARM_LDRS_PC_G1:
25700 case BFD_RELOC_ARM_LDRS_PC_G2:
25701 case BFD_RELOC_ARM_LDRS_SB_G0:
25702 case BFD_RELOC_ARM_LDRS_SB_G1:
25703 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 25704 gas_assert (!fixP->fx_done);
4962c51a 25705 if (!seg->use_rela_p)
477330fc
RM
25706 {
25707 bfd_vma insn;
3ca4a8ec 25708 bfd_vma addend_abs = llabs (value);
4962c51a 25709
477330fc
RM
25710 /* Check that the absolute value of the addend can be
25711 encoded in 8 bits. */
25712 if (addend_abs >= 0x100)
4962c51a 25713 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
25714 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
25715 (unsigned long) addend_abs);
25716
25717 /* Extract the instruction. */
25718 insn = md_chars_to_number (buf, INSN_SIZE);
25719
25720 /* If the addend is negative, clear bit 23 of the instruction.
25721 Otherwise set it. */
25722 if (value < 0)
25723 insn &= ~(1 << 23);
25724 else
25725 insn |= 1 << 23;
25726
25727 /* Place the first four bits of the absolute value of the addend
25728 into the first 4 bits of the instruction, and the remaining
25729 four into bits 8 .. 11. */
25730 insn &= 0xfffff0f0;
25731 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
25732
25733 /* Update the instruction. */
25734 md_number_to_chars (buf, insn, INSN_SIZE);
25735 }
4962c51a
MS
25736 break;
25737
25738 case BFD_RELOC_ARM_LDC_PC_G0:
25739 case BFD_RELOC_ARM_LDC_PC_G1:
25740 case BFD_RELOC_ARM_LDC_PC_G2:
25741 case BFD_RELOC_ARM_LDC_SB_G0:
25742 case BFD_RELOC_ARM_LDC_SB_G1:
25743 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 25744 gas_assert (!fixP->fx_done);
4962c51a 25745 if (!seg->use_rela_p)
477330fc
RM
25746 {
25747 bfd_vma insn;
3ca4a8ec 25748 bfd_vma addend_abs = llabs (value);
4962c51a 25749
477330fc
RM
25750 /* Check that the absolute value of the addend is a multiple of
25751 four and, when divided by four, fits in 8 bits. */
25752 if (addend_abs & 0x3)
4962c51a 25753 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
25754 _("bad offset 0x%08lX (must be word-aligned)"),
25755 (unsigned long) addend_abs);
4962c51a 25756
477330fc 25757 if ((addend_abs >> 2) > 0xff)
4962c51a 25758 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
25759 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
25760 (unsigned long) addend_abs);
25761
25762 /* Extract the instruction. */
25763 insn = md_chars_to_number (buf, INSN_SIZE);
25764
25765 /* If the addend is negative, clear bit 23 of the instruction.
25766 Otherwise set it. */
25767 if (value < 0)
25768 insn &= ~(1 << 23);
25769 else
25770 insn |= 1 << 23;
25771
25772 /* Place the addend (divided by four) into the first eight
25773 bits of the instruction. */
25774 insn &= 0xfffffff0;
25775 insn |= addend_abs >> 2;
25776
25777 /* Update the instruction. */
25778 md_number_to_chars (buf, insn, INSN_SIZE);
25779 }
4962c51a
MS
25780 break;
25781
e12437dc
AV
25782 case BFD_RELOC_THUMB_PCREL_BRANCH5:
25783 if (fixP->fx_addsy
25784 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25785 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25786 && ARM_IS_FUNC (fixP->fx_addsy)
25787 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25788 {
25789 /* Force a relocation for a branch 5 bits wide. */
25790 fixP->fx_done = 0;
25791 }
25792 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
25793 as_bad_where (fixP->fx_file, fixP->fx_line,
25794 BAD_BRANCH_OFF);
25795
25796 if (fixP->fx_done || !seg->use_rela_p)
25797 {
25798 addressT boff = value >> 1;
25799
25800 newval = md_chars_to_number (buf, THUMB_SIZE);
25801 newval |= (boff << 7);
25802 md_number_to_chars (buf, newval, THUMB_SIZE);
25803 }
25804 break;
25805
f6b2b12d
AV
25806 case BFD_RELOC_THUMB_PCREL_BFCSEL:
25807 if (fixP->fx_addsy
25808 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25809 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25810 && ARM_IS_FUNC (fixP->fx_addsy)
25811 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25812 {
25813 fixP->fx_done = 0;
25814 }
25815 if ((value & ~0x7f) && ((value & ~0x3f) != ~0x3f))
25816 as_bad_where (fixP->fx_file, fixP->fx_line,
25817 _("branch out of range"));
25818
25819 if (fixP->fx_done || !seg->use_rela_p)
25820 {
25821 newval = md_chars_to_number (buf, THUMB_SIZE);
25822
25823 addressT boff = ((newval & 0x0780) >> 7) << 1;
25824 addressT diff = value - boff;
25825
25826 if (diff == 4)
25827 {
25828 newval |= 1 << 1; /* T bit. */
25829 }
25830 else if (diff != 2)
25831 {
25832 as_bad_where (fixP->fx_file, fixP->fx_line,
25833 _("out of range label-relative fixup value"));
25834 }
25835 md_number_to_chars (buf, newval, THUMB_SIZE);
25836 }
25837 break;
25838
e5d6e09e
AV
25839 case BFD_RELOC_ARM_THUMB_BF17:
25840 if (fixP->fx_addsy
25841 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25842 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25843 && ARM_IS_FUNC (fixP->fx_addsy)
25844 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25845 {
25846 /* Force a relocation for a branch 17 bits wide. */
25847 fixP->fx_done = 0;
25848 }
25849
25850 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
25851 as_bad_where (fixP->fx_file, fixP->fx_line,
25852 BAD_BRANCH_OFF);
25853
25854 if (fixP->fx_done || !seg->use_rela_p)
25855 {
25856 offsetT newval2;
25857 addressT immA, immB, immC;
25858
25859 immA = (value & 0x0001f000) >> 12;
25860 immB = (value & 0x00000ffc) >> 2;
25861 immC = (value & 0x00000002) >> 1;
25862
25863 newval = md_chars_to_number (buf, THUMB_SIZE);
25864 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25865 newval |= immA;
25866 newval2 |= (immC << 11) | (immB << 1);
25867 md_number_to_chars (buf, newval, THUMB_SIZE);
25868 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25869 }
25870 break;
25871
1caf72a5
AV
25872 case BFD_RELOC_ARM_THUMB_BF19:
25873 if (fixP->fx_addsy
25874 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25875 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25876 && ARM_IS_FUNC (fixP->fx_addsy)
25877 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25878 {
25879 /* Force a relocation for a branch 19 bits wide. */
25880 fixP->fx_done = 0;
25881 }
25882
25883 if (v8_1_branch_value_check (value, 19, TRUE) == FAIL)
25884 as_bad_where (fixP->fx_file, fixP->fx_line,
25885 BAD_BRANCH_OFF);
25886
25887 if (fixP->fx_done || !seg->use_rela_p)
25888 {
25889 offsetT newval2;
25890 addressT immA, immB, immC;
25891
25892 immA = (value & 0x0007f000) >> 12;
25893 immB = (value & 0x00000ffc) >> 2;
25894 immC = (value & 0x00000002) >> 1;
25895
25896 newval = md_chars_to_number (buf, THUMB_SIZE);
25897 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25898 newval |= immA;
25899 newval2 |= (immC << 11) | (immB << 1);
25900 md_number_to_chars (buf, newval, THUMB_SIZE);
25901 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25902 }
25903 break;
25904
1889da70
AV
25905 case BFD_RELOC_ARM_THUMB_BF13:
25906 if (fixP->fx_addsy
25907 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25908 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25909 && ARM_IS_FUNC (fixP->fx_addsy)
25910 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25911 {
25912 /* Force a relocation for a branch 13 bits wide. */
25913 fixP->fx_done = 0;
25914 }
25915
25916 if (v8_1_branch_value_check (value, 13, TRUE) == FAIL)
25917 as_bad_where (fixP->fx_file, fixP->fx_line,
25918 BAD_BRANCH_OFF);
25919
25920 if (fixP->fx_done || !seg->use_rela_p)
25921 {
25922 offsetT newval2;
25923 addressT immA, immB, immC;
25924
25925 immA = (value & 0x00001000) >> 12;
25926 immB = (value & 0x00000ffc) >> 2;
25927 immC = (value & 0x00000002) >> 1;
25928
25929 newval = md_chars_to_number (buf, THUMB_SIZE);
25930 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25931 newval |= immA;
25932 newval2 |= (immC << 11) | (immB << 1);
25933 md_number_to_chars (buf, newval, THUMB_SIZE);
25934 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25935 }
25936 break;
25937
60f993ce
AV
25938 case BFD_RELOC_ARM_THUMB_LOOP12:
25939 if (fixP->fx_addsy
25940 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25941 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25942 && ARM_IS_FUNC (fixP->fx_addsy)
25943 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25944 {
25945 /* Force a relocation for a branch 12 bits wide. */
25946 fixP->fx_done = 0;
25947 }
25948
25949 bfd_vma insn = get_thumb32_insn (buf);
25950 /* le lr, <label> or le <label> */
25951 if (((insn & 0xffffffff) == 0xf00fc001)
25952 || ((insn & 0xffffffff) == 0xf02fc001))
25953 value = -value;
25954
25955 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
25956 as_bad_where (fixP->fx_file, fixP->fx_line,
25957 BAD_BRANCH_OFF);
25958 if (fixP->fx_done || !seg->use_rela_p)
25959 {
25960 addressT imml, immh;
25961
25962 immh = (value & 0x00000ffc) >> 2;
25963 imml = (value & 0x00000002) >> 1;
25964
25965 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25966 newval |= (imml << 11) | (immh << 1);
25967 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
25968 }
25969 break;
25970
845b51d6
PB
25971 case BFD_RELOC_ARM_V4BX:
25972 /* This will need to go in the object file. */
25973 fixP->fx_done = 0;
25974 break;
25975
c19d1205
ZW
25976 case BFD_RELOC_UNUSED:
25977 default:
25978 as_bad_where (fixP->fx_file, fixP->fx_line,
25979 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
25980 }
6c43fab6
RE
25981}
25982
c19d1205
ZW
25983/* Translate internal representation of relocation info to BFD target
25984 format. */
a737bd4d 25985
c19d1205 25986arelent *
00a97672 25987tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 25988{
c19d1205
ZW
25989 arelent * reloc;
25990 bfd_reloc_code_real_type code;
a737bd4d 25991
325801bd 25992 reloc = XNEW (arelent);
a737bd4d 25993
325801bd 25994 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
25995 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
25996 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 25997
2fc8bdac 25998 if (fixp->fx_pcrel)
00a97672
RS
25999 {
26000 if (section->use_rela_p)
26001 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
26002 else
26003 fixp->fx_offset = reloc->address;
26004 }
c19d1205 26005 reloc->addend = fixp->fx_offset;
a737bd4d 26006
c19d1205 26007 switch (fixp->fx_r_type)
a737bd4d 26008 {
c19d1205
ZW
26009 case BFD_RELOC_8:
26010 if (fixp->fx_pcrel)
26011 {
26012 code = BFD_RELOC_8_PCREL;
26013 break;
26014 }
1a0670f3 26015 /* Fall through. */
a737bd4d 26016
c19d1205
ZW
26017 case BFD_RELOC_16:
26018 if (fixp->fx_pcrel)
26019 {
26020 code = BFD_RELOC_16_PCREL;
26021 break;
26022 }
1a0670f3 26023 /* Fall through. */
6c43fab6 26024
c19d1205
ZW
26025 case BFD_RELOC_32:
26026 if (fixp->fx_pcrel)
26027 {
26028 code = BFD_RELOC_32_PCREL;
26029 break;
26030 }
1a0670f3 26031 /* Fall through. */
a737bd4d 26032
b6895b4f
PB
26033 case BFD_RELOC_ARM_MOVW:
26034 if (fixp->fx_pcrel)
26035 {
26036 code = BFD_RELOC_ARM_MOVW_PCREL;
26037 break;
26038 }
1a0670f3 26039 /* Fall through. */
b6895b4f
PB
26040
26041 case BFD_RELOC_ARM_MOVT:
26042 if (fixp->fx_pcrel)
26043 {
26044 code = BFD_RELOC_ARM_MOVT_PCREL;
26045 break;
26046 }
1a0670f3 26047 /* Fall through. */
b6895b4f
PB
26048
26049 case BFD_RELOC_ARM_THUMB_MOVW:
26050 if (fixp->fx_pcrel)
26051 {
26052 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
26053 break;
26054 }
1a0670f3 26055 /* Fall through. */
b6895b4f
PB
26056
26057 case BFD_RELOC_ARM_THUMB_MOVT:
26058 if (fixp->fx_pcrel)
26059 {
26060 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
26061 break;
26062 }
1a0670f3 26063 /* Fall through. */
b6895b4f 26064
c19d1205
ZW
26065 case BFD_RELOC_NONE:
26066 case BFD_RELOC_ARM_PCREL_BRANCH:
26067 case BFD_RELOC_ARM_PCREL_BLX:
26068 case BFD_RELOC_RVA:
26069 case BFD_RELOC_THUMB_PCREL_BRANCH7:
26070 case BFD_RELOC_THUMB_PCREL_BRANCH9:
26071 case BFD_RELOC_THUMB_PCREL_BRANCH12:
26072 case BFD_RELOC_THUMB_PCREL_BRANCH20:
26073 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26074 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
26075 case BFD_RELOC_VTABLE_ENTRY:
26076 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
26077#ifdef TE_PE
26078 case BFD_RELOC_32_SECREL:
26079#endif
c19d1205
ZW
26080 code = fixp->fx_r_type;
26081 break;
a737bd4d 26082
00adf2d4
JB
26083 case BFD_RELOC_THUMB_PCREL_BLX:
26084#ifdef OBJ_ELF
26085 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
26086 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
26087 else
26088#endif
26089 code = BFD_RELOC_THUMB_PCREL_BLX;
26090 break;
26091
c19d1205
ZW
26092 case BFD_RELOC_ARM_LITERAL:
26093 case BFD_RELOC_ARM_HWLITERAL:
26094 /* If this is called then the a literal has
26095 been referenced across a section boundary. */
26096 as_bad_where (fixp->fx_file, fixp->fx_line,
26097 _("literal referenced across section boundary"));
26098 return NULL;
a737bd4d 26099
c19d1205 26100#ifdef OBJ_ELF
0855e32b
NS
26101 case BFD_RELOC_ARM_TLS_CALL:
26102 case BFD_RELOC_ARM_THM_TLS_CALL:
26103 case BFD_RELOC_ARM_TLS_DESCSEQ:
26104 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
26105 case BFD_RELOC_ARM_GOT32:
26106 case BFD_RELOC_ARM_GOTOFF:
b43420e6 26107 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
26108 case BFD_RELOC_ARM_PLT32:
26109 case BFD_RELOC_ARM_TARGET1:
26110 case BFD_RELOC_ARM_ROSEGREL32:
26111 case BFD_RELOC_ARM_SBREL32:
26112 case BFD_RELOC_ARM_PREL31:
26113 case BFD_RELOC_ARM_TARGET2:
c19d1205 26114 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
26115 case BFD_RELOC_ARM_PCREL_CALL:
26116 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
26117 case BFD_RELOC_ARM_ALU_PC_G0_NC:
26118 case BFD_RELOC_ARM_ALU_PC_G0:
26119 case BFD_RELOC_ARM_ALU_PC_G1_NC:
26120 case BFD_RELOC_ARM_ALU_PC_G1:
26121 case BFD_RELOC_ARM_ALU_PC_G2:
26122 case BFD_RELOC_ARM_LDR_PC_G0:
26123 case BFD_RELOC_ARM_LDR_PC_G1:
26124 case BFD_RELOC_ARM_LDR_PC_G2:
26125 case BFD_RELOC_ARM_LDRS_PC_G0:
26126 case BFD_RELOC_ARM_LDRS_PC_G1:
26127 case BFD_RELOC_ARM_LDRS_PC_G2:
26128 case BFD_RELOC_ARM_LDC_PC_G0:
26129 case BFD_RELOC_ARM_LDC_PC_G1:
26130 case BFD_RELOC_ARM_LDC_PC_G2:
26131 case BFD_RELOC_ARM_ALU_SB_G0_NC:
26132 case BFD_RELOC_ARM_ALU_SB_G0:
26133 case BFD_RELOC_ARM_ALU_SB_G1_NC:
26134 case BFD_RELOC_ARM_ALU_SB_G1:
26135 case BFD_RELOC_ARM_ALU_SB_G2:
26136 case BFD_RELOC_ARM_LDR_SB_G0:
26137 case BFD_RELOC_ARM_LDR_SB_G1:
26138 case BFD_RELOC_ARM_LDR_SB_G2:
26139 case BFD_RELOC_ARM_LDRS_SB_G0:
26140 case BFD_RELOC_ARM_LDRS_SB_G1:
26141 case BFD_RELOC_ARM_LDRS_SB_G2:
26142 case BFD_RELOC_ARM_LDC_SB_G0:
26143 case BFD_RELOC_ARM_LDC_SB_G1:
26144 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 26145 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
26146 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
26147 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
26148 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
26149 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
188fd7ae
CL
26150 case BFD_RELOC_ARM_GOTFUNCDESC:
26151 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
26152 case BFD_RELOC_ARM_FUNCDESC:
e5d6e09e 26153 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 26154 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 26155 case BFD_RELOC_ARM_THUMB_BF13:
c19d1205
ZW
26156 code = fixp->fx_r_type;
26157 break;
a737bd4d 26158
0855e32b 26159 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 26160 case BFD_RELOC_ARM_TLS_GD32:
5c5a4843 26161 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
75c11999 26162 case BFD_RELOC_ARM_TLS_LE32:
c19d1205 26163 case BFD_RELOC_ARM_TLS_IE32:
5c5a4843 26164 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
c19d1205 26165 case BFD_RELOC_ARM_TLS_LDM32:
5c5a4843 26166 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
c19d1205
ZW
26167 /* BFD will include the symbol's address in the addend.
26168 But we don't want that, so subtract it out again here. */
26169 if (!S_IS_COMMON (fixp->fx_addsy))
26170 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
26171 code = fixp->fx_r_type;
26172 break;
26173#endif
a737bd4d 26174
c19d1205
ZW
26175 case BFD_RELOC_ARM_IMMEDIATE:
26176 as_bad_where (fixp->fx_file, fixp->fx_line,
26177 _("internal relocation (type: IMMEDIATE) not fixed up"));
26178 return NULL;
a737bd4d 26179
c19d1205
ZW
26180 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
26181 as_bad_where (fixp->fx_file, fixp->fx_line,
26182 _("ADRL used for a symbol not defined in the same file"));
26183 return NULL;
a737bd4d 26184
e12437dc 26185 case BFD_RELOC_THUMB_PCREL_BRANCH5:
f6b2b12d 26186 case BFD_RELOC_THUMB_PCREL_BFCSEL:
60f993ce 26187 case BFD_RELOC_ARM_THUMB_LOOP12:
e12437dc
AV
26188 as_bad_where (fixp->fx_file, fixp->fx_line,
26189 _("%s used for a symbol not defined in the same file"),
26190 bfd_get_reloc_code_name (fixp->fx_r_type));
26191 return NULL;
26192
c19d1205 26193 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
26194 if (section->use_rela_p)
26195 {
26196 code = fixp->fx_r_type;
26197 break;
26198 }
26199
c19d1205
ZW
26200 if (fixp->fx_addsy != NULL
26201 && !S_IS_DEFINED (fixp->fx_addsy)
26202 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 26203 {
c19d1205
ZW
26204 as_bad_where (fixp->fx_file, fixp->fx_line,
26205 _("undefined local label `%s'"),
26206 S_GET_NAME (fixp->fx_addsy));
26207 return NULL;
a737bd4d
NC
26208 }
26209
c19d1205
ZW
26210 as_bad_where (fixp->fx_file, fixp->fx_line,
26211 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
26212 return NULL;
a737bd4d 26213
c19d1205
ZW
26214 default:
26215 {
e0471c16 26216 const char * type;
6c43fab6 26217
c19d1205
ZW
26218 switch (fixp->fx_r_type)
26219 {
26220 case BFD_RELOC_NONE: type = "NONE"; break;
26221 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
26222 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 26223 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
26224 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
26225 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
26226 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 26227 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 26228 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
26229 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
26230 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
26231 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
26232 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
26233 default: type = _("<unknown>"); break;
26234 }
26235 as_bad_where (fixp->fx_file, fixp->fx_line,
26236 _("cannot represent %s relocation in this object file format"),
26237 type);
26238 return NULL;
26239 }
a737bd4d 26240 }
6c43fab6 26241
c19d1205
ZW
26242#ifdef OBJ_ELF
26243 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
26244 && GOT_symbol
26245 && fixp->fx_addsy == GOT_symbol)
26246 {
26247 code = BFD_RELOC_ARM_GOTPC;
26248 reloc->addend = fixp->fx_offset = reloc->address;
26249 }
26250#endif
6c43fab6 26251
c19d1205 26252 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 26253
c19d1205
ZW
26254 if (reloc->howto == NULL)
26255 {
26256 as_bad_where (fixp->fx_file, fixp->fx_line,
26257 _("cannot represent %s relocation in this object file format"),
26258 bfd_get_reloc_code_name (code));
26259 return NULL;
26260 }
6c43fab6 26261
c19d1205
ZW
26262 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
26263 vtable entry to be used in the relocation's section offset. */
26264 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
26265 reloc->address = fixp->fx_offset;
6c43fab6 26266
c19d1205 26267 return reloc;
6c43fab6
RE
26268}
26269
c19d1205 26270/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 26271
c19d1205
ZW
26272void
26273cons_fix_new_arm (fragS * frag,
26274 int where,
26275 int size,
62ebcb5c
AM
26276 expressionS * exp,
26277 bfd_reloc_code_real_type reloc)
6c43fab6 26278{
c19d1205 26279 int pcrel = 0;
6c43fab6 26280
c19d1205
ZW
26281 /* Pick a reloc.
26282 FIXME: @@ Should look at CPU word size. */
26283 switch (size)
26284 {
26285 case 1:
62ebcb5c 26286 reloc = BFD_RELOC_8;
c19d1205
ZW
26287 break;
26288 case 2:
62ebcb5c 26289 reloc = BFD_RELOC_16;
c19d1205
ZW
26290 break;
26291 case 4:
26292 default:
62ebcb5c 26293 reloc = BFD_RELOC_32;
c19d1205
ZW
26294 break;
26295 case 8:
62ebcb5c 26296 reloc = BFD_RELOC_64;
c19d1205
ZW
26297 break;
26298 }
6c43fab6 26299
f0927246
NC
26300#ifdef TE_PE
26301 if (exp->X_op == O_secrel)
26302 {
26303 exp->X_op = O_symbol;
62ebcb5c 26304 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
26305 }
26306#endif
26307
62ebcb5c 26308 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 26309}
6c43fab6 26310
4343666d 26311#if defined (OBJ_COFF)
c19d1205
ZW
26312void
26313arm_validate_fix (fixS * fixP)
6c43fab6 26314{
c19d1205
ZW
26315 /* If the destination of the branch is a defined symbol which does not have
26316 the THUMB_FUNC attribute, then we must be calling a function which has
26317 the (interfacearm) attribute. We look for the Thumb entry point to that
26318 function and change the branch to refer to that function instead. */
26319 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
26320 && fixP->fx_addsy != NULL
26321 && S_IS_DEFINED (fixP->fx_addsy)
26322 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 26323 {
c19d1205 26324 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 26325 }
c19d1205
ZW
26326}
26327#endif
6c43fab6 26328
267bf995 26329
c19d1205
ZW
26330int
26331arm_force_relocation (struct fix * fixp)
26332{
26333#if defined (OBJ_COFF) && defined (TE_PE)
26334 if (fixp->fx_r_type == BFD_RELOC_RVA)
26335 return 1;
26336#endif
6c43fab6 26337
267bf995
RR
26338 /* In case we have a call or a branch to a function in ARM ISA mode from
26339 a thumb function or vice-versa force the relocation. These relocations
26340 are cleared off for some cores that might have blx and simple transformations
26341 are possible. */
26342
26343#ifdef OBJ_ELF
26344 switch (fixp->fx_r_type)
26345 {
26346 case BFD_RELOC_ARM_PCREL_JUMP:
26347 case BFD_RELOC_ARM_PCREL_CALL:
26348 case BFD_RELOC_THUMB_PCREL_BLX:
26349 if (THUMB_IS_FUNC (fixp->fx_addsy))
26350 return 1;
26351 break;
26352
26353 case BFD_RELOC_ARM_PCREL_BLX:
26354 case BFD_RELOC_THUMB_PCREL_BRANCH25:
26355 case BFD_RELOC_THUMB_PCREL_BRANCH20:
26356 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26357 if (ARM_IS_FUNC (fixp->fx_addsy))
26358 return 1;
26359 break;
26360
26361 default:
26362 break;
26363 }
26364#endif
26365
b5884301
PB
26366 /* Resolve these relocations even if the symbol is extern or weak.
26367 Technically this is probably wrong due to symbol preemption.
26368 In practice these relocations do not have enough range to be useful
26369 at dynamic link time, and some code (e.g. in the Linux kernel)
26370 expects these references to be resolved. */
c19d1205
ZW
26371 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
26372 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 26373 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 26374 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
26375 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
26376 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
26377 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 26378 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
26379 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
26380 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
26381 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
26382 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
26383 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
26384 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 26385 return 0;
a737bd4d 26386
4962c51a
MS
26387 /* Always leave these relocations for the linker. */
26388 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
26389 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
26390 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
26391 return 1;
26392
f0291e4c
PB
26393 /* Always generate relocations against function symbols. */
26394 if (fixp->fx_r_type == BFD_RELOC_32
26395 && fixp->fx_addsy
26396 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
26397 return 1;
26398
c19d1205 26399 return generic_force_reloc (fixp);
404ff6b5
AH
26400}
26401
0ffdc86c 26402#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
26403/* Relocations against function names must be left unadjusted,
26404 so that the linker can use this information to generate interworking
26405 stubs. The MIPS version of this function
c19d1205
ZW
26406 also prevents relocations that are mips-16 specific, but I do not
26407 know why it does this.
404ff6b5 26408
c19d1205
ZW
26409 FIXME:
26410 There is one other problem that ought to be addressed here, but
26411 which currently is not: Taking the address of a label (rather
26412 than a function) and then later jumping to that address. Such
26413 addresses also ought to have their bottom bit set (assuming that
26414 they reside in Thumb code), but at the moment they will not. */
404ff6b5 26415
c19d1205
ZW
26416bfd_boolean
26417arm_fix_adjustable (fixS * fixP)
404ff6b5 26418{
c19d1205
ZW
26419 if (fixP->fx_addsy == NULL)
26420 return 1;
404ff6b5 26421
e28387c3
PB
26422 /* Preserve relocations against symbols with function type. */
26423 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 26424 return FALSE;
e28387c3 26425
c19d1205
ZW
26426 if (THUMB_IS_FUNC (fixP->fx_addsy)
26427 && fixP->fx_subsy == NULL)
c921be7d 26428 return FALSE;
a737bd4d 26429
c19d1205
ZW
26430 /* We need the symbol name for the VTABLE entries. */
26431 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
26432 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 26433 return FALSE;
404ff6b5 26434
c19d1205
ZW
26435 /* Don't allow symbols to be discarded on GOT related relocs. */
26436 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
26437 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
26438 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
26439 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
5c5a4843 26440 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
c19d1205
ZW
26441 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
26442 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
5c5a4843 26443 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
c19d1205 26444 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
5c5a4843 26445 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
c19d1205 26446 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
26447 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
26448 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
26449 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
26450 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
26451 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 26452 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 26453 return FALSE;
a737bd4d 26454
4962c51a
MS
26455 /* Similarly for group relocations. */
26456 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
26457 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
26458 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 26459 return FALSE;
4962c51a 26460
79947c54
CD
26461 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
26462 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
26463 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
26464 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
26465 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
26466 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
26467 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
26468 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
26469 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 26470 return FALSE;
79947c54 26471
72d98d16
MG
26472 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
26473 offsets, so keep these symbols. */
26474 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
26475 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
26476 return FALSE;
26477
c921be7d 26478 return TRUE;
a737bd4d 26479}
0ffdc86c
NC
26480#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
26481
26482#ifdef OBJ_ELF
c19d1205
ZW
26483const char *
26484elf32_arm_target_format (void)
404ff6b5 26485{
c19d1205
ZW
26486#ifdef TE_SYMBIAN
26487 return (target_big_endian
26488 ? "elf32-bigarm-symbian"
26489 : "elf32-littlearm-symbian");
26490#elif defined (TE_VXWORKS)
26491 return (target_big_endian
26492 ? "elf32-bigarm-vxworks"
26493 : "elf32-littlearm-vxworks");
b38cadfb
NC
26494#elif defined (TE_NACL)
26495 return (target_big_endian
26496 ? "elf32-bigarm-nacl"
26497 : "elf32-littlearm-nacl");
c19d1205 26498#else
18a20338
CL
26499 if (arm_fdpic)
26500 {
26501 if (target_big_endian)
26502 return "elf32-bigarm-fdpic";
26503 else
26504 return "elf32-littlearm-fdpic";
26505 }
c19d1205 26506 else
18a20338
CL
26507 {
26508 if (target_big_endian)
26509 return "elf32-bigarm";
26510 else
26511 return "elf32-littlearm";
26512 }
c19d1205 26513#endif
404ff6b5
AH
26514}
26515
c19d1205
ZW
26516void
26517armelf_frob_symbol (symbolS * symp,
26518 int * puntp)
404ff6b5 26519{
c19d1205
ZW
26520 elf_frob_symbol (symp, puntp);
26521}
26522#endif
404ff6b5 26523
c19d1205 26524/* MD interface: Finalization. */
a737bd4d 26525
c19d1205
ZW
26526void
26527arm_cleanup (void)
26528{
26529 literal_pool * pool;
a737bd4d 26530
5ee91343
AV
26531 /* Ensure that all the predication blocks are properly closed. */
26532 check_pred_blocks_finished ();
e07e6e58 26533
c19d1205
ZW
26534 for (pool = list_of_pools; pool; pool = pool->next)
26535 {
5f4273c7 26536 /* Put it at the end of the relevant section. */
c19d1205
ZW
26537 subseg_set (pool->section, pool->sub_section);
26538#ifdef OBJ_ELF
26539 arm_elf_change_section ();
26540#endif
26541 s_ltorg (0);
26542 }
404ff6b5
AH
26543}
26544
cd000bff
DJ
26545#ifdef OBJ_ELF
26546/* Remove any excess mapping symbols generated for alignment frags in
26547 SEC. We may have created a mapping symbol before a zero byte
26548 alignment; remove it if there's a mapping symbol after the
26549 alignment. */
26550static void
26551check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
26552 void *dummy ATTRIBUTE_UNUSED)
26553{
26554 segment_info_type *seginfo = seg_info (sec);
26555 fragS *fragp;
26556
26557 if (seginfo == NULL || seginfo->frchainP == NULL)
26558 return;
26559
26560 for (fragp = seginfo->frchainP->frch_root;
26561 fragp != NULL;
26562 fragp = fragp->fr_next)
26563 {
26564 symbolS *sym = fragp->tc_frag_data.last_map;
26565 fragS *next = fragp->fr_next;
26566
26567 /* Variable-sized frags have been converted to fixed size by
26568 this point. But if this was variable-sized to start with,
26569 there will be a fixed-size frag after it. So don't handle
26570 next == NULL. */
26571 if (sym == NULL || next == NULL)
26572 continue;
26573
26574 if (S_GET_VALUE (sym) < next->fr_address)
26575 /* Not at the end of this frag. */
26576 continue;
26577 know (S_GET_VALUE (sym) == next->fr_address);
26578
26579 do
26580 {
26581 if (next->tc_frag_data.first_map != NULL)
26582 {
26583 /* Next frag starts with a mapping symbol. Discard this
26584 one. */
26585 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
26586 break;
26587 }
26588
26589 if (next->fr_next == NULL)
26590 {
26591 /* This mapping symbol is at the end of the section. Discard
26592 it. */
26593 know (next->fr_fix == 0 && next->fr_var == 0);
26594 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
26595 break;
26596 }
26597
26598 /* As long as we have empty frags without any mapping symbols,
26599 keep looking. */
26600 /* If the next frag is non-empty and does not start with a
26601 mapping symbol, then this mapping symbol is required. */
26602 if (next->fr_address != next->fr_next->fr_address)
26603 break;
26604
26605 next = next->fr_next;
26606 }
26607 while (next != NULL);
26608 }
26609}
26610#endif
26611
c19d1205
ZW
26612/* Adjust the symbol table. This marks Thumb symbols as distinct from
26613 ARM ones. */
404ff6b5 26614
c19d1205
ZW
26615void
26616arm_adjust_symtab (void)
404ff6b5 26617{
c19d1205
ZW
26618#ifdef OBJ_COFF
26619 symbolS * sym;
404ff6b5 26620
c19d1205
ZW
26621 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
26622 {
26623 if (ARM_IS_THUMB (sym))
26624 {
26625 if (THUMB_IS_FUNC (sym))
26626 {
26627 /* Mark the symbol as a Thumb function. */
26628 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
26629 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
26630 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 26631
c19d1205
ZW
26632 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
26633 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
26634 else
26635 as_bad (_("%s: unexpected function type: %d"),
26636 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
26637 }
26638 else switch (S_GET_STORAGE_CLASS (sym))
26639 {
26640 case C_EXT:
26641 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
26642 break;
26643 case C_STAT:
26644 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
26645 break;
26646 case C_LABEL:
26647 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
26648 break;
26649 default:
26650 /* Do nothing. */
26651 break;
26652 }
26653 }
a737bd4d 26654
c19d1205
ZW
26655 if (ARM_IS_INTERWORK (sym))
26656 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 26657 }
c19d1205
ZW
26658#endif
26659#ifdef OBJ_ELF
26660 symbolS * sym;
26661 char bind;
404ff6b5 26662
c19d1205 26663 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 26664 {
c19d1205
ZW
26665 if (ARM_IS_THUMB (sym))
26666 {
26667 elf_symbol_type * elf_sym;
404ff6b5 26668
c19d1205
ZW
26669 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
26670 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 26671
b0796911
PB
26672 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
26673 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
26674 {
26675 /* If it's a .thumb_func, declare it as so,
26676 otherwise tag label as .code 16. */
26677 if (THUMB_IS_FUNC (sym))
39d911fc
TP
26678 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
26679 ST_BRANCH_TO_THUMB);
3ba67470 26680 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
26681 elf_sym->internal_elf_sym.st_info =
26682 ELF_ST_INFO (bind, STT_ARM_16BIT);
26683 }
26684 }
26685 }
cd000bff
DJ
26686
26687 /* Remove any overlapping mapping symbols generated by alignment frags. */
26688 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
26689 /* Now do generic ELF adjustments. */
26690 elf_adjust_symtab ();
c19d1205 26691#endif
404ff6b5
AH
26692}
26693
c19d1205 26694/* MD interface: Initialization. */
404ff6b5 26695
a737bd4d 26696static void
c19d1205 26697set_constant_flonums (void)
a737bd4d 26698{
c19d1205 26699 int i;
404ff6b5 26700
c19d1205
ZW
26701 for (i = 0; i < NUM_FLOAT_VALS; i++)
26702 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
26703 abort ();
a737bd4d 26704}
404ff6b5 26705
3e9e4fcf
JB
26706/* Auto-select Thumb mode if it's the only available instruction set for the
26707 given architecture. */
26708
26709static void
26710autoselect_thumb_from_cpu_variant (void)
26711{
26712 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
26713 opcode_select (16);
26714}
26715
c19d1205
ZW
26716void
26717md_begin (void)
a737bd4d 26718{
c19d1205
ZW
26719 unsigned mach;
26720 unsigned int i;
404ff6b5 26721
c19d1205
ZW
26722 if ( (arm_ops_hsh = hash_new ()) == NULL
26723 || (arm_cond_hsh = hash_new ()) == NULL
5ee91343 26724 || (arm_vcond_hsh = hash_new ()) == NULL
c19d1205
ZW
26725 || (arm_shift_hsh = hash_new ()) == NULL
26726 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 26727 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 26728 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
26729 || (arm_reloc_hsh = hash_new ()) == NULL
26730 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
26731 as_fatal (_("virtual memory exhausted"));
26732
26733 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 26734 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 26735 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 26736 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
5ee91343
AV
26737 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
26738 hash_insert (arm_vcond_hsh, vconds[i].template_name, (void *) (vconds + i));
c19d1205 26739 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 26740 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 26741 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 26742 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 26743 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 26744 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 26745 (void *) (v7m_psrs + i));
c19d1205 26746 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 26747 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
26748 for (i = 0;
26749 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
26750 i++)
d3ce72d0 26751 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 26752 (void *) (barrier_opt_names + i));
c19d1205 26753#ifdef OBJ_ELF
3da1d841
NC
26754 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
26755 {
26756 struct reloc_entry * entry = reloc_names + i;
26757
26758 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
26759 /* This makes encode_branch() use the EABI versions of this relocation. */
26760 entry->reloc = BFD_RELOC_UNUSED;
26761
26762 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
26763 }
c19d1205
ZW
26764#endif
26765
26766 set_constant_flonums ();
404ff6b5 26767
c19d1205
ZW
26768 /* Set the cpu variant based on the command-line options. We prefer
26769 -mcpu= over -march= if both are set (as for GCC); and we prefer
26770 -mfpu= over any other way of setting the floating point unit.
26771 Use of legacy options with new options are faulted. */
e74cfd16 26772 if (legacy_cpu)
404ff6b5 26773 {
e74cfd16 26774 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
26775 as_bad (_("use of old and new-style options to set CPU type"));
26776
4d354d8b 26777 selected_arch = *legacy_cpu;
404ff6b5 26778 }
4d354d8b
TP
26779 else if (mcpu_cpu_opt)
26780 {
26781 selected_arch = *mcpu_cpu_opt;
26782 selected_ext = *mcpu_ext_opt;
26783 }
26784 else if (march_cpu_opt)
c168ce07 26785 {
4d354d8b
TP
26786 selected_arch = *march_cpu_opt;
26787 selected_ext = *march_ext_opt;
c168ce07 26788 }
4d354d8b 26789 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
404ff6b5 26790
e74cfd16 26791 if (legacy_fpu)
c19d1205 26792 {
e74cfd16 26793 if (mfpu_opt)
c19d1205 26794 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f 26795
4d354d8b 26796 selected_fpu = *legacy_fpu;
03b1477f 26797 }
4d354d8b
TP
26798 else if (mfpu_opt)
26799 selected_fpu = *mfpu_opt;
26800 else
03b1477f 26801 {
45eb4c1b
NS
26802#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
26803 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
26804 /* Some environments specify a default FPU. If they don't, infer it
26805 from the processor. */
e74cfd16 26806 if (mcpu_fpu_opt)
4d354d8b 26807 selected_fpu = *mcpu_fpu_opt;
e7da50fa 26808 else if (march_fpu_opt)
4d354d8b 26809 selected_fpu = *march_fpu_opt;
39c2da32 26810#else
4d354d8b 26811 selected_fpu = fpu_default;
39c2da32 26812#endif
03b1477f
RE
26813 }
26814
4d354d8b 26815 if (ARM_FEATURE_ZERO (selected_fpu))
03b1477f 26816 {
4d354d8b
TP
26817 if (!no_cpu_selected ())
26818 selected_fpu = fpu_default;
03b1477f 26819 else
4d354d8b 26820 selected_fpu = fpu_arch_fpa;
03b1477f
RE
26821 }
26822
ee065d83 26823#ifdef CPU_DEFAULT
4d354d8b 26824 if (ARM_FEATURE_ZERO (selected_arch))
ee065d83 26825 {
4d354d8b
TP
26826 selected_arch = cpu_default;
26827 selected_cpu = selected_arch;
ee065d83 26828 }
4d354d8b 26829 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
e74cfd16 26830#else
4d354d8b
TP
26831 /* Autodection of feature mode: allow all features in cpu_variant but leave
26832 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
26833 after all instruction have been processed and we can decide what CPU
26834 should be selected. */
26835 if (ARM_FEATURE_ZERO (selected_arch))
26836 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
ee065d83 26837 else
4d354d8b 26838 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83 26839#endif
03b1477f 26840
3e9e4fcf
JB
26841 autoselect_thumb_from_cpu_variant ();
26842
e74cfd16 26843 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 26844
f17c130b 26845#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 26846 {
7cc69913
NC
26847 unsigned int flags = 0;
26848
26849#if defined OBJ_ELF
26850 flags = meabi_flags;
d507cf36
PB
26851
26852 switch (meabi_flags)
33a392fb 26853 {
d507cf36 26854 case EF_ARM_EABI_UNKNOWN:
7cc69913 26855#endif
d507cf36
PB
26856 /* Set the flags in the private structure. */
26857 if (uses_apcs_26) flags |= F_APCS26;
26858 if (support_interwork) flags |= F_INTERWORK;
26859 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 26860 if (pic_code) flags |= F_PIC;
e74cfd16 26861 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
26862 flags |= F_SOFT_FLOAT;
26863
d507cf36
PB
26864 switch (mfloat_abi_opt)
26865 {
26866 case ARM_FLOAT_ABI_SOFT:
26867 case ARM_FLOAT_ABI_SOFTFP:
26868 flags |= F_SOFT_FLOAT;
26869 break;
33a392fb 26870
d507cf36
PB
26871 case ARM_FLOAT_ABI_HARD:
26872 if (flags & F_SOFT_FLOAT)
26873 as_bad (_("hard-float conflicts with specified fpu"));
26874 break;
26875 }
03b1477f 26876
e74cfd16
PB
26877 /* Using pure-endian doubles (even if soft-float). */
26878 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 26879 flags |= F_VFP_FLOAT;
f17c130b 26880
fde78edd 26881#if defined OBJ_ELF
e74cfd16 26882 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 26883 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
26884 break;
26885
8cb51566 26886 case EF_ARM_EABI_VER4:
3a4a14e9 26887 case EF_ARM_EABI_VER5:
c19d1205 26888 /* No additional flags to set. */
d507cf36
PB
26889 break;
26890
26891 default:
26892 abort ();
26893 }
7cc69913 26894#endif
b99bd4ef
NC
26895 bfd_set_private_flags (stdoutput, flags);
26896
26897 /* We have run out flags in the COFF header to encode the
26898 status of ATPCS support, so instead we create a dummy,
c19d1205 26899 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
26900 if (atpcs)
26901 {
26902 asection * sec;
26903
26904 sec = bfd_make_section (stdoutput, ".arm.atpcs");
26905
26906 if (sec != NULL)
26907 {
26908 bfd_set_section_flags
26909 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
26910 bfd_set_section_size (stdoutput, sec, 0);
26911 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
26912 }
26913 }
7cc69913 26914 }
f17c130b 26915#endif
b99bd4ef
NC
26916
26917 /* Record the CPU type as well. */
2d447fca
JM
26918 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
26919 mach = bfd_mach_arm_iWMMXt2;
26920 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 26921 mach = bfd_mach_arm_iWMMXt;
e74cfd16 26922 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 26923 mach = bfd_mach_arm_XScale;
e74cfd16 26924 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 26925 mach = bfd_mach_arm_ep9312;
e74cfd16 26926 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 26927 mach = bfd_mach_arm_5TE;
e74cfd16 26928 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 26929 {
e74cfd16 26930 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
26931 mach = bfd_mach_arm_5T;
26932 else
26933 mach = bfd_mach_arm_5;
26934 }
e74cfd16 26935 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 26936 {
e74cfd16 26937 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
26938 mach = bfd_mach_arm_4T;
26939 else
26940 mach = bfd_mach_arm_4;
26941 }
e74cfd16 26942 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 26943 mach = bfd_mach_arm_3M;
e74cfd16
PB
26944 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
26945 mach = bfd_mach_arm_3;
26946 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
26947 mach = bfd_mach_arm_2a;
26948 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
26949 mach = bfd_mach_arm_2;
26950 else
26951 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
26952
26953 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
26954}
26955
c19d1205 26956/* Command line processing. */
b99bd4ef 26957
c19d1205
ZW
26958/* md_parse_option
26959 Invocation line includes a switch not recognized by the base assembler.
26960 See if it's a processor-specific option.
b99bd4ef 26961
c19d1205
ZW
26962 This routine is somewhat complicated by the need for backwards
26963 compatibility (since older releases of gcc can't be changed).
26964 The new options try to make the interface as compatible as
26965 possible with GCC.
b99bd4ef 26966
c19d1205 26967 New options (supported) are:
b99bd4ef 26968
c19d1205
ZW
26969 -mcpu=<cpu name> Assemble for selected processor
26970 -march=<architecture name> Assemble for selected architecture
26971 -mfpu=<fpu architecture> Assemble for selected FPU.
26972 -EB/-mbig-endian Big-endian
26973 -EL/-mlittle-endian Little-endian
26974 -k Generate PIC code
26975 -mthumb Start in Thumb mode
26976 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 26977
278df34e 26978 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 26979 -m[no-]warn-syms Warn when symbols match instructions
267bf995 26980
c19d1205 26981 For now we will also provide support for:
b99bd4ef 26982
c19d1205
ZW
26983 -mapcs-32 32-bit Program counter
26984 -mapcs-26 26-bit Program counter
26985 -macps-float Floats passed in FP registers
26986 -mapcs-reentrant Reentrant code
26987 -matpcs
26988 (sometime these will probably be replaced with -mapcs=<list of options>
26989 and -matpcs=<list of options>)
b99bd4ef 26990
c19d1205
ZW
26991 The remaining options are only supported for back-wards compatibility.
26992 Cpu variants, the arm part is optional:
26993 -m[arm]1 Currently not supported.
26994 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
26995 -m[arm]3 Arm 3 processor
26996 -m[arm]6[xx], Arm 6 processors
26997 -m[arm]7[xx][t][[d]m] Arm 7 processors
26998 -m[arm]8[10] Arm 8 processors
26999 -m[arm]9[20][tdmi] Arm 9 processors
27000 -mstrongarm[110[0]] StrongARM processors
27001 -mxscale XScale processors
27002 -m[arm]v[2345[t[e]]] Arm architectures
27003 -mall All (except the ARM1)
27004 FP variants:
27005 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
27006 -mfpe-old (No float load/store multiples)
27007 -mvfpxd VFP Single precision
27008 -mvfp All VFP
27009 -mno-fpu Disable all floating point instructions
b99bd4ef 27010
c19d1205
ZW
27011 The following CPU names are recognized:
27012 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
27013 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
27014 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
27015 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
27016 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
27017 arm10t arm10e, arm1020t, arm1020e, arm10200e,
27018 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 27019
c19d1205 27020 */
b99bd4ef 27021
c19d1205 27022const char * md_shortopts = "m:k";
b99bd4ef 27023
c19d1205
ZW
27024#ifdef ARM_BI_ENDIAN
27025#define OPTION_EB (OPTION_MD_BASE + 0)
27026#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 27027#else
c19d1205
ZW
27028#if TARGET_BYTES_BIG_ENDIAN
27029#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 27030#else
c19d1205
ZW
27031#define OPTION_EL (OPTION_MD_BASE + 1)
27032#endif
b99bd4ef 27033#endif
845b51d6 27034#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
18a20338 27035#define OPTION_FDPIC (OPTION_MD_BASE + 3)
b99bd4ef 27036
c19d1205 27037struct option md_longopts[] =
b99bd4ef 27038{
c19d1205
ZW
27039#ifdef OPTION_EB
27040 {"EB", no_argument, NULL, OPTION_EB},
27041#endif
27042#ifdef OPTION_EL
27043 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 27044#endif
845b51d6 27045 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
18a20338
CL
27046#ifdef OBJ_ELF
27047 {"fdpic", no_argument, NULL, OPTION_FDPIC},
27048#endif
c19d1205
ZW
27049 {NULL, no_argument, NULL, 0}
27050};
b99bd4ef 27051
c19d1205 27052size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 27053
c19d1205 27054struct arm_option_table
b99bd4ef 27055{
0198d5e6
TC
27056 const char * option; /* Option name to match. */
27057 const char * help; /* Help information. */
27058 int * var; /* Variable to change. */
27059 int value; /* What to change it to. */
27060 const char * deprecated; /* If non-null, print this message. */
c19d1205 27061};
b99bd4ef 27062
c19d1205
ZW
27063struct arm_option_table arm_opts[] =
27064{
27065 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
27066 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
27067 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
27068 &support_interwork, 1, NULL},
27069 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
27070 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
27071 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
27072 1, NULL},
27073 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
27074 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
27075 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
27076 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
27077 NULL},
b99bd4ef 27078
c19d1205
ZW
27079 /* These are recognized by the assembler, but have no affect on code. */
27080 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
27081 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
27082
27083 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
27084 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
27085 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
27086 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
27087 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
27088 {NULL, NULL, NULL, 0, NULL}
27089};
27090
27091struct arm_legacy_option_table
27092{
0198d5e6
TC
27093 const char * option; /* Option name to match. */
27094 const arm_feature_set ** var; /* Variable to change. */
27095 const arm_feature_set value; /* What to change it to. */
27096 const char * deprecated; /* If non-null, print this message. */
e74cfd16 27097};
b99bd4ef 27098
e74cfd16
PB
27099const struct arm_legacy_option_table arm_legacy_opts[] =
27100{
c19d1205
ZW
27101 /* DON'T add any new processors to this list -- we want the whole list
27102 to go away... Add them to the processors table instead. */
e74cfd16
PB
27103 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
27104 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
27105 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
27106 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
27107 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
27108 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
27109 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
27110 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
27111 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
27112 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
27113 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
27114 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
27115 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
27116 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
27117 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
27118 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
27119 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
27120 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
27121 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
27122 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
27123 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
27124 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
27125 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
27126 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
27127 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
27128 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
27129 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
27130 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
27131 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
27132 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
27133 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
27134 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
27135 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
27136 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
27137 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
27138 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
27139 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
27140 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
27141 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
27142 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
27143 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
27144 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
27145 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
27146 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
27147 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
27148 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
27149 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
27150 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
27151 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
27152 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
27153 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
27154 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
27155 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
27156 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
27157 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
27158 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
27159 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
27160 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
27161 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
27162 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
27163 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
27164 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
27165 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
27166 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
27167 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
27168 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
27169 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
27170 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
27171 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
27172 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 27173 N_("use -mcpu=strongarm110")},
e74cfd16 27174 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 27175 N_("use -mcpu=strongarm1100")},
e74cfd16 27176 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 27177 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
27178 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
27179 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
27180 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 27181
c19d1205 27182 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
27183 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
27184 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
27185 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
27186 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
27187 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
27188 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
27189 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
27190 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
27191 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
27192 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
27193 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
27194 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
27195 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
27196 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
27197 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
27198 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
27199 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
27200 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 27201
c19d1205 27202 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
27203 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
27204 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
27205 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
27206 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 27207 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 27208
e74cfd16 27209 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 27210};
7ed4c4c5 27211
c19d1205 27212struct arm_cpu_option_table
7ed4c4c5 27213{
0198d5e6
TC
27214 const char * name;
27215 size_t name_len;
27216 const arm_feature_set value;
27217 const arm_feature_set ext;
c19d1205
ZW
27218 /* For some CPUs we assume an FPU unless the user explicitly sets
27219 -mfpu=... */
0198d5e6 27220 const arm_feature_set default_fpu;
ee065d83
PB
27221 /* The canonical name of the CPU, or NULL to use NAME converted to upper
27222 case. */
0198d5e6 27223 const char * canonical_name;
c19d1205 27224};
7ed4c4c5 27225
c19d1205
ZW
27226/* This list should, at a minimum, contain all the cpu names
27227 recognized by GCC. */
996b5569 27228#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 27229
e74cfd16 27230static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 27231{
996b5569
TP
27232 ARM_CPU_OPT ("all", NULL, ARM_ANY,
27233 ARM_ARCH_NONE,
27234 FPU_ARCH_FPA),
27235 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
27236 ARM_ARCH_NONE,
27237 FPU_ARCH_FPA),
27238 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
27239 ARM_ARCH_NONE,
27240 FPU_ARCH_FPA),
27241 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
27242 ARM_ARCH_NONE,
27243 FPU_ARCH_FPA),
27244 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
27245 ARM_ARCH_NONE,
27246 FPU_ARCH_FPA),
27247 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
27248 ARM_ARCH_NONE,
27249 FPU_ARCH_FPA),
27250 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
27251 ARM_ARCH_NONE,
27252 FPU_ARCH_FPA),
27253 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
27254 ARM_ARCH_NONE,
27255 FPU_ARCH_FPA),
27256 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
27257 ARM_ARCH_NONE,
27258 FPU_ARCH_FPA),
27259 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
27260 ARM_ARCH_NONE,
27261 FPU_ARCH_FPA),
27262 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
27263 ARM_ARCH_NONE,
27264 FPU_ARCH_FPA),
27265 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
27266 ARM_ARCH_NONE,
27267 FPU_ARCH_FPA),
27268 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
27269 ARM_ARCH_NONE,
27270 FPU_ARCH_FPA),
27271 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
27272 ARM_ARCH_NONE,
27273 FPU_ARCH_FPA),
27274 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
27275 ARM_ARCH_NONE,
27276 FPU_ARCH_FPA),
27277 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
27278 ARM_ARCH_NONE,
27279 FPU_ARCH_FPA),
27280 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
27281 ARM_ARCH_NONE,
27282 FPU_ARCH_FPA),
27283 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
27284 ARM_ARCH_NONE,
27285 FPU_ARCH_FPA),
27286 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
27287 ARM_ARCH_NONE,
27288 FPU_ARCH_FPA),
27289 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
27290 ARM_ARCH_NONE,
27291 FPU_ARCH_FPA),
27292 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
27293 ARM_ARCH_NONE,
27294 FPU_ARCH_FPA),
27295 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
27296 ARM_ARCH_NONE,
27297 FPU_ARCH_FPA),
27298 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
27299 ARM_ARCH_NONE,
27300 FPU_ARCH_FPA),
27301 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
27302 ARM_ARCH_NONE,
27303 FPU_ARCH_FPA),
27304 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
27305 ARM_ARCH_NONE,
27306 FPU_ARCH_FPA),
27307 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
27308 ARM_ARCH_NONE,
27309 FPU_ARCH_FPA),
27310 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
27311 ARM_ARCH_NONE,
27312 FPU_ARCH_FPA),
27313 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
27314 ARM_ARCH_NONE,
27315 FPU_ARCH_FPA),
27316 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
27317 ARM_ARCH_NONE,
27318 FPU_ARCH_FPA),
27319 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
27320 ARM_ARCH_NONE,
27321 FPU_ARCH_FPA),
27322 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
27323 ARM_ARCH_NONE,
27324 FPU_ARCH_FPA),
27325 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
27326 ARM_ARCH_NONE,
27327 FPU_ARCH_FPA),
27328 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
27329 ARM_ARCH_NONE,
27330 FPU_ARCH_FPA),
27331 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
27332 ARM_ARCH_NONE,
27333 FPU_ARCH_FPA),
27334 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
27335 ARM_ARCH_NONE,
27336 FPU_ARCH_FPA),
27337 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
27338 ARM_ARCH_NONE,
27339 FPU_ARCH_FPA),
27340 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
27341 ARM_ARCH_NONE,
27342 FPU_ARCH_FPA),
27343 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
27344 ARM_ARCH_NONE,
27345 FPU_ARCH_FPA),
27346 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
27347 ARM_ARCH_NONE,
27348 FPU_ARCH_FPA),
27349 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
27350 ARM_ARCH_NONE,
27351 FPU_ARCH_FPA),
27352 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
27353 ARM_ARCH_NONE,
27354 FPU_ARCH_FPA),
27355 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
27356 ARM_ARCH_NONE,
27357 FPU_ARCH_FPA),
27358 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
27359 ARM_ARCH_NONE,
27360 FPU_ARCH_FPA),
27361 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
27362 ARM_ARCH_NONE,
27363 FPU_ARCH_FPA),
27364 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
27365 ARM_ARCH_NONE,
27366 FPU_ARCH_FPA),
27367 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
27368 ARM_ARCH_NONE,
27369 FPU_ARCH_FPA),
27370
c19d1205
ZW
27371 /* For V5 or later processors we default to using VFP; but the user
27372 should really set the FPU type explicitly. */
996b5569
TP
27373 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
27374 ARM_ARCH_NONE,
27375 FPU_ARCH_VFP_V2),
27376 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
27377 ARM_ARCH_NONE,
27378 FPU_ARCH_VFP_V2),
27379 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
27380 ARM_ARCH_NONE,
27381 FPU_ARCH_VFP_V2),
27382 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
27383 ARM_ARCH_NONE,
27384 FPU_ARCH_VFP_V2),
27385 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
27386 ARM_ARCH_NONE,
27387 FPU_ARCH_VFP_V2),
27388 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
27389 ARM_ARCH_NONE,
27390 FPU_ARCH_VFP_V2),
27391 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
27392 ARM_ARCH_NONE,
27393 FPU_ARCH_VFP_V2),
27394 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
27395 ARM_ARCH_NONE,
27396 FPU_ARCH_VFP_V2),
27397 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
27398 ARM_ARCH_NONE,
27399 FPU_ARCH_VFP_V2),
27400 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
27401 ARM_ARCH_NONE,
27402 FPU_ARCH_VFP_V2),
27403 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
27404 ARM_ARCH_NONE,
27405 FPU_ARCH_VFP_V2),
27406 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
27407 ARM_ARCH_NONE,
27408 FPU_ARCH_VFP_V2),
27409 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
27410 ARM_ARCH_NONE,
27411 FPU_ARCH_VFP_V1),
27412 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
27413 ARM_ARCH_NONE,
27414 FPU_ARCH_VFP_V1),
27415 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
27416 ARM_ARCH_NONE,
27417 FPU_ARCH_VFP_V2),
27418 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
27419 ARM_ARCH_NONE,
27420 FPU_ARCH_VFP_V2),
27421 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
27422 ARM_ARCH_NONE,
27423 FPU_ARCH_VFP_V1),
27424 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
27425 ARM_ARCH_NONE,
27426 FPU_ARCH_VFP_V2),
27427 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
27428 ARM_ARCH_NONE,
27429 FPU_ARCH_VFP_V2),
27430 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
27431 ARM_ARCH_NONE,
27432 FPU_ARCH_VFP_V2),
27433 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
27434 ARM_ARCH_NONE,
27435 FPU_ARCH_VFP_V2),
27436 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
27437 ARM_ARCH_NONE,
27438 FPU_ARCH_VFP_V2),
27439 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
27440 ARM_ARCH_NONE,
27441 FPU_ARCH_VFP_V2),
27442 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
27443 ARM_ARCH_NONE,
27444 FPU_ARCH_VFP_V2),
27445 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
27446 ARM_ARCH_NONE,
27447 FPU_ARCH_VFP_V2),
27448 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
27449 ARM_ARCH_NONE,
27450 FPU_ARCH_VFP_V2),
27451 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
27452 ARM_ARCH_NONE,
27453 FPU_NONE),
27454 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
27455 ARM_ARCH_NONE,
27456 FPU_NONE),
27457 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
27458 ARM_ARCH_NONE,
27459 FPU_ARCH_VFP_V2),
27460 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
27461 ARM_ARCH_NONE,
27462 FPU_ARCH_VFP_V2),
27463 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
27464 ARM_ARCH_NONE,
27465 FPU_ARCH_VFP_V2),
27466 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
27467 ARM_ARCH_NONE,
27468 FPU_NONE),
27469 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
27470 ARM_ARCH_NONE,
27471 FPU_NONE),
27472 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
27473 ARM_ARCH_NONE,
27474 FPU_ARCH_VFP_V2),
27475 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
27476 ARM_ARCH_NONE,
27477 FPU_NONE),
27478 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
27479 ARM_ARCH_NONE,
27480 FPU_ARCH_VFP_V2),
27481 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
27482 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
27483 FPU_NONE),
27484 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
27485 ARM_ARCH_NONE,
27486 FPU_ARCH_NEON_VFP_V4),
27487 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
27488 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
27489 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
27490 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
27491 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
27492 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
27493 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
27494 ARM_ARCH_NONE,
27495 FPU_ARCH_NEON_VFP_V4),
27496 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
27497 ARM_ARCH_NONE,
27498 FPU_ARCH_NEON_VFP_V4),
27499 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
27500 ARM_ARCH_NONE,
27501 FPU_ARCH_NEON_VFP_V4),
27502 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
27503 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27504 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27505 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
27506 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27507 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27508 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
27509 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27510 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
27511 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
27512 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 27513 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
27514 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
27515 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27516 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27517 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
27518 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27519 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27520 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
27521 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27522 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
27523 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
27524 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 27525 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
7ebd1359 27526 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
27527 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27528 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
ef8df4ca
KT
27529 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
27530 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27531 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
27532 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
27533 ARM_ARCH_NONE,
27534 FPU_NONE),
27535 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
27536 ARM_ARCH_NONE,
27537 FPU_ARCH_VFP_V3D16),
27538 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
27539 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
27540 FPU_NONE),
27541 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
27542 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
27543 FPU_ARCH_VFP_V3D16),
27544 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
27545 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
27546 FPU_ARCH_VFP_V3D16),
0cda1e19
TP
27547 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
27548 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27549 FPU_ARCH_NEON_VFP_ARMV8),
996b5569
TP
27550 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
27551 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27552 FPU_NONE),
27553 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
27554 ARM_ARCH_NONE,
27555 FPU_NONE),
27556 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
27557 ARM_ARCH_NONE,
27558 FPU_NONE),
27559 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
27560 ARM_ARCH_NONE,
27561 FPU_NONE),
27562 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
27563 ARM_ARCH_NONE,
27564 FPU_NONE),
27565 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
27566 ARM_ARCH_NONE,
27567 FPU_NONE),
27568 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
27569 ARM_ARCH_NONE,
27570 FPU_NONE),
27571 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
27572 ARM_ARCH_NONE,
27573 FPU_NONE),
27574 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
27575 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27576 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
83f43c83
KT
27577 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
27578 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27579 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
c19d1205 27580 /* ??? XSCALE is really an architecture. */
996b5569
TP
27581 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
27582 ARM_ARCH_NONE,
27583 FPU_ARCH_VFP_V2),
27584
c19d1205 27585 /* ??? iwmmxt is not a processor. */
996b5569
TP
27586 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
27587 ARM_ARCH_NONE,
27588 FPU_ARCH_VFP_V2),
27589 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
27590 ARM_ARCH_NONE,
27591 FPU_ARCH_VFP_V2),
27592 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
27593 ARM_ARCH_NONE,
27594 FPU_ARCH_VFP_V2),
27595
0198d5e6 27596 /* Maverick. */
996b5569
TP
27597 ARM_CPU_OPT ("ep9312", "ARM920T",
27598 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
27599 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
27600
da4339ed 27601 /* Marvell processors. */
996b5569
TP
27602 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
27603 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
27604 FPU_ARCH_VFP_V3D16),
27605 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
27606 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
27607 FPU_ARCH_NEON_VFP_V4),
da4339ed 27608
996b5569
TP
27609 /* APM X-Gene family. */
27610 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
27611 ARM_ARCH_NONE,
27612 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27613 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
27614 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27615 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27616
27617 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 27618};
f3bad469 27619#undef ARM_CPU_OPT
7ed4c4c5 27620
34ef62f4
AV
27621struct arm_ext_table
27622{
27623 const char * name;
27624 size_t name_len;
27625 const arm_feature_set merge;
27626 const arm_feature_set clear;
27627};
27628
c19d1205 27629struct arm_arch_option_table
7ed4c4c5 27630{
34ef62f4
AV
27631 const char * name;
27632 size_t name_len;
27633 const arm_feature_set value;
27634 const arm_feature_set default_fpu;
27635 const struct arm_ext_table * ext_table;
27636};
27637
27638/* Used to add support for +E and +noE extension. */
27639#define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
27640/* Used to add support for a +E extension. */
27641#define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
27642/* Used to add support for a +noE extension. */
27643#define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
27644
27645#define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
27646 ~0 & ~FPU_ENDIAN_PURE)
27647
27648static const struct arm_ext_table armv5te_ext_table[] =
27649{
27650 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
27651 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27652};
27653
27654static const struct arm_ext_table armv7_ext_table[] =
27655{
27656 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
27657 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27658};
27659
27660static const struct arm_ext_table armv7ve_ext_table[] =
27661{
27662 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
27663 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
27664 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
27665 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
27666 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
27667 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
27668 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
27669
27670 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
27671 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
27672
27673 /* Aliases for +simd. */
27674 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
27675
27676 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
27677 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
27678 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
27679
27680 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27681};
27682
27683static const struct arm_ext_table armv7a_ext_table[] =
27684{
27685 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
27686 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
27687 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
27688 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
27689 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
27690 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
27691 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
27692
27693 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
27694 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
27695
27696 /* Aliases for +simd. */
27697 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
27698 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
27699
27700 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
27701 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
27702
27703 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
27704 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
27705 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27706};
27707
27708static const struct arm_ext_table armv7r_ext_table[] =
27709{
27710 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
27711 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
27712 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
27713 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
27714 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
27715 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
27716 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
27717 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
27718 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27719};
27720
27721static const struct arm_ext_table armv7em_ext_table[] =
27722{
27723 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
27724 /* Alias for +fp, used to be known as fpv4-sp-d16. */
27725 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
27726 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
27727 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
27728 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
27729 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27730};
27731
27732static const struct arm_ext_table armv8a_ext_table[] =
27733{
27734 ARM_ADD ("crc", ARCH_CRC_ARMV8),
27735 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
27736 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
27737 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27738
27739 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27740 should use the +simd option to turn on FP. */
27741 ARM_REMOVE ("fp", ALL_FP),
27742 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
27743 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
27744 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27745};
27746
27747
27748static const struct arm_ext_table armv81a_ext_table[] =
27749{
27750 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
27751 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
27752 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27753
27754 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27755 should use the +simd option to turn on FP. */
27756 ARM_REMOVE ("fp", ALL_FP),
27757 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
27758 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
27759 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27760};
27761
27762static const struct arm_ext_table armv82a_ext_table[] =
27763{
27764 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
27765 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
27766 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
27767 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
27768 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27769 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
27770
27771 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27772 should use the +simd option to turn on FP. */
27773 ARM_REMOVE ("fp", ALL_FP),
27774 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
27775 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
27776 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27777};
27778
27779static const struct arm_ext_table armv84a_ext_table[] =
27780{
27781 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
27782 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
27783 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
27784 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27785
27786 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27787 should use the +simd option to turn on FP. */
27788 ARM_REMOVE ("fp", ALL_FP),
27789 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
27790 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
27791 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27792};
27793
27794static const struct arm_ext_table armv85a_ext_table[] =
27795{
27796 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
27797 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
27798 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
27799 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27800
27801 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27802 should use the +simd option to turn on FP. */
27803 ARM_REMOVE ("fp", ALL_FP),
27804 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27805};
27806
27807static const struct arm_ext_table armv8m_main_ext_table[] =
27808{
27809 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27810 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
27811 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
27812 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
27813 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27814};
27815
e0991585
AV
27816static const struct arm_ext_table armv8_1m_main_ext_table[] =
27817{
27818 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27819 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
27820 ARM_EXT ("fp",
27821 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
27822 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
27823 ALL_FP),
27824 ARM_ADD ("fp.dp",
27825 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
27826 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
a7ad558c
AV
27827 ARM_EXT ("mve", ARM_FEATURE_COPROC (FPU_MVE),
27828 ARM_FEATURE_COPROC (FPU_MVE | FPU_MVE_FP)),
27829 ARM_ADD ("mve.fp",
27830 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
27831 FPU_MVE | FPU_MVE_FP | FPU_VFP_V5_SP_D16 |
27832 FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
e0991585
AV
27833 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27834};
27835
34ef62f4
AV
27836static const struct arm_ext_table armv8r_ext_table[] =
27837{
27838 ARM_ADD ("crc", ARCH_CRC_ARMV8),
27839 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
27840 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
27841 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27842 ARM_REMOVE ("fp", ALL_FP),
27843 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
27844 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 27845};
7ed4c4c5 27846
c19d1205
ZW
27847/* This list should, at a minimum, contain all the architecture names
27848 recognized by GCC. */
34ef62f4
AV
27849#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
27850#define ARM_ARCH_OPT2(N, V, DF, ext) \
27851 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
0198d5e6 27852
e74cfd16 27853static const struct arm_arch_option_table arm_archs[] =
c19d1205 27854{
497d849d
TP
27855 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
27856 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
27857 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
27858 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
27859 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
27860 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
27861 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
27862 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
27863 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
27864 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
27865 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
27866 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
27867 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
27868 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
34ef62f4
AV
27869 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
27870 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
27871 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
27872 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
27873 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
27874 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
27875 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
f33026a9
MW
27876 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
27877 kept to preserve existing behaviour. */
34ef62f4
AV
27878 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
27879 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
27880 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
27881 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
27882 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
f33026a9
MW
27883 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
27884 kept to preserve existing behaviour. */
34ef62f4
AV
27885 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
27886 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
497d849d
TP
27887 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
27888 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
34ef62f4 27889 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
c450d570
PB
27890 /* The official spelling of the ARMv7 profile variants is the dashed form.
27891 Accept the non-dashed form for compatibility with old toolchains. */
34ef62f4
AV
27892 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
27893 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
27894 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 27895 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4
AV
27896 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
27897 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 27898 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4 27899 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
497d849d 27900 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
34ef62f4
AV
27901 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
27902 armv8m_main),
e0991585
AV
27903 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
27904 armv8_1m_main),
34ef62f4
AV
27905 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
27906 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
27907 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
27908 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
27909 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
27910 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
27911 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
497d849d
TP
27912 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
27913 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
27914 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
34ef62f4 27915 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 27916};
f3bad469 27917#undef ARM_ARCH_OPT
7ed4c4c5 27918
69133863 27919/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 27920
69133863 27921struct arm_option_extension_value_table
c19d1205 27922{
0198d5e6
TC
27923 const char * name;
27924 size_t name_len;
27925 const arm_feature_set merge_value;
27926 const arm_feature_set clear_value;
d942732e
TP
27927 /* List of architectures for which an extension is available. ARM_ARCH_NONE
27928 indicates that an extension is available for all architectures while
27929 ARM_ANY marks an empty entry. */
0198d5e6 27930 const arm_feature_set allowed_archs[2];
c19d1205 27931};
7ed4c4c5 27932
0198d5e6
TC
27933/* The following table must be in alphabetical order with a NULL last entry. */
27934
d942732e
TP
27935#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
27936#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 27937
34ef62f4
AV
27938/* DEPRECATED: Refrain from using this table to add any new extensions, instead
27939 use the context sensitive approach using arm_ext_table's. */
69133863 27940static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 27941{
823d2571
TG
27942 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27943 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 27944 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
27945 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
27946 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
27947 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
27948 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
27949 ARM_ARCH_V8_2A),
15afaa63
TP
27950 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27951 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27952 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
27953 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
27954 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
27955 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27956 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27957 ARM_ARCH_V8_2A),
01f48020
TC
27958 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
27959 | ARM_EXT2_FP16_FML),
27960 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
27961 | ARM_EXT2_FP16_FML),
27962 ARM_ARCH_V8_2A),
d942732e 27963 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 27964 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
27965 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
27966 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
27967 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
27968 Thumb divide instruction. Due to this having the same name as the
27969 previous entry, this will be ignored when doing command-line parsing and
27970 only considered by build attribute selection code. */
27971 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
27972 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
27973 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 27974 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 27975 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 27976 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 27977 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 27978 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
27979 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
27980 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 27981 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
27982 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
27983 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
27984 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
27985 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
27986 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
27987 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
27988 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 27989 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
dad0c3bf
SD
27990 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
27991 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
27992 ARM_ARCH_V8A),
4d1464f2
MW
27993 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
27994 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 27995 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
27996 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
27997 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 27998 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
7fadb25d
SD
27999 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
28000 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
28001 ARM_ARCH_V8A),
d942732e 28002 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 28003 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
28004 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
28005 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
28006 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
28007 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
28008 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
28009 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
28010 | ARM_EXT_DIV),
28011 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
28012 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
28013 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
28014 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
28015 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 28016};
f3bad469 28017#undef ARM_EXT_OPT
69133863
MGD
28018
28019/* ISA floating-point and Advanced SIMD extensions. */
28020struct arm_option_fpu_value_table
28021{
0198d5e6
TC
28022 const char * name;
28023 const arm_feature_set value;
c19d1205 28024};
7ed4c4c5 28025
c19d1205
ZW
28026/* This list should, at a minimum, contain all the fpu names
28027 recognized by GCC. */
69133863 28028static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
28029{
28030 {"softfpa", FPU_NONE},
28031 {"fpe", FPU_ARCH_FPE},
28032 {"fpe2", FPU_ARCH_FPE},
28033 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
28034 {"fpa", FPU_ARCH_FPA},
28035 {"fpa10", FPU_ARCH_FPA},
28036 {"fpa11", FPU_ARCH_FPA},
28037 {"arm7500fe", FPU_ARCH_FPA},
28038 {"softvfp", FPU_ARCH_VFP},
28039 {"softvfp+vfp", FPU_ARCH_VFP_V2},
28040 {"vfp", FPU_ARCH_VFP_V2},
28041 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 28042 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
28043 {"vfp10", FPU_ARCH_VFP_V2},
28044 {"vfp10-r0", FPU_ARCH_VFP_V1},
28045 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
28046 {"vfpv2", FPU_ARCH_VFP_V2},
28047 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 28048 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 28049 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
28050 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
28051 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
28052 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
28053 {"arm1020t", FPU_ARCH_VFP_V1},
28054 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 28055 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
28056 {"arm1136jf-s", FPU_ARCH_VFP_V2},
28057 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 28058 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 28059 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 28060 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
28061 {"vfpv4", FPU_ARCH_VFP_V4},
28062 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 28063 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
28064 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
28065 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 28066 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
28067 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
28068 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
28069 {"crypto-neon-fp-armv8",
28070 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 28071 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
28072 {"crypto-neon-fp-armv8.1",
28073 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
28074 {NULL, ARM_ARCH_NONE}
28075};
28076
28077struct arm_option_value_table
28078{
e0471c16 28079 const char *name;
e74cfd16 28080 long value;
c19d1205 28081};
7ed4c4c5 28082
e74cfd16 28083static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
28084{
28085 {"hard", ARM_FLOAT_ABI_HARD},
28086 {"softfp", ARM_FLOAT_ABI_SOFTFP},
28087 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 28088 {NULL, 0}
c19d1205 28089};
7ed4c4c5 28090
c19d1205 28091#ifdef OBJ_ELF
3a4a14e9 28092/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 28093static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
28094{
28095 {"gnu", EF_ARM_EABI_UNKNOWN},
28096 {"4", EF_ARM_EABI_VER4},
3a4a14e9 28097 {"5", EF_ARM_EABI_VER5},
e74cfd16 28098 {NULL, 0}
c19d1205
ZW
28099};
28100#endif
7ed4c4c5 28101
c19d1205
ZW
28102struct arm_long_option_table
28103{
0198d5e6 28104 const char * option; /* Substring to match. */
e0471c16 28105 const char * help; /* Help information. */
17b9d67d 28106 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 28107 const char * deprecated; /* If non-null, print this message. */
c19d1205 28108};
7ed4c4c5 28109
c921be7d 28110static bfd_boolean
c168ce07 28111arm_parse_extension (const char *str, const arm_feature_set *opt_set,
34ef62f4
AV
28112 arm_feature_set *ext_set,
28113 const struct arm_ext_table *ext_table)
7ed4c4c5 28114{
69133863 28115 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
28116 extensions being added before being removed. We achieve this by having
28117 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 28118 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 28119 or removing it (0) and only allowing it to change in the order
69133863
MGD
28120 -1 -> 1 -> 0. */
28121 const struct arm_option_extension_value_table * opt = NULL;
d942732e 28122 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
28123 int adding_value = -1;
28124
c19d1205 28125 while (str != NULL && *str != 0)
7ed4c4c5 28126 {
82b8a785 28127 const char *ext;
f3bad469 28128 size_t len;
7ed4c4c5 28129
c19d1205
ZW
28130 if (*str != '+')
28131 {
28132 as_bad (_("invalid architectural extension"));
c921be7d 28133 return FALSE;
c19d1205 28134 }
7ed4c4c5 28135
c19d1205
ZW
28136 str++;
28137 ext = strchr (str, '+');
7ed4c4c5 28138
c19d1205 28139 if (ext != NULL)
f3bad469 28140 len = ext - str;
c19d1205 28141 else
f3bad469 28142 len = strlen (str);
7ed4c4c5 28143
f3bad469 28144 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
28145 {
28146 if (adding_value != 0)
28147 {
28148 adding_value = 0;
28149 opt = arm_extensions;
28150 }
28151
f3bad469 28152 len -= 2;
69133863
MGD
28153 str += 2;
28154 }
f3bad469 28155 else if (len > 0)
69133863
MGD
28156 {
28157 if (adding_value == -1)
28158 {
28159 adding_value = 1;
28160 opt = arm_extensions;
28161 }
28162 else if (adding_value != 1)
28163 {
28164 as_bad (_("must specify extensions to add before specifying "
28165 "those to remove"));
28166 return FALSE;
28167 }
28168 }
28169
f3bad469 28170 if (len == 0)
c19d1205
ZW
28171 {
28172 as_bad (_("missing architectural extension"));
c921be7d 28173 return FALSE;
c19d1205 28174 }
7ed4c4c5 28175
69133863
MGD
28176 gas_assert (adding_value != -1);
28177 gas_assert (opt != NULL);
28178
34ef62f4
AV
28179 if (ext_table != NULL)
28180 {
28181 const struct arm_ext_table * ext_opt = ext_table;
28182 bfd_boolean found = FALSE;
28183 for (; ext_opt->name != NULL; ext_opt++)
28184 if (ext_opt->name_len == len
28185 && strncmp (ext_opt->name, str, len) == 0)
28186 {
28187 if (adding_value)
28188 {
28189 if (ARM_FEATURE_ZERO (ext_opt->merge))
28190 /* TODO: Option not supported. When we remove the
28191 legacy table this case should error out. */
28192 continue;
28193
28194 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
28195 }
28196 else
28197 {
28198 if (ARM_FEATURE_ZERO (ext_opt->clear))
28199 /* TODO: Option not supported. When we remove the
28200 legacy table this case should error out. */
28201 continue;
28202 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
28203 }
28204 found = TRUE;
28205 break;
28206 }
28207 if (found)
28208 {
28209 str = ext;
28210 continue;
28211 }
28212 }
28213
69133863
MGD
28214 /* Scan over the options table trying to find an exact match. */
28215 for (; opt->name != NULL; opt++)
f3bad469 28216 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 28217 {
d942732e
TP
28218 int i, nb_allowed_archs =
28219 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 28220 /* Check we can apply the extension to this architecture. */
d942732e
TP
28221 for (i = 0; i < nb_allowed_archs; i++)
28222 {
28223 /* Empty entry. */
28224 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
28225 continue;
c168ce07 28226 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
28227 break;
28228 }
28229 if (i == nb_allowed_archs)
69133863
MGD
28230 {
28231 as_bad (_("extension does not apply to the base architecture"));
28232 return FALSE;
28233 }
28234
28235 /* Add or remove the extension. */
28236 if (adding_value)
4d354d8b 28237 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 28238 else
4d354d8b 28239 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 28240
3d030cdb
TP
28241 /* Allowing Thumb division instructions for ARMv7 in autodetection
28242 rely on this break so that duplicate extensions (extensions
28243 with the same name as a previous extension in the list) are not
28244 considered for command-line parsing. */
c19d1205
ZW
28245 break;
28246 }
7ed4c4c5 28247
c19d1205
ZW
28248 if (opt->name == NULL)
28249 {
69133863
MGD
28250 /* Did we fail to find an extension because it wasn't specified in
28251 alphabetical order, or because it does not exist? */
28252
28253 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 28254 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
28255 break;
28256
28257 if (opt->name == NULL)
28258 as_bad (_("unknown architectural extension `%s'"), str);
28259 else
28260 as_bad (_("architectural extensions must be specified in "
28261 "alphabetical order"));
28262
c921be7d 28263 return FALSE;
c19d1205 28264 }
69133863
MGD
28265 else
28266 {
28267 /* We should skip the extension we've just matched the next time
28268 round. */
28269 opt++;
28270 }
7ed4c4c5 28271
c19d1205
ZW
28272 str = ext;
28273 };
7ed4c4c5 28274
c921be7d 28275 return TRUE;
c19d1205 28276}
7ed4c4c5 28277
c921be7d 28278static bfd_boolean
17b9d67d 28279arm_parse_cpu (const char *str)
7ed4c4c5 28280{
f3bad469 28281 const struct arm_cpu_option_table *opt;
82b8a785 28282 const char *ext = strchr (str, '+');
f3bad469 28283 size_t len;
7ed4c4c5 28284
c19d1205 28285 if (ext != NULL)
f3bad469 28286 len = ext - str;
7ed4c4c5 28287 else
f3bad469 28288 len = strlen (str);
7ed4c4c5 28289
f3bad469 28290 if (len == 0)
7ed4c4c5 28291 {
c19d1205 28292 as_bad (_("missing cpu name `%s'"), str);
c921be7d 28293 return FALSE;
7ed4c4c5
NC
28294 }
28295
c19d1205 28296 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 28297 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 28298 {
c168ce07 28299 mcpu_cpu_opt = &opt->value;
4d354d8b
TP
28300 if (mcpu_ext_opt == NULL)
28301 mcpu_ext_opt = XNEW (arm_feature_set);
28302 *mcpu_ext_opt = opt->ext;
e74cfd16 28303 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 28304 if (opt->canonical_name)
ef8e6722
JW
28305 {
28306 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
28307 strcpy (selected_cpu_name, opt->canonical_name);
28308 }
ee065d83
PB
28309 else
28310 {
f3bad469 28311 size_t i;
c921be7d 28312
ef8e6722
JW
28313 if (len >= sizeof selected_cpu_name)
28314 len = (sizeof selected_cpu_name) - 1;
28315
f3bad469 28316 for (i = 0; i < len; i++)
ee065d83
PB
28317 selected_cpu_name[i] = TOUPPER (opt->name[i]);
28318 selected_cpu_name[i] = 0;
28319 }
7ed4c4c5 28320
c19d1205 28321 if (ext != NULL)
34ef62f4 28322 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
7ed4c4c5 28323
c921be7d 28324 return TRUE;
c19d1205 28325 }
7ed4c4c5 28326
c19d1205 28327 as_bad (_("unknown cpu `%s'"), str);
c921be7d 28328 return FALSE;
7ed4c4c5
NC
28329}
28330
c921be7d 28331static bfd_boolean
17b9d67d 28332arm_parse_arch (const char *str)
7ed4c4c5 28333{
e74cfd16 28334 const struct arm_arch_option_table *opt;
82b8a785 28335 const char *ext = strchr (str, '+');
f3bad469 28336 size_t len;
7ed4c4c5 28337
c19d1205 28338 if (ext != NULL)
f3bad469 28339 len = ext - str;
7ed4c4c5 28340 else
f3bad469 28341 len = strlen (str);
7ed4c4c5 28342
f3bad469 28343 if (len == 0)
7ed4c4c5 28344 {
c19d1205 28345 as_bad (_("missing architecture name `%s'"), str);
c921be7d 28346 return FALSE;
7ed4c4c5
NC
28347 }
28348
c19d1205 28349 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 28350 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 28351 {
e74cfd16 28352 march_cpu_opt = &opt->value;
4d354d8b
TP
28353 if (march_ext_opt == NULL)
28354 march_ext_opt = XNEW (arm_feature_set);
28355 *march_ext_opt = arm_arch_none;
e74cfd16 28356 march_fpu_opt = &opt->default_fpu;
5f4273c7 28357 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 28358
c19d1205 28359 if (ext != NULL)
34ef62f4
AV
28360 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
28361 opt->ext_table);
7ed4c4c5 28362
c921be7d 28363 return TRUE;
c19d1205
ZW
28364 }
28365
28366 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 28367 return FALSE;
7ed4c4c5 28368}
eb043451 28369
c921be7d 28370static bfd_boolean
17b9d67d 28371arm_parse_fpu (const char * str)
c19d1205 28372{
69133863 28373 const struct arm_option_fpu_value_table * opt;
b99bd4ef 28374
c19d1205
ZW
28375 for (opt = arm_fpus; opt->name != NULL; opt++)
28376 if (streq (opt->name, str))
28377 {
e74cfd16 28378 mfpu_opt = &opt->value;
c921be7d 28379 return TRUE;
c19d1205 28380 }
b99bd4ef 28381
c19d1205 28382 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 28383 return FALSE;
c19d1205
ZW
28384}
28385
c921be7d 28386static bfd_boolean
17b9d67d 28387arm_parse_float_abi (const char * str)
b99bd4ef 28388{
e74cfd16 28389 const struct arm_option_value_table * opt;
b99bd4ef 28390
c19d1205
ZW
28391 for (opt = arm_float_abis; opt->name != NULL; opt++)
28392 if (streq (opt->name, str))
28393 {
28394 mfloat_abi_opt = opt->value;
c921be7d 28395 return TRUE;
c19d1205 28396 }
cc8a6dd0 28397
c19d1205 28398 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 28399 return FALSE;
c19d1205 28400}
b99bd4ef 28401
c19d1205 28402#ifdef OBJ_ELF
c921be7d 28403static bfd_boolean
17b9d67d 28404arm_parse_eabi (const char * str)
c19d1205 28405{
e74cfd16 28406 const struct arm_option_value_table *opt;
cc8a6dd0 28407
c19d1205
ZW
28408 for (opt = arm_eabis; opt->name != NULL; opt++)
28409 if (streq (opt->name, str))
28410 {
28411 meabi_flags = opt->value;
c921be7d 28412 return TRUE;
c19d1205
ZW
28413 }
28414 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 28415 return FALSE;
c19d1205
ZW
28416}
28417#endif
cc8a6dd0 28418
c921be7d 28419static bfd_boolean
17b9d67d 28420arm_parse_it_mode (const char * str)
e07e6e58 28421{
c921be7d 28422 bfd_boolean ret = TRUE;
e07e6e58
NC
28423
28424 if (streq ("arm", str))
28425 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
28426 else if (streq ("thumb", str))
28427 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
28428 else if (streq ("always", str))
28429 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
28430 else if (streq ("never", str))
28431 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
28432 else
28433 {
28434 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 28435 "arm, thumb, always, or never."), str);
c921be7d 28436 ret = FALSE;
e07e6e58
NC
28437 }
28438
28439 return ret;
28440}
28441
2e6976a8 28442static bfd_boolean
17b9d67d 28443arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
28444{
28445 codecomposer_syntax = TRUE;
28446 arm_comment_chars[0] = ';';
28447 arm_line_separator_chars[0] = 0;
28448 return TRUE;
28449}
28450
c19d1205
ZW
28451struct arm_long_option_table arm_long_opts[] =
28452{
28453 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
28454 arm_parse_cpu, NULL},
28455 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
28456 arm_parse_arch, NULL},
28457 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
28458 arm_parse_fpu, NULL},
28459 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
28460 arm_parse_float_abi, NULL},
28461#ifdef OBJ_ELF
7fac0536 28462 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
28463 arm_parse_eabi, NULL},
28464#endif
e07e6e58
NC
28465 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
28466 arm_parse_it_mode, NULL},
2e6976a8
DG
28467 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
28468 arm_ccs_mode, NULL},
c19d1205
ZW
28469 {NULL, NULL, 0, NULL}
28470};
cc8a6dd0 28471
c19d1205 28472int
17b9d67d 28473md_parse_option (int c, const char * arg)
c19d1205
ZW
28474{
28475 struct arm_option_table *opt;
e74cfd16 28476 const struct arm_legacy_option_table *fopt;
c19d1205 28477 struct arm_long_option_table *lopt;
b99bd4ef 28478
c19d1205 28479 switch (c)
b99bd4ef 28480 {
c19d1205
ZW
28481#ifdef OPTION_EB
28482 case OPTION_EB:
28483 target_big_endian = 1;
28484 break;
28485#endif
cc8a6dd0 28486
c19d1205
ZW
28487#ifdef OPTION_EL
28488 case OPTION_EL:
28489 target_big_endian = 0;
28490 break;
28491#endif
b99bd4ef 28492
845b51d6
PB
28493 case OPTION_FIX_V4BX:
28494 fix_v4bx = TRUE;
28495 break;
28496
18a20338
CL
28497#ifdef OBJ_ELF
28498 case OPTION_FDPIC:
28499 arm_fdpic = TRUE;
28500 break;
28501#endif /* OBJ_ELF */
28502
c19d1205
ZW
28503 case 'a':
28504 /* Listing option. Just ignore these, we don't support additional
28505 ones. */
28506 return 0;
b99bd4ef 28507
c19d1205
ZW
28508 default:
28509 for (opt = arm_opts; opt->option != NULL; opt++)
28510 {
28511 if (c == opt->option[0]
28512 && ((arg == NULL && opt->option[1] == 0)
28513 || streq (arg, opt->option + 1)))
28514 {
c19d1205 28515 /* If the option is deprecated, tell the user. */
278df34e 28516 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
28517 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
28518 arg ? arg : "", _(opt->deprecated));
b99bd4ef 28519
c19d1205
ZW
28520 if (opt->var != NULL)
28521 *opt->var = opt->value;
cc8a6dd0 28522
c19d1205
ZW
28523 return 1;
28524 }
28525 }
b99bd4ef 28526
e74cfd16
PB
28527 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
28528 {
28529 if (c == fopt->option[0]
28530 && ((arg == NULL && fopt->option[1] == 0)
28531 || streq (arg, fopt->option + 1)))
28532 {
e74cfd16 28533 /* If the option is deprecated, tell the user. */
278df34e 28534 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
28535 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
28536 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
28537
28538 if (fopt->var != NULL)
28539 *fopt->var = &fopt->value;
28540
28541 return 1;
28542 }
28543 }
28544
c19d1205
ZW
28545 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
28546 {
28547 /* These options are expected to have an argument. */
28548 if (c == lopt->option[0]
28549 && arg != NULL
28550 && strncmp (arg, lopt->option + 1,
28551 strlen (lopt->option + 1)) == 0)
28552 {
c19d1205 28553 /* If the option is deprecated, tell the user. */
278df34e 28554 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
28555 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
28556 _(lopt->deprecated));
b99bd4ef 28557
c19d1205
ZW
28558 /* Call the sup-option parser. */
28559 return lopt->func (arg + strlen (lopt->option) - 1);
28560 }
28561 }
a737bd4d 28562
c19d1205
ZW
28563 return 0;
28564 }
a394c00f 28565
c19d1205
ZW
28566 return 1;
28567}
a394c00f 28568
c19d1205
ZW
28569void
28570md_show_usage (FILE * fp)
a394c00f 28571{
c19d1205
ZW
28572 struct arm_option_table *opt;
28573 struct arm_long_option_table *lopt;
a394c00f 28574
c19d1205 28575 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 28576
c19d1205
ZW
28577 for (opt = arm_opts; opt->option != NULL; opt++)
28578 if (opt->help != NULL)
28579 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 28580
c19d1205
ZW
28581 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
28582 if (lopt->help != NULL)
28583 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 28584
c19d1205
ZW
28585#ifdef OPTION_EB
28586 fprintf (fp, _("\
28587 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
28588#endif
28589
c19d1205
ZW
28590#ifdef OPTION_EL
28591 fprintf (fp, _("\
28592 -EL assemble code for a little-endian cpu\n"));
a737bd4d 28593#endif
845b51d6
PB
28594
28595 fprintf (fp, _("\
28596 --fix-v4bx Allow BX in ARMv4 code\n"));
18a20338
CL
28597
28598#ifdef OBJ_ELF
28599 fprintf (fp, _("\
28600 --fdpic generate an FDPIC object file\n"));
28601#endif /* OBJ_ELF */
c19d1205 28602}
ee065d83 28603
ee065d83 28604#ifdef OBJ_ELF
0198d5e6 28605
62b3e311
PB
28606typedef struct
28607{
28608 int val;
28609 arm_feature_set flags;
28610} cpu_arch_ver_table;
28611
2c6b98ea
TP
28612/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
28613 chronologically for architectures, with an exception for ARMv6-M and
28614 ARMv6S-M due to legacy reasons. No new architecture should have a
28615 special case. This allows for build attribute selection results to be
28616 stable when new architectures are added. */
62b3e311
PB
28617static const cpu_arch_ver_table cpu_arch_ver[] =
28618{
031254f2
AV
28619 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
28620 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
28621 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
28622 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
28623 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
28624 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
28625 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
28626 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
28627 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
28628 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
28629 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
28630 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
28631 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
28632 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
28633 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
28634 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
28635 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
28636 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
28637 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
28638 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
28639 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
28640 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
28641 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
28642 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
2c6b98ea
TP
28643
28644 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
28645 always selected build attributes to match those of ARMv6-M
28646 (resp. ARMv6S-M). However, due to these architectures being a strict
28647 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
28648 would be selected when fully respecting chronology of architectures.
28649 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
28650 move them before ARMv7 architectures. */
031254f2
AV
28651 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
28652 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
28653
28654 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
28655 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
28656 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
28657 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
28658 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
28659 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
28660 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
28661 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
28662 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
28663 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
28664 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
28665 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
28666 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
28667 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
28668 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
28669 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
28670 {-1, ARM_ARCH_NONE}
62b3e311
PB
28671};
28672
ee3c0378 28673/* Set an attribute if it has not already been set by the user. */
0198d5e6 28674
ee3c0378
AS
28675static void
28676aeabi_set_attribute_int (int tag, int value)
28677{
28678 if (tag < 1
28679 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
28680 || !attributes_set_explicitly[tag])
28681 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
28682}
28683
28684static void
28685aeabi_set_attribute_string (int tag, const char *value)
28686{
28687 if (tag < 1
28688 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
28689 || !attributes_set_explicitly[tag])
28690 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
28691}
28692
2c6b98ea
TP
28693/* Return whether features in the *NEEDED feature set are available via
28694 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 28695
2c6b98ea
TP
28696static bfd_boolean
28697have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
28698 const arm_feature_set *needed)
28699{
28700 int i, nb_allowed_archs;
28701 arm_feature_set ext_fset;
28702 const struct arm_option_extension_value_table *opt;
28703
28704 ext_fset = arm_arch_none;
28705 for (opt = arm_extensions; opt->name != NULL; opt++)
28706 {
28707 /* Extension does not provide any feature we need. */
28708 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
28709 continue;
28710
28711 nb_allowed_archs =
28712 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
28713 for (i = 0; i < nb_allowed_archs; i++)
28714 {
28715 /* Empty entry. */
28716 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
28717 break;
28718
28719 /* Extension is available, add it. */
28720 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
28721 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
28722 }
28723 }
28724
28725 /* Can we enable all features in *needed? */
28726 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
28727}
28728
28729/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
28730 a given architecture feature set *ARCH_EXT_FSET including extension feature
28731 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
28732 - if true, check for an exact match of the architecture modulo extensions;
28733 - otherwise, select build attribute value of the first superset
28734 architecture released so that results remains stable when new architectures
28735 are added.
28736 For -march/-mcpu=all the build attribute value of the most featureful
28737 architecture is returned. Tag_CPU_arch_profile result is returned in
28738 PROFILE. */
0198d5e6 28739
2c6b98ea
TP
28740static int
28741get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
28742 const arm_feature_set *ext_fset,
28743 char *profile, int exact_match)
28744{
28745 arm_feature_set arch_fset;
28746 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
28747
28748 /* Select most featureful architecture with all its extensions if building
28749 for -march=all as the feature sets used to set build attributes. */
28750 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
28751 {
28752 /* Force revisiting of decision for each new architecture. */
031254f2 28753 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
2c6b98ea
TP
28754 *profile = 'A';
28755 return TAG_CPU_ARCH_V8;
28756 }
28757
28758 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
28759
28760 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
28761 {
28762 arm_feature_set known_arch_fset;
28763
28764 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
28765 if (exact_match)
28766 {
28767 /* Base architecture match user-specified architecture and
28768 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
28769 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
28770 {
28771 p_ver_ret = p_ver;
28772 goto found;
28773 }
28774 /* Base architecture match user-specified architecture only
28775 (eg. ARMv6-M in the same case as above). Record it in case we
28776 find a match with above condition. */
28777 else if (p_ver_ret == NULL
28778 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
28779 p_ver_ret = p_ver;
28780 }
28781 else
28782 {
28783
28784 /* Architecture has all features wanted. */
28785 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
28786 {
28787 arm_feature_set added_fset;
28788
28789 /* Compute features added by this architecture over the one
28790 recorded in p_ver_ret. */
28791 if (p_ver_ret != NULL)
28792 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
28793 p_ver_ret->flags);
28794 /* First architecture that match incl. with extensions, or the
28795 only difference in features over the recorded match is
28796 features that were optional and are now mandatory. */
28797 if (p_ver_ret == NULL
28798 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
28799 {
28800 p_ver_ret = p_ver;
28801 goto found;
28802 }
28803 }
28804 else if (p_ver_ret == NULL)
28805 {
28806 arm_feature_set needed_ext_fset;
28807
28808 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
28809
28810 /* Architecture has all features needed when using some
28811 extensions. Record it and continue searching in case there
28812 exist an architecture providing all needed features without
28813 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
28814 OS extension). */
28815 if (have_ext_for_needed_feat_p (&known_arch_fset,
28816 &needed_ext_fset))
28817 p_ver_ret = p_ver;
28818 }
28819 }
28820 }
28821
28822 if (p_ver_ret == NULL)
28823 return -1;
28824
28825found:
28826 /* Tag_CPU_arch_profile. */
28827 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
28828 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
28829 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
28830 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
28831 *profile = 'A';
28832 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
28833 *profile = 'R';
28834 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
28835 *profile = 'M';
28836 else
28837 *profile = '\0';
28838 return p_ver_ret->val;
28839}
28840
ee065d83 28841/* Set the public EABI object attributes. */
0198d5e6 28842
c168ce07 28843static void
ee065d83
PB
28844aeabi_set_public_attributes (void)
28845{
b90d5ba0 28846 char profile = '\0';
2c6b98ea 28847 int arch = -1;
90ec0d68 28848 int virt_sec = 0;
bca38921 28849 int fp16_optional = 0;
2c6b98ea
TP
28850 int skip_exact_match = 0;
28851 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 28852
54bab281
TP
28853 /* Autodetection mode, choose the architecture based the instructions
28854 actually used. */
28855 if (no_cpu_selected ())
28856 {
28857 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 28858
54bab281
TP
28859 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
28860 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 28861
54bab281
TP
28862 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
28863 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 28864
54bab281 28865 /* Code run during relaxation relies on selected_cpu being set. */
4d354d8b
TP
28866 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
28867 flags_ext = arm_arch_none;
28868 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
28869 selected_ext = flags_ext;
54bab281
TP
28870 selected_cpu = flags;
28871 }
28872 /* Otherwise, choose the architecture based on the capabilities of the
28873 requested cpu. */
28874 else
4d354d8b
TP
28875 {
28876 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
28877 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
28878 flags_ext = selected_ext;
28879 flags = selected_cpu;
28880 }
28881 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
7f78eb34 28882
ddd7f988 28883 /* Allow the user to override the reported architecture. */
4d354d8b 28884 if (!ARM_FEATURE_ZERO (selected_object_arch))
7a1d4c38 28885 {
4d354d8b 28886 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
2c6b98ea 28887 flags_ext = arm_arch_none;
7a1d4c38 28888 }
2c6b98ea 28889 else
4d354d8b 28890 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
2c6b98ea
TP
28891
28892 /* When this function is run again after relaxation has happened there is no
28893 way to determine whether an architecture or CPU was specified by the user:
28894 - selected_cpu is set above for relaxation to work;
28895 - march_cpu_opt is not set if only -mcpu or .cpu is used;
28896 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
28897 Therefore, if not in -march=all case we first try an exact match and fall
28898 back to autodetection. */
28899 if (!skip_exact_match)
28900 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
28901 if (arch == -1)
28902 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
28903 if (arch == -1)
28904 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 28905
ee065d83
PB
28906 /* Tag_CPU_name. */
28907 if (selected_cpu_name[0])
28908 {
91d6fa6a 28909 char *q;
ee065d83 28910
91d6fa6a
NC
28911 q = selected_cpu_name;
28912 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
28913 {
28914 int i;
5f4273c7 28915
91d6fa6a
NC
28916 q += 4;
28917 for (i = 0; q[i]; i++)
28918 q[i] = TOUPPER (q[i]);
ee065d83 28919 }
91d6fa6a 28920 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 28921 }
62f3b8c8 28922
ee065d83 28923 /* Tag_CPU_arch. */
ee3c0378 28924 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 28925
62b3e311 28926 /* Tag_CPU_arch_profile. */
69239280
MGD
28927 if (profile != '\0')
28928 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 28929
15afaa63 28930 /* Tag_DSP_extension. */
4d354d8b 28931 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
6c290d53 28932 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 28933
2c6b98ea 28934 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 28935 /* Tag_ARM_ISA_use. */
ee3c0378 28936 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 28937 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 28938 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 28939
ee065d83 28940 /* Tag_THUMB_ISA_use. */
ee3c0378 28941 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 28942 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
28943 {
28944 int thumb_isa_use;
28945
28946 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 28947 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
28948 thumb_isa_use = 3;
28949 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
28950 thumb_isa_use = 2;
28951 else
28952 thumb_isa_use = 1;
28953 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
28954 }
62f3b8c8 28955
ee065d83 28956 /* Tag_VFP_arch. */
a715796b
TG
28957 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
28958 aeabi_set_attribute_int (Tag_VFP_arch,
28959 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
28960 ? 7 : 8);
bca38921 28961 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
28962 aeabi_set_attribute_int (Tag_VFP_arch,
28963 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
28964 ? 5 : 6);
28965 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
28966 {
28967 fp16_optional = 1;
28968 aeabi_set_attribute_int (Tag_VFP_arch, 3);
28969 }
ada65aa3 28970 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
28971 {
28972 aeabi_set_attribute_int (Tag_VFP_arch, 4);
28973 fp16_optional = 1;
28974 }
ee3c0378
AS
28975 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
28976 aeabi_set_attribute_int (Tag_VFP_arch, 2);
28977 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 28978 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 28979 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 28980
4547cb56
NC
28981 /* Tag_ABI_HardFP_use. */
28982 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
28983 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
28984 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
28985
ee065d83 28986 /* Tag_WMMX_arch. */
ee3c0378
AS
28987 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
28988 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
28989 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
28990 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 28991
ee3c0378 28992 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
28993 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
28994 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
28995 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
28996 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
28997 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
28998 {
28999 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
29000 {
29001 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
29002 }
29003 else
29004 {
29005 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
29006 fp16_optional = 1;
29007 }
29008 }
fa94de6b 29009
a7ad558c
AV
29010 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
29011 aeabi_set_attribute_int (Tag_MVE_arch, 2);
29012 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
29013 aeabi_set_attribute_int (Tag_MVE_arch, 1);
29014
ee3c0378 29015 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 29016 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 29017 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 29018
69239280
MGD
29019 /* Tag_DIV_use.
29020
29021 We set Tag_DIV_use to two when integer divide instructions have been used
29022 in ARM state, or when Thumb integer divide instructions have been used,
29023 but we have no architecture profile set, nor have we any ARM instructions.
29024
4ed7ed8d
TP
29025 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
29026 by the base architecture.
bca38921 29027
69239280 29028 For new architectures we will have to check these tests. */
031254f2 29029 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
4ed7ed8d
TP
29030 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
29031 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
29032 aeabi_set_attribute_int (Tag_DIV_use, 0);
29033 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
29034 || (profile == '\0'
29035 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
29036 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 29037 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
29038
29039 /* Tag_MP_extension_use. */
29040 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
29041 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
29042
29043 /* Tag Virtualization_use. */
29044 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
29045 virt_sec |= 1;
29046 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
29047 virt_sec |= 2;
29048 if (virt_sec != 0)
29049 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
29050}
29051
c168ce07
TP
29052/* Post relaxation hook. Recompute ARM attributes now that relaxation is
29053 finished and free extension feature bits which will not be used anymore. */
0198d5e6 29054
c168ce07
TP
29055void
29056arm_md_post_relax (void)
29057{
29058 aeabi_set_public_attributes ();
4d354d8b
TP
29059 XDELETE (mcpu_ext_opt);
29060 mcpu_ext_opt = NULL;
29061 XDELETE (march_ext_opt);
29062 march_ext_opt = NULL;
c168ce07
TP
29063}
29064
104d59d1 29065/* Add the default contents for the .ARM.attributes section. */
0198d5e6 29066
ee065d83
PB
29067void
29068arm_md_end (void)
29069{
ee065d83
PB
29070 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
29071 return;
29072
29073 aeabi_set_public_attributes ();
ee065d83 29074}
8463be01 29075#endif /* OBJ_ELF */
ee065d83 29076
ee065d83
PB
29077/* Parse a .cpu directive. */
29078
29079static void
29080s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
29081{
e74cfd16 29082 const struct arm_cpu_option_table *opt;
ee065d83
PB
29083 char *name;
29084 char saved_char;
29085
29086 name = input_line_pointer;
5f4273c7 29087 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
29088 input_line_pointer++;
29089 saved_char = *input_line_pointer;
29090 *input_line_pointer = 0;
29091
29092 /* Skip the first "all" entry. */
29093 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
29094 if (streq (opt->name, name))
29095 {
4d354d8b
TP
29096 selected_arch = opt->value;
29097 selected_ext = opt->ext;
29098 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
ee065d83 29099 if (opt->canonical_name)
5f4273c7 29100 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
29101 else
29102 {
29103 int i;
29104 for (i = 0; opt->name[i]; i++)
29105 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 29106
ee065d83
PB
29107 selected_cpu_name[i] = 0;
29108 }
4d354d8b
TP
29109 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
29110
ee065d83
PB
29111 *input_line_pointer = saved_char;
29112 demand_empty_rest_of_line ();
29113 return;
29114 }
29115 as_bad (_("unknown cpu `%s'"), name);
29116 *input_line_pointer = saved_char;
29117 ignore_rest_of_line ();
29118}
29119
ee065d83
PB
29120/* Parse a .arch directive. */
29121
29122static void
29123s_arm_arch (int ignored ATTRIBUTE_UNUSED)
29124{
e74cfd16 29125 const struct arm_arch_option_table *opt;
ee065d83
PB
29126 char saved_char;
29127 char *name;
29128
29129 name = input_line_pointer;
5f4273c7 29130 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
29131 input_line_pointer++;
29132 saved_char = *input_line_pointer;
29133 *input_line_pointer = 0;
29134
29135 /* Skip the first "all" entry. */
29136 for (opt = arm_archs + 1; opt->name != NULL; opt++)
29137 if (streq (opt->name, name))
29138 {
4d354d8b
TP
29139 selected_arch = opt->value;
29140 selected_ext = arm_arch_none;
29141 selected_cpu = selected_arch;
5f4273c7 29142 strcpy (selected_cpu_name, opt->name);
4d354d8b 29143 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
29144 *input_line_pointer = saved_char;
29145 demand_empty_rest_of_line ();
29146 return;
29147 }
29148
29149 as_bad (_("unknown architecture `%s'\n"), name);
29150 *input_line_pointer = saved_char;
29151 ignore_rest_of_line ();
29152}
29153
7a1d4c38
PB
29154/* Parse a .object_arch directive. */
29155
29156static void
29157s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
29158{
29159 const struct arm_arch_option_table *opt;
29160 char saved_char;
29161 char *name;
29162
29163 name = input_line_pointer;
5f4273c7 29164 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
29165 input_line_pointer++;
29166 saved_char = *input_line_pointer;
29167 *input_line_pointer = 0;
29168
29169 /* Skip the first "all" entry. */
29170 for (opt = arm_archs + 1; opt->name != NULL; opt++)
29171 if (streq (opt->name, name))
29172 {
4d354d8b 29173 selected_object_arch = opt->value;
7a1d4c38
PB
29174 *input_line_pointer = saved_char;
29175 demand_empty_rest_of_line ();
29176 return;
29177 }
29178
29179 as_bad (_("unknown architecture `%s'\n"), name);
29180 *input_line_pointer = saved_char;
29181 ignore_rest_of_line ();
29182}
29183
69133863
MGD
29184/* Parse a .arch_extension directive. */
29185
29186static void
29187s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
29188{
29189 const struct arm_option_extension_value_table *opt;
29190 char saved_char;
29191 char *name;
29192 int adding_value = 1;
29193
29194 name = input_line_pointer;
29195 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
29196 input_line_pointer++;
29197 saved_char = *input_line_pointer;
29198 *input_line_pointer = 0;
29199
29200 if (strlen (name) >= 2
29201 && strncmp (name, "no", 2) == 0)
29202 {
29203 adding_value = 0;
29204 name += 2;
29205 }
29206
29207 for (opt = arm_extensions; opt->name != NULL; opt++)
29208 if (streq (opt->name, name))
29209 {
d942732e
TP
29210 int i, nb_allowed_archs =
29211 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
29212 for (i = 0; i < nb_allowed_archs; i++)
29213 {
29214 /* Empty entry. */
4d354d8b 29215 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
d942732e 29216 continue;
4d354d8b 29217 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
d942732e
TP
29218 break;
29219 }
29220
29221 if (i == nb_allowed_archs)
69133863
MGD
29222 {
29223 as_bad (_("architectural extension `%s' is not allowed for the "
29224 "current base architecture"), name);
29225 break;
29226 }
29227
29228 if (adding_value)
4d354d8b 29229 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
5a70a223 29230 opt->merge_value);
69133863 29231 else
4d354d8b 29232 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
69133863 29233
4d354d8b
TP
29234 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
29235 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
69133863
MGD
29236 *input_line_pointer = saved_char;
29237 demand_empty_rest_of_line ();
3d030cdb
TP
29238 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
29239 on this return so that duplicate extensions (extensions with the
29240 same name as a previous extension in the list) are not considered
29241 for command-line parsing. */
69133863
MGD
29242 return;
29243 }
29244
29245 if (opt->name == NULL)
e673710a 29246 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
29247
29248 *input_line_pointer = saved_char;
29249 ignore_rest_of_line ();
29250}
29251
ee065d83
PB
29252/* Parse a .fpu directive. */
29253
29254static void
29255s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
29256{
69133863 29257 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
29258 char saved_char;
29259 char *name;
29260
29261 name = input_line_pointer;
5f4273c7 29262 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
29263 input_line_pointer++;
29264 saved_char = *input_line_pointer;
29265 *input_line_pointer = 0;
5f4273c7 29266
ee065d83
PB
29267 for (opt = arm_fpus; opt->name != NULL; opt++)
29268 if (streq (opt->name, name))
29269 {
4d354d8b
TP
29270 selected_fpu = opt->value;
29271#ifndef CPU_DEFAULT
29272 if (no_cpu_selected ())
29273 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
29274 else
29275#endif
29276 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
29277 *input_line_pointer = saved_char;
29278 demand_empty_rest_of_line ();
29279 return;
29280 }
29281
29282 as_bad (_("unknown floating point format `%s'\n"), name);
29283 *input_line_pointer = saved_char;
29284 ignore_rest_of_line ();
29285}
ee065d83 29286
794ba86a 29287/* Copy symbol information. */
f31fef98 29288
794ba86a
DJ
29289void
29290arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
29291{
29292 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
29293}
e04befd0 29294
f31fef98 29295#ifdef OBJ_ELF
e04befd0
AS
29296/* Given a symbolic attribute NAME, return the proper integer value.
29297 Returns -1 if the attribute is not known. */
f31fef98 29298
e04befd0
AS
29299int
29300arm_convert_symbolic_attribute (const char *name)
29301{
f31fef98
NC
29302 static const struct
29303 {
29304 const char * name;
29305 const int tag;
29306 }
29307 attribute_table[] =
29308 {
29309 /* When you modify this table you should
29310 also modify the list in doc/c-arm.texi. */
e04befd0 29311#define T(tag) {#tag, tag}
f31fef98
NC
29312 T (Tag_CPU_raw_name),
29313 T (Tag_CPU_name),
29314 T (Tag_CPU_arch),
29315 T (Tag_CPU_arch_profile),
29316 T (Tag_ARM_ISA_use),
29317 T (Tag_THUMB_ISA_use),
75375b3e 29318 T (Tag_FP_arch),
f31fef98
NC
29319 T (Tag_VFP_arch),
29320 T (Tag_WMMX_arch),
29321 T (Tag_Advanced_SIMD_arch),
29322 T (Tag_PCS_config),
29323 T (Tag_ABI_PCS_R9_use),
29324 T (Tag_ABI_PCS_RW_data),
29325 T (Tag_ABI_PCS_RO_data),
29326 T (Tag_ABI_PCS_GOT_use),
29327 T (Tag_ABI_PCS_wchar_t),
29328 T (Tag_ABI_FP_rounding),
29329 T (Tag_ABI_FP_denormal),
29330 T (Tag_ABI_FP_exceptions),
29331 T (Tag_ABI_FP_user_exceptions),
29332 T (Tag_ABI_FP_number_model),
75375b3e 29333 T (Tag_ABI_align_needed),
f31fef98 29334 T (Tag_ABI_align8_needed),
75375b3e 29335 T (Tag_ABI_align_preserved),
f31fef98
NC
29336 T (Tag_ABI_align8_preserved),
29337 T (Tag_ABI_enum_size),
29338 T (Tag_ABI_HardFP_use),
29339 T (Tag_ABI_VFP_args),
29340 T (Tag_ABI_WMMX_args),
29341 T (Tag_ABI_optimization_goals),
29342 T (Tag_ABI_FP_optimization_goals),
29343 T (Tag_compatibility),
29344 T (Tag_CPU_unaligned_access),
75375b3e 29345 T (Tag_FP_HP_extension),
f31fef98
NC
29346 T (Tag_VFP_HP_extension),
29347 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
29348 T (Tag_MPextension_use),
29349 T (Tag_DIV_use),
f31fef98
NC
29350 T (Tag_nodefaults),
29351 T (Tag_also_compatible_with),
29352 T (Tag_conformance),
29353 T (Tag_T2EE_use),
29354 T (Tag_Virtualization_use),
15afaa63 29355 T (Tag_DSP_extension),
a7ad558c 29356 T (Tag_MVE_arch),
cd21e546 29357 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 29358#undef T
f31fef98 29359 };
e04befd0
AS
29360 unsigned int i;
29361
29362 if (name == NULL)
29363 return -1;
29364
f31fef98 29365 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 29366 if (streq (name, attribute_table[i].name))
e04befd0
AS
29367 return attribute_table[i].tag;
29368
29369 return -1;
29370}
267bf995 29371
93ef582d
NC
29372/* Apply sym value for relocations only in the case that they are for
29373 local symbols in the same segment as the fixup and you have the
29374 respective architectural feature for blx and simple switches. */
0198d5e6 29375
267bf995 29376int
93ef582d 29377arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
29378{
29379 if (fixP->fx_addsy
29380 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
29381 /* PR 17444: If the local symbol is in a different section then a reloc
29382 will always be generated for it, so applying the symbol value now
29383 will result in a double offset being stored in the relocation. */
29384 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 29385 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
29386 {
29387 switch (fixP->fx_r_type)
29388 {
29389 case BFD_RELOC_ARM_PCREL_BLX:
29390 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29391 if (ARM_IS_FUNC (fixP->fx_addsy))
29392 return 1;
29393 break;
29394
29395 case BFD_RELOC_ARM_PCREL_CALL:
29396 case BFD_RELOC_THUMB_PCREL_BLX:
29397 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 29398 return 1;
267bf995
RR
29399 break;
29400
29401 default:
29402 break;
29403 }
29404
29405 }
29406 return 0;
29407}
f31fef98 29408#endif /* OBJ_ELF */
This page took 3.728425 seconds and 4 git commands to generate.