]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
[binutils, ARM, 6/16] New BF instruction for Armv8.1-M Mainline
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
82704155 2 Copyright (C) 1994-2019 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b
RE
34#include "opcode/arm.h"
35
b99bd4ef
NC
36#ifdef OBJ_ELF
37#include "elf/arm.h"
a394c00f 38#include "dw2gencfi.h"
b99bd4ef
NC
39#endif
40
f0927246
NC
41#include "dwarf2dbg.h"
42
7ed4c4c5
NC
43#ifdef OBJ_ELF
44/* Must be at least the size of the largest unwind opcode (currently two). */
45#define ARM_OPCODE_CHUNK_SIZE 8
46
47/* This structure holds the unwinding state. */
48
49static struct
50{
c19d1205
ZW
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
7ed4c4c5 55 /* The segment containing the function. */
c19d1205
ZW
56 segT saved_seg;
57 subsegT saved_subseg;
7ed4c4c5
NC
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
c19d1205
ZW
60 int opcode_count;
61 int opcode_alloc;
7ed4c4c5 62 /* The number of bytes pushed to the stack. */
c19d1205 63 offsetT frame_size;
7ed4c4c5
NC
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
c19d1205 67 offsetT pending_offset;
7ed4c4c5 68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
7ed4c4c5 72 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 73 unsigned fp_used:1;
7ed4c4c5 74 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 75 unsigned sp_restored:1;
7ed4c4c5
NC
76} unwind;
77
18a20338
CL
78/* Whether --fdpic was given. */
79static int arm_fdpic;
80
8b1ad454
NC
81#endif /* OBJ_ELF */
82
4962c51a
MS
83/* Results from operand parsing worker functions. */
84
85typedef enum
86{
87 PARSE_OPERAND_SUCCESS,
88 PARSE_OPERAND_FAIL,
89 PARSE_OPERAND_FAIL_NO_BACKTRACK
90} parse_operand_result;
91
33a392fb
PB
92enum arm_float_abi
93{
94 ARM_FLOAT_ABI_HARD,
95 ARM_FLOAT_ABI_SOFTFP,
96 ARM_FLOAT_ABI_SOFT
97};
98
c19d1205 99/* Types of processor to assemble for. */
b99bd4ef 100#ifndef CPU_DEFAULT
8a59fff3 101/* The code that was here used to select a default CPU depending on compiler
fa94de6b 102 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
103 changing gas' default behaviour depending upon the build host.
104
105 If you have a target that requires a default CPU option then the you
106 should define CPU_DEFAULT here. */
b99bd4ef
NC
107#endif
108
109#ifndef FPU_DEFAULT
c820d418
MM
110# ifdef TE_LINUX
111# define FPU_DEFAULT FPU_ARCH_FPA
112# elif defined (TE_NetBSD)
113# ifdef OBJ_ELF
114# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
115# else
116 /* Legacy a.out format. */
117# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
118# endif
4e7fd91e
PB
119# elif defined (TE_VXWORKS)
120# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
121# else
122 /* For backwards compatibility, default to FPA. */
123# define FPU_DEFAULT FPU_ARCH_FPA
124# endif
125#endif /* ifndef FPU_DEFAULT */
b99bd4ef 126
c19d1205 127#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 128
4d354d8b
TP
129/* Current set of feature bits available (CPU+FPU). Different from
130 selected_cpu + selected_fpu in case of autodetection since the CPU
131 feature bits are then all set. */
e74cfd16 132static arm_feature_set cpu_variant;
4d354d8b
TP
133/* Feature bits used in each execution state. Used to set build attribute
134 (in particular Tag_*_ISA_use) in CPU autodetection mode. */
e74cfd16
PB
135static arm_feature_set arm_arch_used;
136static arm_feature_set thumb_arch_used;
b99bd4ef 137
b99bd4ef 138/* Flags stored in private area of BFD structure. */
c19d1205
ZW
139static int uses_apcs_26 = FALSE;
140static int atpcs = FALSE;
b34976b6
AM
141static int support_interwork = FALSE;
142static int uses_apcs_float = FALSE;
c19d1205 143static int pic_code = FALSE;
845b51d6 144static int fix_v4bx = FALSE;
278df34e
NS
145/* Warn on using deprecated features. */
146static int warn_on_deprecated = TRUE;
147
2e6976a8
DG
148/* Understand CodeComposer Studio assembly syntax. */
149bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
150
151/* Variables that we set while parsing command-line options. Once all
152 options have been read we re-process these values to set the real
153 assembly flags. */
4d354d8b
TP
154
155/* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1
156 instead of -mcpu=arm1). */
157static const arm_feature_set *legacy_cpu = NULL;
158static const arm_feature_set *legacy_fpu = NULL;
159
160/* CPU, extension and FPU feature bits selected by -mcpu. */
161static const arm_feature_set *mcpu_cpu_opt = NULL;
162static arm_feature_set *mcpu_ext_opt = NULL;
163static const arm_feature_set *mcpu_fpu_opt = NULL;
164
165/* CPU, extension and FPU feature bits selected by -march. */
166static const arm_feature_set *march_cpu_opt = NULL;
167static arm_feature_set *march_ext_opt = NULL;
168static const arm_feature_set *march_fpu_opt = NULL;
169
170/* Feature bits selected by -mfpu. */
171static const arm_feature_set *mfpu_opt = NULL;
e74cfd16
PB
172
173/* Constants for known architecture features. */
174static const arm_feature_set fpu_default = FPU_DEFAULT;
f85d59c3 175static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 176static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
177static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
178static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
e74cfd16
PB
179static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
180static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
69c9e028 181#ifdef OBJ_ELF
e74cfd16 182static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
69c9e028 183#endif
e74cfd16
PB
184static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
185
186#ifdef CPU_DEFAULT
187static const arm_feature_set cpu_default = CPU_DEFAULT;
188#endif
189
823d2571 190static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
4070243b 191static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
823d2571
TG
192static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
193static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
194static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
195static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
196static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
197static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 198static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
199 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
200static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
201static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
202static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
203static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
204static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
205static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
206static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
55e8aae7
SP
207/* Only for compatability of hint instructions. */
208static const arm_feature_set arm_ext_v6k_v6t2 =
209 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2);
823d2571
TG
210static const arm_feature_set arm_ext_v6_notm =
211 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
212static const arm_feature_set arm_ext_v6_dsp =
213 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
214static const arm_feature_set arm_ext_barrier =
215 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
216static const arm_feature_set arm_ext_msr =
217 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
218static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
219static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
220static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
221static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 222#ifdef OBJ_ELF
e7d39ed3 223static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 224#endif
823d2571 225static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 226static const arm_feature_set arm_ext_m =
173205ca 227 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
16a1fa25 228 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
229static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
230static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
231static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
232static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
233static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 234static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 235static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
236static const arm_feature_set arm_ext_v8m_main =
237 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
e12437dc
AV
238static const arm_feature_set arm_ext_v8_1m_main =
239ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
16a1fa25
TP
240/* Instructions in ARMv8-M only found in M profile architectures. */
241static const arm_feature_set arm_ext_v8m_m_only =
242 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
243static const arm_feature_set arm_ext_v6t2_v8m =
244 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
245/* Instructions shared between ARMv8-A and ARMv8-M. */
246static const arm_feature_set arm_ext_atomics =
247 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 248#ifdef OBJ_ELF
15afaa63
TP
249/* DSP instructions Tag_DSP_extension refers to. */
250static const arm_feature_set arm_ext_dsp =
251 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 252#endif
4d1464f2
MW
253static const arm_feature_set arm_ext_ras =
254 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
255/* FP16 instructions. */
256static const arm_feature_set arm_ext_fp16 =
257 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
01f48020
TC
258static const arm_feature_set arm_ext_fp16_fml =
259 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
dec41383
JW
260static const arm_feature_set arm_ext_v8_2 =
261 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
49e8a725
SN
262static const arm_feature_set arm_ext_v8_3 =
263 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
7fadb25d
SD
264static const arm_feature_set arm_ext_sb =
265 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
dad0c3bf
SD
266static const arm_feature_set arm_ext_predres =
267 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
e74cfd16
PB
268
269static const arm_feature_set arm_arch_any = ARM_ANY;
49fa50ef 270#ifdef OBJ_ELF
2c6b98ea 271static const arm_feature_set fpu_any = FPU_ANY;
49fa50ef 272#endif
f85d59c3 273static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
274static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
275static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
276
2d447fca 277static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 278 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 279static const arm_feature_set arm_cext_iwmmxt =
823d2571 280 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 281static const arm_feature_set arm_cext_xscale =
823d2571 282 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 283static const arm_feature_set arm_cext_maverick =
823d2571
TG
284 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
285static const arm_feature_set fpu_fpa_ext_v1 =
286 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
287static const arm_feature_set fpu_fpa_ext_v2 =
288 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 289static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
290 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
291static const arm_feature_set fpu_vfp_ext_v1 =
292 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
293static const arm_feature_set fpu_vfp_ext_v2 =
294 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
295static const arm_feature_set fpu_vfp_ext_v3xd =
296 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
297static const arm_feature_set fpu_vfp_ext_v3 =
298 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 299static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
300 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
301static const arm_feature_set fpu_neon_ext_v1 =
302 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 303static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 304 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
69c9e028 305#ifdef OBJ_ELF
823d2571
TG
306static const arm_feature_set fpu_vfp_fp16 =
307 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
308static const arm_feature_set fpu_neon_ext_fma =
309 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 310#endif
823d2571
TG
311static const arm_feature_set fpu_vfp_ext_fma =
312 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 313static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 314 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 315static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 316 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 317static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 318 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 319static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 320 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 321static const arm_feature_set crc_ext_armv8 =
823d2571 322 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 323static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 324 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
325static const arm_feature_set fpu_neon_ext_dotprod =
326 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 327
33a392fb 328static int mfloat_abi_opt = -1;
4d354d8b
TP
329/* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
330 directive. */
331static arm_feature_set selected_arch = ARM_ARCH_NONE;
332/* Extension feature bits selected by the last -mcpu/-march or .arch_extension
333 directive. */
334static arm_feature_set selected_ext = ARM_ARCH_NONE;
335/* Feature bits selected by the last -mcpu/-march or by the combination of the
336 last .cpu/.arch directive .arch_extension directives since that
337 directive. */
e74cfd16 338static arm_feature_set selected_cpu = ARM_ARCH_NONE;
4d354d8b
TP
339/* FPU feature bits selected by the last -mfpu or .fpu directive. */
340static arm_feature_set selected_fpu = FPU_NONE;
341/* Feature bits selected by the last .object_arch directive. */
342static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
ee065d83 343/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 344static char selected_cpu_name[20];
8d67f500 345
aacf0b33
KT
346extern FLONUM_TYPE generic_floating_point_number;
347
8d67f500
NC
348/* Return if no cpu was selected on command-line. */
349static bfd_boolean
350no_cpu_selected (void)
351{
823d2571 352 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
353}
354
7cc69913 355#ifdef OBJ_ELF
deeaaff8
DJ
356# ifdef EABI_DEFAULT
357static int meabi_flags = EABI_DEFAULT;
358# else
d507cf36 359static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 360# endif
e1da3f5b 361
ee3c0378
AS
362static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
363
e1da3f5b 364bfd_boolean
5f4273c7 365arm_is_eabi (void)
e1da3f5b
PB
366{
367 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
368}
7cc69913 369#endif
b99bd4ef 370
b99bd4ef 371#ifdef OBJ_ELF
c19d1205 372/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
373symbolS * GOT_symbol;
374#endif
375
b99bd4ef
NC
376/* 0: assemble for ARM,
377 1: assemble for Thumb,
378 2: assemble for Thumb even though target CPU does not support thumb
379 instructions. */
380static int thumb_mode = 0;
8dc2430f
NC
381/* A value distinct from the possible values for thumb_mode that we
382 can use to record whether thumb_mode has been copied into the
383 tc_frag_data field of a frag. */
384#define MODE_RECORDED (1 << 4)
b99bd4ef 385
e07e6e58
NC
386/* Specifies the intrinsic IT insn behavior mode. */
387enum implicit_it_mode
388{
389 IMPLICIT_IT_MODE_NEVER = 0x00,
390 IMPLICIT_IT_MODE_ARM = 0x01,
391 IMPLICIT_IT_MODE_THUMB = 0x02,
392 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
393};
394static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
395
c19d1205
ZW
396/* If unified_syntax is true, we are processing the new unified
397 ARM/Thumb syntax. Important differences from the old ARM mode:
398
399 - Immediate operands do not require a # prefix.
400 - Conditional affixes always appear at the end of the
401 instruction. (For backward compatibility, those instructions
402 that formerly had them in the middle, continue to accept them
403 there.)
404 - The IT instruction may appear, and if it does is validated
405 against subsequent conditional affixes. It does not generate
406 machine code.
407
408 Important differences from the old Thumb mode:
409
410 - Immediate operands do not require a # prefix.
411 - Most of the V6T2 instructions are only available in unified mode.
412 - The .N and .W suffixes are recognized and honored (it is an error
413 if they cannot be honored).
414 - All instructions set the flags if and only if they have an 's' affix.
415 - Conditional affixes may be used. They are validated against
416 preceding IT instructions. Unlike ARM mode, you cannot use a
417 conditional affix except in the scope of an IT instruction. */
418
419static bfd_boolean unified_syntax = FALSE;
b99bd4ef 420
bacebabc
RM
421/* An immediate operand can start with #, and ld*, st*, pld operands
422 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
423 before a [, which can appear as the first operand for pld.
424 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
425const char arm_symbol_chars[] = "#[]{}";
bacebabc 426
5287ad62
JB
427enum neon_el_type
428{
dcbf9037 429 NT_invtype,
5287ad62
JB
430 NT_untyped,
431 NT_integer,
432 NT_float,
433 NT_poly,
434 NT_signed,
dcbf9037 435 NT_unsigned
5287ad62
JB
436};
437
438struct neon_type_el
439{
440 enum neon_el_type type;
441 unsigned size;
442};
443
444#define NEON_MAX_TYPE_ELS 4
445
446struct neon_type
447{
448 struct neon_type_el el[NEON_MAX_TYPE_ELS];
449 unsigned elems;
450};
451
e07e6e58
NC
452enum it_instruction_type
453{
454 OUTSIDE_IT_INSN,
455 INSIDE_IT_INSN,
456 INSIDE_IT_LAST_INSN,
457 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 458 if inside, should be the last one. */
e07e6e58 459 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 460 i.e. BKPT and NOP. */
e07e6e58
NC
461 IT_INSN /* The IT insn has been parsed. */
462};
463
ad6cec43
MGD
464/* The maximum number of operands we need. */
465#define ARM_IT_MAX_OPERANDS 6
e2b0ab59 466#define ARM_IT_MAX_RELOCS 3
ad6cec43 467
b99bd4ef
NC
468struct arm_it
469{
c19d1205 470 const char * error;
b99bd4ef 471 unsigned long instruction;
c19d1205
ZW
472 int size;
473 int size_req;
474 int cond;
037e8744
JB
475 /* "uncond_value" is set to the value in place of the conditional field in
476 unconditional versions of the instruction, or -1 if nothing is
477 appropriate. */
478 int uncond_value;
5287ad62 479 struct neon_type vectype;
88714cb8
DG
480 /* This does not indicate an actual NEON instruction, only that
481 the mnemonic accepts neon-style type suffixes. */
482 int is_neon;
0110f2b8
PB
483 /* Set to the opcode if the instruction needs relaxation.
484 Zero if the instruction is not relaxed. */
485 unsigned long relax;
b99bd4ef
NC
486 struct
487 {
488 bfd_reloc_code_real_type type;
c19d1205
ZW
489 expressionS exp;
490 int pc_rel;
e2b0ab59 491 } relocs[ARM_IT_MAX_RELOCS];
b99bd4ef 492
e07e6e58
NC
493 enum it_instruction_type it_insn_type;
494
c19d1205
ZW
495 struct
496 {
497 unsigned reg;
ca3f61f7 498 signed int imm;
dcbf9037 499 struct neon_type_el vectype;
ca3f61f7
NC
500 unsigned present : 1; /* Operand present. */
501 unsigned isreg : 1; /* Operand was a register. */
502 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
503 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
504 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 505 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
506 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
507 instructions. This allows us to disambiguate ARM <-> vector insns. */
508 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 509 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 510 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 511 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
512 unsigned hasreloc : 1; /* Operand has relocation suffix. */
513 unsigned writeback : 1; /* Operand has trailing ! */
514 unsigned preind : 1; /* Preindexed address. */
515 unsigned postind : 1; /* Postindexed address. */
516 unsigned negative : 1; /* Index register was negated. */
517 unsigned shifted : 1; /* Shift applied to operation. */
518 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 519 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
520};
521
c19d1205 522static struct arm_it inst;
b99bd4ef
NC
523
524#define NUM_FLOAT_VALS 8
525
05d2d07e 526const char * fp_const[] =
b99bd4ef
NC
527{
528 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
529};
530
c19d1205 531/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
532#define MAX_LITTLENUMS 6
533
534LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
535
536#define FAIL (-1)
537#define SUCCESS (0)
538
539#define SUFF_S 1
540#define SUFF_D 2
541#define SUFF_E 3
542#define SUFF_P 4
543
c19d1205
ZW
544#define CP_T_X 0x00008000
545#define CP_T_Y 0x00400000
b99bd4ef 546
c19d1205
ZW
547#define CONDS_BIT 0x00100000
548#define LOAD_BIT 0x00100000
b99bd4ef
NC
549
550#define DOUBLE_LOAD_FLAG 0x00000001
551
552struct asm_cond
553{
d3ce72d0 554 const char * template_name;
c921be7d 555 unsigned long value;
b99bd4ef
NC
556};
557
c19d1205 558#define COND_ALWAYS 0xE
b99bd4ef 559
b99bd4ef
NC
560struct asm_psr
561{
d3ce72d0 562 const char * template_name;
c921be7d 563 unsigned long field;
b99bd4ef
NC
564};
565
62b3e311
PB
566struct asm_barrier_opt
567{
e797f7e0
MGD
568 const char * template_name;
569 unsigned long value;
570 const arm_feature_set arch;
62b3e311
PB
571};
572
2d2255b5 573/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
574#define SPSR_BIT (1 << 22)
575
c19d1205
ZW
576/* The individual PSR flag bits. */
577#define PSR_c (1 << 16)
578#define PSR_x (1 << 17)
579#define PSR_s (1 << 18)
580#define PSR_f (1 << 19)
b99bd4ef 581
c19d1205 582struct reloc_entry
bfae80f2 583{
0198d5e6 584 const char * name;
c921be7d 585 bfd_reloc_code_real_type reloc;
bfae80f2
RE
586};
587
5287ad62 588enum vfp_reg_pos
bfae80f2 589{
5287ad62
JB
590 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
591 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
592};
593
594enum vfp_ldstm_type
595{
596 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
597};
598
dcbf9037
JB
599/* Bits for DEFINED field in neon_typed_alias. */
600#define NTA_HASTYPE 1
601#define NTA_HASINDEX 2
602
603struct neon_typed_alias
604{
c921be7d
NC
605 unsigned char defined;
606 unsigned char index;
607 struct neon_type_el eltype;
dcbf9037
JB
608};
609
c19d1205 610/* ARM register categories. This includes coprocessor numbers and various
5aa75429
TP
611 architecture extensions' registers. Each entry should have an error message
612 in reg_expected_msgs below. */
c19d1205 613enum arm_reg_type
bfae80f2 614{
c19d1205
ZW
615 REG_TYPE_RN,
616 REG_TYPE_CP,
617 REG_TYPE_CN,
618 REG_TYPE_FN,
619 REG_TYPE_VFS,
620 REG_TYPE_VFD,
5287ad62 621 REG_TYPE_NQ,
037e8744 622 REG_TYPE_VFSD,
5287ad62 623 REG_TYPE_NDQ,
dec41383 624 REG_TYPE_NSD,
037e8744 625 REG_TYPE_NSDQ,
c19d1205
ZW
626 REG_TYPE_VFC,
627 REG_TYPE_MVF,
628 REG_TYPE_MVD,
629 REG_TYPE_MVFX,
630 REG_TYPE_MVDX,
631 REG_TYPE_MVAX,
632 REG_TYPE_DSPSC,
633 REG_TYPE_MMXWR,
634 REG_TYPE_MMXWC,
635 REG_TYPE_MMXWCG,
636 REG_TYPE_XSCALE,
90ec0d68 637 REG_TYPE_RNB
bfae80f2
RE
638};
639
dcbf9037
JB
640/* Structure for a hash table entry for a register.
641 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
642 information which states whether a vector type or index is specified (for a
643 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
644struct reg_entry
645{
c921be7d 646 const char * name;
90ec0d68 647 unsigned int number;
c921be7d
NC
648 unsigned char type;
649 unsigned char builtin;
650 struct neon_typed_alias * neon;
6c43fab6
RE
651};
652
c19d1205 653/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 654const char * const reg_expected_msgs[] =
c19d1205 655{
5aa75429
TP
656 [REG_TYPE_RN] = N_("ARM register expected"),
657 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
658 [REG_TYPE_CN] = N_("co-processor register expected"),
659 [REG_TYPE_FN] = N_("FPA register expected"),
660 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
661 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
662 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
663 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
664 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
665 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
666 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
667 " expected"),
668 [REG_TYPE_VFC] = N_("VFP system register expected"),
669 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
670 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
671 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
672 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
673 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
674 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
675 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
676 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
677 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
678 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
679 [REG_TYPE_RNB] = N_("")
6c43fab6
RE
680};
681
c19d1205 682/* Some well known registers that we refer to directly elsewhere. */
bd340a04 683#define REG_R12 12
c19d1205
ZW
684#define REG_SP 13
685#define REG_LR 14
686#define REG_PC 15
404ff6b5 687
b99bd4ef
NC
688/* ARM instructions take 4bytes in the object file, Thumb instructions
689 take 2: */
c19d1205 690#define INSN_SIZE 4
b99bd4ef
NC
691
692struct asm_opcode
693{
694 /* Basic string to match. */
d3ce72d0 695 const char * template_name;
c19d1205
ZW
696
697 /* Parameters to instruction. */
5be8be5d 698 unsigned int operands[8];
c19d1205
ZW
699
700 /* Conditional tag - see opcode_lookup. */
701 unsigned int tag : 4;
b99bd4ef
NC
702
703 /* Basic instruction code. */
c19d1205 704 unsigned int avalue : 28;
b99bd4ef 705
c19d1205
ZW
706 /* Thumb-format instruction code. */
707 unsigned int tvalue;
b99bd4ef 708
90e4755a 709 /* Which architecture variant provides this instruction. */
c921be7d
NC
710 const arm_feature_set * avariant;
711 const arm_feature_set * tvariant;
c19d1205
ZW
712
713 /* Function to call to encode instruction in ARM format. */
714 void (* aencode) (void);
b99bd4ef 715
c19d1205
ZW
716 /* Function to call to encode instruction in Thumb format. */
717 void (* tencode) (void);
b99bd4ef
NC
718};
719
a737bd4d
NC
720/* Defines for various bits that we will want to toggle. */
721#define INST_IMMEDIATE 0x02000000
722#define OFFSET_REG 0x02000000
c19d1205 723#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
724#define SHIFT_BY_REG 0x00000010
725#define PRE_INDEX 0x01000000
726#define INDEX_UP 0x00800000
727#define WRITE_BACK 0x00200000
728#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 729#define CPSI_MMOD 0x00020000
90e4755a 730
a737bd4d
NC
731#define LITERAL_MASK 0xf000f000
732#define OPCODE_MASK 0xfe1fffff
733#define V4_STR_BIT 0x00000020
8335d6aa 734#define VLDR_VMOV_SAME 0x0040f000
90e4755a 735
efd81785
PB
736#define T2_SUBS_PC_LR 0xf3de8f00
737
a737bd4d 738#define DATA_OP_SHIFT 21
bada4342 739#define SBIT_SHIFT 20
90e4755a 740
ef8d22e6
PB
741#define T2_OPCODE_MASK 0xfe1fffff
742#define T2_DATA_OP_SHIFT 21
bada4342 743#define T2_SBIT_SHIFT 20
ef8d22e6 744
6530b175
NC
745#define A_COND_MASK 0xf0000000
746#define A_PUSH_POP_OP_MASK 0x0fff0000
747
748/* Opcodes for pushing/poping registers to/from the stack. */
749#define A1_OPCODE_PUSH 0x092d0000
750#define A2_OPCODE_PUSH 0x052d0004
751#define A2_OPCODE_POP 0x049d0004
752
a737bd4d
NC
753/* Codes to distinguish the arithmetic instructions. */
754#define OPCODE_AND 0
755#define OPCODE_EOR 1
756#define OPCODE_SUB 2
757#define OPCODE_RSB 3
758#define OPCODE_ADD 4
759#define OPCODE_ADC 5
760#define OPCODE_SBC 6
761#define OPCODE_RSC 7
762#define OPCODE_TST 8
763#define OPCODE_TEQ 9
764#define OPCODE_CMP 10
765#define OPCODE_CMN 11
766#define OPCODE_ORR 12
767#define OPCODE_MOV 13
768#define OPCODE_BIC 14
769#define OPCODE_MVN 15
90e4755a 770
ef8d22e6
PB
771#define T2_OPCODE_AND 0
772#define T2_OPCODE_BIC 1
773#define T2_OPCODE_ORR 2
774#define T2_OPCODE_ORN 3
775#define T2_OPCODE_EOR 4
776#define T2_OPCODE_ADD 8
777#define T2_OPCODE_ADC 10
778#define T2_OPCODE_SBC 11
779#define T2_OPCODE_SUB 13
780#define T2_OPCODE_RSB 14
781
a737bd4d
NC
782#define T_OPCODE_MUL 0x4340
783#define T_OPCODE_TST 0x4200
784#define T_OPCODE_CMN 0x42c0
785#define T_OPCODE_NEG 0x4240
786#define T_OPCODE_MVN 0x43c0
90e4755a 787
a737bd4d
NC
788#define T_OPCODE_ADD_R3 0x1800
789#define T_OPCODE_SUB_R3 0x1a00
790#define T_OPCODE_ADD_HI 0x4400
791#define T_OPCODE_ADD_ST 0xb000
792#define T_OPCODE_SUB_ST 0xb080
793#define T_OPCODE_ADD_SP 0xa800
794#define T_OPCODE_ADD_PC 0xa000
795#define T_OPCODE_ADD_I8 0x3000
796#define T_OPCODE_SUB_I8 0x3800
797#define T_OPCODE_ADD_I3 0x1c00
798#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 799
a737bd4d
NC
800#define T_OPCODE_ASR_R 0x4100
801#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
802#define T_OPCODE_LSR_R 0x40c0
803#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
804#define T_OPCODE_ASR_I 0x1000
805#define T_OPCODE_LSL_I 0x0000
806#define T_OPCODE_LSR_I 0x0800
b99bd4ef 807
a737bd4d
NC
808#define T_OPCODE_MOV_I8 0x2000
809#define T_OPCODE_CMP_I8 0x2800
810#define T_OPCODE_CMP_LR 0x4280
811#define T_OPCODE_MOV_HR 0x4600
812#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 813
a737bd4d
NC
814#define T_OPCODE_LDR_PC 0x4800
815#define T_OPCODE_LDR_SP 0x9800
816#define T_OPCODE_STR_SP 0x9000
817#define T_OPCODE_LDR_IW 0x6800
818#define T_OPCODE_STR_IW 0x6000
819#define T_OPCODE_LDR_IH 0x8800
820#define T_OPCODE_STR_IH 0x8000
821#define T_OPCODE_LDR_IB 0x7800
822#define T_OPCODE_STR_IB 0x7000
823#define T_OPCODE_LDR_RW 0x5800
824#define T_OPCODE_STR_RW 0x5000
825#define T_OPCODE_LDR_RH 0x5a00
826#define T_OPCODE_STR_RH 0x5200
827#define T_OPCODE_LDR_RB 0x5c00
828#define T_OPCODE_STR_RB 0x5400
c9b604bd 829
a737bd4d
NC
830#define T_OPCODE_PUSH 0xb400
831#define T_OPCODE_POP 0xbc00
b99bd4ef 832
2fc8bdac 833#define T_OPCODE_BRANCH 0xe000
b99bd4ef 834
a737bd4d 835#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 836#define THUMB_PP_PC_LR 0x0100
c19d1205 837#define THUMB_LOAD_BIT 0x0800
53365c0d 838#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
839
840#define BAD_ARGS _("bad arguments to instruction")
fdfde340 841#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
842#define BAD_PC _("r15 not allowed here")
843#define BAD_COND _("instruction cannot be conditional")
844#define BAD_OVERLAP _("registers may not be the same")
845#define BAD_HIREG _("lo register required")
846#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 847#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5 848#define BAD_BRANCH _("branch must be last instruction in IT block")
e12437dc 849#define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
dfa9f0d5 850#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 851#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
852#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
853#define BAD_IT_COND _("incorrect condition in IT block")
854#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 855#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
856#define BAD_PC_ADDRESSING \
857 _("cannot use register index with PC-relative addressing")
858#define BAD_PC_WRITEBACK \
859 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
860#define BAD_RANGE _("branch out of range")
861#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 862#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 863#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
c19d1205 864
c921be7d
NC
865static struct hash_control * arm_ops_hsh;
866static struct hash_control * arm_cond_hsh;
867static struct hash_control * arm_shift_hsh;
868static struct hash_control * arm_psr_hsh;
869static struct hash_control * arm_v7m_psr_hsh;
870static struct hash_control * arm_reg_hsh;
871static struct hash_control * arm_reloc_hsh;
872static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 873
b99bd4ef
NC
874/* Stuff needed to resolve the label ambiguity
875 As:
876 ...
877 label: <insn>
878 may differ from:
879 ...
880 label:
5f4273c7 881 <insn> */
b99bd4ef
NC
882
883symbolS * last_label_seen;
b34976b6 884static int label_is_thumb_function_name = FALSE;
e07e6e58 885
3d0c9500
NC
886/* Literal pool structure. Held on a per-section
887 and per-sub-section basis. */
a737bd4d 888
c19d1205 889#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 890typedef struct literal_pool
b99bd4ef 891{
c921be7d
NC
892 expressionS literals [MAX_LITERAL_POOL_SIZE];
893 unsigned int next_free_entry;
894 unsigned int id;
895 symbolS * symbol;
896 segT section;
897 subsegT sub_section;
a8040cf2
NC
898#ifdef OBJ_ELF
899 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
900#endif
c921be7d 901 struct literal_pool * next;
8335d6aa 902 unsigned int alignment;
3d0c9500 903} literal_pool;
b99bd4ef 904
3d0c9500
NC
905/* Pointer to a linked list of literal pools. */
906literal_pool * list_of_pools = NULL;
e27ec89e 907
2e6976a8
DG
908typedef enum asmfunc_states
909{
910 OUTSIDE_ASMFUNC,
911 WAITING_ASMFUNC_NAME,
912 WAITING_ENDASMFUNC
913} asmfunc_states;
914
915static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
916
e07e6e58
NC
917#ifdef OBJ_ELF
918# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
919#else
920static struct current_it now_it;
921#endif
922
923static inline int
924now_it_compatible (int cond)
925{
926 return (cond & ~1) == (now_it.cc & ~1);
927}
928
929static inline int
930conditional_insn (void)
931{
932 return inst.cond != COND_ALWAYS;
933}
934
935static int in_it_block (void);
936
937static int handle_it_state (void);
938
939static void force_automatic_it_block_close (void);
940
c921be7d
NC
941static void it_fsm_post_encode (void);
942
e07e6e58
NC
943#define set_it_insn_type(type) \
944 do \
945 { \
946 inst.it_insn_type = type; \
947 if (handle_it_state () == FAIL) \
477330fc 948 return; \
e07e6e58
NC
949 } \
950 while (0)
951
c921be7d
NC
952#define set_it_insn_type_nonvoid(type, failret) \
953 do \
954 { \
955 inst.it_insn_type = type; \
956 if (handle_it_state () == FAIL) \
477330fc 957 return failret; \
c921be7d
NC
958 } \
959 while(0)
960
e07e6e58
NC
961#define set_it_insn_type_last() \
962 do \
963 { \
964 if (inst.cond == COND_ALWAYS) \
477330fc 965 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 966 else \
477330fc 967 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
968 } \
969 while (0)
970
c19d1205 971/* Pure syntax. */
b99bd4ef 972
c19d1205
ZW
973/* This array holds the chars that always start a comment. If the
974 pre-processor is disabled, these aren't very useful. */
2e6976a8 975char arm_comment_chars[] = "@";
3d0c9500 976
c19d1205
ZW
977/* This array holds the chars that only start a comment at the beginning of
978 a line. If the line seems to have the form '# 123 filename'
979 .line and .file directives will appear in the pre-processed output. */
980/* Note that input_file.c hand checks for '#' at the beginning of the
981 first line of the input file. This is because the compiler outputs
982 #NO_APP at the beginning of its output. */
983/* Also note that comments like this one will always work. */
984const char line_comment_chars[] = "#";
3d0c9500 985
2e6976a8 986char arm_line_separator_chars[] = ";";
b99bd4ef 987
c19d1205
ZW
988/* Chars that can be used to separate mant
989 from exp in floating point numbers. */
990const char EXP_CHARS[] = "eE";
3d0c9500 991
c19d1205
ZW
992/* Chars that mean this number is a floating point constant. */
993/* As in 0f12.456 */
994/* or 0d1.2345e12 */
b99bd4ef 995
c19d1205 996const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 997
c19d1205
ZW
998/* Prefix characters that indicate the start of an immediate
999 value. */
1000#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 1001
c19d1205
ZW
1002/* Separator character handling. */
1003
1004#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1005
1006static inline int
1007skip_past_char (char ** str, char c)
1008{
8ab8155f
NC
1009 /* PR gas/14987: Allow for whitespace before the expected character. */
1010 skip_whitespace (*str);
427d0db6 1011
c19d1205
ZW
1012 if (**str == c)
1013 {
1014 (*str)++;
1015 return SUCCESS;
3d0c9500 1016 }
c19d1205
ZW
1017 else
1018 return FAIL;
1019}
c921be7d 1020
c19d1205 1021#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 1022
c19d1205
ZW
1023/* Arithmetic expressions (possibly involving symbols). */
1024
1025/* Return TRUE if anything in the expression is a bignum. */
1026
0198d5e6 1027static bfd_boolean
c19d1205
ZW
1028walk_no_bignums (symbolS * sp)
1029{
1030 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 1031 return TRUE;
c19d1205
ZW
1032
1033 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 1034 {
c19d1205
ZW
1035 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1036 || (symbol_get_value_expression (sp)->X_op_symbol
1037 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
1038 }
1039
0198d5e6 1040 return FALSE;
3d0c9500
NC
1041}
1042
0198d5e6 1043static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
1044
1045/* Third argument to my_get_expression. */
1046#define GE_NO_PREFIX 0
1047#define GE_IMM_PREFIX 1
1048#define GE_OPT_PREFIX 2
5287ad62
JB
1049/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1050 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1051#define GE_OPT_PREFIX_BIG 3
a737bd4d 1052
b99bd4ef 1053static int
c19d1205 1054my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1055{
c19d1205 1056 char * save_in;
b99bd4ef 1057
c19d1205
ZW
1058 /* In unified syntax, all prefixes are optional. */
1059 if (unified_syntax)
5287ad62 1060 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1061 : GE_OPT_PREFIX;
b99bd4ef 1062
c19d1205 1063 switch (prefix_mode)
b99bd4ef 1064 {
c19d1205
ZW
1065 case GE_NO_PREFIX: break;
1066 case GE_IMM_PREFIX:
1067 if (!is_immediate_prefix (**str))
1068 {
1069 inst.error = _("immediate expression requires a # prefix");
1070 return FAIL;
1071 }
1072 (*str)++;
1073 break;
1074 case GE_OPT_PREFIX:
5287ad62 1075 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1076 if (is_immediate_prefix (**str))
1077 (*str)++;
1078 break;
0198d5e6
TC
1079 default:
1080 abort ();
c19d1205 1081 }
b99bd4ef 1082
c19d1205 1083 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1084
c19d1205
ZW
1085 save_in = input_line_pointer;
1086 input_line_pointer = *str;
0198d5e6 1087 in_my_get_expression = TRUE;
2ac93be7 1088 expression (ep);
0198d5e6 1089 in_my_get_expression = FALSE;
c19d1205 1090
f86adc07 1091 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1092 {
f86adc07 1093 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1094 *str = input_line_pointer;
1095 input_line_pointer = save_in;
1096 if (inst.error == NULL)
f86adc07
NS
1097 inst.error = (ep->X_op == O_absent
1098 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1099 return 1;
1100 }
b99bd4ef 1101
c19d1205
ZW
1102 /* Get rid of any bignums now, so that we don't generate an error for which
1103 we can't establish a line number later on. Big numbers are never valid
1104 in instructions, which is where this routine is always called. */
5287ad62
JB
1105 if (prefix_mode != GE_OPT_PREFIX_BIG
1106 && (ep->X_op == O_big
477330fc 1107 || (ep->X_add_symbol
5287ad62 1108 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1109 || (ep->X_op_symbol
5287ad62 1110 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1111 {
1112 inst.error = _("invalid constant");
1113 *str = input_line_pointer;
1114 input_line_pointer = save_in;
1115 return 1;
1116 }
b99bd4ef 1117
c19d1205
ZW
1118 *str = input_line_pointer;
1119 input_line_pointer = save_in;
0198d5e6 1120 return SUCCESS;
b99bd4ef
NC
1121}
1122
c19d1205
ZW
1123/* Turn a string in input_line_pointer into a floating point constant
1124 of type TYPE, and store the appropriate bytes in *LITP. The number
1125 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1126 returned, or NULL on OK.
b99bd4ef 1127
c19d1205
ZW
1128 Note that fp constants aren't represent in the normal way on the ARM.
1129 In big endian mode, things are as expected. However, in little endian
1130 mode fp constants are big-endian word-wise, and little-endian byte-wise
1131 within the words. For example, (double) 1.1 in big endian mode is
1132 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1133 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1134
c19d1205 1135 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1136
6d4af3c2 1137const char *
c19d1205
ZW
1138md_atof (int type, char * litP, int * sizeP)
1139{
1140 int prec;
1141 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1142 char *t;
1143 int i;
b99bd4ef 1144
c19d1205
ZW
1145 switch (type)
1146 {
1147 case 'f':
1148 case 'F':
1149 case 's':
1150 case 'S':
1151 prec = 2;
1152 break;
b99bd4ef 1153
c19d1205
ZW
1154 case 'd':
1155 case 'D':
1156 case 'r':
1157 case 'R':
1158 prec = 4;
1159 break;
b99bd4ef 1160
c19d1205
ZW
1161 case 'x':
1162 case 'X':
499ac353 1163 prec = 5;
c19d1205 1164 break;
b99bd4ef 1165
c19d1205
ZW
1166 case 'p':
1167 case 'P':
499ac353 1168 prec = 5;
c19d1205 1169 break;
a737bd4d 1170
c19d1205
ZW
1171 default:
1172 *sizeP = 0;
499ac353 1173 return _("Unrecognized or unsupported floating point constant");
c19d1205 1174 }
b99bd4ef 1175
c19d1205
ZW
1176 t = atof_ieee (input_line_pointer, type, words);
1177 if (t)
1178 input_line_pointer = t;
499ac353 1179 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1180
c19d1205
ZW
1181 if (target_big_endian)
1182 {
1183 for (i = 0; i < prec; i++)
1184 {
499ac353
NC
1185 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1186 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1187 }
1188 }
1189 else
1190 {
e74cfd16 1191 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1192 for (i = prec - 1; i >= 0; i--)
1193 {
499ac353
NC
1194 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1195 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1196 }
1197 else
1198 /* For a 4 byte float the order of elements in `words' is 1 0.
1199 For an 8 byte float the order is 1 0 3 2. */
1200 for (i = 0; i < prec; i += 2)
1201 {
499ac353
NC
1202 md_number_to_chars (litP, (valueT) words[i + 1],
1203 sizeof (LITTLENUM_TYPE));
1204 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1205 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1206 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1207 }
1208 }
b99bd4ef 1209
499ac353 1210 return NULL;
c19d1205 1211}
b99bd4ef 1212
c19d1205
ZW
1213/* We handle all bad expressions here, so that we can report the faulty
1214 instruction in the error message. */
0198d5e6 1215
c19d1205 1216void
91d6fa6a 1217md_operand (expressionS * exp)
c19d1205
ZW
1218{
1219 if (in_my_get_expression)
91d6fa6a 1220 exp->X_op = O_illegal;
b99bd4ef
NC
1221}
1222
c19d1205 1223/* Immediate values. */
b99bd4ef 1224
0198d5e6 1225#ifdef OBJ_ELF
c19d1205
ZW
1226/* Generic immediate-value read function for use in directives.
1227 Accepts anything that 'expression' can fold to a constant.
1228 *val receives the number. */
0198d5e6 1229
c19d1205
ZW
1230static int
1231immediate_for_directive (int *val)
b99bd4ef 1232{
c19d1205
ZW
1233 expressionS exp;
1234 exp.X_op = O_illegal;
b99bd4ef 1235
c19d1205
ZW
1236 if (is_immediate_prefix (*input_line_pointer))
1237 {
1238 input_line_pointer++;
1239 expression (&exp);
1240 }
b99bd4ef 1241
c19d1205
ZW
1242 if (exp.X_op != O_constant)
1243 {
1244 as_bad (_("expected #constant"));
1245 ignore_rest_of_line ();
1246 return FAIL;
1247 }
1248 *val = exp.X_add_number;
1249 return SUCCESS;
b99bd4ef 1250}
c19d1205 1251#endif
b99bd4ef 1252
c19d1205 1253/* Register parsing. */
b99bd4ef 1254
c19d1205
ZW
1255/* Generic register parser. CCP points to what should be the
1256 beginning of a register name. If it is indeed a valid register
1257 name, advance CCP over it and return the reg_entry structure;
1258 otherwise return NULL. Does not issue diagnostics. */
1259
1260static struct reg_entry *
1261arm_reg_parse_multi (char **ccp)
b99bd4ef 1262{
c19d1205
ZW
1263 char *start = *ccp;
1264 char *p;
1265 struct reg_entry *reg;
b99bd4ef 1266
477330fc
RM
1267 skip_whitespace (start);
1268
c19d1205
ZW
1269#ifdef REGISTER_PREFIX
1270 if (*start != REGISTER_PREFIX)
01cfc07f 1271 return NULL;
c19d1205
ZW
1272 start++;
1273#endif
1274#ifdef OPTIONAL_REGISTER_PREFIX
1275 if (*start == OPTIONAL_REGISTER_PREFIX)
1276 start++;
1277#endif
b99bd4ef 1278
c19d1205
ZW
1279 p = start;
1280 if (!ISALPHA (*p) || !is_name_beginner (*p))
1281 return NULL;
b99bd4ef 1282
c19d1205
ZW
1283 do
1284 p++;
1285 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1286
1287 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1288
1289 if (!reg)
1290 return NULL;
1291
1292 *ccp = p;
1293 return reg;
b99bd4ef
NC
1294}
1295
1296static int
dcbf9037 1297arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1298 enum arm_reg_type type)
b99bd4ef 1299{
c19d1205
ZW
1300 /* Alternative syntaxes are accepted for a few register classes. */
1301 switch (type)
1302 {
1303 case REG_TYPE_MVF:
1304 case REG_TYPE_MVD:
1305 case REG_TYPE_MVFX:
1306 case REG_TYPE_MVDX:
1307 /* Generic coprocessor register names are allowed for these. */
79134647 1308 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1309 return reg->number;
1310 break;
69b97547 1311
c19d1205
ZW
1312 case REG_TYPE_CP:
1313 /* For backward compatibility, a bare number is valid here. */
1314 {
1315 unsigned long processor = strtoul (start, ccp, 10);
1316 if (*ccp != start && processor <= 15)
1317 return processor;
1318 }
1a0670f3 1319 /* Fall through. */
6057a28f 1320
c19d1205
ZW
1321 case REG_TYPE_MMXWC:
1322 /* WC includes WCG. ??? I'm not sure this is true for all
1323 instructions that take WC registers. */
79134647 1324 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1325 return reg->number;
6057a28f 1326 break;
c19d1205 1327
6057a28f 1328 default:
c19d1205 1329 break;
6057a28f
NC
1330 }
1331
dcbf9037
JB
1332 return FAIL;
1333}
1334
1335/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1336 return value is the register number or FAIL. */
1337
1338static int
1339arm_reg_parse (char **ccp, enum arm_reg_type type)
1340{
1341 char *start = *ccp;
1342 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1343 int ret;
1344
1345 /* Do not allow a scalar (reg+index) to parse as a register. */
1346 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1347 return FAIL;
1348
1349 if (reg && reg->type == type)
1350 return reg->number;
1351
1352 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1353 return ret;
1354
c19d1205
ZW
1355 *ccp = start;
1356 return FAIL;
1357}
69b97547 1358
dcbf9037
JB
1359/* Parse a Neon type specifier. *STR should point at the leading '.'
1360 character. Does no verification at this stage that the type fits the opcode
1361 properly. E.g.,
1362
1363 .i32.i32.s16
1364 .s32.f32
1365 .u16
1366
1367 Can all be legally parsed by this function.
1368
1369 Fills in neon_type struct pointer with parsed information, and updates STR
1370 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1371 type, FAIL if not. */
1372
1373static int
1374parse_neon_type (struct neon_type *type, char **str)
1375{
1376 char *ptr = *str;
1377
1378 if (type)
1379 type->elems = 0;
1380
1381 while (type->elems < NEON_MAX_TYPE_ELS)
1382 {
1383 enum neon_el_type thistype = NT_untyped;
1384 unsigned thissize = -1u;
1385
1386 if (*ptr != '.')
1387 break;
1388
1389 ptr++;
1390
1391 /* Just a size without an explicit type. */
1392 if (ISDIGIT (*ptr))
1393 goto parsesize;
1394
1395 switch (TOLOWER (*ptr))
1396 {
1397 case 'i': thistype = NT_integer; break;
1398 case 'f': thistype = NT_float; break;
1399 case 'p': thistype = NT_poly; break;
1400 case 's': thistype = NT_signed; break;
1401 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1402 case 'd':
1403 thistype = NT_float;
1404 thissize = 64;
1405 ptr++;
1406 goto done;
dcbf9037
JB
1407 default:
1408 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1409 return FAIL;
1410 }
1411
1412 ptr++;
1413
1414 /* .f is an abbreviation for .f32. */
1415 if (thistype == NT_float && !ISDIGIT (*ptr))
1416 thissize = 32;
1417 else
1418 {
1419 parsesize:
1420 thissize = strtoul (ptr, &ptr, 10);
1421
1422 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1423 && thissize != 64)
1424 {
1425 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1426 return FAIL;
1427 }
1428 }
1429
037e8744 1430 done:
dcbf9037 1431 if (type)
477330fc
RM
1432 {
1433 type->el[type->elems].type = thistype;
dcbf9037
JB
1434 type->el[type->elems].size = thissize;
1435 type->elems++;
1436 }
1437 }
1438
1439 /* Empty/missing type is not a successful parse. */
1440 if (type->elems == 0)
1441 return FAIL;
1442
1443 *str = ptr;
1444
1445 return SUCCESS;
1446}
1447
1448/* Errors may be set multiple times during parsing or bit encoding
1449 (particularly in the Neon bits), but usually the earliest error which is set
1450 will be the most meaningful. Avoid overwriting it with later (cascading)
1451 errors by calling this function. */
1452
1453static void
1454first_error (const char *err)
1455{
1456 if (!inst.error)
1457 inst.error = err;
1458}
1459
1460/* Parse a single type, e.g. ".s32", leading period included. */
1461static int
1462parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1463{
1464 char *str = *ccp;
1465 struct neon_type optype;
1466
1467 if (*str == '.')
1468 {
1469 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1470 {
1471 if (optype.elems == 1)
1472 *vectype = optype.el[0];
1473 else
1474 {
1475 first_error (_("only one type should be specified for operand"));
1476 return FAIL;
1477 }
1478 }
dcbf9037 1479 else
477330fc
RM
1480 {
1481 first_error (_("vector type expected"));
1482 return FAIL;
1483 }
dcbf9037
JB
1484 }
1485 else
1486 return FAIL;
5f4273c7 1487
dcbf9037 1488 *ccp = str;
5f4273c7 1489
dcbf9037
JB
1490 return SUCCESS;
1491}
1492
1493/* Special meanings for indices (which have a range of 0-7), which will fit into
1494 a 4-bit integer. */
1495
1496#define NEON_ALL_LANES 15
1497#define NEON_INTERLEAVE_LANES 14
1498
1499/* Parse either a register or a scalar, with an optional type. Return the
1500 register number, and optionally fill in the actual type of the register
1501 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1502 type/index information in *TYPEINFO. */
1503
1504static int
1505parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1506 enum arm_reg_type *rtype,
1507 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1508{
1509 char *str = *ccp;
1510 struct reg_entry *reg = arm_reg_parse_multi (&str);
1511 struct neon_typed_alias atype;
1512 struct neon_type_el parsetype;
1513
1514 atype.defined = 0;
1515 atype.index = -1;
1516 atype.eltype.type = NT_invtype;
1517 atype.eltype.size = -1;
1518
1519 /* Try alternate syntax for some types of register. Note these are mutually
1520 exclusive with the Neon syntax extensions. */
1521 if (reg == NULL)
1522 {
1523 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1524 if (altreg != FAIL)
477330fc 1525 *ccp = str;
dcbf9037 1526 if (typeinfo)
477330fc 1527 *typeinfo = atype;
dcbf9037
JB
1528 return altreg;
1529 }
1530
037e8744
JB
1531 /* Undo polymorphism when a set of register types may be accepted. */
1532 if ((type == REG_TYPE_NDQ
1533 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1534 || (type == REG_TYPE_VFSD
477330fc 1535 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1536 || (type == REG_TYPE_NSDQ
477330fc
RM
1537 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1538 || reg->type == REG_TYPE_NQ))
dec41383
JW
1539 || (type == REG_TYPE_NSD
1540 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
f512f76f
NC
1541 || (type == REG_TYPE_MMXWC
1542 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1543 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1544
1545 if (type != reg->type)
1546 return FAIL;
1547
1548 if (reg->neon)
1549 atype = *reg->neon;
5f4273c7 1550
dcbf9037
JB
1551 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1552 {
1553 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1554 {
1555 first_error (_("can't redefine type for operand"));
1556 return FAIL;
1557 }
dcbf9037
JB
1558 atype.defined |= NTA_HASTYPE;
1559 atype.eltype = parsetype;
1560 }
5f4273c7 1561
dcbf9037
JB
1562 if (skip_past_char (&str, '[') == SUCCESS)
1563 {
dec41383
JW
1564 if (type != REG_TYPE_VFD
1565 && !(type == REG_TYPE_VFS
1566 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2)))
477330fc
RM
1567 {
1568 first_error (_("only D registers may be indexed"));
1569 return FAIL;
1570 }
5f4273c7 1571
dcbf9037 1572 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1573 {
1574 first_error (_("can't change index for operand"));
1575 return FAIL;
1576 }
dcbf9037
JB
1577
1578 atype.defined |= NTA_HASINDEX;
1579
1580 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1581 atype.index = NEON_ALL_LANES;
dcbf9037 1582 else
477330fc
RM
1583 {
1584 expressionS exp;
dcbf9037 1585
477330fc 1586 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1587
477330fc
RM
1588 if (exp.X_op != O_constant)
1589 {
1590 first_error (_("constant expression required"));
1591 return FAIL;
1592 }
dcbf9037 1593
477330fc
RM
1594 if (skip_past_char (&str, ']') == FAIL)
1595 return FAIL;
dcbf9037 1596
477330fc
RM
1597 atype.index = exp.X_add_number;
1598 }
dcbf9037 1599 }
5f4273c7 1600
dcbf9037
JB
1601 if (typeinfo)
1602 *typeinfo = atype;
5f4273c7 1603
dcbf9037
JB
1604 if (rtype)
1605 *rtype = type;
5f4273c7 1606
dcbf9037 1607 *ccp = str;
5f4273c7 1608
dcbf9037
JB
1609 return reg->number;
1610}
1611
1612/* Like arm_reg_parse, but allow allow the following extra features:
1613 - If RTYPE is non-zero, return the (possibly restricted) type of the
1614 register (e.g. Neon double or quad reg when either has been requested).
1615 - If this is a Neon vector type with additional type information, fill
1616 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1617 This function will fault on encountering a scalar. */
dcbf9037
JB
1618
1619static int
1620arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1621 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1622{
1623 struct neon_typed_alias atype;
1624 char *str = *ccp;
1625 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1626
1627 if (reg == FAIL)
1628 return FAIL;
1629
0855e32b
NS
1630 /* Do not allow regname(... to parse as a register. */
1631 if (*str == '(')
1632 return FAIL;
1633
dcbf9037
JB
1634 /* Do not allow a scalar (reg+index) to parse as a register. */
1635 if ((atype.defined & NTA_HASINDEX) != 0)
1636 {
1637 first_error (_("register operand expected, but got scalar"));
1638 return FAIL;
1639 }
1640
1641 if (vectype)
1642 *vectype = atype.eltype;
1643
1644 *ccp = str;
1645
1646 return reg;
1647}
1648
1649#define NEON_SCALAR_REG(X) ((X) >> 4)
1650#define NEON_SCALAR_INDEX(X) ((X) & 15)
1651
5287ad62
JB
1652/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1653 have enough information to be able to do a good job bounds-checking. So, we
1654 just do easy checks here, and do further checks later. */
1655
1656static int
dcbf9037 1657parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1658{
dcbf9037 1659 int reg;
5287ad62 1660 char *str = *ccp;
dcbf9037 1661 struct neon_typed_alias atype;
dec41383
JW
1662 enum arm_reg_type reg_type = REG_TYPE_VFD;
1663
1664 if (elsize == 4)
1665 reg_type = REG_TYPE_VFS;
5f4273c7 1666
dec41383 1667 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
5f4273c7 1668
dcbf9037 1669 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1670 return FAIL;
5f4273c7 1671
dcbf9037 1672 if (atype.index == NEON_ALL_LANES)
5287ad62 1673 {
dcbf9037 1674 first_error (_("scalar must have an index"));
5287ad62
JB
1675 return FAIL;
1676 }
dcbf9037 1677 else if (atype.index >= 64 / elsize)
5287ad62 1678 {
dcbf9037 1679 first_error (_("scalar index out of range"));
5287ad62
JB
1680 return FAIL;
1681 }
5f4273c7 1682
dcbf9037
JB
1683 if (type)
1684 *type = atype.eltype;
5f4273c7 1685
5287ad62 1686 *ccp = str;
5f4273c7 1687
dcbf9037 1688 return reg * 16 + atype.index;
5287ad62
JB
1689}
1690
c19d1205 1691/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1692
c19d1205
ZW
1693static long
1694parse_reg_list (char ** strp)
1695{
1696 char * str = * strp;
1697 long range = 0;
1698 int another_range;
a737bd4d 1699
c19d1205
ZW
1700 /* We come back here if we get ranges concatenated by '+' or '|'. */
1701 do
6057a28f 1702 {
477330fc
RM
1703 skip_whitespace (str);
1704
c19d1205 1705 another_range = 0;
a737bd4d 1706
c19d1205
ZW
1707 if (*str == '{')
1708 {
1709 int in_range = 0;
1710 int cur_reg = -1;
a737bd4d 1711
c19d1205
ZW
1712 str++;
1713 do
1714 {
1715 int reg;
6057a28f 1716
dcbf9037 1717 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1718 {
dcbf9037 1719 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1720 return FAIL;
1721 }
a737bd4d 1722
c19d1205
ZW
1723 if (in_range)
1724 {
1725 int i;
a737bd4d 1726
c19d1205
ZW
1727 if (reg <= cur_reg)
1728 {
dcbf9037 1729 first_error (_("bad range in register list"));
c19d1205
ZW
1730 return FAIL;
1731 }
40a18ebd 1732
c19d1205
ZW
1733 for (i = cur_reg + 1; i < reg; i++)
1734 {
1735 if (range & (1 << i))
1736 as_tsktsk
1737 (_("Warning: duplicated register (r%d) in register list"),
1738 i);
1739 else
1740 range |= 1 << i;
1741 }
1742 in_range = 0;
1743 }
a737bd4d 1744
c19d1205
ZW
1745 if (range & (1 << reg))
1746 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1747 reg);
1748 else if (reg <= cur_reg)
1749 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1750
c19d1205
ZW
1751 range |= 1 << reg;
1752 cur_reg = reg;
1753 }
1754 while (skip_past_comma (&str) != FAIL
1755 || (in_range = 1, *str++ == '-'));
1756 str--;
a737bd4d 1757
d996d970 1758 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1759 {
dcbf9037 1760 first_error (_("missing `}'"));
c19d1205
ZW
1761 return FAIL;
1762 }
1763 }
1764 else
1765 {
91d6fa6a 1766 expressionS exp;
40a18ebd 1767
91d6fa6a 1768 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1769 return FAIL;
40a18ebd 1770
91d6fa6a 1771 if (exp.X_op == O_constant)
c19d1205 1772 {
91d6fa6a
NC
1773 if (exp.X_add_number
1774 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1775 {
1776 inst.error = _("invalid register mask");
1777 return FAIL;
1778 }
a737bd4d 1779
91d6fa6a 1780 if ((range & exp.X_add_number) != 0)
c19d1205 1781 {
91d6fa6a 1782 int regno = range & exp.X_add_number;
a737bd4d 1783
c19d1205
ZW
1784 regno &= -regno;
1785 regno = (1 << regno) - 1;
1786 as_tsktsk
1787 (_("Warning: duplicated register (r%d) in register list"),
1788 regno);
1789 }
a737bd4d 1790
91d6fa6a 1791 range |= exp.X_add_number;
c19d1205
ZW
1792 }
1793 else
1794 {
e2b0ab59 1795 if (inst.relocs[0].type != 0)
c19d1205
ZW
1796 {
1797 inst.error = _("expression too complex");
1798 return FAIL;
1799 }
a737bd4d 1800
e2b0ab59
AV
1801 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
1802 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
1803 inst.relocs[0].pc_rel = 0;
c19d1205
ZW
1804 }
1805 }
a737bd4d 1806
c19d1205
ZW
1807 if (*str == '|' || *str == '+')
1808 {
1809 str++;
1810 another_range = 1;
1811 }
a737bd4d 1812 }
c19d1205 1813 while (another_range);
a737bd4d 1814
c19d1205
ZW
1815 *strp = str;
1816 return range;
a737bd4d
NC
1817}
1818
5287ad62
JB
1819/* Types of registers in a list. */
1820
1821enum reg_list_els
1822{
1823 REGLIST_VFP_S,
1824 REGLIST_VFP_D,
1825 REGLIST_NEON_D
1826};
1827
c19d1205
ZW
1828/* Parse a VFP register list. If the string is invalid return FAIL.
1829 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1830 register. Parses registers of type ETYPE.
1831 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1832 - Q registers can be used to specify pairs of D registers
1833 - { } can be omitted from around a singleton register list
477330fc
RM
1834 FIXME: This is not implemented, as it would require backtracking in
1835 some cases, e.g.:
1836 vtbl.8 d3,d4,d5
1837 This could be done (the meaning isn't really ambiguous), but doesn't
1838 fit in well with the current parsing framework.
dcbf9037
JB
1839 - 32 D registers may be used (also true for VFPv3).
1840 FIXME: Types are ignored in these register lists, which is probably a
1841 bug. */
6057a28f 1842
c19d1205 1843static int
037e8744 1844parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1845{
037e8744 1846 char *str = *ccp;
c19d1205
ZW
1847 int base_reg;
1848 int new_base;
21d799b5 1849 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1850 int max_regs = 0;
c19d1205
ZW
1851 int count = 0;
1852 int warned = 0;
1853 unsigned long mask = 0;
a737bd4d 1854 int i;
6057a28f 1855
477330fc 1856 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1857 {
1858 inst.error = _("expecting {");
1859 return FAIL;
1860 }
6057a28f 1861
5287ad62 1862 switch (etype)
c19d1205 1863 {
5287ad62 1864 case REGLIST_VFP_S:
c19d1205
ZW
1865 regtype = REG_TYPE_VFS;
1866 max_regs = 32;
5287ad62 1867 break;
5f4273c7 1868
5287ad62
JB
1869 case REGLIST_VFP_D:
1870 regtype = REG_TYPE_VFD;
b7fc2769 1871 break;
5f4273c7 1872
b7fc2769
JB
1873 case REGLIST_NEON_D:
1874 regtype = REG_TYPE_NDQ;
1875 break;
1876 }
1877
1878 if (etype != REGLIST_VFP_S)
1879 {
b1cc4aeb
PB
1880 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1881 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1882 {
1883 max_regs = 32;
1884 if (thumb_mode)
1885 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1886 fpu_vfp_ext_d32);
1887 else
1888 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1889 fpu_vfp_ext_d32);
1890 }
5287ad62 1891 else
477330fc 1892 max_regs = 16;
c19d1205 1893 }
6057a28f 1894
c19d1205 1895 base_reg = max_regs;
a737bd4d 1896
c19d1205
ZW
1897 do
1898 {
5287ad62 1899 int setmask = 1, addregs = 1;
dcbf9037 1900
037e8744 1901 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1902
c19d1205 1903 if (new_base == FAIL)
a737bd4d 1904 {
dcbf9037 1905 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1906 return FAIL;
1907 }
5f4273c7 1908
b7fc2769 1909 if (new_base >= max_regs)
477330fc
RM
1910 {
1911 first_error (_("register out of range in list"));
1912 return FAIL;
1913 }
5f4273c7 1914
5287ad62
JB
1915 /* Note: a value of 2 * n is returned for the register Q<n>. */
1916 if (regtype == REG_TYPE_NQ)
477330fc
RM
1917 {
1918 setmask = 3;
1919 addregs = 2;
1920 }
5287ad62 1921
c19d1205
ZW
1922 if (new_base < base_reg)
1923 base_reg = new_base;
a737bd4d 1924
5287ad62 1925 if (mask & (setmask << new_base))
c19d1205 1926 {
dcbf9037 1927 first_error (_("invalid register list"));
c19d1205 1928 return FAIL;
a737bd4d 1929 }
a737bd4d 1930
c19d1205
ZW
1931 if ((mask >> new_base) != 0 && ! warned)
1932 {
1933 as_tsktsk (_("register list not in ascending order"));
1934 warned = 1;
1935 }
0bbf2aa4 1936
5287ad62
JB
1937 mask |= setmask << new_base;
1938 count += addregs;
0bbf2aa4 1939
037e8744 1940 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1941 {
1942 int high_range;
0bbf2aa4 1943
037e8744 1944 str++;
0bbf2aa4 1945
037e8744 1946 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1947 == FAIL)
c19d1205
ZW
1948 {
1949 inst.error = gettext (reg_expected_msgs[regtype]);
1950 return FAIL;
1951 }
0bbf2aa4 1952
477330fc
RM
1953 if (high_range >= max_regs)
1954 {
1955 first_error (_("register out of range in list"));
1956 return FAIL;
1957 }
b7fc2769 1958
477330fc
RM
1959 if (regtype == REG_TYPE_NQ)
1960 high_range = high_range + 1;
5287ad62 1961
c19d1205
ZW
1962 if (high_range <= new_base)
1963 {
1964 inst.error = _("register range not in ascending order");
1965 return FAIL;
1966 }
0bbf2aa4 1967
5287ad62 1968 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1969 {
5287ad62 1970 if (mask & (setmask << new_base))
0bbf2aa4 1971 {
c19d1205
ZW
1972 inst.error = _("invalid register list");
1973 return FAIL;
0bbf2aa4 1974 }
c19d1205 1975
5287ad62
JB
1976 mask |= setmask << new_base;
1977 count += addregs;
0bbf2aa4 1978 }
0bbf2aa4 1979 }
0bbf2aa4 1980 }
037e8744 1981 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1982
037e8744 1983 str++;
0bbf2aa4 1984
c19d1205
ZW
1985 /* Sanity check -- should have raised a parse error above. */
1986 if (count == 0 || count > max_regs)
1987 abort ();
1988
1989 *pbase = base_reg;
1990
1991 /* Final test -- the registers must be consecutive. */
1992 mask >>= base_reg;
1993 for (i = 0; i < count; i++)
1994 {
1995 if ((mask & (1u << i)) == 0)
1996 {
1997 inst.error = _("non-contiguous register range");
1998 return FAIL;
1999 }
2000 }
2001
037e8744
JB
2002 *ccp = str;
2003
c19d1205 2004 return count;
b99bd4ef
NC
2005}
2006
dcbf9037
JB
2007/* True if two alias types are the same. */
2008
c921be7d 2009static bfd_boolean
dcbf9037
JB
2010neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2011{
2012 if (!a && !b)
c921be7d 2013 return TRUE;
5f4273c7 2014
dcbf9037 2015 if (!a || !b)
c921be7d 2016 return FALSE;
dcbf9037
JB
2017
2018 if (a->defined != b->defined)
c921be7d 2019 return FALSE;
5f4273c7 2020
dcbf9037
JB
2021 if ((a->defined & NTA_HASTYPE) != 0
2022 && (a->eltype.type != b->eltype.type
477330fc 2023 || a->eltype.size != b->eltype.size))
c921be7d 2024 return FALSE;
dcbf9037
JB
2025
2026 if ((a->defined & NTA_HASINDEX) != 0
2027 && (a->index != b->index))
c921be7d 2028 return FALSE;
5f4273c7 2029
c921be7d 2030 return TRUE;
dcbf9037
JB
2031}
2032
5287ad62
JB
2033/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2034 The base register is put in *PBASE.
dcbf9037 2035 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
2036 the return value.
2037 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2038 Bits [6:5] encode the list length (minus one).
2039 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2040
5287ad62 2041#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2042#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2043#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2044
2045static int
dcbf9037 2046parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 2047 struct neon_type_el *eltype)
5287ad62
JB
2048{
2049 char *ptr = *str;
2050 int base_reg = -1;
2051 int reg_incr = -1;
2052 int count = 0;
2053 int lane = -1;
2054 int leading_brace = 0;
2055 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
2056 const char *const incr_error = _("register stride must be 1 or 2");
2057 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2058 struct neon_typed_alias firsttype;
f85d59c3
KT
2059 firsttype.defined = 0;
2060 firsttype.eltype.type = NT_invtype;
2061 firsttype.eltype.size = -1;
2062 firsttype.index = -1;
5f4273c7 2063
5287ad62
JB
2064 if (skip_past_char (&ptr, '{') == SUCCESS)
2065 leading_brace = 1;
5f4273c7 2066
5287ad62
JB
2067 do
2068 {
dcbf9037
JB
2069 struct neon_typed_alias atype;
2070 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2071
5287ad62 2072 if (getreg == FAIL)
477330fc
RM
2073 {
2074 first_error (_(reg_expected_msgs[rtype]));
2075 return FAIL;
2076 }
5f4273c7 2077
5287ad62 2078 if (base_reg == -1)
477330fc
RM
2079 {
2080 base_reg = getreg;
2081 if (rtype == REG_TYPE_NQ)
2082 {
2083 reg_incr = 1;
2084 }
2085 firsttype = atype;
2086 }
5287ad62 2087 else if (reg_incr == -1)
477330fc
RM
2088 {
2089 reg_incr = getreg - base_reg;
2090 if (reg_incr < 1 || reg_incr > 2)
2091 {
2092 first_error (_(incr_error));
2093 return FAIL;
2094 }
2095 }
5287ad62 2096 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2097 {
2098 first_error (_(incr_error));
2099 return FAIL;
2100 }
dcbf9037 2101
c921be7d 2102 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2103 {
2104 first_error (_(type_error));
2105 return FAIL;
2106 }
5f4273c7 2107
5287ad62 2108 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2109 modes. */
5287ad62 2110 if (ptr[0] == '-')
477330fc
RM
2111 {
2112 struct neon_typed_alias htype;
2113 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2114 if (lane == -1)
2115 lane = NEON_INTERLEAVE_LANES;
2116 else if (lane != NEON_INTERLEAVE_LANES)
2117 {
2118 first_error (_(type_error));
2119 return FAIL;
2120 }
2121 if (reg_incr == -1)
2122 reg_incr = 1;
2123 else if (reg_incr != 1)
2124 {
2125 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2126 return FAIL;
2127 }
2128 ptr++;
2129 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2130 if (hireg == FAIL)
2131 {
2132 first_error (_(reg_expected_msgs[rtype]));
2133 return FAIL;
2134 }
2135 if (! neon_alias_types_same (&htype, &firsttype))
2136 {
2137 first_error (_(type_error));
2138 return FAIL;
2139 }
2140 count += hireg + dregs - getreg;
2141 continue;
2142 }
5f4273c7 2143
5287ad62
JB
2144 /* If we're using Q registers, we can't use [] or [n] syntax. */
2145 if (rtype == REG_TYPE_NQ)
477330fc
RM
2146 {
2147 count += 2;
2148 continue;
2149 }
5f4273c7 2150
dcbf9037 2151 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2152 {
2153 if (lane == -1)
2154 lane = atype.index;
2155 else if (lane != atype.index)
2156 {
2157 first_error (_(type_error));
2158 return FAIL;
2159 }
2160 }
5287ad62 2161 else if (lane == -1)
477330fc 2162 lane = NEON_INTERLEAVE_LANES;
5287ad62 2163 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2164 {
2165 first_error (_(type_error));
2166 return FAIL;
2167 }
5287ad62
JB
2168 count++;
2169 }
2170 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2171
5287ad62
JB
2172 /* No lane set by [x]. We must be interleaving structures. */
2173 if (lane == -1)
2174 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2175
5287ad62
JB
2176 /* Sanity check. */
2177 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2178 || (count > 1 && reg_incr == -1))
2179 {
dcbf9037 2180 first_error (_("error parsing element/structure list"));
5287ad62
JB
2181 return FAIL;
2182 }
2183
2184 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2185 {
dcbf9037 2186 first_error (_("expected }"));
5287ad62
JB
2187 return FAIL;
2188 }
5f4273c7 2189
5287ad62
JB
2190 if (reg_incr == -1)
2191 reg_incr = 1;
2192
dcbf9037
JB
2193 if (eltype)
2194 *eltype = firsttype.eltype;
2195
5287ad62
JB
2196 *pbase = base_reg;
2197 *str = ptr;
5f4273c7 2198
5287ad62
JB
2199 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2200}
2201
c19d1205
ZW
2202/* Parse an explicit relocation suffix on an expression. This is
2203 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2204 arm_reloc_hsh contains no entries, so this function can only
2205 succeed if there is no () after the word. Returns -1 on error,
2206 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2207
c19d1205
ZW
2208static int
2209parse_reloc (char **str)
b99bd4ef 2210{
c19d1205
ZW
2211 struct reloc_entry *r;
2212 char *p, *q;
b99bd4ef 2213
c19d1205
ZW
2214 if (**str != '(')
2215 return BFD_RELOC_UNUSED;
b99bd4ef 2216
c19d1205
ZW
2217 p = *str + 1;
2218 q = p;
2219
2220 while (*q && *q != ')' && *q != ',')
2221 q++;
2222 if (*q != ')')
2223 return -1;
2224
21d799b5
NC
2225 if ((r = (struct reloc_entry *)
2226 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2227 return -1;
2228
2229 *str = q + 1;
2230 return r->reloc;
b99bd4ef
NC
2231}
2232
c19d1205
ZW
2233/* Directives: register aliases. */
2234
dcbf9037 2235static struct reg_entry *
90ec0d68 2236insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2237{
d3ce72d0 2238 struct reg_entry *new_reg;
c19d1205 2239 const char *name;
b99bd4ef 2240
d3ce72d0 2241 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2242 {
d3ce72d0 2243 if (new_reg->builtin)
c19d1205 2244 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2245
c19d1205
ZW
2246 /* Only warn about a redefinition if it's not defined as the
2247 same register. */
d3ce72d0 2248 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2249 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2250
d929913e 2251 return NULL;
c19d1205 2252 }
b99bd4ef 2253
c19d1205 2254 name = xstrdup (str);
325801bd 2255 new_reg = XNEW (struct reg_entry);
b99bd4ef 2256
d3ce72d0
NC
2257 new_reg->name = name;
2258 new_reg->number = number;
2259 new_reg->type = type;
2260 new_reg->builtin = FALSE;
2261 new_reg->neon = NULL;
b99bd4ef 2262
d3ce72d0 2263 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2264 abort ();
5f4273c7 2265
d3ce72d0 2266 return new_reg;
dcbf9037
JB
2267}
2268
2269static void
2270insert_neon_reg_alias (char *str, int number, int type,
477330fc 2271 struct neon_typed_alias *atype)
dcbf9037
JB
2272{
2273 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2274
dcbf9037
JB
2275 if (!reg)
2276 {
2277 first_error (_("attempt to redefine typed alias"));
2278 return;
2279 }
5f4273c7 2280
dcbf9037
JB
2281 if (atype)
2282 {
325801bd 2283 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2284 *reg->neon = *atype;
2285 }
c19d1205 2286}
b99bd4ef 2287
c19d1205 2288/* Look for the .req directive. This is of the form:
b99bd4ef 2289
c19d1205 2290 new_register_name .req existing_register_name
b99bd4ef 2291
c19d1205 2292 If we find one, or if it looks sufficiently like one that we want to
d929913e 2293 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2294
d929913e 2295static bfd_boolean
c19d1205
ZW
2296create_register_alias (char * newname, char *p)
2297{
2298 struct reg_entry *old;
2299 char *oldname, *nbuf;
2300 size_t nlen;
b99bd4ef 2301
c19d1205
ZW
2302 /* The input scrubber ensures that whitespace after the mnemonic is
2303 collapsed to single spaces. */
2304 oldname = p;
2305 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2306 return FALSE;
b99bd4ef 2307
c19d1205
ZW
2308 oldname += 6;
2309 if (*oldname == '\0')
d929913e 2310 return FALSE;
b99bd4ef 2311
21d799b5 2312 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2313 if (!old)
b99bd4ef 2314 {
c19d1205 2315 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2316 return TRUE;
b99bd4ef
NC
2317 }
2318
c19d1205
ZW
2319 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2320 the desired alias name, and p points to its end. If not, then
2321 the desired alias name is in the global original_case_string. */
2322#ifdef TC_CASE_SENSITIVE
2323 nlen = p - newname;
2324#else
2325 newname = original_case_string;
2326 nlen = strlen (newname);
2327#endif
b99bd4ef 2328
29a2809e 2329 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2330
c19d1205
ZW
2331 /* Create aliases under the new name as stated; an all-lowercase
2332 version of the new name; and an all-uppercase version of the new
2333 name. */
d929913e
NC
2334 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2335 {
2336 for (p = nbuf; *p; p++)
2337 *p = TOUPPER (*p);
c19d1205 2338
d929913e
NC
2339 if (strncmp (nbuf, newname, nlen))
2340 {
2341 /* If this attempt to create an additional alias fails, do not bother
2342 trying to create the all-lower case alias. We will fail and issue
2343 a second, duplicate error message. This situation arises when the
2344 programmer does something like:
2345 foo .req r0
2346 Foo .req r1
2347 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2348 the artificial FOO alias because it has already been created by the
d929913e
NC
2349 first .req. */
2350 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2351 {
2352 free (nbuf);
2353 return TRUE;
2354 }
d929913e 2355 }
c19d1205 2356
d929913e
NC
2357 for (p = nbuf; *p; p++)
2358 *p = TOLOWER (*p);
c19d1205 2359
d929913e
NC
2360 if (strncmp (nbuf, newname, nlen))
2361 insert_reg_alias (nbuf, old->number, old->type);
2362 }
c19d1205 2363
e1fa0163 2364 free (nbuf);
d929913e 2365 return TRUE;
b99bd4ef
NC
2366}
2367
dcbf9037
JB
2368/* Create a Neon typed/indexed register alias using directives, e.g.:
2369 X .dn d5.s32[1]
2370 Y .qn 6.s16
2371 Z .dn d7
2372 T .dn Z[0]
2373 These typed registers can be used instead of the types specified after the
2374 Neon mnemonic, so long as all operands given have types. Types can also be
2375 specified directly, e.g.:
5f4273c7 2376 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2377
c921be7d 2378static bfd_boolean
dcbf9037
JB
2379create_neon_reg_alias (char *newname, char *p)
2380{
2381 enum arm_reg_type basetype;
2382 struct reg_entry *basereg;
2383 struct reg_entry mybasereg;
2384 struct neon_type ntype;
2385 struct neon_typed_alias typeinfo;
12d6b0b7 2386 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2387 int namelen;
5f4273c7 2388
dcbf9037
JB
2389 typeinfo.defined = 0;
2390 typeinfo.eltype.type = NT_invtype;
2391 typeinfo.eltype.size = -1;
2392 typeinfo.index = -1;
5f4273c7 2393
dcbf9037 2394 nameend = p;
5f4273c7 2395
dcbf9037
JB
2396 if (strncmp (p, " .dn ", 5) == 0)
2397 basetype = REG_TYPE_VFD;
2398 else if (strncmp (p, " .qn ", 5) == 0)
2399 basetype = REG_TYPE_NQ;
2400 else
c921be7d 2401 return FALSE;
5f4273c7 2402
dcbf9037 2403 p += 5;
5f4273c7 2404
dcbf9037 2405 if (*p == '\0')
c921be7d 2406 return FALSE;
5f4273c7 2407
dcbf9037
JB
2408 basereg = arm_reg_parse_multi (&p);
2409
2410 if (basereg && basereg->type != basetype)
2411 {
2412 as_bad (_("bad type for register"));
c921be7d 2413 return FALSE;
dcbf9037
JB
2414 }
2415
2416 if (basereg == NULL)
2417 {
2418 expressionS exp;
2419 /* Try parsing as an integer. */
2420 my_get_expression (&exp, &p, GE_NO_PREFIX);
2421 if (exp.X_op != O_constant)
477330fc
RM
2422 {
2423 as_bad (_("expression must be constant"));
2424 return FALSE;
2425 }
dcbf9037
JB
2426 basereg = &mybasereg;
2427 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2428 : exp.X_add_number;
dcbf9037
JB
2429 basereg->neon = 0;
2430 }
2431
2432 if (basereg->neon)
2433 typeinfo = *basereg->neon;
2434
2435 if (parse_neon_type (&ntype, &p) == SUCCESS)
2436 {
2437 /* We got a type. */
2438 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2439 {
2440 as_bad (_("can't redefine the type of a register alias"));
2441 return FALSE;
2442 }
5f4273c7 2443
dcbf9037
JB
2444 typeinfo.defined |= NTA_HASTYPE;
2445 if (ntype.elems != 1)
477330fc
RM
2446 {
2447 as_bad (_("you must specify a single type only"));
2448 return FALSE;
2449 }
dcbf9037
JB
2450 typeinfo.eltype = ntype.el[0];
2451 }
5f4273c7 2452
dcbf9037
JB
2453 if (skip_past_char (&p, '[') == SUCCESS)
2454 {
2455 expressionS exp;
2456 /* We got a scalar index. */
5f4273c7 2457
dcbf9037 2458 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2459 {
2460 as_bad (_("can't redefine the index of a scalar alias"));
2461 return FALSE;
2462 }
5f4273c7 2463
dcbf9037 2464 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2465
dcbf9037 2466 if (exp.X_op != O_constant)
477330fc
RM
2467 {
2468 as_bad (_("scalar index must be constant"));
2469 return FALSE;
2470 }
5f4273c7 2471
dcbf9037
JB
2472 typeinfo.defined |= NTA_HASINDEX;
2473 typeinfo.index = exp.X_add_number;
5f4273c7 2474
dcbf9037 2475 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2476 {
2477 as_bad (_("expecting ]"));
2478 return FALSE;
2479 }
dcbf9037
JB
2480 }
2481
15735687
NS
2482 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2483 the desired alias name, and p points to its end. If not, then
2484 the desired alias name is in the global original_case_string. */
2485#ifdef TC_CASE_SENSITIVE
dcbf9037 2486 namelen = nameend - newname;
15735687
NS
2487#else
2488 newname = original_case_string;
2489 namelen = strlen (newname);
2490#endif
2491
29a2809e 2492 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2493
dcbf9037 2494 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2495 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2496
dcbf9037
JB
2497 /* Insert name in all uppercase. */
2498 for (p = namebuf; *p; p++)
2499 *p = TOUPPER (*p);
5f4273c7 2500
dcbf9037
JB
2501 if (strncmp (namebuf, newname, namelen))
2502 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2503 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2504
dcbf9037
JB
2505 /* Insert name in all lowercase. */
2506 for (p = namebuf; *p; p++)
2507 *p = TOLOWER (*p);
5f4273c7 2508
dcbf9037
JB
2509 if (strncmp (namebuf, newname, namelen))
2510 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2511 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2512
e1fa0163 2513 free (namebuf);
c921be7d 2514 return TRUE;
dcbf9037
JB
2515}
2516
c19d1205
ZW
2517/* Should never be called, as .req goes between the alias and the
2518 register name, not at the beginning of the line. */
c921be7d 2519
b99bd4ef 2520static void
c19d1205 2521s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2522{
c19d1205
ZW
2523 as_bad (_("invalid syntax for .req directive"));
2524}
b99bd4ef 2525
dcbf9037
JB
2526static void
2527s_dn (int a ATTRIBUTE_UNUSED)
2528{
2529 as_bad (_("invalid syntax for .dn directive"));
2530}
2531
2532static void
2533s_qn (int a ATTRIBUTE_UNUSED)
2534{
2535 as_bad (_("invalid syntax for .qn directive"));
2536}
2537
c19d1205
ZW
2538/* The .unreq directive deletes an alias which was previously defined
2539 by .req. For example:
b99bd4ef 2540
c19d1205
ZW
2541 my_alias .req r11
2542 .unreq my_alias */
b99bd4ef
NC
2543
2544static void
c19d1205 2545s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2546{
c19d1205
ZW
2547 char * name;
2548 char saved_char;
b99bd4ef 2549
c19d1205
ZW
2550 name = input_line_pointer;
2551
2552 while (*input_line_pointer != 0
2553 && *input_line_pointer != ' '
2554 && *input_line_pointer != '\n')
2555 ++input_line_pointer;
2556
2557 saved_char = *input_line_pointer;
2558 *input_line_pointer = 0;
2559
2560 if (!*name)
2561 as_bad (_("invalid syntax for .unreq directive"));
2562 else
2563 {
21d799b5 2564 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2565 name);
c19d1205
ZW
2566
2567 if (!reg)
2568 as_bad (_("unknown register alias '%s'"), name);
2569 else if (reg->builtin)
a1727c1a 2570 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2571 name);
2572 else
2573 {
d929913e
NC
2574 char * p;
2575 char * nbuf;
2576
db0bc284 2577 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2578 free ((char *) reg->name);
477330fc
RM
2579 if (reg->neon)
2580 free (reg->neon);
c19d1205 2581 free (reg);
d929913e
NC
2582
2583 /* Also locate the all upper case and all lower case versions.
2584 Do not complain if we cannot find one or the other as it
2585 was probably deleted above. */
5f4273c7 2586
d929913e
NC
2587 nbuf = strdup (name);
2588 for (p = nbuf; *p; p++)
2589 *p = TOUPPER (*p);
21d799b5 2590 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2591 if (reg)
2592 {
db0bc284 2593 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2594 free ((char *) reg->name);
2595 if (reg->neon)
2596 free (reg->neon);
2597 free (reg);
2598 }
2599
2600 for (p = nbuf; *p; p++)
2601 *p = TOLOWER (*p);
21d799b5 2602 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2603 if (reg)
2604 {
db0bc284 2605 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2606 free ((char *) reg->name);
2607 if (reg->neon)
2608 free (reg->neon);
2609 free (reg);
2610 }
2611
2612 free (nbuf);
c19d1205
ZW
2613 }
2614 }
b99bd4ef 2615
c19d1205 2616 *input_line_pointer = saved_char;
b99bd4ef
NC
2617 demand_empty_rest_of_line ();
2618}
2619
c19d1205
ZW
2620/* Directives: Instruction set selection. */
2621
2622#ifdef OBJ_ELF
2623/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2624 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2625 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2626 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2627
cd000bff
DJ
2628/* Create a new mapping symbol for the transition to STATE. */
2629
2630static void
2631make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2632{
a737bd4d 2633 symbolS * symbolP;
c19d1205
ZW
2634 const char * symname;
2635 int type;
b99bd4ef 2636
c19d1205 2637 switch (state)
b99bd4ef 2638 {
c19d1205
ZW
2639 case MAP_DATA:
2640 symname = "$d";
2641 type = BSF_NO_FLAGS;
2642 break;
2643 case MAP_ARM:
2644 symname = "$a";
2645 type = BSF_NO_FLAGS;
2646 break;
2647 case MAP_THUMB:
2648 symname = "$t";
2649 type = BSF_NO_FLAGS;
2650 break;
c19d1205
ZW
2651 default:
2652 abort ();
2653 }
2654
cd000bff 2655 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2656 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2657
2658 switch (state)
2659 {
2660 case MAP_ARM:
2661 THUMB_SET_FUNC (symbolP, 0);
2662 ARM_SET_THUMB (symbolP, 0);
2663 ARM_SET_INTERWORK (symbolP, support_interwork);
2664 break;
2665
2666 case MAP_THUMB:
2667 THUMB_SET_FUNC (symbolP, 1);
2668 ARM_SET_THUMB (symbolP, 1);
2669 ARM_SET_INTERWORK (symbolP, support_interwork);
2670 break;
2671
2672 case MAP_DATA:
2673 default:
cd000bff
DJ
2674 break;
2675 }
2676
2677 /* Save the mapping symbols for future reference. Also check that
2678 we do not place two mapping symbols at the same offset within a
2679 frag. We'll handle overlap between frags in
2de7820f
JZ
2680 check_mapping_symbols.
2681
2682 If .fill or other data filling directive generates zero sized data,
2683 the mapping symbol for the following code will have the same value
2684 as the one generated for the data filling directive. In this case,
2685 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2686 if (value == 0)
2687 {
2de7820f
JZ
2688 if (frag->tc_frag_data.first_map != NULL)
2689 {
2690 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2691 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2692 }
cd000bff
DJ
2693 frag->tc_frag_data.first_map = symbolP;
2694 }
2695 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2696 {
2697 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2698 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2699 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2700 }
cd000bff
DJ
2701 frag->tc_frag_data.last_map = symbolP;
2702}
2703
2704/* We must sometimes convert a region marked as code to data during
2705 code alignment, if an odd number of bytes have to be padded. The
2706 code mapping symbol is pushed to an aligned address. */
2707
2708static void
2709insert_data_mapping_symbol (enum mstate state,
2710 valueT value, fragS *frag, offsetT bytes)
2711{
2712 /* If there was already a mapping symbol, remove it. */
2713 if (frag->tc_frag_data.last_map != NULL
2714 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2715 {
2716 symbolS *symp = frag->tc_frag_data.last_map;
2717
2718 if (value == 0)
2719 {
2720 know (frag->tc_frag_data.first_map == symp);
2721 frag->tc_frag_data.first_map = NULL;
2722 }
2723 frag->tc_frag_data.last_map = NULL;
2724 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2725 }
cd000bff
DJ
2726
2727 make_mapping_symbol (MAP_DATA, value, frag);
2728 make_mapping_symbol (state, value + bytes, frag);
2729}
2730
2731static void mapping_state_2 (enum mstate state, int max_chars);
2732
2733/* Set the mapping state to STATE. Only call this when about to
2734 emit some STATE bytes to the file. */
2735
4e9aaefb 2736#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2737void
2738mapping_state (enum mstate state)
2739{
940b5ce0
DJ
2740 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2741
cd000bff
DJ
2742 if (mapstate == state)
2743 /* The mapping symbol has already been emitted.
2744 There is nothing else to do. */
2745 return;
49c62a33
NC
2746
2747 if (state == MAP_ARM || state == MAP_THUMB)
2748 /* PR gas/12931
2749 All ARM instructions require 4-byte alignment.
2750 (Almost) all Thumb instructions require 2-byte alignment.
2751
2752 When emitting instructions into any section, mark the section
2753 appropriately.
2754
2755 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2756 but themselves require 2-byte alignment; this applies to some
33eaf5de 2757 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
2758 literal pool generation or an explicit .align >=2, both of
2759 which will cause the section to me marked with sufficient
2760 alignment. Thus, we don't handle those cases here. */
2761 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2762
2763 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2764 /* This case will be evaluated later. */
cd000bff 2765 return;
cd000bff
DJ
2766
2767 mapping_state_2 (state, 0);
cd000bff
DJ
2768}
2769
2770/* Same as mapping_state, but MAX_CHARS bytes have already been
2771 allocated. Put the mapping symbol that far back. */
2772
2773static void
2774mapping_state_2 (enum mstate state, int max_chars)
2775{
940b5ce0
DJ
2776 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2777
2778 if (!SEG_NORMAL (now_seg))
2779 return;
2780
cd000bff
DJ
2781 if (mapstate == state)
2782 /* The mapping symbol has already been emitted.
2783 There is nothing else to do. */
2784 return;
2785
4e9aaefb
SA
2786 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2787 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2788 {
2789 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2790 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2791
2792 if (add_symbol)
2793 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2794 }
2795
cd000bff
DJ
2796 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2797 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2798}
4e9aaefb 2799#undef TRANSITION
c19d1205 2800#else
d3106081
NS
2801#define mapping_state(x) ((void)0)
2802#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2803#endif
2804
2805/* Find the real, Thumb encoded start of a Thumb function. */
2806
4343666d 2807#ifdef OBJ_COFF
c19d1205
ZW
2808static symbolS *
2809find_real_start (symbolS * symbolP)
2810{
2811 char * real_start;
2812 const char * name = S_GET_NAME (symbolP);
2813 symbolS * new_target;
2814
2815 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2816#define STUB_NAME ".real_start_of"
2817
2818 if (name == NULL)
2819 abort ();
2820
37f6032b
ZW
2821 /* The compiler may generate BL instructions to local labels because
2822 it needs to perform a branch to a far away location. These labels
2823 do not have a corresponding ".real_start_of" label. We check
2824 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2825 the ".real_start_of" convention for nonlocal branches. */
2826 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2827 return symbolP;
2828
e1fa0163 2829 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2830 new_target = symbol_find (real_start);
e1fa0163 2831 free (real_start);
c19d1205
ZW
2832
2833 if (new_target == NULL)
2834 {
bd3ba5d1 2835 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2836 new_target = symbolP;
2837 }
2838
c19d1205
ZW
2839 return new_target;
2840}
4343666d 2841#endif
c19d1205
ZW
2842
2843static void
2844opcode_select (int width)
2845{
2846 switch (width)
2847 {
2848 case 16:
2849 if (! thumb_mode)
2850 {
e74cfd16 2851 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2852 as_bad (_("selected processor does not support THUMB opcodes"));
2853
2854 thumb_mode = 1;
2855 /* No need to force the alignment, since we will have been
2856 coming from ARM mode, which is word-aligned. */
2857 record_alignment (now_seg, 1);
2858 }
c19d1205
ZW
2859 break;
2860
2861 case 32:
2862 if (thumb_mode)
2863 {
e74cfd16 2864 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2865 as_bad (_("selected processor does not support ARM opcodes"));
2866
2867 thumb_mode = 0;
2868
2869 if (!need_pass_2)
2870 frag_align (2, 0, 0);
2871
2872 record_alignment (now_seg, 1);
2873 }
c19d1205
ZW
2874 break;
2875
2876 default:
2877 as_bad (_("invalid instruction size selected (%d)"), width);
2878 }
2879}
2880
2881static void
2882s_arm (int ignore ATTRIBUTE_UNUSED)
2883{
2884 opcode_select (32);
2885 demand_empty_rest_of_line ();
2886}
2887
2888static void
2889s_thumb (int ignore ATTRIBUTE_UNUSED)
2890{
2891 opcode_select (16);
2892 demand_empty_rest_of_line ();
2893}
2894
2895static void
2896s_code (int unused ATTRIBUTE_UNUSED)
2897{
2898 int temp;
2899
2900 temp = get_absolute_expression ();
2901 switch (temp)
2902 {
2903 case 16:
2904 case 32:
2905 opcode_select (temp);
2906 break;
2907
2908 default:
2909 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2910 }
2911}
2912
2913static void
2914s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2915{
2916 /* If we are not already in thumb mode go into it, EVEN if
2917 the target processor does not support thumb instructions.
2918 This is used by gcc/config/arm/lib1funcs.asm for example
2919 to compile interworking support functions even if the
2920 target processor should not support interworking. */
2921 if (! thumb_mode)
2922 {
2923 thumb_mode = 2;
2924 record_alignment (now_seg, 1);
2925 }
2926
2927 demand_empty_rest_of_line ();
2928}
2929
2930static void
2931s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2932{
2933 s_thumb (0);
2934
2935 /* The following label is the name/address of the start of a Thumb function.
2936 We need to know this for the interworking support. */
2937 label_is_thumb_function_name = TRUE;
2938}
2939
2940/* Perform a .set directive, but also mark the alias as
2941 being a thumb function. */
2942
2943static void
2944s_thumb_set (int equiv)
2945{
2946 /* XXX the following is a duplicate of the code for s_set() in read.c
2947 We cannot just call that code as we need to get at the symbol that
2948 is created. */
2949 char * name;
2950 char delim;
2951 char * end_name;
2952 symbolS * symbolP;
2953
2954 /* Especial apologies for the random logic:
2955 This just grew, and could be parsed much more simply!
2956 Dean - in haste. */
d02603dc 2957 delim = get_symbol_name (& name);
c19d1205 2958 end_name = input_line_pointer;
d02603dc 2959 (void) restore_line_pointer (delim);
c19d1205
ZW
2960
2961 if (*input_line_pointer != ',')
2962 {
2963 *end_name = 0;
2964 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2965 *end_name = delim;
2966 ignore_rest_of_line ();
2967 return;
2968 }
2969
2970 input_line_pointer++;
2971 *end_name = 0;
2972
2973 if (name[0] == '.' && name[1] == '\0')
2974 {
2975 /* XXX - this should not happen to .thumb_set. */
2976 abort ();
2977 }
2978
2979 if ((symbolP = symbol_find (name)) == NULL
2980 && (symbolP = md_undefined_symbol (name)) == NULL)
2981 {
2982#ifndef NO_LISTING
2983 /* When doing symbol listings, play games with dummy fragments living
2984 outside the normal fragment chain to record the file and line info
c19d1205 2985 for this symbol. */
b99bd4ef
NC
2986 if (listing & LISTING_SYMBOLS)
2987 {
2988 extern struct list_info_struct * listing_tail;
21d799b5 2989 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2990
2991 memset (dummy_frag, 0, sizeof (fragS));
2992 dummy_frag->fr_type = rs_fill;
2993 dummy_frag->line = listing_tail;
2994 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2995 dummy_frag->fr_symbol = symbolP;
2996 }
2997 else
2998#endif
2999 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
3000
3001#ifdef OBJ_COFF
3002 /* "set" symbols are local unless otherwise specified. */
3003 SF_SET_LOCAL (symbolP);
3004#endif /* OBJ_COFF */
3005 } /* Make a new symbol. */
3006
3007 symbol_table_insert (symbolP);
3008
3009 * end_name = delim;
3010
3011 if (equiv
3012 && S_IS_DEFINED (symbolP)
3013 && S_GET_SEGMENT (symbolP) != reg_section)
3014 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3015
3016 pseudo_set (symbolP);
3017
3018 demand_empty_rest_of_line ();
3019
c19d1205 3020 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
3021
3022 THUMB_SET_FUNC (symbolP, 1);
3023 ARM_SET_THUMB (symbolP, 1);
3024#if defined OBJ_ELF || defined OBJ_COFF
3025 ARM_SET_INTERWORK (symbolP, support_interwork);
3026#endif
3027}
3028
c19d1205 3029/* Directives: Mode selection. */
b99bd4ef 3030
c19d1205
ZW
3031/* .syntax [unified|divided] - choose the new unified syntax
3032 (same for Arm and Thumb encoding, modulo slight differences in what
3033 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 3034static void
c19d1205 3035s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 3036{
c19d1205
ZW
3037 char *name, delim;
3038
d02603dc 3039 delim = get_symbol_name (& name);
c19d1205
ZW
3040
3041 if (!strcasecmp (name, "unified"))
3042 unified_syntax = TRUE;
3043 else if (!strcasecmp (name, "divided"))
3044 unified_syntax = FALSE;
3045 else
3046 {
3047 as_bad (_("unrecognized syntax mode \"%s\""), name);
3048 return;
3049 }
d02603dc 3050 (void) restore_line_pointer (delim);
b99bd4ef
NC
3051 demand_empty_rest_of_line ();
3052}
3053
c19d1205
ZW
3054/* Directives: sectioning and alignment. */
3055
c19d1205
ZW
3056static void
3057s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3058{
c19d1205
ZW
3059 /* We don't support putting frags in the BSS segment, we fake it by
3060 marking in_bss, then looking at s_skip for clues. */
3061 subseg_set (bss_section, 0);
3062 demand_empty_rest_of_line ();
cd000bff
DJ
3063
3064#ifdef md_elf_section_change_hook
3065 md_elf_section_change_hook ();
3066#endif
c19d1205 3067}
b99bd4ef 3068
c19d1205
ZW
3069static void
3070s_even (int ignore ATTRIBUTE_UNUSED)
3071{
3072 /* Never make frag if expect extra pass. */
3073 if (!need_pass_2)
3074 frag_align (1, 0, 0);
b99bd4ef 3075
c19d1205 3076 record_alignment (now_seg, 1);
b99bd4ef 3077
c19d1205 3078 demand_empty_rest_of_line ();
b99bd4ef
NC
3079}
3080
2e6976a8
DG
3081/* Directives: CodeComposer Studio. */
3082
3083/* .ref (for CodeComposer Studio syntax only). */
3084static void
3085s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3086{
3087 if (codecomposer_syntax)
3088 ignore_rest_of_line ();
3089 else
3090 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3091}
3092
3093/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3094 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3095static void
3096asmfunc_debug (const char * name)
3097{
3098 static const char * last_name = NULL;
3099
3100 if (name != NULL)
3101 {
3102 gas_assert (last_name == NULL);
3103 last_name = name;
3104
3105 if (debug_type == DEBUG_STABS)
3106 stabs_generate_asm_func (name, name);
3107 }
3108 else
3109 {
3110 gas_assert (last_name != NULL);
3111
3112 if (debug_type == DEBUG_STABS)
3113 stabs_generate_asm_endfunc (last_name, last_name);
3114
3115 last_name = NULL;
3116 }
3117}
3118
3119static void
3120s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3121{
3122 if (codecomposer_syntax)
3123 {
3124 switch (asmfunc_state)
3125 {
3126 case OUTSIDE_ASMFUNC:
3127 asmfunc_state = WAITING_ASMFUNC_NAME;
3128 break;
3129
3130 case WAITING_ASMFUNC_NAME:
3131 as_bad (_(".asmfunc repeated."));
3132 break;
3133
3134 case WAITING_ENDASMFUNC:
3135 as_bad (_(".asmfunc without function."));
3136 break;
3137 }
3138 demand_empty_rest_of_line ();
3139 }
3140 else
3141 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3142}
3143
3144static void
3145s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3146{
3147 if (codecomposer_syntax)
3148 {
3149 switch (asmfunc_state)
3150 {
3151 case OUTSIDE_ASMFUNC:
3152 as_bad (_(".endasmfunc without a .asmfunc."));
3153 break;
3154
3155 case WAITING_ASMFUNC_NAME:
3156 as_bad (_(".endasmfunc without function."));
3157 break;
3158
3159 case WAITING_ENDASMFUNC:
3160 asmfunc_state = OUTSIDE_ASMFUNC;
3161 asmfunc_debug (NULL);
3162 break;
3163 }
3164 demand_empty_rest_of_line ();
3165 }
3166 else
3167 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3168}
3169
3170static void
3171s_ccs_def (int name)
3172{
3173 if (codecomposer_syntax)
3174 s_globl (name);
3175 else
3176 as_bad (_(".def pseudo-op only available with -mccs flag."));
3177}
3178
c19d1205 3179/* Directives: Literal pools. */
a737bd4d 3180
c19d1205
ZW
3181static literal_pool *
3182find_literal_pool (void)
a737bd4d 3183{
c19d1205 3184 literal_pool * pool;
a737bd4d 3185
c19d1205 3186 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3187 {
c19d1205
ZW
3188 if (pool->section == now_seg
3189 && pool->sub_section == now_subseg)
3190 break;
a737bd4d
NC
3191 }
3192
c19d1205 3193 return pool;
a737bd4d
NC
3194}
3195
c19d1205
ZW
3196static literal_pool *
3197find_or_make_literal_pool (void)
a737bd4d 3198{
c19d1205
ZW
3199 /* Next literal pool ID number. */
3200 static unsigned int latest_pool_num = 1;
3201 literal_pool * pool;
a737bd4d 3202
c19d1205 3203 pool = find_literal_pool ();
a737bd4d 3204
c19d1205 3205 if (pool == NULL)
a737bd4d 3206 {
c19d1205 3207 /* Create a new pool. */
325801bd 3208 pool = XNEW (literal_pool);
c19d1205
ZW
3209 if (! pool)
3210 return NULL;
a737bd4d 3211
c19d1205
ZW
3212 pool->next_free_entry = 0;
3213 pool->section = now_seg;
3214 pool->sub_section = now_subseg;
3215 pool->next = list_of_pools;
3216 pool->symbol = NULL;
8335d6aa 3217 pool->alignment = 2;
c19d1205
ZW
3218
3219 /* Add it to the list. */
3220 list_of_pools = pool;
a737bd4d 3221 }
a737bd4d 3222
c19d1205
ZW
3223 /* New pools, and emptied pools, will have a NULL symbol. */
3224 if (pool->symbol == NULL)
a737bd4d 3225 {
c19d1205
ZW
3226 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3227 (valueT) 0, &zero_address_frag);
3228 pool->id = latest_pool_num ++;
a737bd4d
NC
3229 }
3230
c19d1205
ZW
3231 /* Done. */
3232 return pool;
a737bd4d
NC
3233}
3234
c19d1205 3235/* Add the literal in the global 'inst'
5f4273c7 3236 structure to the relevant literal pool. */
b99bd4ef
NC
3237
3238static int
8335d6aa 3239add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3240{
8335d6aa
JW
3241#define PADDING_SLOT 0x1
3242#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3243 literal_pool * pool;
8335d6aa
JW
3244 unsigned int entry, pool_size = 0;
3245 bfd_boolean padding_slot_p = FALSE;
e56c722b 3246 unsigned imm1 = 0;
8335d6aa
JW
3247 unsigned imm2 = 0;
3248
3249 if (nbytes == 8)
3250 {
3251 imm1 = inst.operands[1].imm;
3252 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
e2b0ab59 3253 : inst.relocs[0].exp.X_unsigned ? 0
2569ceb0 3254 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3255 if (target_big_endian)
3256 {
3257 imm1 = imm2;
3258 imm2 = inst.operands[1].imm;
3259 }
3260 }
b99bd4ef 3261
c19d1205
ZW
3262 pool = find_or_make_literal_pool ();
3263
3264 /* Check if this literal value is already in the pool. */
3265 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3266 {
8335d6aa
JW
3267 if (nbytes == 4)
3268 {
e2b0ab59
AV
3269 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3270 && (inst.relocs[0].exp.X_op == O_constant)
8335d6aa 3271 && (pool->literals[entry].X_add_number
e2b0ab59 3272 == inst.relocs[0].exp.X_add_number)
8335d6aa
JW
3273 && (pool->literals[entry].X_md == nbytes)
3274 && (pool->literals[entry].X_unsigned
e2b0ab59 3275 == inst.relocs[0].exp.X_unsigned))
8335d6aa
JW
3276 break;
3277
e2b0ab59
AV
3278 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3279 && (inst.relocs[0].exp.X_op == O_symbol)
8335d6aa 3280 && (pool->literals[entry].X_add_number
e2b0ab59 3281 == inst.relocs[0].exp.X_add_number)
8335d6aa 3282 && (pool->literals[entry].X_add_symbol
e2b0ab59 3283 == inst.relocs[0].exp.X_add_symbol)
8335d6aa 3284 && (pool->literals[entry].X_op_symbol
e2b0ab59 3285 == inst.relocs[0].exp.X_op_symbol)
8335d6aa
JW
3286 && (pool->literals[entry].X_md == nbytes))
3287 break;
3288 }
3289 else if ((nbytes == 8)
3290 && !(pool_size & 0x7)
3291 && ((entry + 1) != pool->next_free_entry)
3292 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3293 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa 3294 && (pool->literals[entry].X_unsigned
e2b0ab59 3295 == inst.relocs[0].exp.X_unsigned)
8335d6aa 3296 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3297 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa 3298 && (pool->literals[entry + 1].X_unsigned
e2b0ab59 3299 == inst.relocs[0].exp.X_unsigned))
c19d1205
ZW
3300 break;
3301
8335d6aa
JW
3302 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3303 if (padding_slot_p && (nbytes == 4))
c19d1205 3304 break;
8335d6aa
JW
3305
3306 pool_size += 4;
b99bd4ef
NC
3307 }
3308
c19d1205
ZW
3309 /* Do we need to create a new entry? */
3310 if (entry == pool->next_free_entry)
3311 {
3312 if (entry >= MAX_LITERAL_POOL_SIZE)
3313 {
3314 inst.error = _("literal pool overflow");
3315 return FAIL;
3316 }
3317
8335d6aa
JW
3318 if (nbytes == 8)
3319 {
3320 /* For 8-byte entries, we align to an 8-byte boundary,
3321 and split it into two 4-byte entries, because on 32-bit
3322 host, 8-byte constants are treated as big num, thus
3323 saved in "generic_bignum" which will be overwritten
3324 by later assignments.
3325
3326 We also need to make sure there is enough space for
3327 the split.
3328
3329 We also check to make sure the literal operand is a
3330 constant number. */
e2b0ab59
AV
3331 if (!(inst.relocs[0].exp.X_op == O_constant
3332 || inst.relocs[0].exp.X_op == O_big))
8335d6aa
JW
3333 {
3334 inst.error = _("invalid type for literal pool");
3335 return FAIL;
3336 }
3337 else if (pool_size & 0x7)
3338 {
3339 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3340 {
3341 inst.error = _("literal pool overflow");
3342 return FAIL;
3343 }
3344
e2b0ab59 3345 pool->literals[entry] = inst.relocs[0].exp;
a6684f0d 3346 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3347 pool->literals[entry].X_add_number = 0;
3348 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3349 pool->next_free_entry += 1;
3350 pool_size += 4;
3351 }
3352 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3353 {
3354 inst.error = _("literal pool overflow");
3355 return FAIL;
3356 }
3357
e2b0ab59 3358 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3359 pool->literals[entry].X_op = O_constant;
3360 pool->literals[entry].X_add_number = imm1;
e2b0ab59 3361 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa 3362 pool->literals[entry++].X_md = 4;
e2b0ab59 3363 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3364 pool->literals[entry].X_op = O_constant;
3365 pool->literals[entry].X_add_number = imm2;
e2b0ab59 3366 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa
JW
3367 pool->literals[entry].X_md = 4;
3368 pool->alignment = 3;
3369 pool->next_free_entry += 1;
3370 }
3371 else
3372 {
e2b0ab59 3373 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3374 pool->literals[entry].X_md = 4;
3375 }
3376
a8040cf2
NC
3377#ifdef OBJ_ELF
3378 /* PR ld/12974: Record the location of the first source line to reference
3379 this entry in the literal pool. If it turns out during linking that the
3380 symbol does not exist we will be able to give an accurate line number for
3381 the (first use of the) missing reference. */
3382 if (debug_type == DEBUG_DWARF2)
3383 dwarf2_where (pool->locs + entry);
3384#endif
c19d1205
ZW
3385 pool->next_free_entry += 1;
3386 }
8335d6aa
JW
3387 else if (padding_slot_p)
3388 {
e2b0ab59 3389 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3390 pool->literals[entry].X_md = nbytes;
3391 }
b99bd4ef 3392
e2b0ab59
AV
3393 inst.relocs[0].exp.X_op = O_symbol;
3394 inst.relocs[0].exp.X_add_number = pool_size;
3395 inst.relocs[0].exp.X_add_symbol = pool->symbol;
b99bd4ef 3396
c19d1205 3397 return SUCCESS;
b99bd4ef
NC
3398}
3399
2e6976a8 3400bfd_boolean
2e57ce7b 3401tc_start_label_without_colon (void)
2e6976a8
DG
3402{
3403 bfd_boolean ret = TRUE;
3404
3405 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3406 {
2e57ce7b 3407 const char *label = input_line_pointer;
2e6976a8
DG
3408
3409 while (!is_end_of_line[(int) label[-1]])
3410 --label;
3411
3412 if (*label == '.')
3413 {
3414 as_bad (_("Invalid label '%s'"), label);
3415 ret = FALSE;
3416 }
3417
3418 asmfunc_debug (label);
3419
3420 asmfunc_state = WAITING_ENDASMFUNC;
3421 }
3422
3423 return ret;
3424}
3425
c19d1205 3426/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3427 a later date assign it a value. That's what these functions do. */
e16bb312 3428
c19d1205
ZW
3429static void
3430symbol_locate (symbolS * symbolP,
3431 const char * name, /* It is copied, the caller can modify. */
3432 segT segment, /* Segment identifier (SEG_<something>). */
3433 valueT valu, /* Symbol value. */
3434 fragS * frag) /* Associated fragment. */
3435{
e57e6ddc 3436 size_t name_length;
c19d1205 3437 char * preserved_copy_of_name;
e16bb312 3438
c19d1205
ZW
3439 name_length = strlen (name) + 1; /* +1 for \0. */
3440 obstack_grow (&notes, name, name_length);
21d799b5 3441 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3442
c19d1205
ZW
3443#ifdef tc_canonicalize_symbol_name
3444 preserved_copy_of_name =
3445 tc_canonicalize_symbol_name (preserved_copy_of_name);
3446#endif
b99bd4ef 3447
c19d1205 3448 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3449
c19d1205
ZW
3450 S_SET_SEGMENT (symbolP, segment);
3451 S_SET_VALUE (symbolP, valu);
3452 symbol_clear_list_pointers (symbolP);
b99bd4ef 3453
c19d1205 3454 symbol_set_frag (symbolP, frag);
b99bd4ef 3455
c19d1205
ZW
3456 /* Link to end of symbol chain. */
3457 {
3458 extern int symbol_table_frozen;
b99bd4ef 3459
c19d1205
ZW
3460 if (symbol_table_frozen)
3461 abort ();
3462 }
b99bd4ef 3463
c19d1205 3464 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3465
c19d1205 3466 obj_symbol_new_hook (symbolP);
b99bd4ef 3467
c19d1205
ZW
3468#ifdef tc_symbol_new_hook
3469 tc_symbol_new_hook (symbolP);
3470#endif
3471
3472#ifdef DEBUG_SYMS
3473 verify_symbol_chain (symbol_rootP, symbol_lastP);
3474#endif /* DEBUG_SYMS */
b99bd4ef
NC
3475}
3476
c19d1205
ZW
3477static void
3478s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3479{
c19d1205
ZW
3480 unsigned int entry;
3481 literal_pool * pool;
3482 char sym_name[20];
b99bd4ef 3483
c19d1205
ZW
3484 pool = find_literal_pool ();
3485 if (pool == NULL
3486 || pool->symbol == NULL
3487 || pool->next_free_entry == 0)
3488 return;
b99bd4ef 3489
c19d1205
ZW
3490 /* Align pool as you have word accesses.
3491 Only make a frag if we have to. */
3492 if (!need_pass_2)
8335d6aa 3493 frag_align (pool->alignment, 0, 0);
b99bd4ef 3494
c19d1205 3495 record_alignment (now_seg, 2);
b99bd4ef 3496
aaca88ef 3497#ifdef OBJ_ELF
47fc6e36
WN
3498 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3499 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3500#endif
c19d1205 3501 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3502
c19d1205
ZW
3503 symbol_locate (pool->symbol, sym_name, now_seg,
3504 (valueT) frag_now_fix (), frag_now);
3505 symbol_table_insert (pool->symbol);
b99bd4ef 3506
c19d1205 3507 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3508
c19d1205
ZW
3509#if defined OBJ_COFF || defined OBJ_ELF
3510 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3511#endif
6c43fab6 3512
c19d1205 3513 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3514 {
3515#ifdef OBJ_ELF
3516 if (debug_type == DEBUG_DWARF2)
3517 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3518#endif
3519 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3520 emit_expr (&(pool->literals[entry]),
3521 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3522 }
b99bd4ef 3523
c19d1205
ZW
3524 /* Mark the pool as empty. */
3525 pool->next_free_entry = 0;
3526 pool->symbol = NULL;
b99bd4ef
NC
3527}
3528
c19d1205
ZW
3529#ifdef OBJ_ELF
3530/* Forward declarations for functions below, in the MD interface
3531 section. */
3532static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3533static valueT create_unwind_entry (int);
3534static void start_unwind_section (const segT, int);
3535static void add_unwind_opcode (valueT, int);
3536static void flush_pending_unwind (void);
b99bd4ef 3537
c19d1205 3538/* Directives: Data. */
b99bd4ef 3539
c19d1205
ZW
3540static void
3541s_arm_elf_cons (int nbytes)
3542{
3543 expressionS exp;
b99bd4ef 3544
c19d1205
ZW
3545#ifdef md_flush_pending_output
3546 md_flush_pending_output ();
3547#endif
b99bd4ef 3548
c19d1205 3549 if (is_it_end_of_statement ())
b99bd4ef 3550 {
c19d1205
ZW
3551 demand_empty_rest_of_line ();
3552 return;
b99bd4ef
NC
3553 }
3554
c19d1205
ZW
3555#ifdef md_cons_align
3556 md_cons_align (nbytes);
3557#endif
b99bd4ef 3558
c19d1205
ZW
3559 mapping_state (MAP_DATA);
3560 do
b99bd4ef 3561 {
c19d1205
ZW
3562 int reloc;
3563 char *base = input_line_pointer;
b99bd4ef 3564
c19d1205 3565 expression (& exp);
b99bd4ef 3566
c19d1205
ZW
3567 if (exp.X_op != O_symbol)
3568 emit_expr (&exp, (unsigned int) nbytes);
3569 else
3570 {
3571 char *before_reloc = input_line_pointer;
3572 reloc = parse_reloc (&input_line_pointer);
3573 if (reloc == -1)
3574 {
3575 as_bad (_("unrecognized relocation suffix"));
3576 ignore_rest_of_line ();
3577 return;
3578 }
3579 else if (reloc == BFD_RELOC_UNUSED)
3580 emit_expr (&exp, (unsigned int) nbytes);
3581 else
3582 {
21d799b5 3583 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3584 bfd_reloc_type_lookup (stdoutput,
3585 (bfd_reloc_code_real_type) reloc);
c19d1205 3586 int size = bfd_get_reloc_size (howto);
b99bd4ef 3587
2fc8bdac
ZW
3588 if (reloc == BFD_RELOC_ARM_PLT32)
3589 {
3590 as_bad (_("(plt) is only valid on branch targets"));
3591 reloc = BFD_RELOC_UNUSED;
3592 size = 0;
3593 }
3594
c19d1205 3595 if (size > nbytes)
992a06ee
AM
3596 as_bad (ngettext ("%s relocations do not fit in %d byte",
3597 "%s relocations do not fit in %d bytes",
3598 nbytes),
c19d1205
ZW
3599 howto->name, nbytes);
3600 else
3601 {
3602 /* We've parsed an expression stopping at O_symbol.
3603 But there may be more expression left now that we
3604 have parsed the relocation marker. Parse it again.
3605 XXX Surely there is a cleaner way to do this. */
3606 char *p = input_line_pointer;
3607 int offset;
325801bd 3608 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3609
c19d1205
ZW
3610 memcpy (save_buf, base, input_line_pointer - base);
3611 memmove (base + (input_line_pointer - before_reloc),
3612 base, before_reloc - base);
3613
3614 input_line_pointer = base + (input_line_pointer-before_reloc);
3615 expression (&exp);
3616 memcpy (base, save_buf, p - base);
3617
3618 offset = nbytes - size;
4b1a927e
AM
3619 p = frag_more (nbytes);
3620 memset (p, 0, nbytes);
c19d1205 3621 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3622 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3623 free (save_buf);
c19d1205
ZW
3624 }
3625 }
3626 }
b99bd4ef 3627 }
c19d1205 3628 while (*input_line_pointer++ == ',');
b99bd4ef 3629
c19d1205
ZW
3630 /* Put terminator back into stream. */
3631 input_line_pointer --;
3632 demand_empty_rest_of_line ();
b99bd4ef
NC
3633}
3634
c921be7d
NC
3635/* Emit an expression containing a 32-bit thumb instruction.
3636 Implementation based on put_thumb32_insn. */
3637
3638static void
3639emit_thumb32_expr (expressionS * exp)
3640{
3641 expressionS exp_high = *exp;
3642
3643 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3644 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3645 exp->X_add_number &= 0xffff;
3646 emit_expr (exp, (unsigned int) THUMB_SIZE);
3647}
3648
3649/* Guess the instruction size based on the opcode. */
3650
3651static int
3652thumb_insn_size (int opcode)
3653{
3654 if ((unsigned int) opcode < 0xe800u)
3655 return 2;
3656 else if ((unsigned int) opcode >= 0xe8000000u)
3657 return 4;
3658 else
3659 return 0;
3660}
3661
3662static bfd_boolean
3663emit_insn (expressionS *exp, int nbytes)
3664{
3665 int size = 0;
3666
3667 if (exp->X_op == O_constant)
3668 {
3669 size = nbytes;
3670
3671 if (size == 0)
3672 size = thumb_insn_size (exp->X_add_number);
3673
3674 if (size != 0)
3675 {
3676 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3677 {
3678 as_bad (_(".inst.n operand too big. "\
3679 "Use .inst.w instead"));
3680 size = 0;
3681 }
3682 else
3683 {
3684 if (now_it.state == AUTOMATIC_IT_BLOCK)
3685 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3686 else
3687 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3688
3689 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3690 emit_thumb32_expr (exp);
3691 else
3692 emit_expr (exp, (unsigned int) size);
3693
3694 it_fsm_post_encode ();
3695 }
3696 }
3697 else
3698 as_bad (_("cannot determine Thumb instruction size. " \
3699 "Use .inst.n/.inst.w instead"));
3700 }
3701 else
3702 as_bad (_("constant expression required"));
3703
3704 return (size != 0);
3705}
3706
3707/* Like s_arm_elf_cons but do not use md_cons_align and
3708 set the mapping state to MAP_ARM/MAP_THUMB. */
3709
3710static void
3711s_arm_elf_inst (int nbytes)
3712{
3713 if (is_it_end_of_statement ())
3714 {
3715 demand_empty_rest_of_line ();
3716 return;
3717 }
3718
3719 /* Calling mapping_state () here will not change ARM/THUMB,
3720 but will ensure not to be in DATA state. */
3721
3722 if (thumb_mode)
3723 mapping_state (MAP_THUMB);
3724 else
3725 {
3726 if (nbytes != 0)
3727 {
3728 as_bad (_("width suffixes are invalid in ARM mode"));
3729 ignore_rest_of_line ();
3730 return;
3731 }
3732
3733 nbytes = 4;
3734
3735 mapping_state (MAP_ARM);
3736 }
3737
3738 do
3739 {
3740 expressionS exp;
3741
3742 expression (& exp);
3743
3744 if (! emit_insn (& exp, nbytes))
3745 {
3746 ignore_rest_of_line ();
3747 return;
3748 }
3749 }
3750 while (*input_line_pointer++ == ',');
3751
3752 /* Put terminator back into stream. */
3753 input_line_pointer --;
3754 demand_empty_rest_of_line ();
3755}
b99bd4ef 3756
c19d1205 3757/* Parse a .rel31 directive. */
b99bd4ef 3758
c19d1205
ZW
3759static void
3760s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3761{
3762 expressionS exp;
3763 char *p;
3764 valueT highbit;
b99bd4ef 3765
c19d1205
ZW
3766 highbit = 0;
3767 if (*input_line_pointer == '1')
3768 highbit = 0x80000000;
3769 else if (*input_line_pointer != '0')
3770 as_bad (_("expected 0 or 1"));
b99bd4ef 3771
c19d1205
ZW
3772 input_line_pointer++;
3773 if (*input_line_pointer != ',')
3774 as_bad (_("missing comma"));
3775 input_line_pointer++;
b99bd4ef 3776
c19d1205
ZW
3777#ifdef md_flush_pending_output
3778 md_flush_pending_output ();
3779#endif
b99bd4ef 3780
c19d1205
ZW
3781#ifdef md_cons_align
3782 md_cons_align (4);
3783#endif
b99bd4ef 3784
c19d1205 3785 mapping_state (MAP_DATA);
b99bd4ef 3786
c19d1205 3787 expression (&exp);
b99bd4ef 3788
c19d1205
ZW
3789 p = frag_more (4);
3790 md_number_to_chars (p, highbit, 4);
3791 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3792 BFD_RELOC_ARM_PREL31);
b99bd4ef 3793
c19d1205 3794 demand_empty_rest_of_line ();
b99bd4ef
NC
3795}
3796
c19d1205 3797/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3798
c19d1205 3799/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3800
c19d1205
ZW
3801static void
3802s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3803{
3804 demand_empty_rest_of_line ();
921e5f0a
PB
3805 if (unwind.proc_start)
3806 {
c921be7d 3807 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3808 return;
3809 }
3810
c19d1205
ZW
3811 /* Mark the start of the function. */
3812 unwind.proc_start = expr_build_dot ();
b99bd4ef 3813
c19d1205
ZW
3814 /* Reset the rest of the unwind info. */
3815 unwind.opcode_count = 0;
3816 unwind.table_entry = NULL;
3817 unwind.personality_routine = NULL;
3818 unwind.personality_index = -1;
3819 unwind.frame_size = 0;
3820 unwind.fp_offset = 0;
fdfde340 3821 unwind.fp_reg = REG_SP;
c19d1205
ZW
3822 unwind.fp_used = 0;
3823 unwind.sp_restored = 0;
3824}
b99bd4ef 3825
b99bd4ef 3826
c19d1205
ZW
3827/* Parse a handlerdata directive. Creates the exception handling table entry
3828 for the function. */
b99bd4ef 3829
c19d1205
ZW
3830static void
3831s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3832{
3833 demand_empty_rest_of_line ();
921e5f0a 3834 if (!unwind.proc_start)
c921be7d 3835 as_bad (MISSING_FNSTART);
921e5f0a 3836
c19d1205 3837 if (unwind.table_entry)
6decc662 3838 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3839
c19d1205
ZW
3840 create_unwind_entry (1);
3841}
a737bd4d 3842
c19d1205 3843/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3844
c19d1205
ZW
3845static void
3846s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3847{
3848 long where;
3849 char *ptr;
3850 valueT val;
940b5ce0 3851 unsigned int marked_pr_dependency;
f02232aa 3852
c19d1205 3853 demand_empty_rest_of_line ();
f02232aa 3854
921e5f0a
PB
3855 if (!unwind.proc_start)
3856 {
c921be7d 3857 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3858 return;
3859 }
3860
c19d1205
ZW
3861 /* Add eh table entry. */
3862 if (unwind.table_entry == NULL)
3863 val = create_unwind_entry (0);
3864 else
3865 val = 0;
f02232aa 3866
c19d1205
ZW
3867 /* Add index table entry. This is two words. */
3868 start_unwind_section (unwind.saved_seg, 1);
3869 frag_align (2, 0, 0);
3870 record_alignment (now_seg, 2);
b99bd4ef 3871
c19d1205 3872 ptr = frag_more (8);
5011093d 3873 memset (ptr, 0, 8);
c19d1205 3874 where = frag_now_fix () - 8;
f02232aa 3875
c19d1205
ZW
3876 /* Self relative offset of the function start. */
3877 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3878 BFD_RELOC_ARM_PREL31);
f02232aa 3879
c19d1205
ZW
3880 /* Indicate dependency on EHABI-defined personality routines to the
3881 linker, if it hasn't been done already. */
940b5ce0
DJ
3882 marked_pr_dependency
3883 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3884 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3885 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3886 {
5f4273c7
NC
3887 static const char *const name[] =
3888 {
3889 "__aeabi_unwind_cpp_pr0",
3890 "__aeabi_unwind_cpp_pr1",
3891 "__aeabi_unwind_cpp_pr2"
3892 };
c19d1205
ZW
3893 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3894 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3895 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3896 |= 1 << unwind.personality_index;
c19d1205 3897 }
f02232aa 3898
c19d1205
ZW
3899 if (val)
3900 /* Inline exception table entry. */
3901 md_number_to_chars (ptr + 4, val, 4);
3902 else
3903 /* Self relative offset of the table entry. */
3904 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3905 BFD_RELOC_ARM_PREL31);
f02232aa 3906
c19d1205
ZW
3907 /* Restore the original section. */
3908 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3909
3910 unwind.proc_start = NULL;
c19d1205 3911}
f02232aa 3912
f02232aa 3913
c19d1205 3914/* Parse an unwind_cantunwind directive. */
b99bd4ef 3915
c19d1205
ZW
3916static void
3917s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3918{
3919 demand_empty_rest_of_line ();
921e5f0a 3920 if (!unwind.proc_start)
c921be7d 3921 as_bad (MISSING_FNSTART);
921e5f0a 3922
c19d1205
ZW
3923 if (unwind.personality_routine || unwind.personality_index != -1)
3924 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3925
c19d1205
ZW
3926 unwind.personality_index = -2;
3927}
b99bd4ef 3928
b99bd4ef 3929
c19d1205 3930/* Parse a personalityindex directive. */
b99bd4ef 3931
c19d1205
ZW
3932static void
3933s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3934{
3935 expressionS exp;
b99bd4ef 3936
921e5f0a 3937 if (!unwind.proc_start)
c921be7d 3938 as_bad (MISSING_FNSTART);
921e5f0a 3939
c19d1205
ZW
3940 if (unwind.personality_routine || unwind.personality_index != -1)
3941 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3942
c19d1205 3943 expression (&exp);
b99bd4ef 3944
c19d1205
ZW
3945 if (exp.X_op != O_constant
3946 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3947 {
c19d1205
ZW
3948 as_bad (_("bad personality routine number"));
3949 ignore_rest_of_line ();
3950 return;
b99bd4ef
NC
3951 }
3952
c19d1205 3953 unwind.personality_index = exp.X_add_number;
b99bd4ef 3954
c19d1205
ZW
3955 demand_empty_rest_of_line ();
3956}
e16bb312 3957
e16bb312 3958
c19d1205 3959/* Parse a personality directive. */
e16bb312 3960
c19d1205
ZW
3961static void
3962s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3963{
3964 char *name, *p, c;
a737bd4d 3965
921e5f0a 3966 if (!unwind.proc_start)
c921be7d 3967 as_bad (MISSING_FNSTART);
921e5f0a 3968
c19d1205
ZW
3969 if (unwind.personality_routine || unwind.personality_index != -1)
3970 as_bad (_("duplicate .personality directive"));
a737bd4d 3971
d02603dc 3972 c = get_symbol_name (& name);
c19d1205 3973 p = input_line_pointer;
d02603dc
NC
3974 if (c == '"')
3975 ++ input_line_pointer;
c19d1205
ZW
3976 unwind.personality_routine = symbol_find_or_make (name);
3977 *p = c;
3978 demand_empty_rest_of_line ();
3979}
e16bb312 3980
e16bb312 3981
c19d1205 3982/* Parse a directive saving core registers. */
e16bb312 3983
c19d1205
ZW
3984static void
3985s_arm_unwind_save_core (void)
e16bb312 3986{
c19d1205
ZW
3987 valueT op;
3988 long range;
3989 int n;
e16bb312 3990
c19d1205
ZW
3991 range = parse_reg_list (&input_line_pointer);
3992 if (range == FAIL)
e16bb312 3993 {
c19d1205
ZW
3994 as_bad (_("expected register list"));
3995 ignore_rest_of_line ();
3996 return;
3997 }
e16bb312 3998
c19d1205 3999 demand_empty_rest_of_line ();
e16bb312 4000
c19d1205
ZW
4001 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4002 into .unwind_save {..., sp...}. We aren't bothered about the value of
4003 ip because it is clobbered by calls. */
4004 if (unwind.sp_restored && unwind.fp_reg == 12
4005 && (range & 0x3000) == 0x1000)
4006 {
4007 unwind.opcode_count--;
4008 unwind.sp_restored = 0;
4009 range = (range | 0x2000) & ~0x1000;
4010 unwind.pending_offset = 0;
4011 }
e16bb312 4012
01ae4198
DJ
4013 /* Pop r4-r15. */
4014 if (range & 0xfff0)
c19d1205 4015 {
01ae4198
DJ
4016 /* See if we can use the short opcodes. These pop a block of up to 8
4017 registers starting with r4, plus maybe r14. */
4018 for (n = 0; n < 8; n++)
4019 {
4020 /* Break at the first non-saved register. */
4021 if ((range & (1 << (n + 4))) == 0)
4022 break;
4023 }
4024 /* See if there are any other bits set. */
4025 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4026 {
4027 /* Use the long form. */
4028 op = 0x8000 | ((range >> 4) & 0xfff);
4029 add_unwind_opcode (op, 2);
4030 }
0dd132b6 4031 else
01ae4198
DJ
4032 {
4033 /* Use the short form. */
4034 if (range & 0x4000)
4035 op = 0xa8; /* Pop r14. */
4036 else
4037 op = 0xa0; /* Do not pop r14. */
4038 op |= (n - 1);
4039 add_unwind_opcode (op, 1);
4040 }
c19d1205 4041 }
0dd132b6 4042
c19d1205
ZW
4043 /* Pop r0-r3. */
4044 if (range & 0xf)
4045 {
4046 op = 0xb100 | (range & 0xf);
4047 add_unwind_opcode (op, 2);
0dd132b6
NC
4048 }
4049
c19d1205
ZW
4050 /* Record the number of bytes pushed. */
4051 for (n = 0; n < 16; n++)
4052 {
4053 if (range & (1 << n))
4054 unwind.frame_size += 4;
4055 }
0dd132b6
NC
4056}
4057
c19d1205
ZW
4058
4059/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4060
4061static void
c19d1205 4062s_arm_unwind_save_fpa (int reg)
b99bd4ef 4063{
c19d1205
ZW
4064 expressionS exp;
4065 int num_regs;
4066 valueT op;
b99bd4ef 4067
c19d1205
ZW
4068 /* Get Number of registers to transfer. */
4069 if (skip_past_comma (&input_line_pointer) != FAIL)
4070 expression (&exp);
4071 else
4072 exp.X_op = O_illegal;
b99bd4ef 4073
c19d1205 4074 if (exp.X_op != O_constant)
b99bd4ef 4075 {
c19d1205
ZW
4076 as_bad (_("expected , <constant>"));
4077 ignore_rest_of_line ();
b99bd4ef
NC
4078 return;
4079 }
4080
c19d1205
ZW
4081 num_regs = exp.X_add_number;
4082
4083 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4084 {
c19d1205
ZW
4085 as_bad (_("number of registers must be in the range [1:4]"));
4086 ignore_rest_of_line ();
b99bd4ef
NC
4087 return;
4088 }
4089
c19d1205 4090 demand_empty_rest_of_line ();
b99bd4ef 4091
c19d1205
ZW
4092 if (reg == 4)
4093 {
4094 /* Short form. */
4095 op = 0xb4 | (num_regs - 1);
4096 add_unwind_opcode (op, 1);
4097 }
b99bd4ef
NC
4098 else
4099 {
c19d1205
ZW
4100 /* Long form. */
4101 op = 0xc800 | (reg << 4) | (num_regs - 1);
4102 add_unwind_opcode (op, 2);
b99bd4ef 4103 }
c19d1205 4104 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4105}
4106
c19d1205 4107
fa073d69
MS
4108/* Parse a directive saving VFP registers for ARMv6 and above. */
4109
4110static void
4111s_arm_unwind_save_vfp_armv6 (void)
4112{
4113 int count;
4114 unsigned int start;
4115 valueT op;
4116 int num_vfpv3_regs = 0;
4117 int num_regs_below_16;
4118
4119 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4120 if (count == FAIL)
4121 {
4122 as_bad (_("expected register list"));
4123 ignore_rest_of_line ();
4124 return;
4125 }
4126
4127 demand_empty_rest_of_line ();
4128
4129 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4130 than FSTMX/FLDMX-style ones). */
4131
4132 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4133 if (start >= 16)
4134 num_vfpv3_regs = count;
4135 else if (start + count > 16)
4136 num_vfpv3_regs = start + count - 16;
4137
4138 if (num_vfpv3_regs > 0)
4139 {
4140 int start_offset = start > 16 ? start - 16 : 0;
4141 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4142 add_unwind_opcode (op, 2);
4143 }
4144
4145 /* Generate opcode for registers numbered in the range 0 .. 15. */
4146 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4147 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4148 if (num_regs_below_16 > 0)
4149 {
4150 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4151 add_unwind_opcode (op, 2);
4152 }
4153
4154 unwind.frame_size += count * 8;
4155}
4156
4157
4158/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4159
4160static void
c19d1205 4161s_arm_unwind_save_vfp (void)
b99bd4ef 4162{
c19d1205 4163 int count;
ca3f61f7 4164 unsigned int reg;
c19d1205 4165 valueT op;
b99bd4ef 4166
5287ad62 4167 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4168 if (count == FAIL)
b99bd4ef 4169 {
c19d1205
ZW
4170 as_bad (_("expected register list"));
4171 ignore_rest_of_line ();
b99bd4ef
NC
4172 return;
4173 }
4174
c19d1205 4175 demand_empty_rest_of_line ();
b99bd4ef 4176
c19d1205 4177 if (reg == 8)
b99bd4ef 4178 {
c19d1205
ZW
4179 /* Short form. */
4180 op = 0xb8 | (count - 1);
4181 add_unwind_opcode (op, 1);
b99bd4ef 4182 }
c19d1205 4183 else
b99bd4ef 4184 {
c19d1205
ZW
4185 /* Long form. */
4186 op = 0xb300 | (reg << 4) | (count - 1);
4187 add_unwind_opcode (op, 2);
b99bd4ef 4188 }
c19d1205
ZW
4189 unwind.frame_size += count * 8 + 4;
4190}
b99bd4ef 4191
b99bd4ef 4192
c19d1205
ZW
4193/* Parse a directive saving iWMMXt data registers. */
4194
4195static void
4196s_arm_unwind_save_mmxwr (void)
4197{
4198 int reg;
4199 int hi_reg;
4200 int i;
4201 unsigned mask = 0;
4202 valueT op;
b99bd4ef 4203
c19d1205
ZW
4204 if (*input_line_pointer == '{')
4205 input_line_pointer++;
b99bd4ef 4206
c19d1205 4207 do
b99bd4ef 4208 {
dcbf9037 4209 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4210
c19d1205 4211 if (reg == FAIL)
b99bd4ef 4212 {
9b7132d3 4213 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4214 goto error;
b99bd4ef
NC
4215 }
4216
c19d1205
ZW
4217 if (mask >> reg)
4218 as_tsktsk (_("register list not in ascending order"));
4219 mask |= 1 << reg;
b99bd4ef 4220
c19d1205
ZW
4221 if (*input_line_pointer == '-')
4222 {
4223 input_line_pointer++;
dcbf9037 4224 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4225 if (hi_reg == FAIL)
4226 {
9b7132d3 4227 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4228 goto error;
4229 }
4230 else if (reg >= hi_reg)
4231 {
4232 as_bad (_("bad register range"));
4233 goto error;
4234 }
4235 for (; reg < hi_reg; reg++)
4236 mask |= 1 << reg;
4237 }
4238 }
4239 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4240
d996d970 4241 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4242
c19d1205 4243 demand_empty_rest_of_line ();
b99bd4ef 4244
708587a4 4245 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4246 the list. */
4247 flush_pending_unwind ();
b99bd4ef 4248
c19d1205 4249 for (i = 0; i < 16; i++)
b99bd4ef 4250 {
c19d1205
ZW
4251 if (mask & (1 << i))
4252 unwind.frame_size += 8;
b99bd4ef
NC
4253 }
4254
c19d1205
ZW
4255 /* Attempt to combine with a previous opcode. We do this because gcc
4256 likes to output separate unwind directives for a single block of
4257 registers. */
4258 if (unwind.opcode_count > 0)
b99bd4ef 4259 {
c19d1205
ZW
4260 i = unwind.opcodes[unwind.opcode_count - 1];
4261 if ((i & 0xf8) == 0xc0)
4262 {
4263 i &= 7;
4264 /* Only merge if the blocks are contiguous. */
4265 if (i < 6)
4266 {
4267 if ((mask & 0xfe00) == (1 << 9))
4268 {
4269 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4270 unwind.opcode_count--;
4271 }
4272 }
4273 else if (i == 6 && unwind.opcode_count >= 2)
4274 {
4275 i = unwind.opcodes[unwind.opcode_count - 2];
4276 reg = i >> 4;
4277 i &= 0xf;
b99bd4ef 4278
c19d1205
ZW
4279 op = 0xffff << (reg - 1);
4280 if (reg > 0
87a1fd79 4281 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4282 {
4283 op = (1 << (reg + i + 1)) - 1;
4284 op &= ~((1 << reg) - 1);
4285 mask |= op;
4286 unwind.opcode_count -= 2;
4287 }
4288 }
4289 }
b99bd4ef
NC
4290 }
4291
c19d1205
ZW
4292 hi_reg = 15;
4293 /* We want to generate opcodes in the order the registers have been
4294 saved, ie. descending order. */
4295 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4296 {
c19d1205
ZW
4297 /* Save registers in blocks. */
4298 if (reg < 0
4299 || !(mask & (1 << reg)))
4300 {
4301 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4302 preceding block. */
c19d1205
ZW
4303 if (reg != hi_reg)
4304 {
4305 if (reg == 9)
4306 {
4307 /* Short form. */
4308 op = 0xc0 | (hi_reg - 10);
4309 add_unwind_opcode (op, 1);
4310 }
4311 else
4312 {
4313 /* Long form. */
4314 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4315 add_unwind_opcode (op, 2);
4316 }
4317 }
4318 hi_reg = reg - 1;
4319 }
b99bd4ef
NC
4320 }
4321
c19d1205
ZW
4322 return;
4323error:
4324 ignore_rest_of_line ();
b99bd4ef
NC
4325}
4326
4327static void
c19d1205 4328s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4329{
c19d1205
ZW
4330 int reg;
4331 int hi_reg;
4332 unsigned mask = 0;
4333 valueT op;
b99bd4ef 4334
c19d1205
ZW
4335 if (*input_line_pointer == '{')
4336 input_line_pointer++;
b99bd4ef 4337
477330fc
RM
4338 skip_whitespace (input_line_pointer);
4339
c19d1205 4340 do
b99bd4ef 4341 {
dcbf9037 4342 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4343
c19d1205
ZW
4344 if (reg == FAIL)
4345 {
9b7132d3 4346 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4347 goto error;
4348 }
b99bd4ef 4349
c19d1205
ZW
4350 reg -= 8;
4351 if (mask >> reg)
4352 as_tsktsk (_("register list not in ascending order"));
4353 mask |= 1 << reg;
b99bd4ef 4354
c19d1205
ZW
4355 if (*input_line_pointer == '-')
4356 {
4357 input_line_pointer++;
dcbf9037 4358 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4359 if (hi_reg == FAIL)
4360 {
9b7132d3 4361 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4362 goto error;
4363 }
4364 else if (reg >= hi_reg)
4365 {
4366 as_bad (_("bad register range"));
4367 goto error;
4368 }
4369 for (; reg < hi_reg; reg++)
4370 mask |= 1 << reg;
4371 }
b99bd4ef 4372 }
c19d1205 4373 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4374
d996d970 4375 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4376
c19d1205
ZW
4377 demand_empty_rest_of_line ();
4378
708587a4 4379 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4380 the list. */
4381 flush_pending_unwind ();
b99bd4ef 4382
c19d1205 4383 for (reg = 0; reg < 16; reg++)
b99bd4ef 4384 {
c19d1205
ZW
4385 if (mask & (1 << reg))
4386 unwind.frame_size += 4;
b99bd4ef 4387 }
c19d1205
ZW
4388 op = 0xc700 | mask;
4389 add_unwind_opcode (op, 2);
4390 return;
4391error:
4392 ignore_rest_of_line ();
b99bd4ef
NC
4393}
4394
c19d1205 4395
fa073d69
MS
4396/* Parse an unwind_save directive.
4397 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4398
b99bd4ef 4399static void
fa073d69 4400s_arm_unwind_save (int arch_v6)
b99bd4ef 4401{
c19d1205
ZW
4402 char *peek;
4403 struct reg_entry *reg;
4404 bfd_boolean had_brace = FALSE;
b99bd4ef 4405
921e5f0a 4406 if (!unwind.proc_start)
c921be7d 4407 as_bad (MISSING_FNSTART);
921e5f0a 4408
c19d1205
ZW
4409 /* Figure out what sort of save we have. */
4410 peek = input_line_pointer;
b99bd4ef 4411
c19d1205 4412 if (*peek == '{')
b99bd4ef 4413 {
c19d1205
ZW
4414 had_brace = TRUE;
4415 peek++;
b99bd4ef
NC
4416 }
4417
c19d1205 4418 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4419
c19d1205 4420 if (!reg)
b99bd4ef 4421 {
c19d1205
ZW
4422 as_bad (_("register expected"));
4423 ignore_rest_of_line ();
b99bd4ef
NC
4424 return;
4425 }
4426
c19d1205 4427 switch (reg->type)
b99bd4ef 4428 {
c19d1205
ZW
4429 case REG_TYPE_FN:
4430 if (had_brace)
4431 {
4432 as_bad (_("FPA .unwind_save does not take a register list"));
4433 ignore_rest_of_line ();
4434 return;
4435 }
93ac2687 4436 input_line_pointer = peek;
c19d1205 4437 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4438 return;
c19d1205 4439
1f5afe1c
NC
4440 case REG_TYPE_RN:
4441 s_arm_unwind_save_core ();
4442 return;
4443
fa073d69
MS
4444 case REG_TYPE_VFD:
4445 if (arch_v6)
477330fc 4446 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4447 else
477330fc 4448 s_arm_unwind_save_vfp ();
fa073d69 4449 return;
1f5afe1c
NC
4450
4451 case REG_TYPE_MMXWR:
4452 s_arm_unwind_save_mmxwr ();
4453 return;
4454
4455 case REG_TYPE_MMXWCG:
4456 s_arm_unwind_save_mmxwcg ();
4457 return;
c19d1205
ZW
4458
4459 default:
4460 as_bad (_(".unwind_save does not support this kind of register"));
4461 ignore_rest_of_line ();
b99bd4ef 4462 }
c19d1205 4463}
b99bd4ef 4464
b99bd4ef 4465
c19d1205
ZW
4466/* Parse an unwind_movsp directive. */
4467
4468static void
4469s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4470{
4471 int reg;
4472 valueT op;
4fa3602b 4473 int offset;
c19d1205 4474
921e5f0a 4475 if (!unwind.proc_start)
c921be7d 4476 as_bad (MISSING_FNSTART);
921e5f0a 4477
dcbf9037 4478 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4479 if (reg == FAIL)
b99bd4ef 4480 {
9b7132d3 4481 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4482 ignore_rest_of_line ();
b99bd4ef
NC
4483 return;
4484 }
4fa3602b
PB
4485
4486 /* Optional constant. */
4487 if (skip_past_comma (&input_line_pointer) != FAIL)
4488 {
4489 if (immediate_for_directive (&offset) == FAIL)
4490 return;
4491 }
4492 else
4493 offset = 0;
4494
c19d1205 4495 demand_empty_rest_of_line ();
b99bd4ef 4496
c19d1205 4497 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4498 {
c19d1205 4499 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4500 return;
4501 }
4502
c19d1205
ZW
4503 if (unwind.fp_reg != REG_SP)
4504 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4505
c19d1205
ZW
4506 /* Generate opcode to restore the value. */
4507 op = 0x90 | reg;
4508 add_unwind_opcode (op, 1);
4509
4510 /* Record the information for later. */
4511 unwind.fp_reg = reg;
4fa3602b 4512 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4513 unwind.sp_restored = 1;
b05fe5cf
ZW
4514}
4515
c19d1205
ZW
4516/* Parse an unwind_pad directive. */
4517
b05fe5cf 4518static void
c19d1205 4519s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4520{
c19d1205 4521 int offset;
b05fe5cf 4522
921e5f0a 4523 if (!unwind.proc_start)
c921be7d 4524 as_bad (MISSING_FNSTART);
921e5f0a 4525
c19d1205
ZW
4526 if (immediate_for_directive (&offset) == FAIL)
4527 return;
b99bd4ef 4528
c19d1205
ZW
4529 if (offset & 3)
4530 {
4531 as_bad (_("stack increment must be multiple of 4"));
4532 ignore_rest_of_line ();
4533 return;
4534 }
b99bd4ef 4535
c19d1205
ZW
4536 /* Don't generate any opcodes, just record the details for later. */
4537 unwind.frame_size += offset;
4538 unwind.pending_offset += offset;
4539
4540 demand_empty_rest_of_line ();
4541}
4542
4543/* Parse an unwind_setfp directive. */
4544
4545static void
4546s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4547{
c19d1205
ZW
4548 int sp_reg;
4549 int fp_reg;
4550 int offset;
4551
921e5f0a 4552 if (!unwind.proc_start)
c921be7d 4553 as_bad (MISSING_FNSTART);
921e5f0a 4554
dcbf9037 4555 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4556 if (skip_past_comma (&input_line_pointer) == FAIL)
4557 sp_reg = FAIL;
4558 else
dcbf9037 4559 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4560
c19d1205
ZW
4561 if (fp_reg == FAIL || sp_reg == FAIL)
4562 {
4563 as_bad (_("expected <reg>, <reg>"));
4564 ignore_rest_of_line ();
4565 return;
4566 }
b99bd4ef 4567
c19d1205
ZW
4568 /* Optional constant. */
4569 if (skip_past_comma (&input_line_pointer) != FAIL)
4570 {
4571 if (immediate_for_directive (&offset) == FAIL)
4572 return;
4573 }
4574 else
4575 offset = 0;
a737bd4d 4576
c19d1205 4577 demand_empty_rest_of_line ();
a737bd4d 4578
fdfde340 4579 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4580 {
c19d1205
ZW
4581 as_bad (_("register must be either sp or set by a previous"
4582 "unwind_movsp directive"));
4583 return;
a737bd4d
NC
4584 }
4585
c19d1205
ZW
4586 /* Don't generate any opcodes, just record the information for later. */
4587 unwind.fp_reg = fp_reg;
4588 unwind.fp_used = 1;
fdfde340 4589 if (sp_reg == REG_SP)
c19d1205
ZW
4590 unwind.fp_offset = unwind.frame_size - offset;
4591 else
4592 unwind.fp_offset -= offset;
a737bd4d
NC
4593}
4594
c19d1205
ZW
4595/* Parse an unwind_raw directive. */
4596
4597static void
4598s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4599{
c19d1205 4600 expressionS exp;
708587a4 4601 /* This is an arbitrary limit. */
c19d1205
ZW
4602 unsigned char op[16];
4603 int count;
a737bd4d 4604
921e5f0a 4605 if (!unwind.proc_start)
c921be7d 4606 as_bad (MISSING_FNSTART);
921e5f0a 4607
c19d1205
ZW
4608 expression (&exp);
4609 if (exp.X_op == O_constant
4610 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4611 {
c19d1205
ZW
4612 unwind.frame_size += exp.X_add_number;
4613 expression (&exp);
4614 }
4615 else
4616 exp.X_op = O_illegal;
a737bd4d 4617
c19d1205
ZW
4618 if (exp.X_op != O_constant)
4619 {
4620 as_bad (_("expected <offset>, <opcode>"));
4621 ignore_rest_of_line ();
4622 return;
4623 }
a737bd4d 4624
c19d1205 4625 count = 0;
a737bd4d 4626
c19d1205
ZW
4627 /* Parse the opcode. */
4628 for (;;)
4629 {
4630 if (count >= 16)
4631 {
4632 as_bad (_("unwind opcode too long"));
4633 ignore_rest_of_line ();
a737bd4d 4634 }
c19d1205 4635 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4636 {
c19d1205
ZW
4637 as_bad (_("invalid unwind opcode"));
4638 ignore_rest_of_line ();
4639 return;
a737bd4d 4640 }
c19d1205 4641 op[count++] = exp.X_add_number;
a737bd4d 4642
c19d1205
ZW
4643 /* Parse the next byte. */
4644 if (skip_past_comma (&input_line_pointer) == FAIL)
4645 break;
a737bd4d 4646
c19d1205
ZW
4647 expression (&exp);
4648 }
b99bd4ef 4649
c19d1205
ZW
4650 /* Add the opcode bytes in reverse order. */
4651 while (count--)
4652 add_unwind_opcode (op[count], 1);
b99bd4ef 4653
c19d1205 4654 demand_empty_rest_of_line ();
b99bd4ef 4655}
ee065d83
PB
4656
4657
4658/* Parse a .eabi_attribute directive. */
4659
4660static void
4661s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4662{
0420f52b 4663 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4664
4665 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4666 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4667}
4668
0855e32b
NS
4669/* Emit a tls fix for the symbol. */
4670
4671static void
4672s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4673{
4674 char *p;
4675 expressionS exp;
4676#ifdef md_flush_pending_output
4677 md_flush_pending_output ();
4678#endif
4679
4680#ifdef md_cons_align
4681 md_cons_align (4);
4682#endif
4683
4684 /* Since we're just labelling the code, there's no need to define a
4685 mapping symbol. */
4686 expression (&exp);
4687 p = obstack_next_free (&frchain_now->frch_obstack);
4688 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4689 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4690 : BFD_RELOC_ARM_TLS_DESCSEQ);
4691}
cdf9ccec 4692#endif /* OBJ_ELF */
0855e32b 4693
ee065d83 4694static void s_arm_arch (int);
7a1d4c38 4695static void s_arm_object_arch (int);
ee065d83
PB
4696static void s_arm_cpu (int);
4697static void s_arm_fpu (int);
69133863 4698static void s_arm_arch_extension (int);
b99bd4ef 4699
f0927246
NC
4700#ifdef TE_PE
4701
4702static void
5f4273c7 4703pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4704{
4705 expressionS exp;
4706
4707 do
4708 {
4709 expression (&exp);
4710 if (exp.X_op == O_symbol)
4711 exp.X_op = O_secrel;
4712
4713 emit_expr (&exp, 4);
4714 }
4715 while (*input_line_pointer++ == ',');
4716
4717 input_line_pointer--;
4718 demand_empty_rest_of_line ();
4719}
4720#endif /* TE_PE */
4721
c19d1205
ZW
4722/* This table describes all the machine specific pseudo-ops the assembler
4723 has to support. The fields are:
4724 pseudo-op name without dot
4725 function to call to execute this pseudo-op
4726 Integer arg to pass to the function. */
b99bd4ef 4727
c19d1205 4728const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4729{
c19d1205
ZW
4730 /* Never called because '.req' does not start a line. */
4731 { "req", s_req, 0 },
dcbf9037
JB
4732 /* Following two are likewise never called. */
4733 { "dn", s_dn, 0 },
4734 { "qn", s_qn, 0 },
c19d1205
ZW
4735 { "unreq", s_unreq, 0 },
4736 { "bss", s_bss, 0 },
db2ed2e0 4737 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4738 { "arm", s_arm, 0 },
4739 { "thumb", s_thumb, 0 },
4740 { "code", s_code, 0 },
4741 { "force_thumb", s_force_thumb, 0 },
4742 { "thumb_func", s_thumb_func, 0 },
4743 { "thumb_set", s_thumb_set, 0 },
4744 { "even", s_even, 0 },
4745 { "ltorg", s_ltorg, 0 },
4746 { "pool", s_ltorg, 0 },
4747 { "syntax", s_syntax, 0 },
8463be01
PB
4748 { "cpu", s_arm_cpu, 0 },
4749 { "arch", s_arm_arch, 0 },
7a1d4c38 4750 { "object_arch", s_arm_object_arch, 0 },
8463be01 4751 { "fpu", s_arm_fpu, 0 },
69133863 4752 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4753#ifdef OBJ_ELF
c921be7d
NC
4754 { "word", s_arm_elf_cons, 4 },
4755 { "long", s_arm_elf_cons, 4 },
4756 { "inst.n", s_arm_elf_inst, 2 },
4757 { "inst.w", s_arm_elf_inst, 4 },
4758 { "inst", s_arm_elf_inst, 0 },
4759 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4760 { "fnstart", s_arm_unwind_fnstart, 0 },
4761 { "fnend", s_arm_unwind_fnend, 0 },
4762 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4763 { "personality", s_arm_unwind_personality, 0 },
4764 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4765 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4766 { "save", s_arm_unwind_save, 0 },
fa073d69 4767 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4768 { "movsp", s_arm_unwind_movsp, 0 },
4769 { "pad", s_arm_unwind_pad, 0 },
4770 { "setfp", s_arm_unwind_setfp, 0 },
4771 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4772 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4773 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4774#else
4775 { "word", cons, 4},
f0927246
NC
4776
4777 /* These are used for dwarf. */
4778 {"2byte", cons, 2},
4779 {"4byte", cons, 4},
4780 {"8byte", cons, 8},
4781 /* These are used for dwarf2. */
68d20676 4782 { "file", dwarf2_directive_file, 0 },
f0927246
NC
4783 { "loc", dwarf2_directive_loc, 0 },
4784 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4785#endif
4786 { "extend", float_cons, 'x' },
4787 { "ldouble", float_cons, 'x' },
4788 { "packed", float_cons, 'p' },
f0927246
NC
4789#ifdef TE_PE
4790 {"secrel32", pe_directive_secrel, 0},
4791#endif
2e6976a8
DG
4792
4793 /* These are for compatibility with CodeComposer Studio. */
4794 {"ref", s_ccs_ref, 0},
4795 {"def", s_ccs_def, 0},
4796 {"asmfunc", s_ccs_asmfunc, 0},
4797 {"endasmfunc", s_ccs_endasmfunc, 0},
4798
c19d1205
ZW
4799 { 0, 0, 0 }
4800};
4801\f
4802/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4803
c19d1205
ZW
4804/* Generic immediate-value read function for use in insn parsing.
4805 STR points to the beginning of the immediate (the leading #);
4806 VAL receives the value; if the value is outside [MIN, MAX]
4807 issue an error. PREFIX_OPT is true if the immediate prefix is
4808 optional. */
b99bd4ef 4809
c19d1205
ZW
4810static int
4811parse_immediate (char **str, int *val, int min, int max,
4812 bfd_boolean prefix_opt)
4813{
4814 expressionS exp;
0198d5e6 4815
c19d1205
ZW
4816 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4817 if (exp.X_op != O_constant)
b99bd4ef 4818 {
c19d1205
ZW
4819 inst.error = _("constant expression required");
4820 return FAIL;
4821 }
b99bd4ef 4822
c19d1205
ZW
4823 if (exp.X_add_number < min || exp.X_add_number > max)
4824 {
4825 inst.error = _("immediate value out of range");
4826 return FAIL;
4827 }
b99bd4ef 4828
c19d1205
ZW
4829 *val = exp.X_add_number;
4830 return SUCCESS;
4831}
b99bd4ef 4832
5287ad62 4833/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4834 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4835 instructions. Puts the result directly in inst.operands[i]. */
4836
4837static int
8335d6aa
JW
4838parse_big_immediate (char **str, int i, expressionS *in_exp,
4839 bfd_boolean allow_symbol_p)
5287ad62
JB
4840{
4841 expressionS exp;
8335d6aa 4842 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4843 char *ptr = *str;
4844
8335d6aa 4845 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4846
8335d6aa 4847 if (exp_p->X_op == O_constant)
036dc3f7 4848 {
8335d6aa 4849 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4850 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4851 O_constant. We have to be careful not to break compilation for
4852 32-bit X_add_number, though. */
8335d6aa 4853 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4854 {
8335d6aa
JW
4855 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4856 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4857 & 0xffffffff);
036dc3f7
PB
4858 inst.operands[i].regisimm = 1;
4859 }
4860 }
8335d6aa
JW
4861 else if (exp_p->X_op == O_big
4862 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4863 {
4864 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4865
5287ad62 4866 /* Bignums have their least significant bits in
477330fc
RM
4867 generic_bignum[0]. Make sure we put 32 bits in imm and
4868 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4869 gas_assert (parts != 0);
95b75c01
NC
4870
4871 /* Make sure that the number is not too big.
4872 PR 11972: Bignums can now be sign-extended to the
4873 size of a .octa so check that the out of range bits
4874 are all zero or all one. */
8335d6aa 4875 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4876 {
4877 LITTLENUM_TYPE m = -1;
4878
4879 if (generic_bignum[parts * 2] != 0
4880 && generic_bignum[parts * 2] != m)
4881 return FAIL;
4882
8335d6aa 4883 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4884 if (generic_bignum[j] != generic_bignum[j-1])
4885 return FAIL;
4886 }
4887
5287ad62
JB
4888 inst.operands[i].imm = 0;
4889 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4890 inst.operands[i].imm |= generic_bignum[idx]
4891 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4892 inst.operands[i].reg = 0;
4893 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4894 inst.operands[i].reg |= generic_bignum[idx]
4895 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4896 inst.operands[i].regisimm = 1;
4897 }
8335d6aa 4898 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4899 return FAIL;
5f4273c7 4900
5287ad62
JB
4901 *str = ptr;
4902
4903 return SUCCESS;
4904}
4905
c19d1205
ZW
4906/* Returns the pseudo-register number of an FPA immediate constant,
4907 or FAIL if there isn't a valid constant here. */
b99bd4ef 4908
c19d1205
ZW
4909static int
4910parse_fpa_immediate (char ** str)
4911{
4912 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4913 char * save_in;
4914 expressionS exp;
4915 int i;
4916 int j;
b99bd4ef 4917
c19d1205
ZW
4918 /* First try and match exact strings, this is to guarantee
4919 that some formats will work even for cross assembly. */
b99bd4ef 4920
c19d1205
ZW
4921 for (i = 0; fp_const[i]; i++)
4922 {
4923 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4924 {
c19d1205 4925 char *start = *str;
b99bd4ef 4926
c19d1205
ZW
4927 *str += strlen (fp_const[i]);
4928 if (is_end_of_line[(unsigned char) **str])
4929 return i + 8;
4930 *str = start;
4931 }
4932 }
b99bd4ef 4933
c19d1205
ZW
4934 /* Just because we didn't get a match doesn't mean that the constant
4935 isn't valid, just that it is in a format that we don't
4936 automatically recognize. Try parsing it with the standard
4937 expression routines. */
b99bd4ef 4938
c19d1205 4939 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4940
c19d1205
ZW
4941 /* Look for a raw floating point number. */
4942 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4943 && is_end_of_line[(unsigned char) *save_in])
4944 {
4945 for (i = 0; i < NUM_FLOAT_VALS; i++)
4946 {
4947 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4948 {
c19d1205
ZW
4949 if (words[j] != fp_values[i][j])
4950 break;
b99bd4ef
NC
4951 }
4952
c19d1205 4953 if (j == MAX_LITTLENUMS)
b99bd4ef 4954 {
c19d1205
ZW
4955 *str = save_in;
4956 return i + 8;
b99bd4ef
NC
4957 }
4958 }
4959 }
b99bd4ef 4960
c19d1205
ZW
4961 /* Try and parse a more complex expression, this will probably fail
4962 unless the code uses a floating point prefix (eg "0f"). */
4963 save_in = input_line_pointer;
4964 input_line_pointer = *str;
4965 if (expression (&exp) == absolute_section
4966 && exp.X_op == O_big
4967 && exp.X_add_number < 0)
4968 {
4969 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4970 Ditto for 15. */
ba592044
AM
4971#define X_PRECISION 5
4972#define E_PRECISION 15L
4973 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4974 {
4975 for (i = 0; i < NUM_FLOAT_VALS; i++)
4976 {
4977 for (j = 0; j < MAX_LITTLENUMS; j++)
4978 {
4979 if (words[j] != fp_values[i][j])
4980 break;
4981 }
b99bd4ef 4982
c19d1205
ZW
4983 if (j == MAX_LITTLENUMS)
4984 {
4985 *str = input_line_pointer;
4986 input_line_pointer = save_in;
4987 return i + 8;
4988 }
4989 }
4990 }
b99bd4ef
NC
4991 }
4992
c19d1205
ZW
4993 *str = input_line_pointer;
4994 input_line_pointer = save_in;
4995 inst.error = _("invalid FPA immediate expression");
4996 return FAIL;
b99bd4ef
NC
4997}
4998
136da414
JB
4999/* Returns 1 if a number has "quarter-precision" float format
5000 0baBbbbbbc defgh000 00000000 00000000. */
5001
5002static int
5003is_quarter_float (unsigned imm)
5004{
5005 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5006 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5007}
5008
aacf0b33
KT
5009
5010/* Detect the presence of a floating point or integer zero constant,
5011 i.e. #0.0 or #0. */
5012
5013static bfd_boolean
5014parse_ifimm_zero (char **in)
5015{
5016 int error_code;
5017
5018 if (!is_immediate_prefix (**in))
3c6452ae
TP
5019 {
5020 /* In unified syntax, all prefixes are optional. */
5021 if (!unified_syntax)
5022 return FALSE;
5023 }
5024 else
5025 ++*in;
0900a05b
JW
5026
5027 /* Accept #0x0 as a synonym for #0. */
5028 if (strncmp (*in, "0x", 2) == 0)
5029 {
5030 int val;
5031 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5032 return FALSE;
5033 return TRUE;
5034 }
5035
aacf0b33
KT
5036 error_code = atof_generic (in, ".", EXP_CHARS,
5037 &generic_floating_point_number);
5038
5039 if (!error_code
5040 && generic_floating_point_number.sign == '+'
5041 && (generic_floating_point_number.low
5042 > generic_floating_point_number.leader))
5043 return TRUE;
5044
5045 return FALSE;
5046}
5047
136da414
JB
5048/* Parse an 8-bit "quarter-precision" floating point number of the form:
5049 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5050 The zero and minus-zero cases need special handling, since they can't be
5051 encoded in the "quarter-precision" float format, but can nonetheless be
5052 loaded as integer constants. */
136da414
JB
5053
5054static unsigned
5055parse_qfloat_immediate (char **ccp, int *immed)
5056{
5057 char *str = *ccp;
c96612cc 5058 char *fpnum;
136da414 5059 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5060 int found_fpchar = 0;
5f4273c7 5061
136da414 5062 skip_past_char (&str, '#');
5f4273c7 5063
c96612cc
JB
5064 /* We must not accidentally parse an integer as a floating-point number. Make
5065 sure that the value we parse is not an integer by checking for special
5066 characters '.' or 'e'.
5067 FIXME: This is a horrible hack, but doing better is tricky because type
5068 information isn't in a very usable state at parse time. */
5069 fpnum = str;
5070 skip_whitespace (fpnum);
5071
5072 if (strncmp (fpnum, "0x", 2) == 0)
5073 return FAIL;
5074 else
5075 {
5076 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5077 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5078 {
5079 found_fpchar = 1;
5080 break;
5081 }
c96612cc
JB
5082
5083 if (!found_fpchar)
477330fc 5084 return FAIL;
c96612cc 5085 }
5f4273c7 5086
136da414
JB
5087 if ((str = atof_ieee (str, 's', words)) != NULL)
5088 {
5089 unsigned fpword = 0;
5090 int i;
5f4273c7 5091
136da414
JB
5092 /* Our FP word must be 32 bits (single-precision FP). */
5093 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5094 {
5095 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5096 fpword |= words[i];
5097 }
5f4273c7 5098
c96612cc 5099 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5100 *immed = fpword;
136da414 5101 else
477330fc 5102 return FAIL;
136da414
JB
5103
5104 *ccp = str;
5f4273c7 5105
136da414
JB
5106 return SUCCESS;
5107 }
5f4273c7 5108
136da414
JB
5109 return FAIL;
5110}
5111
c19d1205
ZW
5112/* Shift operands. */
5113enum shift_kind
b99bd4ef 5114{
c19d1205
ZW
5115 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5116};
b99bd4ef 5117
c19d1205
ZW
5118struct asm_shift_name
5119{
5120 const char *name;
5121 enum shift_kind kind;
5122};
b99bd4ef 5123
c19d1205
ZW
5124/* Third argument to parse_shift. */
5125enum parse_shift_mode
5126{
5127 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5128 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5129 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5130 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5131 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5132};
b99bd4ef 5133
c19d1205
ZW
5134/* Parse a <shift> specifier on an ARM data processing instruction.
5135 This has three forms:
b99bd4ef 5136
c19d1205
ZW
5137 (LSL|LSR|ASL|ASR|ROR) Rs
5138 (LSL|LSR|ASL|ASR|ROR) #imm
5139 RRX
b99bd4ef 5140
c19d1205
ZW
5141 Note that ASL is assimilated to LSL in the instruction encoding, and
5142 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5143
c19d1205
ZW
5144static int
5145parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5146{
c19d1205
ZW
5147 const struct asm_shift_name *shift_name;
5148 enum shift_kind shift;
5149 char *s = *str;
5150 char *p = s;
5151 int reg;
b99bd4ef 5152
c19d1205
ZW
5153 for (p = *str; ISALPHA (*p); p++)
5154 ;
b99bd4ef 5155
c19d1205 5156 if (p == *str)
b99bd4ef 5157 {
c19d1205
ZW
5158 inst.error = _("shift expression expected");
5159 return FAIL;
b99bd4ef
NC
5160 }
5161
21d799b5 5162 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5163 p - *str);
c19d1205
ZW
5164
5165 if (shift_name == NULL)
b99bd4ef 5166 {
c19d1205
ZW
5167 inst.error = _("shift expression expected");
5168 return FAIL;
b99bd4ef
NC
5169 }
5170
c19d1205 5171 shift = shift_name->kind;
b99bd4ef 5172
c19d1205
ZW
5173 switch (mode)
5174 {
5175 case NO_SHIFT_RESTRICT:
5176 case SHIFT_IMMEDIATE: break;
b99bd4ef 5177
c19d1205
ZW
5178 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5179 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5180 {
5181 inst.error = _("'LSL' or 'ASR' required");
5182 return FAIL;
5183 }
5184 break;
b99bd4ef 5185
c19d1205
ZW
5186 case SHIFT_LSL_IMMEDIATE:
5187 if (shift != SHIFT_LSL)
5188 {
5189 inst.error = _("'LSL' required");
5190 return FAIL;
5191 }
5192 break;
b99bd4ef 5193
c19d1205
ZW
5194 case SHIFT_ASR_IMMEDIATE:
5195 if (shift != SHIFT_ASR)
5196 {
5197 inst.error = _("'ASR' required");
5198 return FAIL;
5199 }
5200 break;
b99bd4ef 5201
c19d1205
ZW
5202 default: abort ();
5203 }
b99bd4ef 5204
c19d1205
ZW
5205 if (shift != SHIFT_RRX)
5206 {
5207 /* Whitespace can appear here if the next thing is a bare digit. */
5208 skip_whitespace (p);
b99bd4ef 5209
c19d1205 5210 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5211 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5212 {
5213 inst.operands[i].imm = reg;
5214 inst.operands[i].immisreg = 1;
5215 }
e2b0ab59 5216 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
c19d1205
ZW
5217 return FAIL;
5218 }
5219 inst.operands[i].shift_kind = shift;
5220 inst.operands[i].shifted = 1;
5221 *str = p;
5222 return SUCCESS;
b99bd4ef
NC
5223}
5224
c19d1205 5225/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5226
c19d1205
ZW
5227 #<immediate>
5228 #<immediate>, <rotate>
5229 <Rm>
5230 <Rm>, <shift>
b99bd4ef 5231
c19d1205
ZW
5232 where <shift> is defined by parse_shift above, and <rotate> is a
5233 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5234 is deferred to md_apply_fix. */
b99bd4ef 5235
c19d1205
ZW
5236static int
5237parse_shifter_operand (char **str, int i)
5238{
5239 int value;
91d6fa6a 5240 expressionS exp;
b99bd4ef 5241
dcbf9037 5242 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5243 {
5244 inst.operands[i].reg = value;
5245 inst.operands[i].isreg = 1;
b99bd4ef 5246
c19d1205 5247 /* parse_shift will override this if appropriate */
e2b0ab59
AV
5248 inst.relocs[0].exp.X_op = O_constant;
5249 inst.relocs[0].exp.X_add_number = 0;
b99bd4ef 5250
c19d1205
ZW
5251 if (skip_past_comma (str) == FAIL)
5252 return SUCCESS;
b99bd4ef 5253
c19d1205
ZW
5254 /* Shift operation on register. */
5255 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5256 }
5257
e2b0ab59 5258 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
c19d1205 5259 return FAIL;
b99bd4ef 5260
c19d1205 5261 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5262 {
c19d1205 5263 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5264 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5265 return FAIL;
b99bd4ef 5266
e2b0ab59 5267 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
c19d1205
ZW
5268 {
5269 inst.error = _("constant expression expected");
5270 return FAIL;
5271 }
b99bd4ef 5272
91d6fa6a 5273 value = exp.X_add_number;
c19d1205
ZW
5274 if (value < 0 || value > 30 || value % 2 != 0)
5275 {
5276 inst.error = _("invalid rotation");
5277 return FAIL;
5278 }
e2b0ab59
AV
5279 if (inst.relocs[0].exp.X_add_number < 0
5280 || inst.relocs[0].exp.X_add_number > 255)
c19d1205
ZW
5281 {
5282 inst.error = _("invalid constant");
5283 return FAIL;
5284 }
09d92015 5285
a415b1cd 5286 /* Encode as specified. */
e2b0ab59 5287 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
a415b1cd 5288 return SUCCESS;
09d92015
MM
5289 }
5290
e2b0ab59
AV
5291 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5292 inst.relocs[0].pc_rel = 0;
c19d1205 5293 return SUCCESS;
09d92015
MM
5294}
5295
4962c51a
MS
5296/* Group relocation information. Each entry in the table contains the
5297 textual name of the relocation as may appear in assembler source
5298 and must end with a colon.
5299 Along with this textual name are the relocation codes to be used if
5300 the corresponding instruction is an ALU instruction (ADD or SUB only),
5301 an LDR, an LDRS, or an LDC. */
5302
5303struct group_reloc_table_entry
5304{
5305 const char *name;
5306 int alu_code;
5307 int ldr_code;
5308 int ldrs_code;
5309 int ldc_code;
5310};
5311
5312typedef enum
5313{
5314 /* Varieties of non-ALU group relocation. */
5315
5316 GROUP_LDR,
5317 GROUP_LDRS,
5318 GROUP_LDC
5319} group_reloc_type;
5320
5321static struct group_reloc_table_entry group_reloc_table[] =
5322 { /* Program counter relative: */
5323 { "pc_g0_nc",
5324 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5325 0, /* LDR */
5326 0, /* LDRS */
5327 0 }, /* LDC */
5328 { "pc_g0",
5329 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5330 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5331 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5332 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5333 { "pc_g1_nc",
5334 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5335 0, /* LDR */
5336 0, /* LDRS */
5337 0 }, /* LDC */
5338 { "pc_g1",
5339 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5340 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5341 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5342 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5343 { "pc_g2",
5344 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5345 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5346 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5347 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5348 /* Section base relative */
5349 { "sb_g0_nc",
5350 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5351 0, /* LDR */
5352 0, /* LDRS */
5353 0 }, /* LDC */
5354 { "sb_g0",
5355 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5356 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5357 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5358 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5359 { "sb_g1_nc",
5360 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5361 0, /* LDR */
5362 0, /* LDRS */
5363 0 }, /* LDC */
5364 { "sb_g1",
5365 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5366 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5367 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5368 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5369 { "sb_g2",
5370 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5371 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5372 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5373 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5374 /* Absolute thumb alu relocations. */
5375 { "lower0_7",
5376 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5377 0, /* LDR. */
5378 0, /* LDRS. */
5379 0 }, /* LDC. */
5380 { "lower8_15",
5381 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5382 0, /* LDR. */
5383 0, /* LDRS. */
5384 0 }, /* LDC. */
5385 { "upper0_7",
5386 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5387 0, /* LDR. */
5388 0, /* LDRS. */
5389 0 }, /* LDC. */
5390 { "upper8_15",
5391 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5392 0, /* LDR. */
5393 0, /* LDRS. */
5394 0 } }; /* LDC. */
4962c51a
MS
5395
5396/* Given the address of a pointer pointing to the textual name of a group
5397 relocation as may appear in assembler source, attempt to find its details
5398 in group_reloc_table. The pointer will be updated to the character after
5399 the trailing colon. On failure, FAIL will be returned; SUCCESS
5400 otherwise. On success, *entry will be updated to point at the relevant
5401 group_reloc_table entry. */
5402
5403static int
5404find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5405{
5406 unsigned int i;
5407 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5408 {
5409 int length = strlen (group_reloc_table[i].name);
5410
5f4273c7
NC
5411 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5412 && (*str)[length] == ':')
477330fc
RM
5413 {
5414 *out = &group_reloc_table[i];
5415 *str += (length + 1);
5416 return SUCCESS;
5417 }
4962c51a
MS
5418 }
5419
5420 return FAIL;
5421}
5422
5423/* Parse a <shifter_operand> for an ARM data processing instruction
5424 (as for parse_shifter_operand) where group relocations are allowed:
5425
5426 #<immediate>
5427 #<immediate>, <rotate>
5428 #:<group_reloc>:<expression>
5429 <Rm>
5430 <Rm>, <shift>
5431
5432 where <group_reloc> is one of the strings defined in group_reloc_table.
5433 The hashes are optional.
5434
5435 Everything else is as for parse_shifter_operand. */
5436
5437static parse_operand_result
5438parse_shifter_operand_group_reloc (char **str, int i)
5439{
5440 /* Determine if we have the sequence of characters #: or just :
5441 coming next. If we do, then we check for a group relocation.
5442 If we don't, punt the whole lot to parse_shifter_operand. */
5443
5444 if (((*str)[0] == '#' && (*str)[1] == ':')
5445 || (*str)[0] == ':')
5446 {
5447 struct group_reloc_table_entry *entry;
5448
5449 if ((*str)[0] == '#')
477330fc 5450 (*str) += 2;
4962c51a 5451 else
477330fc 5452 (*str)++;
4962c51a
MS
5453
5454 /* Try to parse a group relocation. Anything else is an error. */
5455 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5456 {
5457 inst.error = _("unknown group relocation");
5458 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5459 }
4962c51a
MS
5460
5461 /* We now have the group relocation table entry corresponding to
477330fc 5462 the name in the assembler source. Next, we parse the expression. */
e2b0ab59 5463 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
477330fc 5464 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5465
5466 /* Record the relocation type (always the ALU variant here). */
e2b0ab59
AV
5467 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5468 gas_assert (inst.relocs[0].type != 0);
4962c51a
MS
5469
5470 return PARSE_OPERAND_SUCCESS;
5471 }
5472 else
5473 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5474 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5475
5476 /* Never reached. */
5477}
5478
8e560766
MGD
5479/* Parse a Neon alignment expression. Information is written to
5480 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5481
8e560766
MGD
5482 align .imm = align << 8, .immisalign=1, .preind=0 */
5483static parse_operand_result
5484parse_neon_alignment (char **str, int i)
5485{
5486 char *p = *str;
5487 expressionS exp;
5488
5489 my_get_expression (&exp, &p, GE_NO_PREFIX);
5490
5491 if (exp.X_op != O_constant)
5492 {
5493 inst.error = _("alignment must be constant");
5494 return PARSE_OPERAND_FAIL;
5495 }
5496
5497 inst.operands[i].imm = exp.X_add_number << 8;
5498 inst.operands[i].immisalign = 1;
5499 /* Alignments are not pre-indexes. */
5500 inst.operands[i].preind = 0;
5501
5502 *str = p;
5503 return PARSE_OPERAND_SUCCESS;
5504}
5505
c19d1205 5506/* Parse all forms of an ARM address expression. Information is written
e2b0ab59 5507 to inst.operands[i] and/or inst.relocs[0].
09d92015 5508
c19d1205 5509 Preindexed addressing (.preind=1):
09d92015 5510
e2b0ab59 5511 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5512 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5513 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5514 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5515
c19d1205 5516 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5517
c19d1205 5518 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5519
e2b0ab59 5520 [Rn], #offset .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5521 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5522 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5523 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5524
c19d1205 5525 Unindexed addressing (.preind=0, .postind=0):
09d92015 5526
c19d1205 5527 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5528
c19d1205 5529 Other:
09d92015 5530
c19d1205 5531 [Rn]{!} shorthand for [Rn,#0]{!}
e2b0ab59
AV
5532 =immediate .isreg=0 .relocs[0].exp=immediate
5533 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
09d92015 5534
c19d1205 5535 It is the caller's responsibility to check for addressing modes not
e2b0ab59 5536 supported by the instruction, and to set inst.relocs[0].type. */
c19d1205 5537
4962c51a
MS
5538static parse_operand_result
5539parse_address_main (char **str, int i, int group_relocations,
477330fc 5540 group_reloc_type group_type)
09d92015 5541{
c19d1205
ZW
5542 char *p = *str;
5543 int reg;
09d92015 5544
c19d1205 5545 if (skip_past_char (&p, '[') == FAIL)
09d92015 5546 {
c19d1205
ZW
5547 if (skip_past_char (&p, '=') == FAIL)
5548 {
974da60d 5549 /* Bare address - translate to PC-relative offset. */
e2b0ab59 5550 inst.relocs[0].pc_rel = 1;
c19d1205
ZW
5551 inst.operands[i].reg = REG_PC;
5552 inst.operands[i].isreg = 1;
5553 inst.operands[i].preind = 1;
09d92015 5554
e2b0ab59 5555 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
8335d6aa
JW
5556 return PARSE_OPERAND_FAIL;
5557 }
e2b0ab59 5558 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
8335d6aa 5559 /*allow_symbol_p=*/TRUE))
4962c51a 5560 return PARSE_OPERAND_FAIL;
09d92015 5561
c19d1205 5562 *str = p;
4962c51a 5563 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5564 }
5565
8ab8155f
NC
5566 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5567 skip_whitespace (p);
5568
dcbf9037 5569 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5570 {
c19d1205 5571 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5572 return PARSE_OPERAND_FAIL;
09d92015 5573 }
c19d1205
ZW
5574 inst.operands[i].reg = reg;
5575 inst.operands[i].isreg = 1;
09d92015 5576
c19d1205 5577 if (skip_past_comma (&p) == SUCCESS)
09d92015 5578 {
c19d1205 5579 inst.operands[i].preind = 1;
09d92015 5580
c19d1205
ZW
5581 if (*p == '+') p++;
5582 else if (*p == '-') p++, inst.operands[i].negative = 1;
5583
dcbf9037 5584 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5585 {
c19d1205
ZW
5586 inst.operands[i].imm = reg;
5587 inst.operands[i].immisreg = 1;
5588
5589 if (skip_past_comma (&p) == SUCCESS)
5590 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5591 return PARSE_OPERAND_FAIL;
c19d1205 5592 }
5287ad62 5593 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5594 {
5595 /* FIXME: '@' should be used here, but it's filtered out by generic
5596 code before we get to see it here. This may be subject to
5597 change. */
5598 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5599
8e560766
MGD
5600 if (result != PARSE_OPERAND_SUCCESS)
5601 return result;
5602 }
c19d1205
ZW
5603 else
5604 {
5605 if (inst.operands[i].negative)
5606 {
5607 inst.operands[i].negative = 0;
5608 p--;
5609 }
4962c51a 5610
5f4273c7
NC
5611 if (group_relocations
5612 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5613 {
5614 struct group_reloc_table_entry *entry;
5615
477330fc
RM
5616 /* Skip over the #: or : sequence. */
5617 if (*p == '#')
5618 p += 2;
5619 else
5620 p++;
4962c51a
MS
5621
5622 /* Try to parse a group relocation. Anything else is an
477330fc 5623 error. */
4962c51a
MS
5624 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5625 {
5626 inst.error = _("unknown group relocation");
5627 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5628 }
5629
5630 /* We now have the group relocation table entry corresponding to
5631 the name in the assembler source. Next, we parse the
477330fc 5632 expression. */
e2b0ab59 5633 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
4962c51a
MS
5634 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5635
5636 /* Record the relocation type. */
477330fc
RM
5637 switch (group_type)
5638 {
5639 case GROUP_LDR:
e2b0ab59
AV
5640 inst.relocs[0].type
5641 = (bfd_reloc_code_real_type) entry->ldr_code;
477330fc 5642 break;
4962c51a 5643
477330fc 5644 case GROUP_LDRS:
e2b0ab59
AV
5645 inst.relocs[0].type
5646 = (bfd_reloc_code_real_type) entry->ldrs_code;
477330fc 5647 break;
4962c51a 5648
477330fc 5649 case GROUP_LDC:
e2b0ab59
AV
5650 inst.relocs[0].type
5651 = (bfd_reloc_code_real_type) entry->ldc_code;
477330fc 5652 break;
4962c51a 5653
477330fc
RM
5654 default:
5655 gas_assert (0);
5656 }
4962c51a 5657
e2b0ab59 5658 if (inst.relocs[0].type == 0)
4962c51a
MS
5659 {
5660 inst.error = _("this group relocation is not allowed on this instruction");
5661 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5662 }
477330fc
RM
5663 }
5664 else
26d97720
NS
5665 {
5666 char *q = p;
0198d5e6 5667
e2b0ab59 5668 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
26d97720
NS
5669 return PARSE_OPERAND_FAIL;
5670 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
5671 if (inst.relocs[0].exp.X_op == O_constant
5672 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
5673 {
5674 skip_whitespace (q);
5675 if (*q == '#')
5676 {
5677 q++;
5678 skip_whitespace (q);
5679 }
5680 if (*q == '-')
5681 inst.operands[i].negative = 1;
5682 }
5683 }
09d92015
MM
5684 }
5685 }
8e560766
MGD
5686 else if (skip_past_char (&p, ':') == SUCCESS)
5687 {
5688 /* FIXME: '@' should be used here, but it's filtered out by generic code
5689 before we get to see it here. This may be subject to change. */
5690 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5691
8e560766
MGD
5692 if (result != PARSE_OPERAND_SUCCESS)
5693 return result;
5694 }
09d92015 5695
c19d1205 5696 if (skip_past_char (&p, ']') == FAIL)
09d92015 5697 {
c19d1205 5698 inst.error = _("']' expected");
4962c51a 5699 return PARSE_OPERAND_FAIL;
09d92015
MM
5700 }
5701
c19d1205
ZW
5702 if (skip_past_char (&p, '!') == SUCCESS)
5703 inst.operands[i].writeback = 1;
09d92015 5704
c19d1205 5705 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5706 {
c19d1205
ZW
5707 if (skip_past_char (&p, '{') == SUCCESS)
5708 {
5709 /* [Rn], {expr} - unindexed, with option */
5710 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5711 0, 255, TRUE) == FAIL)
4962c51a 5712 return PARSE_OPERAND_FAIL;
09d92015 5713
c19d1205
ZW
5714 if (skip_past_char (&p, '}') == FAIL)
5715 {
5716 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5717 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5718 }
5719 if (inst.operands[i].preind)
5720 {
5721 inst.error = _("cannot combine index with option");
4962c51a 5722 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5723 }
5724 *str = p;
4962c51a 5725 return PARSE_OPERAND_SUCCESS;
09d92015 5726 }
c19d1205
ZW
5727 else
5728 {
5729 inst.operands[i].postind = 1;
5730 inst.operands[i].writeback = 1;
09d92015 5731
c19d1205
ZW
5732 if (inst.operands[i].preind)
5733 {
5734 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5735 return PARSE_OPERAND_FAIL;
c19d1205 5736 }
09d92015 5737
c19d1205
ZW
5738 if (*p == '+') p++;
5739 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5740
dcbf9037 5741 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5742 {
477330fc
RM
5743 /* We might be using the immediate for alignment already. If we
5744 are, OR the register number into the low-order bits. */
5745 if (inst.operands[i].immisalign)
5746 inst.operands[i].imm |= reg;
5747 else
5748 inst.operands[i].imm = reg;
c19d1205 5749 inst.operands[i].immisreg = 1;
a737bd4d 5750
c19d1205
ZW
5751 if (skip_past_comma (&p) == SUCCESS)
5752 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5753 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5754 }
5755 else
5756 {
26d97720 5757 char *q = p;
0198d5e6 5758
c19d1205
ZW
5759 if (inst.operands[i].negative)
5760 {
5761 inst.operands[i].negative = 0;
5762 p--;
5763 }
e2b0ab59 5764 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
4962c51a 5765 return PARSE_OPERAND_FAIL;
26d97720 5766 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
5767 if (inst.relocs[0].exp.X_op == O_constant
5768 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
5769 {
5770 skip_whitespace (q);
5771 if (*q == '#')
5772 {
5773 q++;
5774 skip_whitespace (q);
5775 }
5776 if (*q == '-')
5777 inst.operands[i].negative = 1;
5778 }
c19d1205
ZW
5779 }
5780 }
a737bd4d
NC
5781 }
5782
c19d1205
ZW
5783 /* If at this point neither .preind nor .postind is set, we have a
5784 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5785 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5786 {
5787 inst.operands[i].preind = 1;
e2b0ab59
AV
5788 inst.relocs[0].exp.X_op = O_constant;
5789 inst.relocs[0].exp.X_add_number = 0;
c19d1205
ZW
5790 }
5791 *str = p;
4962c51a
MS
5792 return PARSE_OPERAND_SUCCESS;
5793}
5794
5795static int
5796parse_address (char **str, int i)
5797{
21d799b5 5798 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5799 ? SUCCESS : FAIL;
4962c51a
MS
5800}
5801
5802static parse_operand_result
5803parse_address_group_reloc (char **str, int i, group_reloc_type type)
5804{
5805 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5806}
5807
b6895b4f
PB
5808/* Parse an operand for a MOVW or MOVT instruction. */
5809static int
5810parse_half (char **str)
5811{
5812 char * p;
5f4273c7 5813
b6895b4f
PB
5814 p = *str;
5815 skip_past_char (&p, '#');
5f4273c7 5816 if (strncasecmp (p, ":lower16:", 9) == 0)
e2b0ab59 5817 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
b6895b4f 5818 else if (strncasecmp (p, ":upper16:", 9) == 0)
e2b0ab59 5819 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
b6895b4f 5820
e2b0ab59 5821 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
b6895b4f
PB
5822 {
5823 p += 9;
5f4273c7 5824 skip_whitespace (p);
b6895b4f
PB
5825 }
5826
e2b0ab59 5827 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
b6895b4f
PB
5828 return FAIL;
5829
e2b0ab59 5830 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 5831 {
e2b0ab59 5832 if (inst.relocs[0].exp.X_op != O_constant)
b6895b4f
PB
5833 {
5834 inst.error = _("constant expression expected");
5835 return FAIL;
5836 }
e2b0ab59
AV
5837 if (inst.relocs[0].exp.X_add_number < 0
5838 || inst.relocs[0].exp.X_add_number > 0xffff)
b6895b4f
PB
5839 {
5840 inst.error = _("immediate value out of range");
5841 return FAIL;
5842 }
5843 }
5844 *str = p;
5845 return SUCCESS;
5846}
5847
c19d1205 5848/* Miscellaneous. */
a737bd4d 5849
c19d1205
ZW
5850/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5851 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5852static int
d2cd1205 5853parse_psr (char **str, bfd_boolean lhs)
09d92015 5854{
c19d1205
ZW
5855 char *p;
5856 unsigned long psr_field;
62b3e311
PB
5857 const struct asm_psr *psr;
5858 char *start;
d2cd1205 5859 bfd_boolean is_apsr = FALSE;
ac7f631b 5860 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5861
a4482bb6
NC
5862 /* PR gas/12698: If the user has specified -march=all then m_profile will
5863 be TRUE, but we want to ignore it in this case as we are building for any
5864 CPU type, including non-m variants. */
823d2571 5865 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5866 m_profile = FALSE;
5867
c19d1205
ZW
5868 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5869 feature for ease of use and backwards compatibility. */
5870 p = *str;
62b3e311 5871 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5872 {
5873 if (m_profile)
5874 goto unsupported_psr;
fa94de6b 5875
d2cd1205
JB
5876 psr_field = SPSR_BIT;
5877 }
5878 else if (strncasecmp (p, "CPSR", 4) == 0)
5879 {
5880 if (m_profile)
5881 goto unsupported_psr;
5882
5883 psr_field = 0;
5884 }
5885 else if (strncasecmp (p, "APSR", 4) == 0)
5886 {
5887 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5888 and ARMv7-R architecture CPUs. */
5889 is_apsr = TRUE;
5890 psr_field = 0;
5891 }
5892 else if (m_profile)
62b3e311
PB
5893 {
5894 start = p;
5895 do
5896 p++;
5897 while (ISALNUM (*p) || *p == '_');
5898
d2cd1205
JB
5899 if (strncasecmp (start, "iapsr", 5) == 0
5900 || strncasecmp (start, "eapsr", 5) == 0
5901 || strncasecmp (start, "xpsr", 4) == 0
5902 || strncasecmp (start, "psr", 3) == 0)
5903 p = start + strcspn (start, "rR") + 1;
5904
21d799b5 5905 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5906 p - start);
d2cd1205 5907
62b3e311
PB
5908 if (!psr)
5909 return FAIL;
09d92015 5910
d2cd1205
JB
5911 /* If APSR is being written, a bitfield may be specified. Note that
5912 APSR itself is handled above. */
5913 if (psr->field <= 3)
5914 {
5915 psr_field = psr->field;
5916 is_apsr = TRUE;
5917 goto check_suffix;
5918 }
5919
62b3e311 5920 *str = p;
d2cd1205
JB
5921 /* M-profile MSR instructions have the mask field set to "10", except
5922 *PSR variants which modify APSR, which may use a different mask (and
5923 have been handled already). Do that by setting the PSR_f field
5924 here. */
5925 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5926 }
d2cd1205
JB
5927 else
5928 goto unsupported_psr;
09d92015 5929
62b3e311 5930 p += 4;
d2cd1205 5931check_suffix:
c19d1205
ZW
5932 if (*p == '_')
5933 {
5934 /* A suffix follows. */
c19d1205
ZW
5935 p++;
5936 start = p;
a737bd4d 5937
c19d1205
ZW
5938 do
5939 p++;
5940 while (ISALNUM (*p) || *p == '_');
a737bd4d 5941
d2cd1205
JB
5942 if (is_apsr)
5943 {
5944 /* APSR uses a notation for bits, rather than fields. */
5945 unsigned int nzcvq_bits = 0;
5946 unsigned int g_bit = 0;
5947 char *bit;
fa94de6b 5948
d2cd1205
JB
5949 for (bit = start; bit != p; bit++)
5950 {
5951 switch (TOLOWER (*bit))
477330fc 5952 {
d2cd1205
JB
5953 case 'n':
5954 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5955 break;
5956
5957 case 'z':
5958 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5959 break;
5960
5961 case 'c':
5962 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5963 break;
5964
5965 case 'v':
5966 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5967 break;
fa94de6b 5968
d2cd1205
JB
5969 case 'q':
5970 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5971 break;
fa94de6b 5972
d2cd1205
JB
5973 case 'g':
5974 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5975 break;
fa94de6b 5976
d2cd1205
JB
5977 default:
5978 inst.error = _("unexpected bit specified after APSR");
5979 return FAIL;
5980 }
5981 }
fa94de6b 5982
d2cd1205
JB
5983 if (nzcvq_bits == 0x1f)
5984 psr_field |= PSR_f;
fa94de6b 5985
d2cd1205
JB
5986 if (g_bit == 0x1)
5987 {
5988 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5989 {
d2cd1205
JB
5990 inst.error = _("selected processor does not "
5991 "support DSP extension");
5992 return FAIL;
5993 }
5994
5995 psr_field |= PSR_s;
5996 }
fa94de6b 5997
d2cd1205
JB
5998 if ((nzcvq_bits & 0x20) != 0
5999 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6000 || (g_bit & 0x2) != 0)
6001 {
6002 inst.error = _("bad bitmask specified after APSR");
6003 return FAIL;
6004 }
6005 }
6006 else
477330fc 6007 {
d2cd1205 6008 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 6009 p - start);
d2cd1205 6010 if (!psr)
477330fc 6011 goto error;
a737bd4d 6012
d2cd1205
JB
6013 psr_field |= psr->field;
6014 }
a737bd4d 6015 }
c19d1205 6016 else
a737bd4d 6017 {
c19d1205
ZW
6018 if (ISALNUM (*p))
6019 goto error; /* Garbage after "[CS]PSR". */
6020
d2cd1205 6021 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 6022 is deprecated, but allow it anyway. */
d2cd1205
JB
6023 if (is_apsr && lhs)
6024 {
6025 psr_field |= PSR_f;
6026 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6027 "deprecated"));
6028 }
6029 else if (!m_profile)
6030 /* These bits are never right for M-profile devices: don't set them
6031 (only code paths which read/write APSR reach here). */
6032 psr_field |= (PSR_c | PSR_f);
a737bd4d 6033 }
c19d1205
ZW
6034 *str = p;
6035 return psr_field;
a737bd4d 6036
d2cd1205
JB
6037 unsupported_psr:
6038 inst.error = _("selected processor does not support requested special "
6039 "purpose register");
6040 return FAIL;
6041
c19d1205
ZW
6042 error:
6043 inst.error = _("flag for {c}psr instruction expected");
6044 return FAIL;
a737bd4d
NC
6045}
6046
c19d1205
ZW
6047/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6048 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6049
c19d1205
ZW
6050static int
6051parse_cps_flags (char **str)
a737bd4d 6052{
c19d1205
ZW
6053 int val = 0;
6054 int saw_a_flag = 0;
6055 char *s = *str;
a737bd4d 6056
c19d1205
ZW
6057 for (;;)
6058 switch (*s++)
6059 {
6060 case '\0': case ',':
6061 goto done;
a737bd4d 6062
c19d1205
ZW
6063 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6064 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6065 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6066
c19d1205
ZW
6067 default:
6068 inst.error = _("unrecognized CPS flag");
6069 return FAIL;
6070 }
a737bd4d 6071
c19d1205
ZW
6072 done:
6073 if (saw_a_flag == 0)
a737bd4d 6074 {
c19d1205
ZW
6075 inst.error = _("missing CPS flags");
6076 return FAIL;
a737bd4d 6077 }
a737bd4d 6078
c19d1205
ZW
6079 *str = s - 1;
6080 return val;
a737bd4d
NC
6081}
6082
c19d1205
ZW
6083/* Parse an endian specifier ("BE" or "LE", case insensitive);
6084 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6085
6086static int
c19d1205 6087parse_endian_specifier (char **str)
a737bd4d 6088{
c19d1205
ZW
6089 int little_endian;
6090 char *s = *str;
a737bd4d 6091
c19d1205
ZW
6092 if (strncasecmp (s, "BE", 2))
6093 little_endian = 0;
6094 else if (strncasecmp (s, "LE", 2))
6095 little_endian = 1;
6096 else
a737bd4d 6097 {
c19d1205 6098 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6099 return FAIL;
6100 }
6101
c19d1205 6102 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6103 {
c19d1205 6104 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6105 return FAIL;
6106 }
6107
c19d1205
ZW
6108 *str = s + 2;
6109 return little_endian;
6110}
a737bd4d 6111
c19d1205
ZW
6112/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6113 value suitable for poking into the rotate field of an sxt or sxta
6114 instruction, or FAIL on error. */
6115
6116static int
6117parse_ror (char **str)
6118{
6119 int rot;
6120 char *s = *str;
6121
6122 if (strncasecmp (s, "ROR", 3) == 0)
6123 s += 3;
6124 else
a737bd4d 6125 {
c19d1205 6126 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6127 return FAIL;
6128 }
c19d1205
ZW
6129
6130 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6131 return FAIL;
6132
6133 switch (rot)
a737bd4d 6134 {
c19d1205
ZW
6135 case 0: *str = s; return 0x0;
6136 case 8: *str = s; return 0x1;
6137 case 16: *str = s; return 0x2;
6138 case 24: *str = s; return 0x3;
6139
6140 default:
6141 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6142 return FAIL;
6143 }
c19d1205 6144}
a737bd4d 6145
c19d1205
ZW
6146/* Parse a conditional code (from conds[] below). The value returned is in the
6147 range 0 .. 14, or FAIL. */
6148static int
6149parse_cond (char **str)
6150{
c462b453 6151 char *q;
c19d1205 6152 const struct asm_cond *c;
c462b453
PB
6153 int n;
6154 /* Condition codes are always 2 characters, so matching up to
6155 3 characters is sufficient. */
6156 char cond[3];
a737bd4d 6157
c462b453
PB
6158 q = *str;
6159 n = 0;
6160 while (ISALPHA (*q) && n < 3)
6161 {
e07e6e58 6162 cond[n] = TOLOWER (*q);
c462b453
PB
6163 q++;
6164 n++;
6165 }
a737bd4d 6166
21d799b5 6167 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6168 if (!c)
a737bd4d 6169 {
c19d1205 6170 inst.error = _("condition required");
a737bd4d
NC
6171 return FAIL;
6172 }
6173
c19d1205
ZW
6174 *str = q;
6175 return c->value;
6176}
6177
643afb90
MW
6178/* Record a use of the given feature. */
6179static void
6180record_feature_use (const arm_feature_set *feature)
6181{
6182 if (thumb_mode)
6183 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6184 else
6185 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6186}
6187
4d354d8b
TP
6188/* If the given feature is currently allowed, mark it as used and return TRUE.
6189 Return FALSE otherwise. */
e797f7e0
MGD
6190static bfd_boolean
6191mark_feature_used (const arm_feature_set *feature)
6192{
4d354d8b 6193 /* Ensure the option is currently allowed. */
e797f7e0
MGD
6194 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6195 return FALSE;
6196
4d354d8b 6197 /* Add the appropriate architecture feature for the barrier option used. */
643afb90 6198 record_feature_use (feature);
e797f7e0
MGD
6199
6200 return TRUE;
6201}
6202
62b3e311
PB
6203/* Parse an option for a barrier instruction. Returns the encoding for the
6204 option, or FAIL. */
6205static int
6206parse_barrier (char **str)
6207{
6208 char *p, *q;
6209 const struct asm_barrier_opt *o;
6210
6211 p = q = *str;
6212 while (ISALPHA (*q))
6213 q++;
6214
21d799b5 6215 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6216 q - p);
62b3e311
PB
6217 if (!o)
6218 return FAIL;
6219
e797f7e0
MGD
6220 if (!mark_feature_used (&o->arch))
6221 return FAIL;
6222
62b3e311
PB
6223 *str = q;
6224 return o->value;
6225}
6226
92e90b6e
PB
6227/* Parse the operands of a table branch instruction. Similar to a memory
6228 operand. */
6229static int
6230parse_tb (char **str)
6231{
6232 char * p = *str;
6233 int reg;
6234
6235 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6236 {
6237 inst.error = _("'[' expected");
6238 return FAIL;
6239 }
92e90b6e 6240
dcbf9037 6241 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6242 {
6243 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6244 return FAIL;
6245 }
6246 inst.operands[0].reg = reg;
6247
6248 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6249 {
6250 inst.error = _("',' expected");
6251 return FAIL;
6252 }
5f4273c7 6253
dcbf9037 6254 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6255 {
6256 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6257 return FAIL;
6258 }
6259 inst.operands[0].imm = reg;
6260
6261 if (skip_past_comma (&p) == SUCCESS)
6262 {
6263 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6264 return FAIL;
e2b0ab59 6265 if (inst.relocs[0].exp.X_add_number != 1)
92e90b6e
PB
6266 {
6267 inst.error = _("invalid shift");
6268 return FAIL;
6269 }
6270 inst.operands[0].shifted = 1;
6271 }
6272
6273 if (skip_past_char (&p, ']') == FAIL)
6274 {
6275 inst.error = _("']' expected");
6276 return FAIL;
6277 }
6278 *str = p;
6279 return SUCCESS;
6280}
6281
5287ad62
JB
6282/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6283 information on the types the operands can take and how they are encoded.
037e8744
JB
6284 Up to four operands may be read; this function handles setting the
6285 ".present" field for each read operand itself.
5287ad62
JB
6286 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6287 else returns FAIL. */
6288
6289static int
6290parse_neon_mov (char **str, int *which_operand)
6291{
6292 int i = *which_operand, val;
6293 enum arm_reg_type rtype;
6294 char *ptr = *str;
dcbf9037 6295 struct neon_type_el optype;
5f4273c7 6296
dcbf9037 6297 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6298 {
6299 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6300 inst.operands[i].reg = val;
6301 inst.operands[i].isscalar = 1;
dcbf9037 6302 inst.operands[i].vectype = optype;
5287ad62
JB
6303 inst.operands[i++].present = 1;
6304
6305 if (skip_past_comma (&ptr) == FAIL)
477330fc 6306 goto wanted_comma;
5f4273c7 6307
dcbf9037 6308 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6309 goto wanted_arm;
5f4273c7 6310
5287ad62
JB
6311 inst.operands[i].reg = val;
6312 inst.operands[i].isreg = 1;
6313 inst.operands[i].present = 1;
6314 }
037e8744 6315 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6316 != FAIL)
5287ad62
JB
6317 {
6318 /* Cases 0, 1, 2, 3, 5 (D only). */
6319 if (skip_past_comma (&ptr) == FAIL)
477330fc 6320 goto wanted_comma;
5f4273c7 6321
5287ad62
JB
6322 inst.operands[i].reg = val;
6323 inst.operands[i].isreg = 1;
6324 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6325 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6326 inst.operands[i].isvec = 1;
dcbf9037 6327 inst.operands[i].vectype = optype;
5287ad62
JB
6328 inst.operands[i++].present = 1;
6329
dcbf9037 6330 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6331 {
6332 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6333 Case 13: VMOV <Sd>, <Rm> */
6334 inst.operands[i].reg = val;
6335 inst.operands[i].isreg = 1;
6336 inst.operands[i].present = 1;
6337
6338 if (rtype == REG_TYPE_NQ)
6339 {
6340 first_error (_("can't use Neon quad register here"));
6341 return FAIL;
6342 }
6343 else if (rtype != REG_TYPE_VFS)
6344 {
6345 i++;
6346 if (skip_past_comma (&ptr) == FAIL)
6347 goto wanted_comma;
6348 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6349 goto wanted_arm;
6350 inst.operands[i].reg = val;
6351 inst.operands[i].isreg = 1;
6352 inst.operands[i].present = 1;
6353 }
6354 }
037e8744 6355 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6356 &optype)) != FAIL)
6357 {
6358 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6359 Case 1: VMOV<c><q> <Dd>, <Dm>
6360 Case 8: VMOV.F32 <Sd>, <Sm>
6361 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6362
6363 inst.operands[i].reg = val;
6364 inst.operands[i].isreg = 1;
6365 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6366 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6367 inst.operands[i].isvec = 1;
6368 inst.operands[i].vectype = optype;
6369 inst.operands[i].present = 1;
6370
6371 if (skip_past_comma (&ptr) == SUCCESS)
6372 {
6373 /* Case 15. */
6374 i++;
6375
6376 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6377 goto wanted_arm;
6378
6379 inst.operands[i].reg = val;
6380 inst.operands[i].isreg = 1;
6381 inst.operands[i++].present = 1;
6382
6383 if (skip_past_comma (&ptr) == FAIL)
6384 goto wanted_comma;
6385
6386 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6387 goto wanted_arm;
6388
6389 inst.operands[i].reg = val;
6390 inst.operands[i].isreg = 1;
6391 inst.operands[i].present = 1;
6392 }
6393 }
4641781c 6394 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6395 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6396 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6397 Case 10: VMOV.F32 <Sd>, #<imm>
6398 Case 11: VMOV.F64 <Dd>, #<imm> */
6399 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6400 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6401 == SUCCESS)
477330fc
RM
6402 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6403 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6404 ;
5287ad62 6405 else
477330fc
RM
6406 {
6407 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6408 return FAIL;
6409 }
5287ad62 6410 }
dcbf9037 6411 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6412 {
6413 /* Cases 6, 7. */
6414 inst.operands[i].reg = val;
6415 inst.operands[i].isreg = 1;
6416 inst.operands[i++].present = 1;
5f4273c7 6417
5287ad62 6418 if (skip_past_comma (&ptr) == FAIL)
477330fc 6419 goto wanted_comma;
5f4273c7 6420
dcbf9037 6421 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6422 {
6423 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6424 inst.operands[i].reg = val;
6425 inst.operands[i].isscalar = 1;
6426 inst.operands[i].present = 1;
6427 inst.operands[i].vectype = optype;
6428 }
dcbf9037 6429 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6430 {
6431 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6432 inst.operands[i].reg = val;
6433 inst.operands[i].isreg = 1;
6434 inst.operands[i++].present = 1;
6435
6436 if (skip_past_comma (&ptr) == FAIL)
6437 goto wanted_comma;
6438
6439 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6440 == FAIL)
6441 {
6442 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6443 return FAIL;
6444 }
6445
6446 inst.operands[i].reg = val;
6447 inst.operands[i].isreg = 1;
6448 inst.operands[i].isvec = 1;
6449 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6450 inst.operands[i].vectype = optype;
6451 inst.operands[i].present = 1;
6452
6453 if (rtype == REG_TYPE_VFS)
6454 {
6455 /* Case 14. */
6456 i++;
6457 if (skip_past_comma (&ptr) == FAIL)
6458 goto wanted_comma;
6459 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6460 &optype)) == FAIL)
6461 {
6462 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6463 return FAIL;
6464 }
6465 inst.operands[i].reg = val;
6466 inst.operands[i].isreg = 1;
6467 inst.operands[i].isvec = 1;
6468 inst.operands[i].issingle = 1;
6469 inst.operands[i].vectype = optype;
6470 inst.operands[i].present = 1;
6471 }
6472 }
037e8744 6473 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6474 != FAIL)
6475 {
6476 /* Case 13. */
6477 inst.operands[i].reg = val;
6478 inst.operands[i].isreg = 1;
6479 inst.operands[i].isvec = 1;
6480 inst.operands[i].issingle = 1;
6481 inst.operands[i].vectype = optype;
6482 inst.operands[i].present = 1;
6483 }
5287ad62
JB
6484 }
6485 else
6486 {
dcbf9037 6487 first_error (_("parse error"));
5287ad62
JB
6488 return FAIL;
6489 }
6490
6491 /* Successfully parsed the operands. Update args. */
6492 *which_operand = i;
6493 *str = ptr;
6494 return SUCCESS;
6495
5f4273c7 6496 wanted_comma:
dcbf9037 6497 first_error (_("expected comma"));
5287ad62 6498 return FAIL;
5f4273c7
NC
6499
6500 wanted_arm:
dcbf9037 6501 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6502 return FAIL;
5287ad62
JB
6503}
6504
5be8be5d
DG
6505/* Use this macro when the operand constraints are different
6506 for ARM and THUMB (e.g. ldrd). */
6507#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6508 ((arm_operand) | ((thumb_operand) << 16))
6509
c19d1205
ZW
6510/* Matcher codes for parse_operands. */
6511enum operand_parse_code
6512{
6513 OP_stop, /* end of line */
6514
6515 OP_RR, /* ARM register */
6516 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6517 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6518 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6519 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6520 optional trailing ! */
c19d1205
ZW
6521 OP_RRw, /* ARM register, not r15, optional trailing ! */
6522 OP_RCP, /* Coprocessor number */
6523 OP_RCN, /* Coprocessor register */
6524 OP_RF, /* FPA register */
6525 OP_RVS, /* VFP single precision register */
5287ad62
JB
6526 OP_RVD, /* VFP double precision register (0..15) */
6527 OP_RND, /* Neon double precision register (0..31) */
6528 OP_RNQ, /* Neon quad precision register */
037e8744 6529 OP_RVSD, /* VFP single or double precision register */
dec41383 6530 OP_RNSD, /* Neon single or double precision register */
5287ad62 6531 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6532 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6533 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6534 OP_RVC, /* VFP control register */
6535 OP_RMF, /* Maverick F register */
6536 OP_RMD, /* Maverick D register */
6537 OP_RMFX, /* Maverick FX register */
6538 OP_RMDX, /* Maverick DX register */
6539 OP_RMAX, /* Maverick AX register */
6540 OP_RMDS, /* Maverick DSPSC register */
6541 OP_RIWR, /* iWMMXt wR register */
6542 OP_RIWC, /* iWMMXt wC register */
6543 OP_RIWG, /* iWMMXt wCG register */
6544 OP_RXA, /* XScale accumulator register */
6545
6546 OP_REGLST, /* ARM register list */
6547 OP_VRSLST, /* VFP single-precision register list */
6548 OP_VRDLST, /* VFP double-precision register list */
037e8744 6549 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6550 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6551 OP_NSTRLST, /* Neon element/structure list */
6552
5287ad62 6553 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6554 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6555 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6556 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 6557 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 6558 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6559 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6560 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6561 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6562 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6563 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6564 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6565
6566 OP_I0, /* immediate zero */
c19d1205
ZW
6567 OP_I7, /* immediate value 0 .. 7 */
6568 OP_I15, /* 0 .. 15 */
6569 OP_I16, /* 1 .. 16 */
5287ad62 6570 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6571 OP_I31, /* 0 .. 31 */
6572 OP_I31w, /* 0 .. 31, optional trailing ! */
6573 OP_I32, /* 1 .. 32 */
5287ad62
JB
6574 OP_I32z, /* 0 .. 32 */
6575 OP_I63, /* 0 .. 63 */
c19d1205 6576 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6577 OP_I64, /* 1 .. 64 */
6578 OP_I64z, /* 0 .. 64 */
c19d1205 6579 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6580
6581 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6582 OP_I7b, /* 0 .. 7 */
6583 OP_I15b, /* 0 .. 15 */
6584 OP_I31b, /* 0 .. 31 */
6585
6586 OP_SH, /* shifter operand */
4962c51a 6587 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6588 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6589 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6590 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6591 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6592 OP_EXP, /* arbitrary expression */
6593 OP_EXPi, /* same, with optional immediate prefix */
6594 OP_EXPr, /* same, with optional relocation suffix */
e2b0ab59 6595 OP_EXPs, /* same, with optional non-first operand relocation suffix */
b6895b4f 6596 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
6597 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6598 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
6599
6600 OP_CPSF, /* CPS flags */
6601 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6602 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6603 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6604 OP_COND, /* conditional code */
92e90b6e 6605 OP_TB, /* Table branch. */
c19d1205 6606
037e8744
JB
6607 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6608
c19d1205 6609 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 6610 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
6611 OP_RR_EXi, /* ARM register or expression with imm prefix */
6612 OP_RF_IF, /* FPA register or immediate */
6613 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6614 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6615
6616 /* Optional operands. */
6617 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6618 OP_oI31b, /* 0 .. 31 */
5287ad62 6619 OP_oI32b, /* 1 .. 32 */
5f1af56b 6620 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6621 OP_oIffffb, /* 0 .. 65535 */
6622 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6623
6624 OP_oRR, /* ARM register */
6625 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6626 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6627 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6628 OP_oRND, /* Optional Neon double precision register */
6629 OP_oRNQ, /* Optional Neon quad precision register */
6630 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6631 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6632 OP_oSHll, /* LSL immediate */
6633 OP_oSHar, /* ASR immediate */
6634 OP_oSHllar, /* LSL or ASR immediate */
6635 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6636 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6637
5be8be5d
DG
6638 /* Some pre-defined mixed (ARM/THUMB) operands. */
6639 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6640 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6641 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6642
c19d1205
ZW
6643 OP_FIRST_OPTIONAL = OP_oI7b
6644};
a737bd4d 6645
c19d1205
ZW
6646/* Generic instruction operand parser. This does no encoding and no
6647 semantic validation; it merely squirrels values away in the inst
6648 structure. Returns SUCCESS or FAIL depending on whether the
6649 specified grammar matched. */
6650static int
5be8be5d 6651parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6652{
5be8be5d 6653 unsigned const int *upat = pattern;
c19d1205
ZW
6654 char *backtrack_pos = 0;
6655 const char *backtrack_error = 0;
99aad254 6656 int i, val = 0, backtrack_index = 0;
5287ad62 6657 enum arm_reg_type rtype;
4962c51a 6658 parse_operand_result result;
5be8be5d 6659 unsigned int op_parse_code;
c19d1205 6660
e07e6e58
NC
6661#define po_char_or_fail(chr) \
6662 do \
6663 { \
6664 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6665 goto bad_args; \
e07e6e58
NC
6666 } \
6667 while (0)
c19d1205 6668
e07e6e58
NC
6669#define po_reg_or_fail(regtype) \
6670 do \
dcbf9037 6671 { \
e07e6e58 6672 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6673 & inst.operands[i].vectype); \
e07e6e58 6674 if (val == FAIL) \
477330fc
RM
6675 { \
6676 first_error (_(reg_expected_msgs[regtype])); \
6677 goto failure; \
6678 } \
e07e6e58
NC
6679 inst.operands[i].reg = val; \
6680 inst.operands[i].isreg = 1; \
6681 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6682 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6683 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6684 || rtype == REG_TYPE_VFD \
6685 || rtype == REG_TYPE_NQ); \
dcbf9037 6686 } \
e07e6e58
NC
6687 while (0)
6688
6689#define po_reg_or_goto(regtype, label) \
6690 do \
6691 { \
6692 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6693 & inst.operands[i].vectype); \
6694 if (val == FAIL) \
6695 goto label; \
dcbf9037 6696 \
e07e6e58
NC
6697 inst.operands[i].reg = val; \
6698 inst.operands[i].isreg = 1; \
6699 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6700 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6701 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6702 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6703 || rtype == REG_TYPE_NQ); \
6704 } \
6705 while (0)
6706
6707#define po_imm_or_fail(min, max, popt) \
6708 do \
6709 { \
6710 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6711 goto failure; \
6712 inst.operands[i].imm = val; \
6713 } \
6714 while (0)
6715
6716#define po_scalar_or_goto(elsz, label) \
6717 do \
6718 { \
6719 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6720 if (val == FAIL) \
6721 goto label; \
6722 inst.operands[i].reg = val; \
6723 inst.operands[i].isscalar = 1; \
6724 } \
6725 while (0)
6726
6727#define po_misc_or_fail(expr) \
6728 do \
6729 { \
6730 if (expr) \
6731 goto failure; \
6732 } \
6733 while (0)
6734
6735#define po_misc_or_fail_no_backtrack(expr) \
6736 do \
6737 { \
6738 result = expr; \
6739 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6740 backtrack_pos = 0; \
6741 if (result != PARSE_OPERAND_SUCCESS) \
6742 goto failure; \
6743 } \
6744 while (0)
4962c51a 6745
52e7f43d
RE
6746#define po_barrier_or_imm(str) \
6747 do \
6748 { \
6749 val = parse_barrier (&str); \
ccb84d65
JB
6750 if (val == FAIL && ! ISALPHA (*str)) \
6751 goto immediate; \
6752 if (val == FAIL \
6753 /* ISB can only take SY as an option. */ \
6754 || ((inst.instruction & 0xf0) == 0x60 \
6755 && val != 0xf)) \
52e7f43d 6756 { \
ccb84d65
JB
6757 inst.error = _("invalid barrier type"); \
6758 backtrack_pos = 0; \
6759 goto failure; \
52e7f43d
RE
6760 } \
6761 } \
6762 while (0)
6763
c19d1205
ZW
6764 skip_whitespace (str);
6765
6766 for (i = 0; upat[i] != OP_stop; i++)
6767 {
5be8be5d
DG
6768 op_parse_code = upat[i];
6769 if (op_parse_code >= 1<<16)
6770 op_parse_code = thumb ? (op_parse_code >> 16)
6771 : (op_parse_code & ((1<<16)-1));
6772
6773 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6774 {
6775 /* Remember where we are in case we need to backtrack. */
9c2799c2 6776 gas_assert (!backtrack_pos);
c19d1205
ZW
6777 backtrack_pos = str;
6778 backtrack_error = inst.error;
6779 backtrack_index = i;
6780 }
6781
b6702015 6782 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6783 po_char_or_fail (',');
6784
5be8be5d 6785 switch (op_parse_code)
c19d1205
ZW
6786 {
6787 /* Registers */
6788 case OP_oRRnpc:
5be8be5d 6789 case OP_oRRnpcsp:
c19d1205 6790 case OP_RRnpc:
5be8be5d 6791 case OP_RRnpcsp:
c19d1205
ZW
6792 case OP_oRR:
6793 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6794 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6795 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6796 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6797 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6798 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6799 case OP_oRND:
5287ad62 6800 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6801 case OP_RVC:
6802 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6803 break;
6804 /* Also accept generic coprocessor regs for unknown registers. */
6805 coproc_reg:
6806 po_reg_or_fail (REG_TYPE_CN);
6807 break;
c19d1205
ZW
6808 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6809 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6810 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6811 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6812 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6813 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6814 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6815 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6816 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6817 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6818 case OP_oRNQ:
5287ad62 6819 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 6820 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
477330fc 6821 case OP_oRNDQ:
5287ad62 6822 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6823 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6824 case OP_oRNSDQ:
6825 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6826
6827 /* Neon scalar. Using an element size of 8 means that some invalid
6828 scalars are accepted here, so deal with those in later code. */
6829 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6830
6831 case OP_RNDQ_I0:
6832 {
6833 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6834 break;
6835 try_imm0:
6836 po_imm_or_fail (0, 0, TRUE);
6837 }
6838 break;
6839
6840 case OP_RVSD_I0:
6841 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6842 break;
6843
aacf0b33
KT
6844 case OP_RSVD_FI0:
6845 {
6846 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6847 break;
6848 try_ifimm0:
6849 if (parse_ifimm_zero (&str))
6850 inst.operands[i].imm = 0;
6851 else
6852 {
6853 inst.error
6854 = _("only floating point zero is allowed as immediate value");
6855 goto failure;
6856 }
6857 }
6858 break;
6859
477330fc
RM
6860 case OP_RR_RNSC:
6861 {
6862 po_scalar_or_goto (8, try_rr);
6863 break;
6864 try_rr:
6865 po_reg_or_fail (REG_TYPE_RN);
6866 }
6867 break;
6868
6869 case OP_RNSDQ_RNSC:
6870 {
6871 po_scalar_or_goto (8, try_nsdq);
6872 break;
6873 try_nsdq:
6874 po_reg_or_fail (REG_TYPE_NSDQ);
6875 }
6876 break;
6877
dec41383
JW
6878 case OP_RNSD_RNSC:
6879 {
6880 po_scalar_or_goto (8, try_s_scalar);
6881 break;
6882 try_s_scalar:
6883 po_scalar_or_goto (4, try_nsd);
6884 break;
6885 try_nsd:
6886 po_reg_or_fail (REG_TYPE_NSD);
6887 }
6888 break;
6889
477330fc
RM
6890 case OP_RNDQ_RNSC:
6891 {
6892 po_scalar_or_goto (8, try_ndq);
6893 break;
6894 try_ndq:
6895 po_reg_or_fail (REG_TYPE_NDQ);
6896 }
6897 break;
6898
6899 case OP_RND_RNSC:
6900 {
6901 po_scalar_or_goto (8, try_vfd);
6902 break;
6903 try_vfd:
6904 po_reg_or_fail (REG_TYPE_VFD);
6905 }
6906 break;
6907
6908 case OP_VMOV:
6909 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6910 not careful then bad things might happen. */
6911 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6912 break;
6913
6914 case OP_RNDQ_Ibig:
6915 {
6916 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6917 break;
6918 try_immbig:
6919 /* There's a possibility of getting a 64-bit immediate here, so
6920 we need special handling. */
8335d6aa
JW
6921 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6922 == FAIL)
477330fc
RM
6923 {
6924 inst.error = _("immediate value is out of range");
6925 goto failure;
6926 }
6927 }
6928 break;
6929
6930 case OP_RNDQ_I63b:
6931 {
6932 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6933 break;
6934 try_shimm:
6935 po_imm_or_fail (0, 63, TRUE);
6936 }
6937 break;
c19d1205
ZW
6938
6939 case OP_RRnpcb:
6940 po_char_or_fail ('[');
6941 po_reg_or_fail (REG_TYPE_RN);
6942 po_char_or_fail (']');
6943 break;
a737bd4d 6944
55881a11 6945 case OP_RRnpctw:
c19d1205 6946 case OP_RRw:
b6702015 6947 case OP_oRRw:
c19d1205
ZW
6948 po_reg_or_fail (REG_TYPE_RN);
6949 if (skip_past_char (&str, '!') == SUCCESS)
6950 inst.operands[i].writeback = 1;
6951 break;
6952
6953 /* Immediates */
6954 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6955 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6956 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6957 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6958 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6959 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6960 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6961 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6962 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6963 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6964 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6965 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6966
6967 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6968 case OP_oI7b:
6969 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6970 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6971 case OP_oI31b:
6972 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6973 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6974 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6975 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6976
6977 /* Immediate variants */
6978 case OP_oI255c:
6979 po_char_or_fail ('{');
6980 po_imm_or_fail (0, 255, TRUE);
6981 po_char_or_fail ('}');
6982 break;
6983
6984 case OP_I31w:
6985 /* The expression parser chokes on a trailing !, so we have
6986 to find it first and zap it. */
6987 {
6988 char *s = str;
6989 while (*s && *s != ',')
6990 s++;
6991 if (s[-1] == '!')
6992 {
6993 s[-1] = '\0';
6994 inst.operands[i].writeback = 1;
6995 }
6996 po_imm_or_fail (0, 31, TRUE);
6997 if (str == s - 1)
6998 str = s;
6999 }
7000 break;
7001
7002 /* Expressions */
7003 case OP_EXPi: EXPi:
e2b0ab59 7004 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7005 GE_OPT_PREFIX));
7006 break;
7007
7008 case OP_EXP:
e2b0ab59 7009 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7010 GE_NO_PREFIX));
7011 break;
7012
7013 case OP_EXPr: EXPr:
e2b0ab59 7014 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205 7015 GE_NO_PREFIX));
e2b0ab59 7016 if (inst.relocs[0].exp.X_op == O_symbol)
a737bd4d 7017 {
c19d1205
ZW
7018 val = parse_reloc (&str);
7019 if (val == -1)
7020 {
7021 inst.error = _("unrecognized relocation suffix");
7022 goto failure;
7023 }
7024 else if (val != BFD_RELOC_UNUSED)
7025 {
7026 inst.operands[i].imm = val;
7027 inst.operands[i].hasreloc = 1;
7028 }
a737bd4d 7029 }
c19d1205 7030 break;
a737bd4d 7031
e2b0ab59
AV
7032 case OP_EXPs:
7033 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7034 GE_NO_PREFIX));
7035 if (inst.relocs[i].exp.X_op == O_symbol)
7036 {
7037 inst.operands[i].hasreloc = 1;
7038 }
7039 else if (inst.relocs[i].exp.X_op == O_constant)
7040 {
7041 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7042 inst.operands[i].hasreloc = 0;
7043 }
7044 break;
7045
b6895b4f
PB
7046 /* Operand for MOVW or MOVT. */
7047 case OP_HALF:
7048 po_misc_or_fail (parse_half (&str));
7049 break;
7050
e07e6e58 7051 /* Register or expression. */
c19d1205
ZW
7052 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7053 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7054
e07e6e58 7055 /* Register or immediate. */
c19d1205
ZW
7056 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7057 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7058
c19d1205
ZW
7059 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7060 IF:
7061 if (!is_immediate_prefix (*str))
7062 goto bad_args;
7063 str++;
7064 val = parse_fpa_immediate (&str);
7065 if (val == FAIL)
7066 goto failure;
7067 /* FPA immediates are encoded as registers 8-15.
7068 parse_fpa_immediate has already applied the offset. */
7069 inst.operands[i].reg = val;
7070 inst.operands[i].isreg = 1;
7071 break;
09d92015 7072
2d447fca
JM
7073 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7074 I32z: po_imm_or_fail (0, 32, FALSE); break;
7075
e07e6e58 7076 /* Two kinds of register. */
c19d1205
ZW
7077 case OP_RIWR_RIWC:
7078 {
7079 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7080 if (!rege
7081 || (rege->type != REG_TYPE_MMXWR
7082 && rege->type != REG_TYPE_MMXWC
7083 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7084 {
7085 inst.error = _("iWMMXt data or control register expected");
7086 goto failure;
7087 }
7088 inst.operands[i].reg = rege->number;
7089 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7090 }
7091 break;
09d92015 7092
41adaa5c
JM
7093 case OP_RIWC_RIWG:
7094 {
7095 struct reg_entry *rege = arm_reg_parse_multi (&str);
7096 if (!rege
7097 || (rege->type != REG_TYPE_MMXWC
7098 && rege->type != REG_TYPE_MMXWCG))
7099 {
7100 inst.error = _("iWMMXt control register expected");
7101 goto failure;
7102 }
7103 inst.operands[i].reg = rege->number;
7104 inst.operands[i].isreg = 1;
7105 }
7106 break;
7107
c19d1205
ZW
7108 /* Misc */
7109 case OP_CPSF: val = parse_cps_flags (&str); break;
7110 case OP_ENDI: val = parse_endian_specifier (&str); break;
7111 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7112 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7113 case OP_oBARRIER_I15:
7114 po_barrier_or_imm (str); break;
7115 immediate:
7116 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7117 goto failure;
52e7f43d 7118 break;
c19d1205 7119
fa94de6b 7120 case OP_wPSR:
d2cd1205 7121 case OP_rPSR:
90ec0d68
MGD
7122 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7123 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7124 {
7125 inst.error = _("Banked registers are not available with this "
7126 "architecture.");
7127 goto failure;
7128 }
7129 break;
d2cd1205
JB
7130 try_psr:
7131 val = parse_psr (&str, op_parse_code == OP_wPSR);
7132 break;
037e8744 7133
477330fc
RM
7134 case OP_APSR_RR:
7135 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7136 break;
7137 try_apsr:
7138 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7139 instruction). */
7140 if (strncasecmp (str, "APSR_", 5) == 0)
7141 {
7142 unsigned found = 0;
7143 str += 5;
7144 while (found < 15)
7145 switch (*str++)
7146 {
7147 case 'c': found = (found & 1) ? 16 : found | 1; break;
7148 case 'n': found = (found & 2) ? 16 : found | 2; break;
7149 case 'z': found = (found & 4) ? 16 : found | 4; break;
7150 case 'v': found = (found & 8) ? 16 : found | 8; break;
7151 default: found = 16;
7152 }
7153 if (found != 15)
7154 goto failure;
7155 inst.operands[i].isvec = 1;
f7c21dc7
NC
7156 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7157 inst.operands[i].reg = REG_PC;
477330fc
RM
7158 }
7159 else
7160 goto failure;
7161 break;
037e8744 7162
92e90b6e
PB
7163 case OP_TB:
7164 po_misc_or_fail (parse_tb (&str));
7165 break;
7166
e07e6e58 7167 /* Register lists. */
c19d1205
ZW
7168 case OP_REGLST:
7169 val = parse_reg_list (&str);
7170 if (*str == '^')
7171 {
5e0d7f77 7172 inst.operands[i].writeback = 1;
c19d1205
ZW
7173 str++;
7174 }
7175 break;
09d92015 7176
c19d1205 7177 case OP_VRSLST:
5287ad62 7178 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7179 break;
09d92015 7180
c19d1205 7181 case OP_VRDLST:
5287ad62 7182 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7183 break;
a737bd4d 7184
477330fc
RM
7185 case OP_VRSDLST:
7186 /* Allow Q registers too. */
7187 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7188 REGLIST_NEON_D);
7189 if (val == FAIL)
7190 {
7191 inst.error = NULL;
7192 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7193 REGLIST_VFP_S);
7194 inst.operands[i].issingle = 1;
7195 }
7196 break;
7197
7198 case OP_NRDLST:
7199 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7200 REGLIST_NEON_D);
7201 break;
5287ad62
JB
7202
7203 case OP_NSTRLST:
477330fc
RM
7204 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7205 &inst.operands[i].vectype);
7206 break;
5287ad62 7207
c19d1205
ZW
7208 /* Addressing modes */
7209 case OP_ADDR:
7210 po_misc_or_fail (parse_address (&str, i));
7211 break;
09d92015 7212
4962c51a
MS
7213 case OP_ADDRGLDR:
7214 po_misc_or_fail_no_backtrack (
477330fc 7215 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7216 break;
7217
7218 case OP_ADDRGLDRS:
7219 po_misc_or_fail_no_backtrack (
477330fc 7220 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7221 break;
7222
7223 case OP_ADDRGLDC:
7224 po_misc_or_fail_no_backtrack (
477330fc 7225 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7226 break;
7227
c19d1205
ZW
7228 case OP_SH:
7229 po_misc_or_fail (parse_shifter_operand (&str, i));
7230 break;
09d92015 7231
4962c51a
MS
7232 case OP_SHG:
7233 po_misc_or_fail_no_backtrack (
477330fc 7234 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7235 break;
7236
c19d1205
ZW
7237 case OP_oSHll:
7238 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7239 break;
09d92015 7240
c19d1205
ZW
7241 case OP_oSHar:
7242 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7243 break;
09d92015 7244
c19d1205
ZW
7245 case OP_oSHllar:
7246 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7247 break;
09d92015 7248
c19d1205 7249 default:
5be8be5d 7250 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7251 }
09d92015 7252
c19d1205
ZW
7253 /* Various value-based sanity checks and shared operations. We
7254 do not signal immediate failures for the register constraints;
7255 this allows a syntax error to take precedence. */
5be8be5d 7256 switch (op_parse_code)
c19d1205
ZW
7257 {
7258 case OP_oRRnpc:
7259 case OP_RRnpc:
7260 case OP_RRnpcb:
7261 case OP_RRw:
b6702015 7262 case OP_oRRw:
c19d1205
ZW
7263 case OP_RRnpc_I0:
7264 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7265 inst.error = BAD_PC;
7266 break;
09d92015 7267
5be8be5d
DG
7268 case OP_oRRnpcsp:
7269 case OP_RRnpcsp:
7270 if (inst.operands[i].isreg)
7271 {
7272 if (inst.operands[i].reg == REG_PC)
7273 inst.error = BAD_PC;
5c8ed6a4
JW
7274 else if (inst.operands[i].reg == REG_SP
7275 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7276 relaxed since ARMv8-A. */
7277 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7278 {
7279 gas_assert (thumb);
7280 inst.error = BAD_SP;
7281 }
5be8be5d
DG
7282 }
7283 break;
7284
55881a11 7285 case OP_RRnpctw:
fa94de6b
RM
7286 if (inst.operands[i].isreg
7287 && inst.operands[i].reg == REG_PC
55881a11
MGD
7288 && (inst.operands[i].writeback || thumb))
7289 inst.error = BAD_PC;
7290 break;
7291
c19d1205
ZW
7292 case OP_CPSF:
7293 case OP_ENDI:
7294 case OP_oROR:
d2cd1205
JB
7295 case OP_wPSR:
7296 case OP_rPSR:
c19d1205 7297 case OP_COND:
52e7f43d 7298 case OP_oBARRIER_I15:
c19d1205
ZW
7299 case OP_REGLST:
7300 case OP_VRSLST:
7301 case OP_VRDLST:
477330fc
RM
7302 case OP_VRSDLST:
7303 case OP_NRDLST:
7304 case OP_NSTRLST:
c19d1205
ZW
7305 if (val == FAIL)
7306 goto failure;
7307 inst.operands[i].imm = val;
7308 break;
a737bd4d 7309
c19d1205
ZW
7310 default:
7311 break;
7312 }
09d92015 7313
c19d1205
ZW
7314 /* If we get here, this operand was successfully parsed. */
7315 inst.operands[i].present = 1;
7316 continue;
09d92015 7317
c19d1205 7318 bad_args:
09d92015 7319 inst.error = BAD_ARGS;
c19d1205
ZW
7320
7321 failure:
7322 if (!backtrack_pos)
d252fdde
PB
7323 {
7324 /* The parse routine should already have set inst.error, but set a
5f4273c7 7325 default here just in case. */
d252fdde
PB
7326 if (!inst.error)
7327 inst.error = _("syntax error");
7328 return FAIL;
7329 }
c19d1205
ZW
7330
7331 /* Do not backtrack over a trailing optional argument that
7332 absorbed some text. We will only fail again, with the
7333 'garbage following instruction' error message, which is
7334 probably less helpful than the current one. */
7335 if (backtrack_index == i && backtrack_pos != str
7336 && upat[i+1] == OP_stop)
d252fdde
PB
7337 {
7338 if (!inst.error)
7339 inst.error = _("syntax error");
7340 return FAIL;
7341 }
c19d1205
ZW
7342
7343 /* Try again, skipping the optional argument at backtrack_pos. */
7344 str = backtrack_pos;
7345 inst.error = backtrack_error;
7346 inst.operands[backtrack_index].present = 0;
7347 i = backtrack_index;
7348 backtrack_pos = 0;
09d92015 7349 }
09d92015 7350
c19d1205
ZW
7351 /* Check that we have parsed all the arguments. */
7352 if (*str != '\0' && !inst.error)
7353 inst.error = _("garbage following instruction");
09d92015 7354
c19d1205 7355 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7356}
7357
c19d1205
ZW
7358#undef po_char_or_fail
7359#undef po_reg_or_fail
7360#undef po_reg_or_goto
7361#undef po_imm_or_fail
5287ad62 7362#undef po_scalar_or_fail
52e7f43d 7363#undef po_barrier_or_imm
e07e6e58 7364
c19d1205 7365/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7366#define constraint(expr, err) \
7367 do \
c19d1205 7368 { \
e07e6e58
NC
7369 if (expr) \
7370 { \
7371 inst.error = err; \
7372 return; \
7373 } \
c19d1205 7374 } \
e07e6e58 7375 while (0)
c19d1205 7376
fdfde340
JM
7377/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7378 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
7379 is the BadReg predicate in ARM's Thumb-2 documentation.
7380
7381 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7382 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7383#define reject_bad_reg(reg) \
7384 do \
7385 if (reg == REG_PC) \
7386 { \
7387 inst.error = BAD_PC; \
7388 return; \
7389 } \
7390 else if (reg == REG_SP \
7391 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7392 { \
7393 inst.error = BAD_SP; \
7394 return; \
7395 } \
fdfde340
JM
7396 while (0)
7397
94206790
MM
7398/* If REG is R13 (the stack pointer), warn that its use is
7399 deprecated. */
7400#define warn_deprecated_sp(reg) \
7401 do \
7402 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7403 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7404 while (0)
7405
c19d1205
ZW
7406/* Functions for operand encoding. ARM, then Thumb. */
7407
d840c081 7408#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7409
9db2f6b4
RL
7410/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7411
7412 The only binary encoding difference is the Coprocessor number. Coprocessor
7413 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 7414 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
7415 exists for Single-Precision operation. */
7416
7417static void
7418do_scalar_fp16_v82_encode (void)
7419{
7420 if (inst.cond != COND_ALWAYS)
7421 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7422 " the behaviour is UNPREDICTABLE"));
7423 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7424 _(BAD_FP16));
7425
7426 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7427 mark_feature_used (&arm_ext_fp16);
7428}
7429
c19d1205
ZW
7430/* If VAL can be encoded in the immediate field of an ARM instruction,
7431 return the encoded form. Otherwise, return FAIL. */
7432
7433static unsigned int
7434encode_arm_immediate (unsigned int val)
09d92015 7435{
c19d1205
ZW
7436 unsigned int a, i;
7437
4f1d6205
L
7438 if (val <= 0xff)
7439 return val;
7440
7441 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7442 if ((a = rotate_left (val, i)) <= 0xff)
7443 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7444
7445 return FAIL;
09d92015
MM
7446}
7447
c19d1205
ZW
7448/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7449 return the encoded form. Otherwise, return FAIL. */
7450static unsigned int
7451encode_thumb32_immediate (unsigned int val)
09d92015 7452{
c19d1205 7453 unsigned int a, i;
09d92015 7454
9c3c69f2 7455 if (val <= 0xff)
c19d1205 7456 return val;
a737bd4d 7457
9c3c69f2 7458 for (i = 1; i <= 24; i++)
09d92015 7459 {
9c3c69f2
PB
7460 a = val >> i;
7461 if ((val & ~(0xff << i)) == 0)
7462 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7463 }
a737bd4d 7464
c19d1205
ZW
7465 a = val & 0xff;
7466 if (val == ((a << 16) | a))
7467 return 0x100 | a;
7468 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7469 return 0x300 | a;
09d92015 7470
c19d1205
ZW
7471 a = val & 0xff00;
7472 if (val == ((a << 16) | a))
7473 return 0x200 | (a >> 8);
a737bd4d 7474
c19d1205 7475 return FAIL;
09d92015 7476}
5287ad62 7477/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7478
7479static void
5287ad62
JB
7480encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7481{
7482 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7483 && reg > 15)
7484 {
b1cc4aeb 7485 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7486 {
7487 if (thumb_mode)
7488 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7489 fpu_vfp_ext_d32);
7490 else
7491 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7492 fpu_vfp_ext_d32);
7493 }
5287ad62 7494 else
477330fc
RM
7495 {
7496 first_error (_("D register out of range for selected VFP version"));
7497 return;
7498 }
5287ad62
JB
7499 }
7500
c19d1205 7501 switch (pos)
09d92015 7502 {
c19d1205
ZW
7503 case VFP_REG_Sd:
7504 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7505 break;
7506
7507 case VFP_REG_Sn:
7508 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7509 break;
7510
7511 case VFP_REG_Sm:
7512 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7513 break;
7514
5287ad62
JB
7515 case VFP_REG_Dd:
7516 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7517 break;
5f4273c7 7518
5287ad62
JB
7519 case VFP_REG_Dn:
7520 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7521 break;
5f4273c7 7522
5287ad62
JB
7523 case VFP_REG_Dm:
7524 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7525 break;
7526
c19d1205
ZW
7527 default:
7528 abort ();
09d92015 7529 }
09d92015
MM
7530}
7531
c19d1205 7532/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7533 if any, is handled by md_apply_fix. */
09d92015 7534static void
c19d1205 7535encode_arm_shift (int i)
09d92015 7536{
008a97ef
RL
7537 /* register-shifted register. */
7538 if (inst.operands[i].immisreg)
7539 {
bf355b69
MR
7540 int op_index;
7541 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 7542 {
5689c942
RL
7543 /* Check the operand only when it's presented. In pre-UAL syntax,
7544 if the destination register is the same as the first operand, two
7545 register form of the instruction can be used. */
bf355b69
MR
7546 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7547 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
7548 as_warn (UNPRED_REG ("r15"));
7549 }
7550
7551 if (inst.operands[i].imm == REG_PC)
7552 as_warn (UNPRED_REG ("r15"));
7553 }
7554
c19d1205
ZW
7555 if (inst.operands[i].shift_kind == SHIFT_RRX)
7556 inst.instruction |= SHIFT_ROR << 5;
7557 else
09d92015 7558 {
c19d1205
ZW
7559 inst.instruction |= inst.operands[i].shift_kind << 5;
7560 if (inst.operands[i].immisreg)
7561 {
7562 inst.instruction |= SHIFT_BY_REG;
7563 inst.instruction |= inst.operands[i].imm << 8;
7564 }
7565 else
e2b0ab59 7566 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7567 }
c19d1205 7568}
09d92015 7569
c19d1205
ZW
7570static void
7571encode_arm_shifter_operand (int i)
7572{
7573 if (inst.operands[i].isreg)
09d92015 7574 {
c19d1205
ZW
7575 inst.instruction |= inst.operands[i].reg;
7576 encode_arm_shift (i);
09d92015 7577 }
c19d1205 7578 else
a415b1cd
JB
7579 {
7580 inst.instruction |= INST_IMMEDIATE;
e2b0ab59 7581 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
a415b1cd
JB
7582 inst.instruction |= inst.operands[i].imm;
7583 }
09d92015
MM
7584}
7585
c19d1205 7586/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7587static void
c19d1205 7588encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7589{
2b2f5df9
NC
7590 /* PR 14260:
7591 Generate an error if the operand is not a register. */
7592 constraint (!inst.operands[i].isreg,
7593 _("Instruction does not support =N addresses"));
7594
c19d1205 7595 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7596
c19d1205 7597 if (inst.operands[i].preind)
09d92015 7598 {
c19d1205
ZW
7599 if (is_t)
7600 {
7601 inst.error = _("instruction does not accept preindexed addressing");
7602 return;
7603 }
7604 inst.instruction |= PRE_INDEX;
7605 if (inst.operands[i].writeback)
7606 inst.instruction |= WRITE_BACK;
09d92015 7607
c19d1205
ZW
7608 }
7609 else if (inst.operands[i].postind)
7610 {
9c2799c2 7611 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7612 if (is_t)
7613 inst.instruction |= WRITE_BACK;
7614 }
7615 else /* unindexed - only for coprocessor */
09d92015 7616 {
c19d1205 7617 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7618 return;
7619 }
7620
c19d1205
ZW
7621 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7622 && (((inst.instruction & 0x000f0000) >> 16)
7623 == ((inst.instruction & 0x0000f000) >> 12)))
7624 as_warn ((inst.instruction & LOAD_BIT)
7625 ? _("destination register same as write-back base")
7626 : _("source register same as write-back base"));
09d92015
MM
7627}
7628
c19d1205
ZW
7629/* inst.operands[i] was set up by parse_address. Encode it into an
7630 ARM-format mode 2 load or store instruction. If is_t is true,
7631 reject forms that cannot be used with a T instruction (i.e. not
7632 post-indexed). */
a737bd4d 7633static void
c19d1205 7634encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7635{
5be8be5d
DG
7636 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7637
c19d1205 7638 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7639
c19d1205 7640 if (inst.operands[i].immisreg)
09d92015 7641 {
5be8be5d
DG
7642 constraint ((inst.operands[i].imm == REG_PC
7643 || (is_pc && inst.operands[i].writeback)),
7644 BAD_PC_ADDRESSING);
c19d1205
ZW
7645 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7646 inst.instruction |= inst.operands[i].imm;
7647 if (!inst.operands[i].negative)
7648 inst.instruction |= INDEX_UP;
7649 if (inst.operands[i].shifted)
7650 {
7651 if (inst.operands[i].shift_kind == SHIFT_RRX)
7652 inst.instruction |= SHIFT_ROR << 5;
7653 else
7654 {
7655 inst.instruction |= inst.operands[i].shift_kind << 5;
e2b0ab59 7656 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
c19d1205
ZW
7657 }
7658 }
09d92015 7659 }
e2b0ab59 7660 else /* immediate offset in inst.relocs[0] */
09d92015 7661 {
e2b0ab59 7662 if (is_pc && !inst.relocs[0].pc_rel)
5be8be5d
DG
7663 {
7664 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7665
7666 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7667 cannot use PC in addressing.
7668 PC cannot be used in writeback addressing, either. */
7669 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7670 BAD_PC_ADDRESSING);
23a10334 7671
dc5ec521 7672 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7673 if (warn_on_deprecated
7674 && !is_load
7675 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7676 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7677 }
7678
e2b0ab59 7679 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
7680 {
7681 /* Prefer + for zero encoded value. */
7682 if (!inst.operands[i].negative)
7683 inst.instruction |= INDEX_UP;
e2b0ab59 7684 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
26d97720 7685 }
09d92015 7686 }
09d92015
MM
7687}
7688
c19d1205
ZW
7689/* inst.operands[i] was set up by parse_address. Encode it into an
7690 ARM-format mode 3 load or store instruction. Reject forms that
7691 cannot be used with such instructions. If is_t is true, reject
7692 forms that cannot be used with a T instruction (i.e. not
7693 post-indexed). */
7694static void
7695encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7696{
c19d1205 7697 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7698 {
c19d1205
ZW
7699 inst.error = _("instruction does not accept scaled register index");
7700 return;
09d92015 7701 }
a737bd4d 7702
c19d1205 7703 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7704
c19d1205
ZW
7705 if (inst.operands[i].immisreg)
7706 {
5be8be5d 7707 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7708 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7709 BAD_PC_ADDRESSING);
eb9f3f00
JB
7710 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7711 BAD_PC_WRITEBACK);
c19d1205
ZW
7712 inst.instruction |= inst.operands[i].imm;
7713 if (!inst.operands[i].negative)
7714 inst.instruction |= INDEX_UP;
7715 }
e2b0ab59 7716 else /* immediate offset in inst.relocs[0] */
c19d1205 7717 {
e2b0ab59 7718 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
5be8be5d
DG
7719 && inst.operands[i].writeback),
7720 BAD_PC_WRITEBACK);
c19d1205 7721 inst.instruction |= HWOFFSET_IMM;
e2b0ab59 7722 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
7723 {
7724 /* Prefer + for zero encoded value. */
7725 if (!inst.operands[i].negative)
7726 inst.instruction |= INDEX_UP;
7727
e2b0ab59 7728 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
26d97720 7729 }
c19d1205 7730 }
a737bd4d
NC
7731}
7732
8335d6aa
JW
7733/* Write immediate bits [7:0] to the following locations:
7734
7735 |28/24|23 19|18 16|15 4|3 0|
7736 | 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|
7737
7738 This function is used by VMOV/VMVN/VORR/VBIC. */
7739
7740static void
7741neon_write_immbits (unsigned immbits)
7742{
7743 inst.instruction |= immbits & 0xf;
7744 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7745 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7746}
7747
7748/* Invert low-order SIZE bits of XHI:XLO. */
7749
7750static void
7751neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7752{
7753 unsigned immlo = xlo ? *xlo : 0;
7754 unsigned immhi = xhi ? *xhi : 0;
7755
7756 switch (size)
7757 {
7758 case 8:
7759 immlo = (~immlo) & 0xff;
7760 break;
7761
7762 case 16:
7763 immlo = (~immlo) & 0xffff;
7764 break;
7765
7766 case 64:
7767 immhi = (~immhi) & 0xffffffff;
7768 /* fall through. */
7769
7770 case 32:
7771 immlo = (~immlo) & 0xffffffff;
7772 break;
7773
7774 default:
7775 abort ();
7776 }
7777
7778 if (xlo)
7779 *xlo = immlo;
7780
7781 if (xhi)
7782 *xhi = immhi;
7783}
7784
7785/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7786 A, B, C, D. */
09d92015 7787
c19d1205 7788static int
8335d6aa 7789neon_bits_same_in_bytes (unsigned imm)
09d92015 7790{
8335d6aa
JW
7791 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7792 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7793 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7794 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7795}
a737bd4d 7796
8335d6aa 7797/* For immediate of above form, return 0bABCD. */
09d92015 7798
8335d6aa
JW
7799static unsigned
7800neon_squash_bits (unsigned imm)
7801{
7802 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7803 | ((imm & 0x01000000) >> 21);
7804}
7805
7806/* Compress quarter-float representation to 0b...000 abcdefgh. */
7807
7808static unsigned
7809neon_qfloat_bits (unsigned imm)
7810{
7811 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7812}
7813
7814/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7815 the instruction. *OP is passed as the initial value of the op field, and
7816 may be set to a different value depending on the constant (i.e.
7817 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7818 MVN). If the immediate looks like a repeated pattern then also
7819 try smaller element sizes. */
7820
7821static int
7822neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7823 unsigned *immbits, int *op, int size,
7824 enum neon_el_type type)
7825{
7826 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7827 float. */
7828 if (type == NT_float && !float_p)
7829 return FAIL;
7830
7831 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7832 {
8335d6aa
JW
7833 if (size != 32 || *op == 1)
7834 return FAIL;
7835 *immbits = neon_qfloat_bits (immlo);
7836 return 0xf;
7837 }
7838
7839 if (size == 64)
7840 {
7841 if (neon_bits_same_in_bytes (immhi)
7842 && neon_bits_same_in_bytes (immlo))
c19d1205 7843 {
8335d6aa
JW
7844 if (*op == 1)
7845 return FAIL;
7846 *immbits = (neon_squash_bits (immhi) << 4)
7847 | neon_squash_bits (immlo);
7848 *op = 1;
7849 return 0xe;
c19d1205 7850 }
a737bd4d 7851
8335d6aa
JW
7852 if (immhi != immlo)
7853 return FAIL;
7854 }
a737bd4d 7855
8335d6aa 7856 if (size >= 32)
09d92015 7857 {
8335d6aa 7858 if (immlo == (immlo & 0x000000ff))
c19d1205 7859 {
8335d6aa
JW
7860 *immbits = immlo;
7861 return 0x0;
c19d1205 7862 }
8335d6aa 7863 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7864 {
8335d6aa
JW
7865 *immbits = immlo >> 8;
7866 return 0x2;
c19d1205 7867 }
8335d6aa
JW
7868 else if (immlo == (immlo & 0x00ff0000))
7869 {
7870 *immbits = immlo >> 16;
7871 return 0x4;
7872 }
7873 else if (immlo == (immlo & 0xff000000))
7874 {
7875 *immbits = immlo >> 24;
7876 return 0x6;
7877 }
7878 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7879 {
7880 *immbits = (immlo >> 8) & 0xff;
7881 return 0xc;
7882 }
7883 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7884 {
7885 *immbits = (immlo >> 16) & 0xff;
7886 return 0xd;
7887 }
7888
7889 if ((immlo & 0xffff) != (immlo >> 16))
7890 return FAIL;
7891 immlo &= 0xffff;
09d92015 7892 }
a737bd4d 7893
8335d6aa 7894 if (size >= 16)
4962c51a 7895 {
8335d6aa
JW
7896 if (immlo == (immlo & 0x000000ff))
7897 {
7898 *immbits = immlo;
7899 return 0x8;
7900 }
7901 else if (immlo == (immlo & 0x0000ff00))
7902 {
7903 *immbits = immlo >> 8;
7904 return 0xa;
7905 }
7906
7907 if ((immlo & 0xff) != (immlo >> 8))
7908 return FAIL;
7909 immlo &= 0xff;
4962c51a
MS
7910 }
7911
8335d6aa
JW
7912 if (immlo == (immlo & 0x000000ff))
7913 {
7914 /* Don't allow MVN with 8-bit immediate. */
7915 if (*op == 1)
7916 return FAIL;
7917 *immbits = immlo;
7918 return 0xe;
7919 }
26d97720 7920
8335d6aa 7921 return FAIL;
c19d1205 7922}
a737bd4d 7923
5fc177c8 7924#if defined BFD_HOST_64_BIT
ba592044
AM
7925/* Returns TRUE if double precision value V may be cast
7926 to single precision without loss of accuracy. */
7927
7928static bfd_boolean
5fc177c8 7929is_double_a_single (bfd_int64_t v)
ba592044 7930{
5fc177c8 7931 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7932 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7933
7934 return (exp == 0 || exp == 0x7FF
7935 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7936 && (mantissa & 0x1FFFFFFFl) == 0;
7937}
7938
3739860c 7939/* Returns a double precision value casted to single precision
ba592044
AM
7940 (ignoring the least significant bits in exponent and mantissa). */
7941
7942static int
5fc177c8 7943double_to_single (bfd_int64_t v)
ba592044
AM
7944{
7945 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7946 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7947 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7948
7949 if (exp == 0x7FF)
7950 exp = 0xFF;
7951 else
7952 {
7953 exp = exp - 1023 + 127;
7954 if (exp >= 0xFF)
7955 {
7956 /* Infinity. */
7957 exp = 0x7F;
7958 mantissa = 0;
7959 }
7960 else if (exp < 0)
7961 {
7962 /* No denormalized numbers. */
7963 exp = 0;
7964 mantissa = 0;
7965 }
7966 }
7967 mantissa >>= 29;
7968 return (sign << 31) | (exp << 23) | mantissa;
7969}
5fc177c8 7970#endif /* BFD_HOST_64_BIT */
ba592044 7971
8335d6aa
JW
7972enum lit_type
7973{
7974 CONST_THUMB,
7975 CONST_ARM,
7976 CONST_VEC
7977};
7978
ba592044
AM
7979static void do_vfp_nsyn_opcode (const char *);
7980
e2b0ab59 7981/* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
c19d1205
ZW
7982 Determine whether it can be performed with a move instruction; if
7983 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7984 return TRUE; if it can't, convert inst.instruction to a literal-pool
7985 load and return FALSE. If this is not a valid thing to do in the
7986 current context, set inst.error and return TRUE.
a737bd4d 7987
c19d1205
ZW
7988 inst.operands[i] describes the destination register. */
7989
c921be7d 7990static bfd_boolean
8335d6aa 7991move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7992{
53365c0d 7993 unsigned long tbit;
8335d6aa
JW
7994 bfd_boolean thumb_p = (t == CONST_THUMB);
7995 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7996
7997 if (thumb_p)
7998 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7999 else
8000 tbit = LOAD_BIT;
8001
8002 if ((inst.instruction & tbit) == 0)
09d92015 8003 {
c19d1205 8004 inst.error = _("invalid pseudo operation");
c921be7d 8005 return TRUE;
09d92015 8006 }
ba592044 8007
e2b0ab59
AV
8008 if (inst.relocs[0].exp.X_op != O_constant
8009 && inst.relocs[0].exp.X_op != O_symbol
8010 && inst.relocs[0].exp.X_op != O_big)
09d92015
MM
8011 {
8012 inst.error = _("constant expression expected");
c921be7d 8013 return TRUE;
09d92015 8014 }
ba592044 8015
e2b0ab59
AV
8016 if (inst.relocs[0].exp.X_op == O_constant
8017 || inst.relocs[0].exp.X_op == O_big)
8335d6aa 8018 {
5fc177c8
NC
8019#if defined BFD_HOST_64_BIT
8020 bfd_int64_t v;
8021#else
ba592044 8022 offsetT v;
5fc177c8 8023#endif
e2b0ab59 8024 if (inst.relocs[0].exp.X_op == O_big)
8335d6aa 8025 {
ba592044
AM
8026 LITTLENUM_TYPE w[X_PRECISION];
8027 LITTLENUM_TYPE * l;
8028
e2b0ab59 8029 if (inst.relocs[0].exp.X_add_number == -1)
8335d6aa 8030 {
ba592044
AM
8031 gen_to_words (w, X_PRECISION, E_PRECISION);
8032 l = w;
8033 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 8034 }
ba592044
AM
8035 else
8036 l = generic_bignum;
3739860c 8037
5fc177c8
NC
8038#if defined BFD_HOST_64_BIT
8039 v =
8040 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8041 << LITTLENUM_NUMBER_OF_BITS)
8042 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8043 << LITTLENUM_NUMBER_OF_BITS)
8044 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8045 << LITTLENUM_NUMBER_OF_BITS)
8046 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8047#else
ba592044
AM
8048 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8049 | (l[0] & LITTLENUM_MASK);
5fc177c8 8050#endif
8335d6aa 8051 }
ba592044 8052 else
e2b0ab59 8053 v = inst.relocs[0].exp.X_add_number;
ba592044
AM
8054
8055 if (!inst.operands[i].issingle)
8335d6aa 8056 {
12569877 8057 if (thumb_p)
8335d6aa 8058 {
53445554
TP
8059 /* LDR should not use lead in a flag-setting instruction being
8060 chosen so we do not check whether movs can be used. */
12569877 8061
53445554 8062 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8063 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8064 && inst.operands[i].reg != 13
8065 && inst.operands[i].reg != 15)
12569877 8066 {
fc289b0a
TP
8067 /* Check if on thumb2 it can be done with a mov.w, mvn or
8068 movw instruction. */
12569877
AM
8069 unsigned int newimm;
8070 bfd_boolean isNegated;
8071
8072 newimm = encode_thumb32_immediate (v);
8073 if (newimm != (unsigned int) FAIL)
8074 isNegated = FALSE;
8075 else
8076 {
582cfe03 8077 newimm = encode_thumb32_immediate (~v);
12569877
AM
8078 if (newimm != (unsigned int) FAIL)
8079 isNegated = TRUE;
8080 }
8081
fc289b0a
TP
8082 /* The number can be loaded with a mov.w or mvn
8083 instruction. */
ff8646ee
TP
8084 if (newimm != (unsigned int) FAIL
8085 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8086 {
fc289b0a 8087 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8088 | (inst.operands[i].reg << 8));
fc289b0a 8089 /* Change to MOVN. */
582cfe03 8090 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8091 inst.instruction |= (newimm & 0x800) << 15;
8092 inst.instruction |= (newimm & 0x700) << 4;
8093 inst.instruction |= (newimm & 0x0ff);
8094 return TRUE;
8095 }
fc289b0a 8096 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8097 else if ((v & ~0xFFFF) == 0
8098 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8099 {
582cfe03 8100 int imm = v & 0xFFFF;
12569877 8101
582cfe03 8102 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8103 inst.instruction |= (inst.operands[i].reg << 8);
8104 inst.instruction |= (imm & 0xf000) << 4;
8105 inst.instruction |= (imm & 0x0800) << 15;
8106 inst.instruction |= (imm & 0x0700) << 4;
8107 inst.instruction |= (imm & 0x00ff);
8108 return TRUE;
8109 }
8110 }
8335d6aa 8111 }
12569877 8112 else if (arm_p)
ba592044
AM
8113 {
8114 int value = encode_arm_immediate (v);
12569877 8115
ba592044
AM
8116 if (value != FAIL)
8117 {
8118 /* This can be done with a mov instruction. */
8119 inst.instruction &= LITERAL_MASK;
8120 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8121 inst.instruction |= value & 0xfff;
8122 return TRUE;
8123 }
8335d6aa 8124
ba592044
AM
8125 value = encode_arm_immediate (~ v);
8126 if (value != FAIL)
8127 {
8128 /* This can be done with a mvn instruction. */
8129 inst.instruction &= LITERAL_MASK;
8130 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8131 inst.instruction |= value & 0xfff;
8132 return TRUE;
8133 }
8134 }
934c2632 8135 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8136 {
ba592044
AM
8137 int op = 0;
8138 unsigned immbits = 0;
8139 unsigned immlo = inst.operands[1].imm;
8140 unsigned immhi = inst.operands[1].regisimm
8141 ? inst.operands[1].reg
e2b0ab59 8142 : inst.relocs[0].exp.X_unsigned
ba592044
AM
8143 ? 0
8144 : ((bfd_int64_t)((int) immlo)) >> 32;
8145 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8146 &op, 64, NT_invtype);
8147
8148 if (cmode == FAIL)
8149 {
8150 neon_invert_size (&immlo, &immhi, 64);
8151 op = !op;
8152 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8153 &op, 64, NT_invtype);
8154 }
8155
8156 if (cmode != FAIL)
8157 {
8158 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8159 | (1 << 23)
8160 | (cmode << 8)
8161 | (op << 5)
8162 | (1 << 4);
8163
8164 /* Fill other bits in vmov encoding for both thumb and arm. */
8165 if (thumb_mode)
eff0bc54 8166 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8167 else
eff0bc54 8168 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8169 neon_write_immbits (immbits);
8170 return TRUE;
8171 }
8335d6aa
JW
8172 }
8173 }
8335d6aa 8174
ba592044
AM
8175 if (t == CONST_VEC)
8176 {
8177 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8178 if (inst.operands[i].issingle
8179 && is_quarter_float (inst.operands[1].imm)
8180 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8181 {
ba592044
AM
8182 inst.operands[1].imm =
8183 neon_qfloat_bits (v);
8184 do_vfp_nsyn_opcode ("fconsts");
8185 return TRUE;
8335d6aa 8186 }
5fc177c8
NC
8187
8188 /* If our host does not support a 64-bit type then we cannot perform
8189 the following optimization. This mean that there will be a
8190 discrepancy between the output produced by an assembler built for
8191 a 32-bit-only host and the output produced from a 64-bit host, but
8192 this cannot be helped. */
8193#if defined BFD_HOST_64_BIT
ba592044
AM
8194 else if (!inst.operands[1].issingle
8195 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8196 {
ba592044
AM
8197 if (is_double_a_single (v)
8198 && is_quarter_float (double_to_single (v)))
8199 {
8200 inst.operands[1].imm =
8201 neon_qfloat_bits (double_to_single (v));
8202 do_vfp_nsyn_opcode ("fconstd");
8203 return TRUE;
8204 }
8335d6aa 8205 }
5fc177c8 8206#endif
8335d6aa
JW
8207 }
8208 }
8209
8210 if (add_to_lit_pool ((!inst.operands[i].isvec
8211 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8212 return TRUE;
8213
8214 inst.operands[1].reg = REG_PC;
8215 inst.operands[1].isreg = 1;
8216 inst.operands[1].preind = 1;
e2b0ab59
AV
8217 inst.relocs[0].pc_rel = 1;
8218 inst.relocs[0].type = (thumb_p
8335d6aa
JW
8219 ? BFD_RELOC_ARM_THUMB_OFFSET
8220 : (mode_3
8221 ? BFD_RELOC_ARM_HWLITERAL
8222 : BFD_RELOC_ARM_LITERAL));
8223 return FALSE;
8224}
8225
8226/* inst.operands[i] was set up by parse_address. Encode it into an
8227 ARM-format instruction. Reject all forms which cannot be encoded
8228 into a coprocessor load/store instruction. If wb_ok is false,
8229 reject use of writeback; if unind_ok is false, reject use of
8230 unindexed addressing. If reloc_override is not 0, use it instead
8231 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8232 (in which case it is preserved). */
8233
8234static int
8235encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8236{
8237 if (!inst.operands[i].isreg)
8238 {
99b2a2dd
NC
8239 /* PR 18256 */
8240 if (! inst.operands[0].isvec)
8241 {
8242 inst.error = _("invalid co-processor operand");
8243 return FAIL;
8244 }
8335d6aa
JW
8245 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8246 return SUCCESS;
8247 }
8248
8249 inst.instruction |= inst.operands[i].reg << 16;
8250
8251 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8252
8253 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8254 {
8255 gas_assert (!inst.operands[i].writeback);
8256 if (!unind_ok)
8257 {
8258 inst.error = _("instruction does not support unindexed addressing");
8259 return FAIL;
8260 }
8261 inst.instruction |= inst.operands[i].imm;
8262 inst.instruction |= INDEX_UP;
8263 return SUCCESS;
8264 }
8265
8266 if (inst.operands[i].preind)
8267 inst.instruction |= PRE_INDEX;
8268
8269 if (inst.operands[i].writeback)
09d92015 8270 {
8335d6aa 8271 if (inst.operands[i].reg == REG_PC)
c19d1205 8272 {
8335d6aa
JW
8273 inst.error = _("pc may not be used with write-back");
8274 return FAIL;
c19d1205 8275 }
8335d6aa 8276 if (!wb_ok)
c19d1205 8277 {
8335d6aa
JW
8278 inst.error = _("instruction does not support writeback");
8279 return FAIL;
c19d1205 8280 }
8335d6aa 8281 inst.instruction |= WRITE_BACK;
09d92015
MM
8282 }
8283
8335d6aa 8284 if (reloc_override)
e2b0ab59
AV
8285 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
8286 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
8287 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
8288 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8289 {
8335d6aa 8290 if (thumb_mode)
e2b0ab59 8291 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8335d6aa 8292 else
e2b0ab59 8293 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8294 }
8335d6aa
JW
8295
8296 /* Prefer + for zero encoded value. */
8297 if (!inst.operands[i].negative)
8298 inst.instruction |= INDEX_UP;
8299
8300 return SUCCESS;
09d92015
MM
8301}
8302
5f4273c7 8303/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8304 First some generics; their names are taken from the conventional
8305 bit positions for register arguments in ARM format instructions. */
09d92015 8306
a737bd4d 8307static void
c19d1205 8308do_noargs (void)
09d92015 8309{
c19d1205 8310}
a737bd4d 8311
c19d1205
ZW
8312static void
8313do_rd (void)
8314{
8315 inst.instruction |= inst.operands[0].reg << 12;
8316}
a737bd4d 8317
16a1fa25
TP
8318static void
8319do_rn (void)
8320{
8321 inst.instruction |= inst.operands[0].reg << 16;
8322}
8323
c19d1205
ZW
8324static void
8325do_rd_rm (void)
8326{
8327 inst.instruction |= inst.operands[0].reg << 12;
8328 inst.instruction |= inst.operands[1].reg;
8329}
09d92015 8330
9eb6c0f1
MGD
8331static void
8332do_rm_rn (void)
8333{
8334 inst.instruction |= inst.operands[0].reg;
8335 inst.instruction |= inst.operands[1].reg << 16;
8336}
8337
c19d1205
ZW
8338static void
8339do_rd_rn (void)
8340{
8341 inst.instruction |= inst.operands[0].reg << 12;
8342 inst.instruction |= inst.operands[1].reg << 16;
8343}
a737bd4d 8344
c19d1205
ZW
8345static void
8346do_rn_rd (void)
8347{
8348 inst.instruction |= inst.operands[0].reg << 16;
8349 inst.instruction |= inst.operands[1].reg << 12;
8350}
09d92015 8351
4ed7ed8d
TP
8352static void
8353do_tt (void)
8354{
8355 inst.instruction |= inst.operands[0].reg << 8;
8356 inst.instruction |= inst.operands[1].reg << 16;
8357}
8358
59d09be6
MGD
8359static bfd_boolean
8360check_obsolete (const arm_feature_set *feature, const char *msg)
8361{
8362 if (ARM_CPU_IS_ANY (cpu_variant))
8363 {
5c3696f8 8364 as_tsktsk ("%s", msg);
59d09be6
MGD
8365 return TRUE;
8366 }
8367 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8368 {
8369 as_bad ("%s", msg);
8370 return TRUE;
8371 }
8372
8373 return FALSE;
8374}
8375
c19d1205
ZW
8376static void
8377do_rd_rm_rn (void)
8378{
9a64e435 8379 unsigned Rn = inst.operands[2].reg;
708587a4 8380 /* Enforce restrictions on SWP instruction. */
9a64e435 8381 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8382 {
8383 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8384 _("Rn must not overlap other operands"));
8385
59d09be6
MGD
8386 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8387 */
8388 if (!check_obsolete (&arm_ext_v8,
8389 _("swp{b} use is obsoleted for ARMv8 and later"))
8390 && warn_on_deprecated
8391 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8392 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8393 }
59d09be6 8394
c19d1205
ZW
8395 inst.instruction |= inst.operands[0].reg << 12;
8396 inst.instruction |= inst.operands[1].reg;
9a64e435 8397 inst.instruction |= Rn << 16;
c19d1205 8398}
09d92015 8399
c19d1205
ZW
8400static void
8401do_rd_rn_rm (void)
8402{
8403 inst.instruction |= inst.operands[0].reg << 12;
8404 inst.instruction |= inst.operands[1].reg << 16;
8405 inst.instruction |= inst.operands[2].reg;
8406}
a737bd4d 8407
c19d1205
ZW
8408static void
8409do_rm_rd_rn (void)
8410{
5be8be5d 8411 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
e2b0ab59
AV
8412 constraint (((inst.relocs[0].exp.X_op != O_constant
8413 && inst.relocs[0].exp.X_op != O_illegal)
8414 || inst.relocs[0].exp.X_add_number != 0),
5be8be5d 8415 BAD_ADDR_MODE);
c19d1205
ZW
8416 inst.instruction |= inst.operands[0].reg;
8417 inst.instruction |= inst.operands[1].reg << 12;
8418 inst.instruction |= inst.operands[2].reg << 16;
8419}
09d92015 8420
c19d1205
ZW
8421static void
8422do_imm0 (void)
8423{
8424 inst.instruction |= inst.operands[0].imm;
8425}
09d92015 8426
c19d1205
ZW
8427static void
8428do_rd_cpaddr (void)
8429{
8430 inst.instruction |= inst.operands[0].reg << 12;
8431 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8432}
a737bd4d 8433
c19d1205
ZW
8434/* ARM instructions, in alphabetical order by function name (except
8435 that wrapper functions appear immediately after the function they
8436 wrap). */
09d92015 8437
c19d1205
ZW
8438/* This is a pseudo-op of the form "adr rd, label" to be converted
8439 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8440
8441static void
c19d1205 8442do_adr (void)
09d92015 8443{
c19d1205 8444 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8445
c19d1205
ZW
8446 /* Frag hacking will turn this into a sub instruction if the offset turns
8447 out to be negative. */
e2b0ab59
AV
8448 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
8449 inst.relocs[0].pc_rel = 1;
8450 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 8451
fc6141f0 8452 if (support_interwork
e2b0ab59
AV
8453 && inst.relocs[0].exp.X_op == O_symbol
8454 && inst.relocs[0].exp.X_add_symbol != NULL
8455 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
8456 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
8457 inst.relocs[0].exp.X_add_number |= 1;
c19d1205 8458}
b99bd4ef 8459
c19d1205
ZW
8460/* This is a pseudo-op of the form "adrl rd, label" to be converted
8461 into a relative address of the form:
8462 add rd, pc, #low(label-.-8)"
8463 add rd, rd, #high(label-.-8)" */
b99bd4ef 8464
c19d1205
ZW
8465static void
8466do_adrl (void)
8467{
8468 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8469
c19d1205
ZW
8470 /* Frag hacking will turn this into a sub instruction if the offset turns
8471 out to be negative. */
e2b0ab59
AV
8472 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
8473 inst.relocs[0].pc_rel = 1;
c19d1205 8474 inst.size = INSN_SIZE * 2;
e2b0ab59 8475 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 8476
fc6141f0 8477 if (support_interwork
e2b0ab59
AV
8478 && inst.relocs[0].exp.X_op == O_symbol
8479 && inst.relocs[0].exp.X_add_symbol != NULL
8480 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
8481 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
8482 inst.relocs[0].exp.X_add_number |= 1;
b99bd4ef
NC
8483}
8484
b99bd4ef 8485static void
c19d1205 8486do_arit (void)
b99bd4ef 8487{
e2b0ab59
AV
8488 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8489 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 8490 THUMB1_RELOC_ONLY);
c19d1205
ZW
8491 if (!inst.operands[1].present)
8492 inst.operands[1].reg = inst.operands[0].reg;
8493 inst.instruction |= inst.operands[0].reg << 12;
8494 inst.instruction |= inst.operands[1].reg << 16;
8495 encode_arm_shifter_operand (2);
8496}
b99bd4ef 8497
62b3e311
PB
8498static void
8499do_barrier (void)
8500{
8501 if (inst.operands[0].present)
ccb84d65 8502 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8503 else
8504 inst.instruction |= 0xf;
8505}
8506
c19d1205
ZW
8507static void
8508do_bfc (void)
8509{
8510 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8511 constraint (msb > 32, _("bit-field extends past end of register"));
8512 /* The instruction encoding stores the LSB and MSB,
8513 not the LSB and width. */
8514 inst.instruction |= inst.operands[0].reg << 12;
8515 inst.instruction |= inst.operands[1].imm << 7;
8516 inst.instruction |= (msb - 1) << 16;
8517}
b99bd4ef 8518
c19d1205
ZW
8519static void
8520do_bfi (void)
8521{
8522 unsigned int msb;
b99bd4ef 8523
c19d1205
ZW
8524 /* #0 in second position is alternative syntax for bfc, which is
8525 the same instruction but with REG_PC in the Rm field. */
8526 if (!inst.operands[1].isreg)
8527 inst.operands[1].reg = REG_PC;
b99bd4ef 8528
c19d1205
ZW
8529 msb = inst.operands[2].imm + inst.operands[3].imm;
8530 constraint (msb > 32, _("bit-field extends past end of register"));
8531 /* The instruction encoding stores the LSB and MSB,
8532 not the LSB and width. */
8533 inst.instruction |= inst.operands[0].reg << 12;
8534 inst.instruction |= inst.operands[1].reg;
8535 inst.instruction |= inst.operands[2].imm << 7;
8536 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8537}
8538
b99bd4ef 8539static void
c19d1205 8540do_bfx (void)
b99bd4ef 8541{
c19d1205
ZW
8542 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8543 _("bit-field extends past end of register"));
8544 inst.instruction |= inst.operands[0].reg << 12;
8545 inst.instruction |= inst.operands[1].reg;
8546 inst.instruction |= inst.operands[2].imm << 7;
8547 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8548}
09d92015 8549
c19d1205
ZW
8550/* ARM V5 breakpoint instruction (argument parse)
8551 BKPT <16 bit unsigned immediate>
8552 Instruction is not conditional.
8553 The bit pattern given in insns[] has the COND_ALWAYS condition,
8554 and it is an error if the caller tried to override that. */
b99bd4ef 8555
c19d1205
ZW
8556static void
8557do_bkpt (void)
8558{
8559 /* Top 12 of 16 bits to bits 19:8. */
8560 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8561
c19d1205
ZW
8562 /* Bottom 4 of 16 bits to bits 3:0. */
8563 inst.instruction |= inst.operands[0].imm & 0xf;
8564}
09d92015 8565
c19d1205
ZW
8566static void
8567encode_branch (int default_reloc)
8568{
8569 if (inst.operands[0].hasreloc)
8570 {
0855e32b
NS
8571 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8572 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8573 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
e2b0ab59 8574 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
0855e32b
NS
8575 ? BFD_RELOC_ARM_PLT32
8576 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8577 }
b99bd4ef 8578 else
e2b0ab59
AV
8579 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
8580 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
8581}
8582
b99bd4ef 8583static void
c19d1205 8584do_branch (void)
b99bd4ef 8585{
39b41c9c
PB
8586#ifdef OBJ_ELF
8587 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8588 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8589 else
8590#endif
8591 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8592}
8593
8594static void
8595do_bl (void)
8596{
8597#ifdef OBJ_ELF
8598 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8599 {
8600 if (inst.cond == COND_ALWAYS)
8601 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8602 else
8603 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8604 }
8605 else
8606#endif
8607 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8608}
b99bd4ef 8609
c19d1205
ZW
8610/* ARM V5 branch-link-exchange instruction (argument parse)
8611 BLX <target_addr> ie BLX(1)
8612 BLX{<condition>} <Rm> ie BLX(2)
8613 Unfortunately, there are two different opcodes for this mnemonic.
8614 So, the insns[].value is not used, and the code here zaps values
8615 into inst.instruction.
8616 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8617
c19d1205
ZW
8618static void
8619do_blx (void)
8620{
8621 if (inst.operands[0].isreg)
b99bd4ef 8622 {
c19d1205
ZW
8623 /* Arg is a register; the opcode provided by insns[] is correct.
8624 It is not illegal to do "blx pc", just useless. */
8625 if (inst.operands[0].reg == REG_PC)
8626 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8627
c19d1205
ZW
8628 inst.instruction |= inst.operands[0].reg;
8629 }
8630 else
b99bd4ef 8631 {
c19d1205 8632 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8633 conditionally, and the opcode must be adjusted.
8634 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8635 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8636 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8637 inst.instruction = 0xfa000000;
267bf995 8638 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8639 }
c19d1205
ZW
8640}
8641
8642static void
8643do_bx (void)
8644{
845b51d6
PB
8645 bfd_boolean want_reloc;
8646
c19d1205
ZW
8647 if (inst.operands[0].reg == REG_PC)
8648 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8649
c19d1205 8650 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8651 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8652 it is for ARMv4t or earlier. */
8653 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
4d354d8b
TP
8654 if (!ARM_FEATURE_ZERO (selected_object_arch)
8655 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
845b51d6
PB
8656 want_reloc = TRUE;
8657
5ad34203 8658#ifdef OBJ_ELF
845b51d6 8659 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8660#endif
584206db 8661 want_reloc = FALSE;
845b51d6
PB
8662
8663 if (want_reloc)
e2b0ab59 8664 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8665}
8666
c19d1205
ZW
8667
8668/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8669
8670static void
c19d1205 8671do_bxj (void)
a737bd4d 8672{
c19d1205
ZW
8673 if (inst.operands[0].reg == REG_PC)
8674 as_tsktsk (_("use of r15 in bxj is not really useful"));
8675
8676 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8677}
8678
c19d1205
ZW
8679/* Co-processor data operation:
8680 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8681 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8682static void
8683do_cdp (void)
8684{
8685 inst.instruction |= inst.operands[0].reg << 8;
8686 inst.instruction |= inst.operands[1].imm << 20;
8687 inst.instruction |= inst.operands[2].reg << 12;
8688 inst.instruction |= inst.operands[3].reg << 16;
8689 inst.instruction |= inst.operands[4].reg;
8690 inst.instruction |= inst.operands[5].imm << 5;
8691}
a737bd4d
NC
8692
8693static void
c19d1205 8694do_cmp (void)
a737bd4d 8695{
c19d1205
ZW
8696 inst.instruction |= inst.operands[0].reg << 16;
8697 encode_arm_shifter_operand (1);
a737bd4d
NC
8698}
8699
c19d1205
ZW
8700/* Transfer between coprocessor and ARM registers.
8701 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8702 MRC2
8703 MCR{cond}
8704 MCR2
8705
8706 No special properties. */
09d92015 8707
dcbd0d71
MGD
8708struct deprecated_coproc_regs_s
8709{
8710 unsigned cp;
8711 int opc1;
8712 unsigned crn;
8713 unsigned crm;
8714 int opc2;
8715 arm_feature_set deprecated;
8716 arm_feature_set obsoleted;
8717 const char *dep_msg;
8718 const char *obs_msg;
8719};
8720
8721#define DEPR_ACCESS_V8 \
8722 N_("This coprocessor register access is deprecated in ARMv8")
8723
8724/* Table of all deprecated coprocessor registers. */
8725static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8726{
8727 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8728 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8729 DEPR_ACCESS_V8, NULL},
8730 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8731 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8732 DEPR_ACCESS_V8, NULL},
8733 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8734 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8735 DEPR_ACCESS_V8, NULL},
8736 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8737 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8738 DEPR_ACCESS_V8, NULL},
8739 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8740 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8741 DEPR_ACCESS_V8, NULL},
8742};
8743
8744#undef DEPR_ACCESS_V8
8745
8746static const size_t deprecated_coproc_reg_count =
8747 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8748
09d92015 8749static void
c19d1205 8750do_co_reg (void)
09d92015 8751{
fdfde340 8752 unsigned Rd;
dcbd0d71 8753 size_t i;
fdfde340
JM
8754
8755 Rd = inst.operands[2].reg;
8756 if (thumb_mode)
8757 {
8758 if (inst.instruction == 0xee000010
8759 || inst.instruction == 0xfe000010)
8760 /* MCR, MCR2 */
8761 reject_bad_reg (Rd);
5c8ed6a4 8762 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
8763 /* MRC, MRC2 */
8764 constraint (Rd == REG_SP, BAD_SP);
8765 }
8766 else
8767 {
8768 /* MCR */
8769 if (inst.instruction == 0xe000010)
8770 constraint (Rd == REG_PC, BAD_PC);
8771 }
8772
dcbd0d71
MGD
8773 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8774 {
8775 const struct deprecated_coproc_regs_s *r =
8776 deprecated_coproc_regs + i;
8777
8778 if (inst.operands[0].reg == r->cp
8779 && inst.operands[1].imm == r->opc1
8780 && inst.operands[3].reg == r->crn
8781 && inst.operands[4].reg == r->crm
8782 && inst.operands[5].imm == r->opc2)
8783 {
b10bf8c5 8784 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8785 && warn_on_deprecated
dcbd0d71 8786 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8787 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8788 }
8789 }
fdfde340 8790
c19d1205
ZW
8791 inst.instruction |= inst.operands[0].reg << 8;
8792 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8793 inst.instruction |= Rd << 12;
c19d1205
ZW
8794 inst.instruction |= inst.operands[3].reg << 16;
8795 inst.instruction |= inst.operands[4].reg;
8796 inst.instruction |= inst.operands[5].imm << 5;
8797}
09d92015 8798
c19d1205
ZW
8799/* Transfer between coprocessor register and pair of ARM registers.
8800 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8801 MCRR2
8802 MRRC{cond}
8803 MRRC2
b99bd4ef 8804
c19d1205 8805 Two XScale instructions are special cases of these:
09d92015 8806
c19d1205
ZW
8807 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8808 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8809
5f4273c7 8810 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8811
c19d1205
ZW
8812static void
8813do_co_reg2c (void)
8814{
fdfde340
JM
8815 unsigned Rd, Rn;
8816
8817 Rd = inst.operands[2].reg;
8818 Rn = inst.operands[3].reg;
8819
8820 if (thumb_mode)
8821 {
8822 reject_bad_reg (Rd);
8823 reject_bad_reg (Rn);
8824 }
8825 else
8826 {
8827 constraint (Rd == REG_PC, BAD_PC);
8828 constraint (Rn == REG_PC, BAD_PC);
8829 }
8830
873f10f0
TC
8831 /* Only check the MRRC{2} variants. */
8832 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8833 {
8834 /* If Rd == Rn, error that the operation is
8835 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8836 constraint (Rd == Rn, BAD_OVERLAP);
8837 }
8838
c19d1205
ZW
8839 inst.instruction |= inst.operands[0].reg << 8;
8840 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8841 inst.instruction |= Rd << 12;
8842 inst.instruction |= Rn << 16;
c19d1205 8843 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8844}
8845
c19d1205
ZW
8846static void
8847do_cpsi (void)
8848{
8849 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8850 if (inst.operands[1].present)
8851 {
8852 inst.instruction |= CPSI_MMOD;
8853 inst.instruction |= inst.operands[1].imm;
8854 }
c19d1205 8855}
b99bd4ef 8856
62b3e311
PB
8857static void
8858do_dbg (void)
8859{
8860 inst.instruction |= inst.operands[0].imm;
8861}
8862
eea54501
MGD
8863static void
8864do_div (void)
8865{
8866 unsigned Rd, Rn, Rm;
8867
8868 Rd = inst.operands[0].reg;
8869 Rn = (inst.operands[1].present
8870 ? inst.operands[1].reg : Rd);
8871 Rm = inst.operands[2].reg;
8872
8873 constraint ((Rd == REG_PC), BAD_PC);
8874 constraint ((Rn == REG_PC), BAD_PC);
8875 constraint ((Rm == REG_PC), BAD_PC);
8876
8877 inst.instruction |= Rd << 16;
8878 inst.instruction |= Rn << 0;
8879 inst.instruction |= Rm << 8;
8880}
8881
b99bd4ef 8882static void
c19d1205 8883do_it (void)
b99bd4ef 8884{
c19d1205 8885 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8886 process it to do the validation as if in
8887 thumb mode, just in case the code gets
8888 assembled for thumb using the unified syntax. */
8889
c19d1205 8890 inst.size = 0;
e07e6e58
NC
8891 if (unified_syntax)
8892 {
8893 set_it_insn_type (IT_INSN);
8894 now_it.mask = (inst.instruction & 0xf) | 0x10;
8895 now_it.cc = inst.operands[0].imm;
8896 }
09d92015 8897}
b99bd4ef 8898
6530b175
NC
8899/* If there is only one register in the register list,
8900 then return its register number. Otherwise return -1. */
8901static int
8902only_one_reg_in_list (int range)
8903{
8904 int i = ffs (range) - 1;
8905 return (i > 15 || range != (1 << i)) ? -1 : i;
8906}
8907
09d92015 8908static void
6530b175 8909encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8910{
c19d1205
ZW
8911 int base_reg = inst.operands[0].reg;
8912 int range = inst.operands[1].imm;
6530b175 8913 int one_reg;
ea6ef066 8914
c19d1205
ZW
8915 inst.instruction |= base_reg << 16;
8916 inst.instruction |= range;
ea6ef066 8917
c19d1205
ZW
8918 if (inst.operands[1].writeback)
8919 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8920
c19d1205 8921 if (inst.operands[0].writeback)
ea6ef066 8922 {
c19d1205
ZW
8923 inst.instruction |= WRITE_BACK;
8924 /* Check for unpredictable uses of writeback. */
8925 if (inst.instruction & LOAD_BIT)
09d92015 8926 {
c19d1205
ZW
8927 /* Not allowed in LDM type 2. */
8928 if ((inst.instruction & LDM_TYPE_2_OR_3)
8929 && ((range & (1 << REG_PC)) == 0))
8930 as_warn (_("writeback of base register is UNPREDICTABLE"));
8931 /* Only allowed if base reg not in list for other types. */
8932 else if (range & (1 << base_reg))
8933 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8934 }
8935 else /* STM. */
8936 {
8937 /* Not allowed for type 2. */
8938 if (inst.instruction & LDM_TYPE_2_OR_3)
8939 as_warn (_("writeback of base register is UNPREDICTABLE"));
8940 /* Only allowed if base reg not in list, or first in list. */
8941 else if ((range & (1 << base_reg))
8942 && (range & ((1 << base_reg) - 1)))
8943 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8944 }
ea6ef066 8945 }
6530b175
NC
8946
8947 /* If PUSH/POP has only one register, then use the A2 encoding. */
8948 one_reg = only_one_reg_in_list (range);
8949 if (from_push_pop_mnem && one_reg >= 0)
8950 {
8951 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8952
4f588891
NC
8953 if (is_push && one_reg == 13 /* SP */)
8954 /* PR 22483: The A2 encoding cannot be used when
8955 pushing the stack pointer as this is UNPREDICTABLE. */
8956 return;
8957
6530b175
NC
8958 inst.instruction &= A_COND_MASK;
8959 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8960 inst.instruction |= one_reg << 12;
8961 }
8962}
8963
8964static void
8965do_ldmstm (void)
8966{
8967 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8968}
8969
c19d1205
ZW
8970/* ARMv5TE load-consecutive (argument parse)
8971 Mode is like LDRH.
8972
8973 LDRccD R, mode
8974 STRccD R, mode. */
8975
a737bd4d 8976static void
c19d1205 8977do_ldrd (void)
a737bd4d 8978{
c19d1205 8979 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8980 _("first transfer register must be even"));
c19d1205
ZW
8981 constraint (inst.operands[1].present
8982 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8983 _("can only transfer two consecutive registers"));
c19d1205
ZW
8984 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8985 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8986
c19d1205
ZW
8987 if (!inst.operands[1].present)
8988 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8989
c56791bb
RE
8990 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8991 register and the first register written; we have to diagnose
8992 overlap between the base and the second register written here. */
ea6ef066 8993
c56791bb
RE
8994 if (inst.operands[2].reg == inst.operands[1].reg
8995 && (inst.operands[2].writeback || inst.operands[2].postind))
8996 as_warn (_("base register written back, and overlaps "
8997 "second transfer register"));
b05fe5cf 8998
c56791bb
RE
8999 if (!(inst.instruction & V4_STR_BIT))
9000 {
c19d1205 9001 /* For an index-register load, the index register must not overlap the
c56791bb
RE
9002 destination (even if not write-back). */
9003 if (inst.operands[2].immisreg
9004 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9005 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9006 as_warn (_("index register overlaps transfer register"));
b05fe5cf 9007 }
c19d1205
ZW
9008 inst.instruction |= inst.operands[0].reg << 12;
9009 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
9010}
9011
9012static void
c19d1205 9013do_ldrex (void)
b05fe5cf 9014{
c19d1205
ZW
9015 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9016 || inst.operands[1].postind || inst.operands[1].writeback
9017 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
9018 || inst.operands[1].negative
9019 /* This can arise if the programmer has written
9020 strex rN, rM, foo
9021 or if they have mistakenly used a register name as the last
9022 operand, eg:
9023 strex rN, rM, rX
9024 It is very difficult to distinguish between these two cases
9025 because "rX" might actually be a label. ie the register
9026 name has been occluded by a symbol of the same name. So we
9027 just generate a general 'bad addressing mode' type error
9028 message and leave it up to the programmer to discover the
9029 true cause and fix their mistake. */
9030 || (inst.operands[1].reg == REG_PC),
9031 BAD_ADDR_MODE);
b05fe5cf 9032
e2b0ab59
AV
9033 constraint (inst.relocs[0].exp.X_op != O_constant
9034 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9035 _("offset must be zero in ARM encoding"));
b05fe5cf 9036
5be8be5d
DG
9037 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9038
c19d1205
ZW
9039 inst.instruction |= inst.operands[0].reg << 12;
9040 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 9041 inst.relocs[0].type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
9042}
9043
9044static void
c19d1205 9045do_ldrexd (void)
b05fe5cf 9046{
c19d1205
ZW
9047 constraint (inst.operands[0].reg % 2 != 0,
9048 _("even register required"));
9049 constraint (inst.operands[1].present
9050 && inst.operands[1].reg != inst.operands[0].reg + 1,
9051 _("can only load two consecutive registers"));
9052 /* If op 1 were present and equal to PC, this function wouldn't
9053 have been called in the first place. */
9054 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9055
c19d1205
ZW
9056 inst.instruction |= inst.operands[0].reg << 12;
9057 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9058}
9059
1be5fd2e
NC
9060/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9061 which is not a multiple of four is UNPREDICTABLE. */
9062static void
9063check_ldr_r15_aligned (void)
9064{
9065 constraint (!(inst.operands[1].immisreg)
9066 && (inst.operands[0].reg == REG_PC
9067 && inst.operands[1].reg == REG_PC
e2b0ab59 9068 && (inst.relocs[0].exp.X_add_number & 0x3)),
de194d85 9069 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9070}
9071
b05fe5cf 9072static void
c19d1205 9073do_ldst (void)
b05fe5cf 9074{
c19d1205
ZW
9075 inst.instruction |= inst.operands[0].reg << 12;
9076 if (!inst.operands[1].isreg)
8335d6aa 9077 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9078 return;
c19d1205 9079 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9080 check_ldr_r15_aligned ();
b05fe5cf
ZW
9081}
9082
9083static void
c19d1205 9084do_ldstt (void)
b05fe5cf 9085{
c19d1205
ZW
9086 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9087 reject [Rn,...]. */
9088 if (inst.operands[1].preind)
b05fe5cf 9089 {
e2b0ab59
AV
9090 constraint (inst.relocs[0].exp.X_op != O_constant
9091 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9092 _("this instruction requires a post-indexed address"));
b05fe5cf 9093
c19d1205
ZW
9094 inst.operands[1].preind = 0;
9095 inst.operands[1].postind = 1;
9096 inst.operands[1].writeback = 1;
b05fe5cf 9097 }
c19d1205
ZW
9098 inst.instruction |= inst.operands[0].reg << 12;
9099 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9100}
b05fe5cf 9101
c19d1205 9102/* Halfword and signed-byte load/store operations. */
b05fe5cf 9103
c19d1205
ZW
9104static void
9105do_ldstv4 (void)
9106{
ff4a8d2b 9107 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9108 inst.instruction |= inst.operands[0].reg << 12;
9109 if (!inst.operands[1].isreg)
8335d6aa 9110 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9111 return;
c19d1205 9112 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9113}
9114
9115static void
c19d1205 9116do_ldsttv4 (void)
b05fe5cf 9117{
c19d1205
ZW
9118 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9119 reject [Rn,...]. */
9120 if (inst.operands[1].preind)
b05fe5cf 9121 {
e2b0ab59
AV
9122 constraint (inst.relocs[0].exp.X_op != O_constant
9123 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9124 _("this instruction requires a post-indexed address"));
b05fe5cf 9125
c19d1205
ZW
9126 inst.operands[1].preind = 0;
9127 inst.operands[1].postind = 1;
9128 inst.operands[1].writeback = 1;
b05fe5cf 9129 }
c19d1205
ZW
9130 inst.instruction |= inst.operands[0].reg << 12;
9131 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9132}
b05fe5cf 9133
c19d1205
ZW
9134/* Co-processor register load/store.
9135 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9136static void
9137do_lstc (void)
9138{
9139 inst.instruction |= inst.operands[0].reg << 8;
9140 inst.instruction |= inst.operands[1].reg << 12;
9141 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9142}
9143
b05fe5cf 9144static void
c19d1205 9145do_mlas (void)
b05fe5cf 9146{
8fb9d7b9 9147 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9148 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9149 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9150 && !(inst.instruction & 0x00400000))
8fb9d7b9 9151 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9152
c19d1205
ZW
9153 inst.instruction |= inst.operands[0].reg << 16;
9154 inst.instruction |= inst.operands[1].reg;
9155 inst.instruction |= inst.operands[2].reg << 8;
9156 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9157}
b05fe5cf 9158
c19d1205
ZW
9159static void
9160do_mov (void)
9161{
e2b0ab59
AV
9162 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9163 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9164 THUMB1_RELOC_ONLY);
c19d1205
ZW
9165 inst.instruction |= inst.operands[0].reg << 12;
9166 encode_arm_shifter_operand (1);
9167}
b05fe5cf 9168
c19d1205
ZW
9169/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9170static void
9171do_mov16 (void)
9172{
b6895b4f
PB
9173 bfd_vma imm;
9174 bfd_boolean top;
9175
9176 top = (inst.instruction & 0x00400000) != 0;
e2b0ab59 9177 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
33eaf5de 9178 _(":lower16: not allowed in this instruction"));
e2b0ab59 9179 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
33eaf5de 9180 _(":upper16: not allowed in this instruction"));
c19d1205 9181 inst.instruction |= inst.operands[0].reg << 12;
e2b0ab59 9182 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 9183 {
e2b0ab59 9184 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
9185 /* The value is in two pieces: 0:11, 16:19. */
9186 inst.instruction |= (imm & 0x00000fff);
9187 inst.instruction |= (imm & 0x0000f000) << 4;
9188 }
b05fe5cf 9189}
b99bd4ef 9190
037e8744
JB
9191static int
9192do_vfp_nsyn_mrs (void)
9193{
9194 if (inst.operands[0].isvec)
9195 {
9196 if (inst.operands[1].reg != 1)
477330fc 9197 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9198 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9199 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9200 do_vfp_nsyn_opcode ("fmstat");
9201 }
9202 else if (inst.operands[1].isvec)
9203 do_vfp_nsyn_opcode ("fmrx");
9204 else
9205 return FAIL;
5f4273c7 9206
037e8744
JB
9207 return SUCCESS;
9208}
9209
9210static int
9211do_vfp_nsyn_msr (void)
9212{
9213 if (inst.operands[0].isvec)
9214 do_vfp_nsyn_opcode ("fmxr");
9215 else
9216 return FAIL;
9217
9218 return SUCCESS;
9219}
9220
f7c21dc7
NC
9221static void
9222do_vmrs (void)
9223{
9224 unsigned Rt = inst.operands[0].reg;
fa94de6b 9225
16d02dc9 9226 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9227 {
9228 inst.error = BAD_SP;
9229 return;
9230 }
9231
40c7d507
RR
9232 /* MVFR2 is only valid at ARMv8-A. */
9233 if (inst.operands[1].reg == 5)
9234 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9235 _(BAD_FPU));
9236
f7c21dc7 9237 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9238 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9239 {
9240 inst.error = BAD_PC;
9241 return;
9242 }
9243
16d02dc9
JB
9244 /* If we get through parsing the register name, we just insert the number
9245 generated into the instruction without further validation. */
9246 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9247 inst.instruction |= (Rt << 12);
9248}
9249
9250static void
9251do_vmsr (void)
9252{
9253 unsigned Rt = inst.operands[1].reg;
fa94de6b 9254
f7c21dc7
NC
9255 if (thumb_mode)
9256 reject_bad_reg (Rt);
9257 else if (Rt == REG_PC)
9258 {
9259 inst.error = BAD_PC;
9260 return;
9261 }
9262
40c7d507
RR
9263 /* MVFR2 is only valid for ARMv8-A. */
9264 if (inst.operands[0].reg == 5)
9265 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9266 _(BAD_FPU));
9267
16d02dc9
JB
9268 /* If we get through parsing the register name, we just insert the number
9269 generated into the instruction without further validation. */
9270 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9271 inst.instruction |= (Rt << 12);
9272}
9273
b99bd4ef 9274static void
c19d1205 9275do_mrs (void)
b99bd4ef 9276{
90ec0d68
MGD
9277 unsigned br;
9278
037e8744
JB
9279 if (do_vfp_nsyn_mrs () == SUCCESS)
9280 return;
9281
ff4a8d2b 9282 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9283 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9284
9285 if (inst.operands[1].isreg)
9286 {
9287 br = inst.operands[1].reg;
806ab1c0 9288 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
90ec0d68
MGD
9289 as_bad (_("bad register for mrs"));
9290 }
9291 else
9292 {
9293 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9294 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9295 != (PSR_c|PSR_f),
d2cd1205 9296 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9297 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9298 }
9299
9300 inst.instruction |= br;
c19d1205 9301}
b99bd4ef 9302
c19d1205
ZW
9303/* Two possible forms:
9304 "{C|S}PSR_<field>, Rm",
9305 "{C|S}PSR_f, #expression". */
b99bd4ef 9306
c19d1205
ZW
9307static void
9308do_msr (void)
9309{
037e8744
JB
9310 if (do_vfp_nsyn_msr () == SUCCESS)
9311 return;
9312
c19d1205
ZW
9313 inst.instruction |= inst.operands[0].imm;
9314 if (inst.operands[1].isreg)
9315 inst.instruction |= inst.operands[1].reg;
9316 else
b99bd4ef 9317 {
c19d1205 9318 inst.instruction |= INST_IMMEDIATE;
e2b0ab59
AV
9319 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9320 inst.relocs[0].pc_rel = 0;
b99bd4ef 9321 }
b99bd4ef
NC
9322}
9323
c19d1205
ZW
9324static void
9325do_mul (void)
a737bd4d 9326{
ff4a8d2b
NC
9327 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9328
c19d1205
ZW
9329 if (!inst.operands[2].present)
9330 inst.operands[2].reg = inst.operands[0].reg;
9331 inst.instruction |= inst.operands[0].reg << 16;
9332 inst.instruction |= inst.operands[1].reg;
9333 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9334
8fb9d7b9
MS
9335 if (inst.operands[0].reg == inst.operands[1].reg
9336 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9337 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9338}
9339
c19d1205
ZW
9340/* Long Multiply Parser
9341 UMULL RdLo, RdHi, Rm, Rs
9342 SMULL RdLo, RdHi, Rm, Rs
9343 UMLAL RdLo, RdHi, Rm, Rs
9344 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9345
9346static void
c19d1205 9347do_mull (void)
b99bd4ef 9348{
c19d1205
ZW
9349 inst.instruction |= inst.operands[0].reg << 12;
9350 inst.instruction |= inst.operands[1].reg << 16;
9351 inst.instruction |= inst.operands[2].reg;
9352 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9353
682b27ad
PB
9354 /* rdhi and rdlo must be different. */
9355 if (inst.operands[0].reg == inst.operands[1].reg)
9356 as_tsktsk (_("rdhi and rdlo must be different"));
9357
9358 /* rdhi, rdlo and rm must all be different before armv6. */
9359 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9360 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9361 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9362 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9363}
b99bd4ef 9364
c19d1205
ZW
9365static void
9366do_nop (void)
9367{
e7495e45
NS
9368 if (inst.operands[0].present
9369 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9370 {
9371 /* Architectural NOP hints are CPSR sets with no bits selected. */
9372 inst.instruction &= 0xf0000000;
e7495e45
NS
9373 inst.instruction |= 0x0320f000;
9374 if (inst.operands[0].present)
9375 inst.instruction |= inst.operands[0].imm;
c19d1205 9376 }
b99bd4ef
NC
9377}
9378
c19d1205
ZW
9379/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9380 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9381 Condition defaults to COND_ALWAYS.
9382 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9383
9384static void
c19d1205 9385do_pkhbt (void)
b99bd4ef 9386{
c19d1205
ZW
9387 inst.instruction |= inst.operands[0].reg << 12;
9388 inst.instruction |= inst.operands[1].reg << 16;
9389 inst.instruction |= inst.operands[2].reg;
9390 if (inst.operands[3].present)
9391 encode_arm_shift (3);
9392}
b99bd4ef 9393
c19d1205 9394/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9395
c19d1205
ZW
9396static void
9397do_pkhtb (void)
9398{
9399 if (!inst.operands[3].present)
b99bd4ef 9400 {
c19d1205
ZW
9401 /* If the shift specifier is omitted, turn the instruction
9402 into pkhbt rd, rm, rn. */
9403 inst.instruction &= 0xfff00010;
9404 inst.instruction |= inst.operands[0].reg << 12;
9405 inst.instruction |= inst.operands[1].reg;
9406 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9407 }
9408 else
9409 {
c19d1205
ZW
9410 inst.instruction |= inst.operands[0].reg << 12;
9411 inst.instruction |= inst.operands[1].reg << 16;
9412 inst.instruction |= inst.operands[2].reg;
9413 encode_arm_shift (3);
b99bd4ef
NC
9414 }
9415}
9416
c19d1205 9417/* ARMv5TE: Preload-Cache
60e5ef9f 9418 MP Extensions: Preload for write
c19d1205 9419
60e5ef9f 9420 PLD(W) <addr_mode>
c19d1205
ZW
9421
9422 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9423
9424static void
c19d1205 9425do_pld (void)
b99bd4ef 9426{
c19d1205
ZW
9427 constraint (!inst.operands[0].isreg,
9428 _("'[' expected after PLD mnemonic"));
9429 constraint (inst.operands[0].postind,
9430 _("post-indexed expression used in preload instruction"));
9431 constraint (inst.operands[0].writeback,
9432 _("writeback used in preload instruction"));
9433 constraint (!inst.operands[0].preind,
9434 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9435 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9436}
b99bd4ef 9437
62b3e311
PB
9438/* ARMv7: PLI <addr_mode> */
9439static void
9440do_pli (void)
9441{
9442 constraint (!inst.operands[0].isreg,
9443 _("'[' expected after PLI mnemonic"));
9444 constraint (inst.operands[0].postind,
9445 _("post-indexed expression used in preload instruction"));
9446 constraint (inst.operands[0].writeback,
9447 _("writeback used in preload instruction"));
9448 constraint (!inst.operands[0].preind,
9449 _("unindexed addressing used in preload instruction"));
9450 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9451 inst.instruction &= ~PRE_INDEX;
9452}
9453
c19d1205
ZW
9454static void
9455do_push_pop (void)
9456{
5e0d7f77
MP
9457 constraint (inst.operands[0].writeback,
9458 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9459 inst.operands[1] = inst.operands[0];
9460 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9461 inst.operands[0].isreg = 1;
9462 inst.operands[0].writeback = 1;
9463 inst.operands[0].reg = REG_SP;
6530b175 9464 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9465}
b99bd4ef 9466
c19d1205
ZW
9467/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9468 word at the specified address and the following word
9469 respectively.
9470 Unconditionally executed.
9471 Error if Rn is R15. */
b99bd4ef 9472
c19d1205
ZW
9473static void
9474do_rfe (void)
9475{
9476 inst.instruction |= inst.operands[0].reg << 16;
9477 if (inst.operands[0].writeback)
9478 inst.instruction |= WRITE_BACK;
9479}
b99bd4ef 9480
c19d1205 9481/* ARM V6 ssat (argument parse). */
b99bd4ef 9482
c19d1205
ZW
9483static void
9484do_ssat (void)
9485{
9486 inst.instruction |= inst.operands[0].reg << 12;
9487 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9488 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9489
c19d1205
ZW
9490 if (inst.operands[3].present)
9491 encode_arm_shift (3);
b99bd4ef
NC
9492}
9493
c19d1205 9494/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9495
9496static void
c19d1205 9497do_usat (void)
b99bd4ef 9498{
c19d1205
ZW
9499 inst.instruction |= inst.operands[0].reg << 12;
9500 inst.instruction |= inst.operands[1].imm << 16;
9501 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9502
c19d1205
ZW
9503 if (inst.operands[3].present)
9504 encode_arm_shift (3);
b99bd4ef
NC
9505}
9506
c19d1205 9507/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9508
9509static void
c19d1205 9510do_ssat16 (void)
09d92015 9511{
c19d1205
ZW
9512 inst.instruction |= inst.operands[0].reg << 12;
9513 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9514 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9515}
9516
c19d1205
ZW
9517static void
9518do_usat16 (void)
a737bd4d 9519{
c19d1205
ZW
9520 inst.instruction |= inst.operands[0].reg << 12;
9521 inst.instruction |= inst.operands[1].imm << 16;
9522 inst.instruction |= inst.operands[2].reg;
9523}
a737bd4d 9524
c19d1205
ZW
9525/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9526 preserving the other bits.
a737bd4d 9527
c19d1205
ZW
9528 setend <endian_specifier>, where <endian_specifier> is either
9529 BE or LE. */
a737bd4d 9530
c19d1205
ZW
9531static void
9532do_setend (void)
9533{
12e37cbc
MGD
9534 if (warn_on_deprecated
9535 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9536 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9537
c19d1205
ZW
9538 if (inst.operands[0].imm)
9539 inst.instruction |= 0x200;
a737bd4d
NC
9540}
9541
9542static void
c19d1205 9543do_shift (void)
a737bd4d 9544{
c19d1205
ZW
9545 unsigned int Rm = (inst.operands[1].present
9546 ? inst.operands[1].reg
9547 : inst.operands[0].reg);
a737bd4d 9548
c19d1205
ZW
9549 inst.instruction |= inst.operands[0].reg << 12;
9550 inst.instruction |= Rm;
9551 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9552 {
c19d1205
ZW
9553 inst.instruction |= inst.operands[2].reg << 8;
9554 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9555 /* PR 12854: Error on extraneous shifts. */
9556 constraint (inst.operands[2].shifted,
9557 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9558 }
9559 else
e2b0ab59 9560 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9561}
9562
09d92015 9563static void
3eb17e6b 9564do_smc (void)
09d92015 9565{
e2b0ab59
AV
9566 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
9567 inst.relocs[0].pc_rel = 0;
09d92015
MM
9568}
9569
90ec0d68
MGD
9570static void
9571do_hvc (void)
9572{
e2b0ab59
AV
9573 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
9574 inst.relocs[0].pc_rel = 0;
90ec0d68
MGD
9575}
9576
09d92015 9577static void
c19d1205 9578do_swi (void)
09d92015 9579{
e2b0ab59
AV
9580 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
9581 inst.relocs[0].pc_rel = 0;
09d92015
MM
9582}
9583
ddfded2f
MW
9584static void
9585do_setpan (void)
9586{
9587 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9588 _("selected processor does not support SETPAN instruction"));
9589
9590 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9591}
9592
9593static void
9594do_t_setpan (void)
9595{
9596 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9597 _("selected processor does not support SETPAN instruction"));
9598
9599 inst.instruction |= (inst.operands[0].imm << 3);
9600}
9601
c19d1205
ZW
9602/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9603 SMLAxy{cond} Rd,Rm,Rs,Rn
9604 SMLAWy{cond} Rd,Rm,Rs,Rn
9605 Error if any register is R15. */
e16bb312 9606
c19d1205
ZW
9607static void
9608do_smla (void)
e16bb312 9609{
c19d1205
ZW
9610 inst.instruction |= inst.operands[0].reg << 16;
9611 inst.instruction |= inst.operands[1].reg;
9612 inst.instruction |= inst.operands[2].reg << 8;
9613 inst.instruction |= inst.operands[3].reg << 12;
9614}
a737bd4d 9615
c19d1205
ZW
9616/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9617 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9618 Error if any register is R15.
9619 Warning if Rdlo == Rdhi. */
a737bd4d 9620
c19d1205
ZW
9621static void
9622do_smlal (void)
9623{
9624 inst.instruction |= inst.operands[0].reg << 12;
9625 inst.instruction |= inst.operands[1].reg << 16;
9626 inst.instruction |= inst.operands[2].reg;
9627 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9628
c19d1205
ZW
9629 if (inst.operands[0].reg == inst.operands[1].reg)
9630 as_tsktsk (_("rdhi and rdlo must be different"));
9631}
a737bd4d 9632
c19d1205
ZW
9633/* ARM V5E (El Segundo) signed-multiply (argument parse)
9634 SMULxy{cond} Rd,Rm,Rs
9635 Error if any register is R15. */
a737bd4d 9636
c19d1205
ZW
9637static void
9638do_smul (void)
9639{
9640 inst.instruction |= inst.operands[0].reg << 16;
9641 inst.instruction |= inst.operands[1].reg;
9642 inst.instruction |= inst.operands[2].reg << 8;
9643}
a737bd4d 9644
b6702015
PB
9645/* ARM V6 srs (argument parse). The variable fields in the encoding are
9646 the same for both ARM and Thumb-2. */
a737bd4d 9647
c19d1205
ZW
9648static void
9649do_srs (void)
9650{
b6702015
PB
9651 int reg;
9652
9653 if (inst.operands[0].present)
9654 {
9655 reg = inst.operands[0].reg;
fdfde340 9656 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9657 }
9658 else
fdfde340 9659 reg = REG_SP;
b6702015
PB
9660
9661 inst.instruction |= reg << 16;
9662 inst.instruction |= inst.operands[1].imm;
9663 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9664 inst.instruction |= WRITE_BACK;
9665}
a737bd4d 9666
c19d1205 9667/* ARM V6 strex (argument parse). */
a737bd4d 9668
c19d1205
ZW
9669static void
9670do_strex (void)
9671{
9672 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9673 || inst.operands[2].postind || inst.operands[2].writeback
9674 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9675 || inst.operands[2].negative
9676 /* See comment in do_ldrex(). */
9677 || (inst.operands[2].reg == REG_PC),
9678 BAD_ADDR_MODE);
a737bd4d 9679
c19d1205
ZW
9680 constraint (inst.operands[0].reg == inst.operands[1].reg
9681 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9682
e2b0ab59
AV
9683 constraint (inst.relocs[0].exp.X_op != O_constant
9684 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9685 _("offset must be zero in ARM encoding"));
a737bd4d 9686
c19d1205
ZW
9687 inst.instruction |= inst.operands[0].reg << 12;
9688 inst.instruction |= inst.operands[1].reg;
9689 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 9690 inst.relocs[0].type = BFD_RELOC_UNUSED;
e16bb312
NC
9691}
9692
877807f8
NC
9693static void
9694do_t_strexbh (void)
9695{
9696 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9697 || inst.operands[2].postind || inst.operands[2].writeback
9698 || inst.operands[2].immisreg || inst.operands[2].shifted
9699 || inst.operands[2].negative,
9700 BAD_ADDR_MODE);
9701
9702 constraint (inst.operands[0].reg == inst.operands[1].reg
9703 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9704
9705 do_rm_rd_rn ();
9706}
9707
e16bb312 9708static void
c19d1205 9709do_strexd (void)
e16bb312 9710{
c19d1205
ZW
9711 constraint (inst.operands[1].reg % 2 != 0,
9712 _("even register required"));
9713 constraint (inst.operands[2].present
9714 && inst.operands[2].reg != inst.operands[1].reg + 1,
9715 _("can only store two consecutive registers"));
9716 /* If op 2 were present and equal to PC, this function wouldn't
9717 have been called in the first place. */
9718 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9719
c19d1205
ZW
9720 constraint (inst.operands[0].reg == inst.operands[1].reg
9721 || inst.operands[0].reg == inst.operands[1].reg + 1
9722 || inst.operands[0].reg == inst.operands[3].reg,
9723 BAD_OVERLAP);
e16bb312 9724
c19d1205
ZW
9725 inst.instruction |= inst.operands[0].reg << 12;
9726 inst.instruction |= inst.operands[1].reg;
9727 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9728}
9729
9eb6c0f1
MGD
9730/* ARM V8 STRL. */
9731static void
4b8c8c02 9732do_stlex (void)
9eb6c0f1
MGD
9733{
9734 constraint (inst.operands[0].reg == inst.operands[1].reg
9735 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9736
9737 do_rd_rm_rn ();
9738}
9739
9740static void
4b8c8c02 9741do_t_stlex (void)
9eb6c0f1
MGD
9742{
9743 constraint (inst.operands[0].reg == inst.operands[1].reg
9744 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9745
9746 do_rm_rd_rn ();
9747}
9748
c19d1205
ZW
9749/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9750 extends it to 32-bits, and adds the result to a value in another
9751 register. You can specify a rotation by 0, 8, 16, or 24 bits
9752 before extracting the 16-bit value.
9753 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9754 Condition defaults to COND_ALWAYS.
9755 Error if any register uses R15. */
9756
e16bb312 9757static void
c19d1205 9758do_sxtah (void)
e16bb312 9759{
c19d1205
ZW
9760 inst.instruction |= inst.operands[0].reg << 12;
9761 inst.instruction |= inst.operands[1].reg << 16;
9762 inst.instruction |= inst.operands[2].reg;
9763 inst.instruction |= inst.operands[3].imm << 10;
9764}
e16bb312 9765
c19d1205 9766/* ARM V6 SXTH.
e16bb312 9767
c19d1205
ZW
9768 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9769 Condition defaults to COND_ALWAYS.
9770 Error if any register uses R15. */
e16bb312
NC
9771
9772static void
c19d1205 9773do_sxth (void)
e16bb312 9774{
c19d1205
ZW
9775 inst.instruction |= inst.operands[0].reg << 12;
9776 inst.instruction |= inst.operands[1].reg;
9777 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9778}
c19d1205
ZW
9779\f
9780/* VFP instructions. In a logical order: SP variant first, monad
9781 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9782
9783static void
c19d1205 9784do_vfp_sp_monadic (void)
e16bb312 9785{
5287ad62
JB
9786 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9787 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9788}
9789
9790static void
c19d1205 9791do_vfp_sp_dyadic (void)
e16bb312 9792{
5287ad62
JB
9793 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9794 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9795 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9796}
9797
9798static void
c19d1205 9799do_vfp_sp_compare_z (void)
e16bb312 9800{
5287ad62 9801 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9802}
9803
9804static void
c19d1205 9805do_vfp_dp_sp_cvt (void)
e16bb312 9806{
5287ad62
JB
9807 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9808 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9809}
9810
9811static void
c19d1205 9812do_vfp_sp_dp_cvt (void)
e16bb312 9813{
5287ad62
JB
9814 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9815 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9816}
9817
9818static void
c19d1205 9819do_vfp_reg_from_sp (void)
e16bb312 9820{
c19d1205 9821 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9822 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9823}
9824
9825static void
c19d1205 9826do_vfp_reg2_from_sp2 (void)
e16bb312 9827{
c19d1205
ZW
9828 constraint (inst.operands[2].imm != 2,
9829 _("only two consecutive VFP SP registers allowed here"));
9830 inst.instruction |= inst.operands[0].reg << 12;
9831 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9832 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9833}
9834
9835static void
c19d1205 9836do_vfp_sp_from_reg (void)
e16bb312 9837{
5287ad62 9838 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9839 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9840}
9841
9842static void
c19d1205 9843do_vfp_sp2_from_reg2 (void)
e16bb312 9844{
c19d1205
ZW
9845 constraint (inst.operands[0].imm != 2,
9846 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9847 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9848 inst.instruction |= inst.operands[1].reg << 12;
9849 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9850}
9851
9852static void
c19d1205 9853do_vfp_sp_ldst (void)
e16bb312 9854{
5287ad62 9855 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9856 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9857}
9858
9859static void
c19d1205 9860do_vfp_dp_ldst (void)
e16bb312 9861{
5287ad62 9862 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9863 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9864}
9865
c19d1205 9866
e16bb312 9867static void
c19d1205 9868vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9869{
c19d1205
ZW
9870 if (inst.operands[0].writeback)
9871 inst.instruction |= WRITE_BACK;
9872 else
9873 constraint (ldstm_type != VFP_LDSTMIA,
9874 _("this addressing mode requires base-register writeback"));
9875 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9876 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9877 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9878}
9879
9880static void
c19d1205 9881vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9882{
c19d1205 9883 int count;
e16bb312 9884
c19d1205
ZW
9885 if (inst.operands[0].writeback)
9886 inst.instruction |= WRITE_BACK;
9887 else
9888 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9889 _("this addressing mode requires base-register writeback"));
e16bb312 9890
c19d1205 9891 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9892 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9893
c19d1205
ZW
9894 count = inst.operands[1].imm << 1;
9895 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9896 count += 1;
e16bb312 9897
c19d1205 9898 inst.instruction |= count;
e16bb312
NC
9899}
9900
9901static void
c19d1205 9902do_vfp_sp_ldstmia (void)
e16bb312 9903{
c19d1205 9904 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9905}
9906
9907static void
c19d1205 9908do_vfp_sp_ldstmdb (void)
e16bb312 9909{
c19d1205 9910 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9911}
9912
9913static void
c19d1205 9914do_vfp_dp_ldstmia (void)
e16bb312 9915{
c19d1205 9916 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9917}
9918
9919static void
c19d1205 9920do_vfp_dp_ldstmdb (void)
e16bb312 9921{
c19d1205 9922 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9923}
9924
9925static void
c19d1205 9926do_vfp_xp_ldstmia (void)
e16bb312 9927{
c19d1205
ZW
9928 vfp_dp_ldstm (VFP_LDSTMIAX);
9929}
e16bb312 9930
c19d1205
ZW
9931static void
9932do_vfp_xp_ldstmdb (void)
9933{
9934 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9935}
5287ad62
JB
9936
9937static void
9938do_vfp_dp_rd_rm (void)
9939{
9940 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9941 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9942}
9943
9944static void
9945do_vfp_dp_rn_rd (void)
9946{
9947 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9948 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9949}
9950
9951static void
9952do_vfp_dp_rd_rn (void)
9953{
9954 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9955 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9956}
9957
9958static void
9959do_vfp_dp_rd_rn_rm (void)
9960{
9961 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9962 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9963 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9964}
9965
9966static void
9967do_vfp_dp_rd (void)
9968{
9969 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9970}
9971
9972static void
9973do_vfp_dp_rm_rd_rn (void)
9974{
9975 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9976 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9977 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9978}
9979
9980/* VFPv3 instructions. */
9981static void
9982do_vfp_sp_const (void)
9983{
9984 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9985 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9986 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9987}
9988
9989static void
9990do_vfp_dp_const (void)
9991{
9992 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9993 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9994 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9995}
9996
9997static void
9998vfp_conv (int srcsize)
9999{
5f1af56b
MGD
10000 int immbits = srcsize - inst.operands[1].imm;
10001
fa94de6b
RM
10002 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10003 {
5f1af56b 10004 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 10005 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
10006 inst.error = _("immediate value out of range, expected range [0, 16]");
10007 return;
10008 }
fa94de6b 10009 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
10010 {
10011 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 10012 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
10013 inst.error = _("immediate value out of range, expected range [1, 32]");
10014 return;
10015 }
10016
5287ad62
JB
10017 inst.instruction |= (immbits & 1) << 5;
10018 inst.instruction |= (immbits >> 1);
10019}
10020
10021static void
10022do_vfp_sp_conv_16 (void)
10023{
10024 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10025 vfp_conv (16);
10026}
10027
10028static void
10029do_vfp_dp_conv_16 (void)
10030{
10031 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10032 vfp_conv (16);
10033}
10034
10035static void
10036do_vfp_sp_conv_32 (void)
10037{
10038 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10039 vfp_conv (32);
10040}
10041
10042static void
10043do_vfp_dp_conv_32 (void)
10044{
10045 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10046 vfp_conv (32);
10047}
c19d1205
ZW
10048\f
10049/* FPA instructions. Also in a logical order. */
e16bb312 10050
c19d1205
ZW
10051static void
10052do_fpa_cmp (void)
10053{
10054 inst.instruction |= inst.operands[0].reg << 16;
10055 inst.instruction |= inst.operands[1].reg;
10056}
b99bd4ef
NC
10057
10058static void
c19d1205 10059do_fpa_ldmstm (void)
b99bd4ef 10060{
c19d1205
ZW
10061 inst.instruction |= inst.operands[0].reg << 12;
10062 switch (inst.operands[1].imm)
10063 {
10064 case 1: inst.instruction |= CP_T_X; break;
10065 case 2: inst.instruction |= CP_T_Y; break;
10066 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10067 case 4: break;
10068 default: abort ();
10069 }
b99bd4ef 10070
c19d1205
ZW
10071 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10072 {
10073 /* The instruction specified "ea" or "fd", so we can only accept
10074 [Rn]{!}. The instruction does not really support stacking or
10075 unstacking, so we have to emulate these by setting appropriate
10076 bits and offsets. */
e2b0ab59
AV
10077 constraint (inst.relocs[0].exp.X_op != O_constant
10078 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 10079 _("this instruction does not support indexing"));
b99bd4ef 10080
c19d1205 10081 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
e2b0ab59 10082 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 10083
c19d1205 10084 if (!(inst.instruction & INDEX_UP))
e2b0ab59 10085 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
b99bd4ef 10086
c19d1205
ZW
10087 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10088 {
10089 inst.operands[2].preind = 0;
10090 inst.operands[2].postind = 1;
10091 }
10092 }
b99bd4ef 10093
c19d1205 10094 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 10095}
c19d1205
ZW
10096\f
10097/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 10098
c19d1205
ZW
10099static void
10100do_iwmmxt_tandorc (void)
10101{
10102 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10103}
b99bd4ef 10104
c19d1205
ZW
10105static void
10106do_iwmmxt_textrc (void)
10107{
10108 inst.instruction |= inst.operands[0].reg << 12;
10109 inst.instruction |= inst.operands[1].imm;
10110}
b99bd4ef
NC
10111
10112static void
c19d1205 10113do_iwmmxt_textrm (void)
b99bd4ef 10114{
c19d1205
ZW
10115 inst.instruction |= inst.operands[0].reg << 12;
10116 inst.instruction |= inst.operands[1].reg << 16;
10117 inst.instruction |= inst.operands[2].imm;
10118}
b99bd4ef 10119
c19d1205
ZW
10120static void
10121do_iwmmxt_tinsr (void)
10122{
10123 inst.instruction |= inst.operands[0].reg << 16;
10124 inst.instruction |= inst.operands[1].reg << 12;
10125 inst.instruction |= inst.operands[2].imm;
10126}
b99bd4ef 10127
c19d1205
ZW
10128static void
10129do_iwmmxt_tmia (void)
10130{
10131 inst.instruction |= inst.operands[0].reg << 5;
10132 inst.instruction |= inst.operands[1].reg;
10133 inst.instruction |= inst.operands[2].reg << 12;
10134}
b99bd4ef 10135
c19d1205
ZW
10136static void
10137do_iwmmxt_waligni (void)
10138{
10139 inst.instruction |= inst.operands[0].reg << 12;
10140 inst.instruction |= inst.operands[1].reg << 16;
10141 inst.instruction |= inst.operands[2].reg;
10142 inst.instruction |= inst.operands[3].imm << 20;
10143}
b99bd4ef 10144
2d447fca
JM
10145static void
10146do_iwmmxt_wmerge (void)
10147{
10148 inst.instruction |= inst.operands[0].reg << 12;
10149 inst.instruction |= inst.operands[1].reg << 16;
10150 inst.instruction |= inst.operands[2].reg;
10151 inst.instruction |= inst.operands[3].imm << 21;
10152}
10153
c19d1205
ZW
10154static void
10155do_iwmmxt_wmov (void)
10156{
10157 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10158 inst.instruction |= inst.operands[0].reg << 12;
10159 inst.instruction |= inst.operands[1].reg << 16;
10160 inst.instruction |= inst.operands[1].reg;
10161}
b99bd4ef 10162
c19d1205
ZW
10163static void
10164do_iwmmxt_wldstbh (void)
10165{
8f06b2d8 10166 int reloc;
c19d1205 10167 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10168 if (thumb_mode)
10169 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10170 else
10171 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10172 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10173}
10174
c19d1205
ZW
10175static void
10176do_iwmmxt_wldstw (void)
10177{
10178 /* RIWR_RIWC clears .isreg for a control register. */
10179 if (!inst.operands[0].isreg)
10180 {
10181 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10182 inst.instruction |= 0xf0000000;
10183 }
b99bd4ef 10184
c19d1205
ZW
10185 inst.instruction |= inst.operands[0].reg << 12;
10186 encode_arm_cp_address (1, TRUE, TRUE, 0);
10187}
b99bd4ef
NC
10188
10189static void
c19d1205 10190do_iwmmxt_wldstd (void)
b99bd4ef 10191{
c19d1205 10192 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10193 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10194 && inst.operands[1].immisreg)
10195 {
10196 inst.instruction &= ~0x1a000ff;
eff0bc54 10197 inst.instruction |= (0xfU << 28);
2d447fca
JM
10198 if (inst.operands[1].preind)
10199 inst.instruction |= PRE_INDEX;
10200 if (!inst.operands[1].negative)
10201 inst.instruction |= INDEX_UP;
10202 if (inst.operands[1].writeback)
10203 inst.instruction |= WRITE_BACK;
10204 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 10205 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
2d447fca
JM
10206 inst.instruction |= inst.operands[1].imm;
10207 }
10208 else
10209 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10210}
b99bd4ef 10211
c19d1205
ZW
10212static void
10213do_iwmmxt_wshufh (void)
10214{
10215 inst.instruction |= inst.operands[0].reg << 12;
10216 inst.instruction |= inst.operands[1].reg << 16;
10217 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10218 inst.instruction |= (inst.operands[2].imm & 0x0f);
10219}
b99bd4ef 10220
c19d1205
ZW
10221static void
10222do_iwmmxt_wzero (void)
10223{
10224 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10225 inst.instruction |= inst.operands[0].reg;
10226 inst.instruction |= inst.operands[0].reg << 12;
10227 inst.instruction |= inst.operands[0].reg << 16;
10228}
2d447fca
JM
10229
10230static void
10231do_iwmmxt_wrwrwr_or_imm5 (void)
10232{
10233 if (inst.operands[2].isreg)
10234 do_rd_rn_rm ();
10235 else {
10236 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10237 _("immediate operand requires iWMMXt2"));
10238 do_rd_rn ();
10239 if (inst.operands[2].imm == 0)
10240 {
10241 switch ((inst.instruction >> 20) & 0xf)
10242 {
10243 case 4:
10244 case 5:
10245 case 6:
5f4273c7 10246 case 7:
2d447fca
JM
10247 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10248 inst.operands[2].imm = 16;
10249 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10250 break;
10251 case 8:
10252 case 9:
10253 case 10:
10254 case 11:
10255 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10256 inst.operands[2].imm = 32;
10257 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10258 break;
10259 case 12:
10260 case 13:
10261 case 14:
10262 case 15:
10263 {
10264 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10265 unsigned long wrn;
10266 wrn = (inst.instruction >> 16) & 0xf;
10267 inst.instruction &= 0xff0fff0f;
10268 inst.instruction |= wrn;
10269 /* Bail out here; the instruction is now assembled. */
10270 return;
10271 }
10272 }
10273 }
10274 /* Map 32 -> 0, etc. */
10275 inst.operands[2].imm &= 0x1f;
eff0bc54 10276 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10277 }
10278}
c19d1205
ZW
10279\f
10280/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10281 operations first, then control, shift, and load/store. */
b99bd4ef 10282
c19d1205 10283/* Insns like "foo X,Y,Z". */
b99bd4ef 10284
c19d1205
ZW
10285static void
10286do_mav_triple (void)
10287{
10288 inst.instruction |= inst.operands[0].reg << 16;
10289 inst.instruction |= inst.operands[1].reg;
10290 inst.instruction |= inst.operands[2].reg << 12;
10291}
b99bd4ef 10292
c19d1205
ZW
10293/* Insns like "foo W,X,Y,Z".
10294 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10295
c19d1205
ZW
10296static void
10297do_mav_quad (void)
10298{
10299 inst.instruction |= inst.operands[0].reg << 5;
10300 inst.instruction |= inst.operands[1].reg << 12;
10301 inst.instruction |= inst.operands[2].reg << 16;
10302 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10303}
10304
c19d1205
ZW
10305/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10306static void
10307do_mav_dspsc (void)
a737bd4d 10308{
c19d1205
ZW
10309 inst.instruction |= inst.operands[1].reg << 12;
10310}
a737bd4d 10311
c19d1205
ZW
10312/* Maverick shift immediate instructions.
10313 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10314 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10315
c19d1205
ZW
10316static void
10317do_mav_shift (void)
10318{
10319 int imm = inst.operands[2].imm;
a737bd4d 10320
c19d1205
ZW
10321 inst.instruction |= inst.operands[0].reg << 12;
10322 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10323
c19d1205
ZW
10324 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10325 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10326 Bit 4 should be 0. */
10327 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10328
c19d1205
ZW
10329 inst.instruction |= imm;
10330}
10331\f
10332/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10333
c19d1205
ZW
10334/* Xscale multiply-accumulate (argument parse)
10335 MIAcc acc0,Rm,Rs
10336 MIAPHcc acc0,Rm,Rs
10337 MIAxycc acc0,Rm,Rs. */
a737bd4d 10338
c19d1205
ZW
10339static void
10340do_xsc_mia (void)
10341{
10342 inst.instruction |= inst.operands[1].reg;
10343 inst.instruction |= inst.operands[2].reg << 12;
10344}
a737bd4d 10345
c19d1205 10346/* Xscale move-accumulator-register (argument parse)
a737bd4d 10347
c19d1205 10348 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10349
c19d1205
ZW
10350static void
10351do_xsc_mar (void)
10352{
10353 inst.instruction |= inst.operands[1].reg << 12;
10354 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10355}
10356
c19d1205 10357/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10358
c19d1205 10359 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10360
10361static void
c19d1205 10362do_xsc_mra (void)
b99bd4ef 10363{
c19d1205
ZW
10364 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10365 inst.instruction |= inst.operands[0].reg << 12;
10366 inst.instruction |= inst.operands[1].reg << 16;
10367}
10368\f
10369/* Encoding functions relevant only to Thumb. */
b99bd4ef 10370
c19d1205
ZW
10371/* inst.operands[i] is a shifted-register operand; encode
10372 it into inst.instruction in the format used by Thumb32. */
10373
10374static void
10375encode_thumb32_shifted_operand (int i)
10376{
e2b0ab59 10377 unsigned int value = inst.relocs[0].exp.X_add_number;
c19d1205 10378 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10379
9c3c69f2
PB
10380 constraint (inst.operands[i].immisreg,
10381 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10382 inst.instruction |= inst.operands[i].reg;
10383 if (shift == SHIFT_RRX)
10384 inst.instruction |= SHIFT_ROR << 4;
10385 else
b99bd4ef 10386 {
e2b0ab59 10387 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
10388 _("expression too complex"));
10389
10390 constraint (value > 32
10391 || (value == 32 && (shift == SHIFT_LSL
10392 || shift == SHIFT_ROR)),
10393 _("shift expression is too large"));
10394
10395 if (value == 0)
10396 shift = SHIFT_LSL;
10397 else if (value == 32)
10398 value = 0;
10399
10400 inst.instruction |= shift << 4;
10401 inst.instruction |= (value & 0x1c) << 10;
10402 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10403 }
c19d1205 10404}
b99bd4ef 10405
b99bd4ef 10406
c19d1205
ZW
10407/* inst.operands[i] was set up by parse_address. Encode it into a
10408 Thumb32 format load or store instruction. Reject forms that cannot
10409 be used with such instructions. If is_t is true, reject forms that
10410 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10411 that cannot be used with a D instruction. If it is a store insn,
10412 reject PC in Rn. */
b99bd4ef 10413
c19d1205
ZW
10414static void
10415encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10416{
5be8be5d 10417 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10418
10419 constraint (!inst.operands[i].isreg,
53365c0d 10420 _("Instruction does not support =N addresses"));
b99bd4ef 10421
c19d1205
ZW
10422 inst.instruction |= inst.operands[i].reg << 16;
10423 if (inst.operands[i].immisreg)
b99bd4ef 10424 {
5be8be5d 10425 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10426 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10427 constraint (inst.operands[i].negative,
10428 _("Thumb does not support negative register indexing"));
10429 constraint (inst.operands[i].postind,
10430 _("Thumb does not support register post-indexing"));
10431 constraint (inst.operands[i].writeback,
10432 _("Thumb does not support register indexing with writeback"));
10433 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10434 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10435
f40d1643 10436 inst.instruction |= inst.operands[i].imm;
c19d1205 10437 if (inst.operands[i].shifted)
b99bd4ef 10438 {
e2b0ab59 10439 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 10440 _("expression too complex"));
e2b0ab59
AV
10441 constraint (inst.relocs[0].exp.X_add_number < 0
10442 || inst.relocs[0].exp.X_add_number > 3,
c19d1205 10443 _("shift out of range"));
e2b0ab59 10444 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
c19d1205 10445 }
e2b0ab59 10446 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205
ZW
10447 }
10448 else if (inst.operands[i].preind)
10449 {
5be8be5d 10450 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10451 constraint (is_t && inst.operands[i].writeback,
c19d1205 10452 _("cannot use writeback with this instruction"));
4755303e
WN
10453 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10454 BAD_PC_ADDRESSING);
c19d1205
ZW
10455
10456 if (is_d)
10457 {
10458 inst.instruction |= 0x01000000;
10459 if (inst.operands[i].writeback)
10460 inst.instruction |= 0x00200000;
b99bd4ef 10461 }
c19d1205 10462 else
b99bd4ef 10463 {
c19d1205
ZW
10464 inst.instruction |= 0x00000c00;
10465 if (inst.operands[i].writeback)
10466 inst.instruction |= 0x00000100;
b99bd4ef 10467 }
e2b0ab59 10468 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10469 }
c19d1205 10470 else if (inst.operands[i].postind)
b99bd4ef 10471 {
9c2799c2 10472 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10473 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10474 constraint (is_t, _("cannot use post-indexing with this instruction"));
10475
10476 if (is_d)
10477 inst.instruction |= 0x00200000;
10478 else
10479 inst.instruction |= 0x00000900;
e2b0ab59 10480 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
c19d1205
ZW
10481 }
10482 else /* unindexed - only for coprocessor */
10483 inst.error = _("instruction does not accept unindexed addressing");
10484}
10485
10486/* Table of Thumb instructions which exist in both 16- and 32-bit
10487 encodings (the latter only in post-V6T2 cores). The index is the
10488 value used in the insns table below. When there is more than one
10489 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10490 holds variant (1).
10491 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10492#define T16_32_TAB \
21d799b5
NC
10493 X(_adc, 4140, eb400000), \
10494 X(_adcs, 4140, eb500000), \
10495 X(_add, 1c00, eb000000), \
10496 X(_adds, 1c00, eb100000), \
10497 X(_addi, 0000, f1000000), \
10498 X(_addis, 0000, f1100000), \
10499 X(_add_pc,000f, f20f0000), \
10500 X(_add_sp,000d, f10d0000), \
10501 X(_adr, 000f, f20f0000), \
10502 X(_and, 4000, ea000000), \
10503 X(_ands, 4000, ea100000), \
10504 X(_asr, 1000, fa40f000), \
10505 X(_asrs, 1000, fa50f000), \
10506 X(_b, e000, f000b000), \
10507 X(_bcond, d000, f0008000), \
4389b29a 10508 X(_bf, 0000, f040e001), \
21d799b5
NC
10509 X(_bic, 4380, ea200000), \
10510 X(_bics, 4380, ea300000), \
10511 X(_cmn, 42c0, eb100f00), \
10512 X(_cmp, 2800, ebb00f00), \
10513 X(_cpsie, b660, f3af8400), \
10514 X(_cpsid, b670, f3af8600), \
10515 X(_cpy, 4600, ea4f0000), \
10516 X(_dec_sp,80dd, f1ad0d00), \
10517 X(_eor, 4040, ea800000), \
10518 X(_eors, 4040, ea900000), \
10519 X(_inc_sp,00dd, f10d0d00), \
10520 X(_ldmia, c800, e8900000), \
10521 X(_ldr, 6800, f8500000), \
10522 X(_ldrb, 7800, f8100000), \
10523 X(_ldrh, 8800, f8300000), \
10524 X(_ldrsb, 5600, f9100000), \
10525 X(_ldrsh, 5e00, f9300000), \
10526 X(_ldr_pc,4800, f85f0000), \
10527 X(_ldr_pc2,4800, f85f0000), \
10528 X(_ldr_sp,9800, f85d0000), \
10529 X(_lsl, 0000, fa00f000), \
10530 X(_lsls, 0000, fa10f000), \
10531 X(_lsr, 0800, fa20f000), \
10532 X(_lsrs, 0800, fa30f000), \
10533 X(_mov, 2000, ea4f0000), \
10534 X(_movs, 2000, ea5f0000), \
10535 X(_mul, 4340, fb00f000), \
10536 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10537 X(_mvn, 43c0, ea6f0000), \
10538 X(_mvns, 43c0, ea7f0000), \
10539 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10540 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10541 X(_orr, 4300, ea400000), \
10542 X(_orrs, 4300, ea500000), \
10543 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10544 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10545 X(_rev, ba00, fa90f080), \
10546 X(_rev16, ba40, fa90f090), \
10547 X(_revsh, bac0, fa90f0b0), \
10548 X(_ror, 41c0, fa60f000), \
10549 X(_rors, 41c0, fa70f000), \
10550 X(_sbc, 4180, eb600000), \
10551 X(_sbcs, 4180, eb700000), \
10552 X(_stmia, c000, e8800000), \
10553 X(_str, 6000, f8400000), \
10554 X(_strb, 7000, f8000000), \
10555 X(_strh, 8000, f8200000), \
10556 X(_str_sp,9000, f84d0000), \
10557 X(_sub, 1e00, eba00000), \
10558 X(_subs, 1e00, ebb00000), \
10559 X(_subi, 8000, f1a00000), \
10560 X(_subis, 8000, f1b00000), \
10561 X(_sxtb, b240, fa4ff080), \
10562 X(_sxth, b200, fa0ff080), \
10563 X(_tst, 4200, ea100f00), \
10564 X(_uxtb, b2c0, fa5ff080), \
10565 X(_uxth, b280, fa1ff080), \
10566 X(_nop, bf00, f3af8000), \
10567 X(_yield, bf10, f3af8001), \
10568 X(_wfe, bf20, f3af8002), \
10569 X(_wfi, bf30, f3af8003), \
53c4b28b 10570 X(_sev, bf40, f3af8004), \
74db7efb
NC
10571 X(_sevl, bf50, f3af8005), \
10572 X(_udf, de00, f7f0a000)
c19d1205
ZW
10573
10574/* To catch errors in encoding functions, the codes are all offset by
10575 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10576 as 16-bit instructions. */
21d799b5 10577#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10578enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10579#undef X
10580
10581#define X(a,b,c) 0x##b
10582static const unsigned short thumb_op16[] = { T16_32_TAB };
10583#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10584#undef X
10585
10586#define X(a,b,c) 0x##c
10587static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10588#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10589#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10590#undef X
10591#undef T16_32_TAB
10592
10593/* Thumb instruction encoders, in alphabetical order. */
10594
92e90b6e 10595/* ADDW or SUBW. */
c921be7d 10596
92e90b6e
PB
10597static void
10598do_t_add_sub_w (void)
10599{
10600 int Rd, Rn;
10601
10602 Rd = inst.operands[0].reg;
10603 Rn = inst.operands[1].reg;
10604
539d4391
NC
10605 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10606 is the SP-{plus,minus}-immediate form of the instruction. */
10607 if (Rn == REG_SP)
10608 constraint (Rd == REG_PC, BAD_PC);
10609 else
10610 reject_bad_reg (Rd);
fdfde340 10611
92e90b6e 10612 inst.instruction |= (Rn << 16) | (Rd << 8);
e2b0ab59 10613 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
92e90b6e
PB
10614}
10615
c19d1205 10616/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 10617 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
10618
10619static void
10620do_t_add_sub (void)
10621{
10622 int Rd, Rs, Rn;
10623
10624 Rd = inst.operands[0].reg;
10625 Rs = (inst.operands[1].present
10626 ? inst.operands[1].reg /* Rd, Rs, foo */
10627 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10628
e07e6e58
NC
10629 if (Rd == REG_PC)
10630 set_it_insn_type_last ();
10631
c19d1205
ZW
10632 if (unified_syntax)
10633 {
0110f2b8
PB
10634 bfd_boolean flags;
10635 bfd_boolean narrow;
10636 int opcode;
10637
10638 flags = (inst.instruction == T_MNEM_adds
10639 || inst.instruction == T_MNEM_subs);
10640 if (flags)
e07e6e58 10641 narrow = !in_it_block ();
0110f2b8 10642 else
e07e6e58 10643 narrow = in_it_block ();
c19d1205 10644 if (!inst.operands[2].isreg)
b99bd4ef 10645 {
16805f35
PB
10646 int add;
10647
5c8ed6a4
JW
10648 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10649 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 10650
16805f35
PB
10651 add = (inst.instruction == T_MNEM_add
10652 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10653 opcode = 0;
10654 if (inst.size_req != 4)
10655 {
0110f2b8 10656 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10657 appropriate. */
0110f2b8
PB
10658 if (Rd == REG_SP && Rs == REG_SP && !flags)
10659 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10660 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10661 opcode = T_MNEM_add_sp;
10662 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10663 opcode = T_MNEM_add_pc;
10664 else if (Rd <= 7 && Rs <= 7 && narrow)
10665 {
10666 if (flags)
10667 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10668 else
10669 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10670 }
10671 if (opcode)
10672 {
10673 inst.instruction = THUMB_OP16(opcode);
10674 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59
AV
10675 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10676 || (inst.relocs[0].type
10677 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
a9f02af8
MG
10678 {
10679 if (inst.size_req == 2)
e2b0ab59 10680 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
a9f02af8
MG
10681 else
10682 inst.relax = opcode;
10683 }
0110f2b8
PB
10684 }
10685 else
10686 constraint (inst.size_req == 2, BAD_HIREG);
10687 }
10688 if (inst.size_req == 4
10689 || (inst.size_req != 2 && !opcode))
10690 {
e2b0ab59
AV
10691 constraint ((inst.relocs[0].type
10692 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
10693 && (inst.relocs[0].type
10694 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8 10695 THUMB1_RELOC_ONLY);
efd81785
PB
10696 if (Rd == REG_PC)
10697 {
fdfde340 10698 constraint (add, BAD_PC);
efd81785
PB
10699 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10700 _("only SUBS PC, LR, #const allowed"));
e2b0ab59 10701 constraint (inst.relocs[0].exp.X_op != O_constant,
efd81785 10702 _("expression too complex"));
e2b0ab59
AV
10703 constraint (inst.relocs[0].exp.X_add_number < 0
10704 || inst.relocs[0].exp.X_add_number > 0xff,
efd81785
PB
10705 _("immediate value out of range"));
10706 inst.instruction = T2_SUBS_PC_LR
e2b0ab59
AV
10707 | inst.relocs[0].exp.X_add_number;
10708 inst.relocs[0].type = BFD_RELOC_UNUSED;
efd81785
PB
10709 return;
10710 }
10711 else if (Rs == REG_PC)
16805f35
PB
10712 {
10713 /* Always use addw/subw. */
10714 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
e2b0ab59 10715 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
16805f35
PB
10716 }
10717 else
10718 {
10719 inst.instruction = THUMB_OP32 (inst.instruction);
10720 inst.instruction = (inst.instruction & 0xe1ffffff)
10721 | 0x10000000;
10722 if (flags)
e2b0ab59 10723 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
16805f35 10724 else
e2b0ab59 10725 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
16805f35 10726 }
dc4503c6
PB
10727 inst.instruction |= Rd << 8;
10728 inst.instruction |= Rs << 16;
0110f2b8 10729 }
b99bd4ef 10730 }
c19d1205
ZW
10731 else
10732 {
e2b0ab59 10733 unsigned int value = inst.relocs[0].exp.X_add_number;
5f4cb198
NC
10734 unsigned int shift = inst.operands[2].shift_kind;
10735
c19d1205
ZW
10736 Rn = inst.operands[2].reg;
10737 /* See if we can do this with a 16-bit instruction. */
10738 if (!inst.operands[2].shifted && inst.size_req != 4)
10739 {
e27ec89e
PB
10740 if (Rd > 7 || Rs > 7 || Rn > 7)
10741 narrow = FALSE;
10742
10743 if (narrow)
c19d1205 10744 {
e27ec89e
PB
10745 inst.instruction = ((inst.instruction == T_MNEM_adds
10746 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10747 ? T_OPCODE_ADD_R3
10748 : T_OPCODE_SUB_R3);
10749 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10750 return;
10751 }
b99bd4ef 10752
7e806470 10753 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10754 {
7e806470
PB
10755 /* Thumb-1 cores (except v6-M) require at least one high
10756 register in a narrow non flag setting add. */
10757 if (Rd > 7 || Rn > 7
10758 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10759 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10760 {
7e806470
PB
10761 if (Rd == Rn)
10762 {
10763 Rn = Rs;
10764 Rs = Rd;
10765 }
c19d1205
ZW
10766 inst.instruction = T_OPCODE_ADD_HI;
10767 inst.instruction |= (Rd & 8) << 4;
10768 inst.instruction |= (Rd & 7);
10769 inst.instruction |= Rn << 3;
10770 return;
10771 }
c19d1205
ZW
10772 }
10773 }
c921be7d 10774
fdfde340 10775 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
10776 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10777 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
10778 constraint (Rs == REG_PC, BAD_PC);
10779 reject_bad_reg (Rn);
10780
c19d1205
ZW
10781 /* If we get here, it can't be done in 16 bits. */
10782 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10783 _("shift must be constant"));
10784 inst.instruction = THUMB_OP32 (inst.instruction);
10785 inst.instruction |= Rd << 8;
10786 inst.instruction |= Rs << 16;
5f4cb198
NC
10787 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10788 _("shift value over 3 not allowed in thumb mode"));
10789 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10790 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10791 encode_thumb32_shifted_operand (2);
10792 }
10793 }
10794 else
10795 {
10796 constraint (inst.instruction == T_MNEM_adds
10797 || inst.instruction == T_MNEM_subs,
10798 BAD_THUMB32);
b99bd4ef 10799
c19d1205 10800 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10801 {
c19d1205
ZW
10802 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10803 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10804 BAD_HIREG);
10805
10806 inst.instruction = (inst.instruction == T_MNEM_add
10807 ? 0x0000 : 0x8000);
10808 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59 10809 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10810 return;
10811 }
10812
c19d1205
ZW
10813 Rn = inst.operands[2].reg;
10814 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10815
c19d1205
ZW
10816 /* We now have Rd, Rs, and Rn set to registers. */
10817 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10818 {
c19d1205
ZW
10819 /* Can't do this for SUB. */
10820 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10821 inst.instruction = T_OPCODE_ADD_HI;
10822 inst.instruction |= (Rd & 8) << 4;
10823 inst.instruction |= (Rd & 7);
10824 if (Rs == Rd)
10825 inst.instruction |= Rn << 3;
10826 else if (Rn == Rd)
10827 inst.instruction |= Rs << 3;
10828 else
10829 constraint (1, _("dest must overlap one source register"));
10830 }
10831 else
10832 {
10833 inst.instruction = (inst.instruction == T_MNEM_add
10834 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10835 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10836 }
b99bd4ef 10837 }
b99bd4ef
NC
10838}
10839
c19d1205
ZW
10840static void
10841do_t_adr (void)
10842{
fdfde340
JM
10843 unsigned Rd;
10844
10845 Rd = inst.operands[0].reg;
10846 reject_bad_reg (Rd);
10847
10848 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10849 {
10850 /* Defer to section relaxation. */
10851 inst.relax = inst.instruction;
10852 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10853 inst.instruction |= Rd << 4;
0110f2b8
PB
10854 }
10855 else if (unified_syntax && inst.size_req != 2)
e9f89963 10856 {
0110f2b8 10857 /* Generate a 32-bit opcode. */
e9f89963 10858 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10859 inst.instruction |= Rd << 8;
e2b0ab59
AV
10860 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
10861 inst.relocs[0].pc_rel = 1;
e9f89963
PB
10862 }
10863 else
10864 {
0110f2b8 10865 /* Generate a 16-bit opcode. */
e9f89963 10866 inst.instruction = THUMB_OP16 (inst.instruction);
e2b0ab59
AV
10867 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
10868 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
10869 inst.relocs[0].pc_rel = 1;
fdfde340 10870 inst.instruction |= Rd << 4;
e9f89963 10871 }
52a86f84 10872
e2b0ab59
AV
10873 if (inst.relocs[0].exp.X_op == O_symbol
10874 && inst.relocs[0].exp.X_add_symbol != NULL
10875 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
10876 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
10877 inst.relocs[0].exp.X_add_number += 1;
c19d1205 10878}
b99bd4ef 10879
c19d1205
ZW
10880/* Arithmetic instructions for which there is just one 16-bit
10881 instruction encoding, and it allows only two low registers.
10882 For maximal compatibility with ARM syntax, we allow three register
10883 operands even when Thumb-32 instructions are not available, as long
10884 as the first two are identical. For instance, both "sbc r0,r1" and
10885 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10886static void
c19d1205 10887do_t_arit3 (void)
b99bd4ef 10888{
c19d1205 10889 int Rd, Rs, Rn;
b99bd4ef 10890
c19d1205
ZW
10891 Rd = inst.operands[0].reg;
10892 Rs = (inst.operands[1].present
10893 ? inst.operands[1].reg /* Rd, Rs, foo */
10894 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10895 Rn = inst.operands[2].reg;
b99bd4ef 10896
fdfde340
JM
10897 reject_bad_reg (Rd);
10898 reject_bad_reg (Rs);
10899 if (inst.operands[2].isreg)
10900 reject_bad_reg (Rn);
10901
c19d1205 10902 if (unified_syntax)
b99bd4ef 10903 {
c19d1205
ZW
10904 if (!inst.operands[2].isreg)
10905 {
10906 /* For an immediate, we always generate a 32-bit opcode;
10907 section relaxation will shrink it later if possible. */
10908 inst.instruction = THUMB_OP32 (inst.instruction);
10909 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10910 inst.instruction |= Rd << 8;
10911 inst.instruction |= Rs << 16;
e2b0ab59 10912 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
c19d1205
ZW
10913 }
10914 else
10915 {
e27ec89e
PB
10916 bfd_boolean narrow;
10917
c19d1205 10918 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10919 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10920 narrow = !in_it_block ();
e27ec89e 10921 else
e07e6e58 10922 narrow = in_it_block ();
e27ec89e
PB
10923
10924 if (Rd > 7 || Rn > 7 || Rs > 7)
10925 narrow = FALSE;
10926 if (inst.operands[2].shifted)
10927 narrow = FALSE;
10928 if (inst.size_req == 4)
10929 narrow = FALSE;
10930
10931 if (narrow
c19d1205
ZW
10932 && Rd == Rs)
10933 {
10934 inst.instruction = THUMB_OP16 (inst.instruction);
10935 inst.instruction |= Rd;
10936 inst.instruction |= Rn << 3;
10937 return;
10938 }
b99bd4ef 10939
c19d1205
ZW
10940 /* If we get here, it can't be done in 16 bits. */
10941 constraint (inst.operands[2].shifted
10942 && inst.operands[2].immisreg,
10943 _("shift must be constant"));
10944 inst.instruction = THUMB_OP32 (inst.instruction);
10945 inst.instruction |= Rd << 8;
10946 inst.instruction |= Rs << 16;
10947 encode_thumb32_shifted_operand (2);
10948 }
a737bd4d 10949 }
c19d1205 10950 else
b99bd4ef 10951 {
c19d1205
ZW
10952 /* On its face this is a lie - the instruction does set the
10953 flags. However, the only supported mnemonic in this mode
10954 says it doesn't. */
10955 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10956
c19d1205
ZW
10957 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10958 _("unshifted register required"));
10959 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10960 constraint (Rd != Rs,
10961 _("dest and source1 must be the same register"));
a737bd4d 10962
c19d1205
ZW
10963 inst.instruction = THUMB_OP16 (inst.instruction);
10964 inst.instruction |= Rd;
10965 inst.instruction |= Rn << 3;
b99bd4ef 10966 }
a737bd4d 10967}
b99bd4ef 10968
c19d1205
ZW
10969/* Similarly, but for instructions where the arithmetic operation is
10970 commutative, so we can allow either of them to be different from
10971 the destination operand in a 16-bit instruction. For instance, all
10972 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10973 accepted. */
10974static void
10975do_t_arit3c (void)
a737bd4d 10976{
c19d1205 10977 int Rd, Rs, Rn;
b99bd4ef 10978
c19d1205
ZW
10979 Rd = inst.operands[0].reg;
10980 Rs = (inst.operands[1].present
10981 ? inst.operands[1].reg /* Rd, Rs, foo */
10982 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10983 Rn = inst.operands[2].reg;
c921be7d 10984
fdfde340
JM
10985 reject_bad_reg (Rd);
10986 reject_bad_reg (Rs);
10987 if (inst.operands[2].isreg)
10988 reject_bad_reg (Rn);
a737bd4d 10989
c19d1205 10990 if (unified_syntax)
a737bd4d 10991 {
c19d1205 10992 if (!inst.operands[2].isreg)
b99bd4ef 10993 {
c19d1205
ZW
10994 /* For an immediate, we always generate a 32-bit opcode;
10995 section relaxation will shrink it later if possible. */
10996 inst.instruction = THUMB_OP32 (inst.instruction);
10997 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10998 inst.instruction |= Rd << 8;
10999 inst.instruction |= Rs << 16;
e2b0ab59 11000 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11001 }
c19d1205 11002 else
a737bd4d 11003 {
e27ec89e
PB
11004 bfd_boolean narrow;
11005
c19d1205 11006 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11007 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11008 narrow = !in_it_block ();
e27ec89e 11009 else
e07e6e58 11010 narrow = in_it_block ();
e27ec89e
PB
11011
11012 if (Rd > 7 || Rn > 7 || Rs > 7)
11013 narrow = FALSE;
11014 if (inst.operands[2].shifted)
11015 narrow = FALSE;
11016 if (inst.size_req == 4)
11017 narrow = FALSE;
11018
11019 if (narrow)
a737bd4d 11020 {
c19d1205 11021 if (Rd == Rs)
a737bd4d 11022 {
c19d1205
ZW
11023 inst.instruction = THUMB_OP16 (inst.instruction);
11024 inst.instruction |= Rd;
11025 inst.instruction |= Rn << 3;
11026 return;
a737bd4d 11027 }
c19d1205 11028 if (Rd == Rn)
a737bd4d 11029 {
c19d1205
ZW
11030 inst.instruction = THUMB_OP16 (inst.instruction);
11031 inst.instruction |= Rd;
11032 inst.instruction |= Rs << 3;
11033 return;
a737bd4d
NC
11034 }
11035 }
c19d1205
ZW
11036
11037 /* If we get here, it can't be done in 16 bits. */
11038 constraint (inst.operands[2].shifted
11039 && 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;
11044 encode_thumb32_shifted_operand (2);
a737bd4d 11045 }
b99bd4ef 11046 }
c19d1205
ZW
11047 else
11048 {
11049 /* On its face this is a lie - the instruction does set the
11050 flags. However, the only supported mnemonic in this mode
11051 says it doesn't. */
11052 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11053
c19d1205
ZW
11054 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11055 _("unshifted register required"));
11056 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11057
11058 inst.instruction = THUMB_OP16 (inst.instruction);
11059 inst.instruction |= Rd;
11060
11061 if (Rd == Rs)
11062 inst.instruction |= Rn << 3;
11063 else if (Rd == Rn)
11064 inst.instruction |= Rs << 3;
11065 else
11066 constraint (1, _("dest must overlap one source register"));
11067 }
a737bd4d
NC
11068}
11069
c19d1205
ZW
11070static void
11071do_t_bfc (void)
a737bd4d 11072{
fdfde340 11073 unsigned Rd;
c19d1205
ZW
11074 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11075 constraint (msb > 32, _("bit-field extends past end of register"));
11076 /* The instruction encoding stores the LSB and MSB,
11077 not the LSB and width. */
fdfde340
JM
11078 Rd = inst.operands[0].reg;
11079 reject_bad_reg (Rd);
11080 inst.instruction |= Rd << 8;
c19d1205
ZW
11081 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11082 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11083 inst.instruction |= msb - 1;
b99bd4ef
NC
11084}
11085
c19d1205
ZW
11086static void
11087do_t_bfi (void)
b99bd4ef 11088{
fdfde340 11089 int Rd, Rn;
c19d1205 11090 unsigned int msb;
b99bd4ef 11091
fdfde340
JM
11092 Rd = inst.operands[0].reg;
11093 reject_bad_reg (Rd);
11094
c19d1205
ZW
11095 /* #0 in second position is alternative syntax for bfc, which is
11096 the same instruction but with REG_PC in the Rm field. */
11097 if (!inst.operands[1].isreg)
fdfde340
JM
11098 Rn = REG_PC;
11099 else
11100 {
11101 Rn = inst.operands[1].reg;
11102 reject_bad_reg (Rn);
11103 }
b99bd4ef 11104
c19d1205
ZW
11105 msb = inst.operands[2].imm + inst.operands[3].imm;
11106 constraint (msb > 32, _("bit-field extends past end of register"));
11107 /* The instruction encoding stores the LSB and MSB,
11108 not the LSB and width. */
fdfde340
JM
11109 inst.instruction |= Rd << 8;
11110 inst.instruction |= Rn << 16;
c19d1205
ZW
11111 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11112 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11113 inst.instruction |= msb - 1;
b99bd4ef
NC
11114}
11115
c19d1205
ZW
11116static void
11117do_t_bfx (void)
b99bd4ef 11118{
fdfde340
JM
11119 unsigned Rd, Rn;
11120
11121 Rd = inst.operands[0].reg;
11122 Rn = inst.operands[1].reg;
11123
11124 reject_bad_reg (Rd);
11125 reject_bad_reg (Rn);
11126
c19d1205
ZW
11127 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11128 _("bit-field extends past end of register"));
fdfde340
JM
11129 inst.instruction |= Rd << 8;
11130 inst.instruction |= Rn << 16;
c19d1205
ZW
11131 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11132 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11133 inst.instruction |= inst.operands[3].imm - 1;
11134}
b99bd4ef 11135
c19d1205
ZW
11136/* ARM V5 Thumb BLX (argument parse)
11137 BLX <target_addr> which is BLX(1)
11138 BLX <Rm> which is BLX(2)
11139 Unfortunately, there are two different opcodes for this mnemonic.
11140 So, the insns[].value is not used, and the code here zaps values
11141 into inst.instruction.
b99bd4ef 11142
c19d1205
ZW
11143 ??? How to take advantage of the additional two bits of displacement
11144 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11145
c19d1205
ZW
11146static void
11147do_t_blx (void)
11148{
e07e6e58
NC
11149 set_it_insn_type_last ();
11150
c19d1205 11151 if (inst.operands[0].isreg)
fdfde340
JM
11152 {
11153 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11154 /* We have a register, so this is BLX(2). */
11155 inst.instruction |= inst.operands[0].reg << 3;
11156 }
b99bd4ef
NC
11157 else
11158 {
c19d1205 11159 /* No register. This must be BLX(1). */
2fc8bdac 11160 inst.instruction = 0xf000e800;
0855e32b 11161 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11162 }
11163}
11164
c19d1205
ZW
11165static void
11166do_t_branch (void)
b99bd4ef 11167{
0110f2b8 11168 int opcode;
dfa9f0d5 11169 int cond;
2fe88214 11170 bfd_reloc_code_real_type reloc;
dfa9f0d5 11171
e07e6e58
NC
11172 cond = inst.cond;
11173 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11174
11175 if (in_it_block ())
dfa9f0d5
PB
11176 {
11177 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11178 branches. */
dfa9f0d5 11179 cond = COND_ALWAYS;
dfa9f0d5
PB
11180 }
11181 else
11182 cond = inst.cond;
11183
11184 if (cond != COND_ALWAYS)
0110f2b8
PB
11185 opcode = T_MNEM_bcond;
11186 else
11187 opcode = inst.instruction;
11188
12d6b0b7
RS
11189 if (unified_syntax
11190 && (inst.size_req == 4
10960bfb
PB
11191 || (inst.size_req != 2
11192 && (inst.operands[0].hasreloc
e2b0ab59 11193 || inst.relocs[0].exp.X_op == O_constant))))
c19d1205 11194 {
0110f2b8 11195 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11196 if (cond == COND_ALWAYS)
9ae92b05 11197 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11198 else
11199 {
ff8646ee
TP
11200 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11201 _("selected architecture does not support "
11202 "wide conditional branch instruction"));
11203
9c2799c2 11204 gas_assert (cond != 0xF);
dfa9f0d5 11205 inst.instruction |= cond << 22;
9ae92b05 11206 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11207 }
11208 }
b99bd4ef
NC
11209 else
11210 {
0110f2b8 11211 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11212 if (cond == COND_ALWAYS)
9ae92b05 11213 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11214 else
b99bd4ef 11215 {
dfa9f0d5 11216 inst.instruction |= cond << 8;
9ae92b05 11217 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11218 }
0110f2b8
PB
11219 /* Allow section relaxation. */
11220 if (unified_syntax && inst.size_req != 2)
11221 inst.relax = opcode;
b99bd4ef 11222 }
e2b0ab59
AV
11223 inst.relocs[0].type = reloc;
11224 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
11225}
11226
8884b720 11227/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11228 between the two is the maximum immediate allowed - which is passed in
8884b720 11229 RANGE. */
b99bd4ef 11230static void
8884b720 11231do_t_bkpt_hlt1 (int range)
b99bd4ef 11232{
dfa9f0d5
PB
11233 constraint (inst.cond != COND_ALWAYS,
11234 _("instruction is always unconditional"));
c19d1205 11235 if (inst.operands[0].present)
b99bd4ef 11236 {
8884b720 11237 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11238 _("immediate value out of range"));
11239 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11240 }
8884b720
MGD
11241
11242 set_it_insn_type (NEUTRAL_IT_INSN);
11243}
11244
11245static void
11246do_t_hlt (void)
11247{
11248 do_t_bkpt_hlt1 (63);
11249}
11250
11251static void
11252do_t_bkpt (void)
11253{
11254 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11255}
11256
11257static void
c19d1205 11258do_t_branch23 (void)
b99bd4ef 11259{
e07e6e58 11260 set_it_insn_type_last ();
0855e32b 11261 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11262
0855e32b
NS
11263 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11264 this file. We used to simply ignore the PLT reloc type here --
11265 the branch encoding is now needed to deal with TLSCALL relocs.
11266 So if we see a PLT reloc now, put it back to how it used to be to
11267 keep the preexisting behaviour. */
e2b0ab59
AV
11268 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
11269 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11270
4343666d 11271#if defined(OBJ_COFF)
c19d1205
ZW
11272 /* If the destination of the branch is a defined symbol which does not have
11273 the THUMB_FUNC attribute, then we must be calling a function which has
11274 the (interfacearm) attribute. We look for the Thumb entry point to that
11275 function and change the branch to refer to that function instead. */
e2b0ab59
AV
11276 if ( inst.relocs[0].exp.X_op == O_symbol
11277 && inst.relocs[0].exp.X_add_symbol != NULL
11278 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11279 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11280 inst.relocs[0].exp.X_add_symbol
11281 = find_real_start (inst.relocs[0].exp.X_add_symbol);
4343666d 11282#endif
90e4755a
RE
11283}
11284
11285static void
c19d1205 11286do_t_bx (void)
90e4755a 11287{
e07e6e58 11288 set_it_insn_type_last ();
c19d1205
ZW
11289 inst.instruction |= inst.operands[0].reg << 3;
11290 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11291 should cause the alignment to be checked once it is known. This is
11292 because BX PC only works if the instruction is word aligned. */
11293}
90e4755a 11294
c19d1205
ZW
11295static void
11296do_t_bxj (void)
11297{
fdfde340 11298 int Rm;
90e4755a 11299
e07e6e58 11300 set_it_insn_type_last ();
fdfde340
JM
11301 Rm = inst.operands[0].reg;
11302 reject_bad_reg (Rm);
11303 inst.instruction |= Rm << 16;
90e4755a
RE
11304}
11305
11306static void
c19d1205 11307do_t_clz (void)
90e4755a 11308{
fdfde340
JM
11309 unsigned Rd;
11310 unsigned Rm;
11311
11312 Rd = inst.operands[0].reg;
11313 Rm = inst.operands[1].reg;
11314
11315 reject_bad_reg (Rd);
11316 reject_bad_reg (Rm);
11317
11318 inst.instruction |= Rd << 8;
11319 inst.instruction |= Rm << 16;
11320 inst.instruction |= Rm;
c19d1205 11321}
90e4755a 11322
91d8b670
JG
11323static void
11324do_t_csdb (void)
11325{
11326 set_it_insn_type (OUTSIDE_IT_INSN);
11327}
11328
dfa9f0d5
PB
11329static void
11330do_t_cps (void)
11331{
e07e6e58 11332 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11333 inst.instruction |= inst.operands[0].imm;
11334}
11335
c19d1205
ZW
11336static void
11337do_t_cpsi (void)
11338{
e07e6e58 11339 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11340 if (unified_syntax
62b3e311
PB
11341 && (inst.operands[1].present || inst.size_req == 4)
11342 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11343 {
c19d1205
ZW
11344 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11345 inst.instruction = 0xf3af8000;
11346 inst.instruction |= imod << 9;
11347 inst.instruction |= inst.operands[0].imm << 5;
11348 if (inst.operands[1].present)
11349 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11350 }
c19d1205 11351 else
90e4755a 11352 {
62b3e311
PB
11353 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11354 && (inst.operands[0].imm & 4),
11355 _("selected processor does not support 'A' form "
11356 "of this instruction"));
11357 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11358 _("Thumb does not support the 2-argument "
11359 "form of this instruction"));
11360 inst.instruction |= inst.operands[0].imm;
90e4755a 11361 }
90e4755a
RE
11362}
11363
c19d1205
ZW
11364/* THUMB CPY instruction (argument parse). */
11365
90e4755a 11366static void
c19d1205 11367do_t_cpy (void)
90e4755a 11368{
c19d1205 11369 if (inst.size_req == 4)
90e4755a 11370 {
c19d1205
ZW
11371 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11372 inst.instruction |= inst.operands[0].reg << 8;
11373 inst.instruction |= inst.operands[1].reg;
90e4755a 11374 }
c19d1205 11375 else
90e4755a 11376 {
c19d1205
ZW
11377 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11378 inst.instruction |= (inst.operands[0].reg & 0x7);
11379 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11380 }
90e4755a
RE
11381}
11382
90e4755a 11383static void
25fe350b 11384do_t_cbz (void)
90e4755a 11385{
e07e6e58 11386 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11387 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11388 inst.instruction |= inst.operands[0].reg;
e2b0ab59
AV
11389 inst.relocs[0].pc_rel = 1;
11390 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
c19d1205 11391}
90e4755a 11392
62b3e311
PB
11393static void
11394do_t_dbg (void)
11395{
11396 inst.instruction |= inst.operands[0].imm;
11397}
11398
11399static void
11400do_t_div (void)
11401{
fdfde340
JM
11402 unsigned Rd, Rn, Rm;
11403
11404 Rd = inst.operands[0].reg;
11405 Rn = (inst.operands[1].present
11406 ? inst.operands[1].reg : Rd);
11407 Rm = inst.operands[2].reg;
11408
11409 reject_bad_reg (Rd);
11410 reject_bad_reg (Rn);
11411 reject_bad_reg (Rm);
11412
11413 inst.instruction |= Rd << 8;
11414 inst.instruction |= Rn << 16;
11415 inst.instruction |= Rm;
62b3e311
PB
11416}
11417
c19d1205
ZW
11418static void
11419do_t_hint (void)
11420{
11421 if (unified_syntax && inst.size_req == 4)
11422 inst.instruction = THUMB_OP32 (inst.instruction);
11423 else
11424 inst.instruction = THUMB_OP16 (inst.instruction);
11425}
90e4755a 11426
c19d1205
ZW
11427static void
11428do_t_it (void)
11429{
11430 unsigned int cond = inst.operands[0].imm;
e27ec89e 11431
e07e6e58
NC
11432 set_it_insn_type (IT_INSN);
11433 now_it.mask = (inst.instruction & 0xf) | 0x10;
11434 now_it.cc = cond;
5a01bb1d 11435 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11436
11437 /* If the condition is a negative condition, invert the mask. */
c19d1205 11438 if ((cond & 0x1) == 0x0)
90e4755a 11439 {
c19d1205 11440 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11441
c19d1205 11442 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11443 {
11444 /* No conversion needed. */
11445 now_it.block_length = 1;
11446 }
c19d1205 11447 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11448 {
11449 mask ^= 0x8;
11450 now_it.block_length = 2;
11451 }
e27ec89e 11452 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11453 {
11454 mask ^= 0xC;
11455 now_it.block_length = 3;
11456 }
c19d1205 11457 else
5a01bb1d
MGD
11458 {
11459 mask ^= 0xE;
11460 now_it.block_length = 4;
11461 }
90e4755a 11462
e27ec89e
PB
11463 inst.instruction &= 0xfff0;
11464 inst.instruction |= mask;
c19d1205 11465 }
90e4755a 11466
c19d1205
ZW
11467 inst.instruction |= cond << 4;
11468}
90e4755a 11469
3c707909
PB
11470/* Helper function used for both push/pop and ldm/stm. */
11471static void
11472encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11473{
11474 bfd_boolean load;
11475
11476 load = (inst.instruction & (1 << 20)) != 0;
11477
11478 if (mask & (1 << 13))
11479 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11480
11481 if ((mask & (1 << base)) != 0
11482 && writeback)
11483 inst.error = _("having the base register in the register list when "
11484 "using write back is UNPREDICTABLE");
11485
3c707909
PB
11486 if (load)
11487 {
e07e6e58 11488 if (mask & (1 << 15))
477330fc
RM
11489 {
11490 if (mask & (1 << 14))
11491 inst.error = _("LR and PC should not both be in register list");
11492 else
11493 set_it_insn_type_last ();
11494 }
3c707909
PB
11495 }
11496 else
11497 {
11498 if (mask & (1 << 15))
11499 inst.error = _("PC not allowed in register list");
3c707909
PB
11500 }
11501
11502 if ((mask & (mask - 1)) == 0)
11503 {
11504 /* Single register transfers implemented as str/ldr. */
11505 if (writeback)
11506 {
11507 if (inst.instruction & (1 << 23))
11508 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11509 else
11510 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11511 }
11512 else
11513 {
11514 if (inst.instruction & (1 << 23))
11515 inst.instruction = 0x00800000; /* ia -> [base] */
11516 else
11517 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11518 }
11519
11520 inst.instruction |= 0xf8400000;
11521 if (load)
11522 inst.instruction |= 0x00100000;
11523
5f4273c7 11524 mask = ffs (mask) - 1;
3c707909
PB
11525 mask <<= 12;
11526 }
11527 else if (writeback)
11528 inst.instruction |= WRITE_BACK;
11529
11530 inst.instruction |= mask;
11531 inst.instruction |= base << 16;
11532}
11533
c19d1205
ZW
11534static void
11535do_t_ldmstm (void)
11536{
11537 /* This really doesn't seem worth it. */
e2b0ab59 11538 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205
ZW
11539 _("expression too complex"));
11540 constraint (inst.operands[1].writeback,
11541 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11542
c19d1205
ZW
11543 if (unified_syntax)
11544 {
3c707909
PB
11545 bfd_boolean narrow;
11546 unsigned mask;
11547
11548 narrow = FALSE;
c19d1205
ZW
11549 /* See if we can use a 16-bit instruction. */
11550 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11551 && inst.size_req != 4
3c707909 11552 && !(inst.operands[1].imm & ~0xff))
90e4755a 11553 {
3c707909 11554 mask = 1 << inst.operands[0].reg;
90e4755a 11555
eab4f823 11556 if (inst.operands[0].reg <= 7)
90e4755a 11557 {
3c707909 11558 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11559 ? inst.operands[0].writeback
11560 : (inst.operands[0].writeback
11561 == !(inst.operands[1].imm & mask)))
477330fc 11562 {
eab4f823
MGD
11563 if (inst.instruction == T_MNEM_stmia
11564 && (inst.operands[1].imm & mask)
11565 && (inst.operands[1].imm & (mask - 1)))
11566 as_warn (_("value stored for r%d is UNKNOWN"),
11567 inst.operands[0].reg);
3c707909 11568
eab4f823
MGD
11569 inst.instruction = THUMB_OP16 (inst.instruction);
11570 inst.instruction |= inst.operands[0].reg << 8;
11571 inst.instruction |= inst.operands[1].imm;
11572 narrow = TRUE;
11573 }
11574 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11575 {
11576 /* This means 1 register in reg list one of 3 situations:
11577 1. Instruction is stmia, but without writeback.
11578 2. lmdia without writeback, but with Rn not in
477330fc 11579 reglist.
eab4f823
MGD
11580 3. ldmia with writeback, but with Rn in reglist.
11581 Case 3 is UNPREDICTABLE behaviour, so we handle
11582 case 1 and 2 which can be converted into a 16-bit
11583 str or ldr. The SP cases are handled below. */
11584 unsigned long opcode;
11585 /* First, record an error for Case 3. */
11586 if (inst.operands[1].imm & mask
11587 && inst.operands[0].writeback)
fa94de6b 11588 inst.error =
eab4f823
MGD
11589 _("having the base register in the register list when "
11590 "using write back is UNPREDICTABLE");
fa94de6b
RM
11591
11592 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11593 : T_MNEM_ldr);
11594 inst.instruction = THUMB_OP16 (opcode);
11595 inst.instruction |= inst.operands[0].reg << 3;
11596 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11597 narrow = TRUE;
11598 }
90e4755a 11599 }
eab4f823 11600 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11601 {
eab4f823
MGD
11602 if (inst.operands[0].writeback)
11603 {
fa94de6b 11604 inst.instruction =
eab4f823 11605 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11606 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11607 inst.instruction |= inst.operands[1].imm;
477330fc 11608 narrow = TRUE;
eab4f823
MGD
11609 }
11610 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11611 {
fa94de6b 11612 inst.instruction =
eab4f823 11613 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11614 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11615 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11616 narrow = TRUE;
eab4f823 11617 }
90e4755a 11618 }
3c707909
PB
11619 }
11620
11621 if (!narrow)
11622 {
c19d1205
ZW
11623 if (inst.instruction < 0xffff)
11624 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11625
5f4273c7
NC
11626 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11627 inst.operands[0].writeback);
90e4755a
RE
11628 }
11629 }
c19d1205 11630 else
90e4755a 11631 {
c19d1205
ZW
11632 constraint (inst.operands[0].reg > 7
11633 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11634 constraint (inst.instruction != T_MNEM_ldmia
11635 && inst.instruction != T_MNEM_stmia,
11636 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11637 if (inst.instruction == T_MNEM_stmia)
f03698e6 11638 {
c19d1205
ZW
11639 if (!inst.operands[0].writeback)
11640 as_warn (_("this instruction will write back the base register"));
11641 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11642 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11643 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11644 inst.operands[0].reg);
f03698e6 11645 }
c19d1205 11646 else
90e4755a 11647 {
c19d1205
ZW
11648 if (!inst.operands[0].writeback
11649 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11650 as_warn (_("this instruction will write back the base register"));
11651 else if (inst.operands[0].writeback
11652 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11653 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11654 }
11655
c19d1205
ZW
11656 inst.instruction = THUMB_OP16 (inst.instruction);
11657 inst.instruction |= inst.operands[0].reg << 8;
11658 inst.instruction |= inst.operands[1].imm;
11659 }
11660}
e28cd48c 11661
c19d1205
ZW
11662static void
11663do_t_ldrex (void)
11664{
11665 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11666 || inst.operands[1].postind || inst.operands[1].writeback
11667 || inst.operands[1].immisreg || inst.operands[1].shifted
11668 || inst.operands[1].negative,
01cfc07f 11669 BAD_ADDR_MODE);
e28cd48c 11670
5be8be5d
DG
11671 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11672
c19d1205
ZW
11673 inst.instruction |= inst.operands[0].reg << 12;
11674 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 11675 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
c19d1205 11676}
e28cd48c 11677
c19d1205
ZW
11678static void
11679do_t_ldrexd (void)
11680{
11681 if (!inst.operands[1].present)
1cac9012 11682 {
c19d1205
ZW
11683 constraint (inst.operands[0].reg == REG_LR,
11684 _("r14 not allowed as first register "
11685 "when second register is omitted"));
11686 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11687 }
c19d1205
ZW
11688 constraint (inst.operands[0].reg == inst.operands[1].reg,
11689 BAD_OVERLAP);
b99bd4ef 11690
c19d1205
ZW
11691 inst.instruction |= inst.operands[0].reg << 12;
11692 inst.instruction |= inst.operands[1].reg << 8;
11693 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11694}
11695
11696static void
c19d1205 11697do_t_ldst (void)
b99bd4ef 11698{
0110f2b8
PB
11699 unsigned long opcode;
11700 int Rn;
11701
e07e6e58
NC
11702 if (inst.operands[0].isreg
11703 && !inst.operands[0].preind
11704 && inst.operands[0].reg == REG_PC)
11705 set_it_insn_type_last ();
11706
0110f2b8 11707 opcode = inst.instruction;
c19d1205 11708 if (unified_syntax)
b99bd4ef 11709 {
53365c0d
PB
11710 if (!inst.operands[1].isreg)
11711 {
11712 if (opcode <= 0xffff)
11713 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11714 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11715 return;
11716 }
0110f2b8
PB
11717 if (inst.operands[1].isreg
11718 && !inst.operands[1].writeback
c19d1205
ZW
11719 && !inst.operands[1].shifted && !inst.operands[1].postind
11720 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11721 && opcode <= 0xffff
11722 && inst.size_req != 4)
c19d1205 11723 {
0110f2b8
PB
11724 /* Insn may have a 16-bit form. */
11725 Rn = inst.operands[1].reg;
11726 if (inst.operands[1].immisreg)
11727 {
11728 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11729 /* [Rn, Rik] */
0110f2b8
PB
11730 if (Rn <= 7 && inst.operands[1].imm <= 7)
11731 goto op16;
5be8be5d
DG
11732 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11733 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11734 }
11735 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11736 && opcode != T_MNEM_ldrsb)
11737 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11738 || (Rn == REG_SP && opcode == T_MNEM_str))
11739 {
11740 /* [Rn, #const] */
11741 if (Rn > 7)
11742 {
11743 if (Rn == REG_PC)
11744 {
e2b0ab59 11745 if (inst.relocs[0].pc_rel)
0110f2b8
PB
11746 opcode = T_MNEM_ldr_pc2;
11747 else
11748 opcode = T_MNEM_ldr_pc;
11749 }
11750 else
11751 {
11752 if (opcode == T_MNEM_ldr)
11753 opcode = T_MNEM_ldr_sp;
11754 else
11755 opcode = T_MNEM_str_sp;
11756 }
11757 inst.instruction = inst.operands[0].reg << 8;
11758 }
11759 else
11760 {
11761 inst.instruction = inst.operands[0].reg;
11762 inst.instruction |= inst.operands[1].reg << 3;
11763 }
11764 inst.instruction |= THUMB_OP16 (opcode);
11765 if (inst.size_req == 2)
e2b0ab59 11766 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
0110f2b8
PB
11767 else
11768 inst.relax = opcode;
11769 return;
11770 }
c19d1205 11771 }
0110f2b8 11772 /* Definitely a 32-bit variant. */
5be8be5d 11773
8d67f500
NC
11774 /* Warning for Erratum 752419. */
11775 if (opcode == T_MNEM_ldr
11776 && inst.operands[0].reg == REG_SP
11777 && inst.operands[1].writeback == 1
11778 && !inst.operands[1].immisreg)
11779 {
11780 if (no_cpu_selected ()
11781 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11782 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11783 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11784 as_warn (_("This instruction may be unpredictable "
11785 "if executed on M-profile cores "
11786 "with interrupts enabled."));
11787 }
11788
5be8be5d 11789 /* Do some validations regarding addressing modes. */
1be5fd2e 11790 if (inst.operands[1].immisreg)
5be8be5d
DG
11791 reject_bad_reg (inst.operands[1].imm);
11792
1be5fd2e
NC
11793 constraint (inst.operands[1].writeback == 1
11794 && inst.operands[0].reg == inst.operands[1].reg,
11795 BAD_OVERLAP);
11796
0110f2b8 11797 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11798 inst.instruction |= inst.operands[0].reg << 12;
11799 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11800 check_ldr_r15_aligned ();
b99bd4ef
NC
11801 return;
11802 }
11803
c19d1205
ZW
11804 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11805
11806 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11807 {
c19d1205
ZW
11808 /* Only [Rn,Rm] is acceptable. */
11809 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11810 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11811 || inst.operands[1].postind || inst.operands[1].shifted
11812 || inst.operands[1].negative,
11813 _("Thumb does not support this addressing mode"));
11814 inst.instruction = THUMB_OP16 (inst.instruction);
11815 goto op16;
b99bd4ef 11816 }
5f4273c7 11817
c19d1205
ZW
11818 inst.instruction = THUMB_OP16 (inst.instruction);
11819 if (!inst.operands[1].isreg)
8335d6aa 11820 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11821 return;
b99bd4ef 11822
c19d1205
ZW
11823 constraint (!inst.operands[1].preind
11824 || inst.operands[1].shifted
11825 || inst.operands[1].writeback,
11826 _("Thumb does not support this addressing mode"));
11827 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11828 {
c19d1205
ZW
11829 constraint (inst.instruction & 0x0600,
11830 _("byte or halfword not valid for base register"));
11831 constraint (inst.operands[1].reg == REG_PC
11832 && !(inst.instruction & THUMB_LOAD_BIT),
11833 _("r15 based store not allowed"));
11834 constraint (inst.operands[1].immisreg,
11835 _("invalid base register for register offset"));
b99bd4ef 11836
c19d1205
ZW
11837 if (inst.operands[1].reg == REG_PC)
11838 inst.instruction = T_OPCODE_LDR_PC;
11839 else if (inst.instruction & THUMB_LOAD_BIT)
11840 inst.instruction = T_OPCODE_LDR_SP;
11841 else
11842 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11843
c19d1205 11844 inst.instruction |= inst.operands[0].reg << 8;
e2b0ab59 11845 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
11846 return;
11847 }
90e4755a 11848
c19d1205
ZW
11849 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11850 if (!inst.operands[1].immisreg)
11851 {
11852 /* Immediate offset. */
11853 inst.instruction |= inst.operands[0].reg;
11854 inst.instruction |= inst.operands[1].reg << 3;
e2b0ab59 11855 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
11856 return;
11857 }
90e4755a 11858
c19d1205
ZW
11859 /* Register offset. */
11860 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11861 constraint (inst.operands[1].negative,
11862 _("Thumb does not support this addressing mode"));
90e4755a 11863
c19d1205
ZW
11864 op16:
11865 switch (inst.instruction)
11866 {
11867 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11868 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11869 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11870 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11871 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11872 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11873 case 0x5600 /* ldrsb */:
11874 case 0x5e00 /* ldrsh */: break;
11875 default: abort ();
11876 }
90e4755a 11877
c19d1205
ZW
11878 inst.instruction |= inst.operands[0].reg;
11879 inst.instruction |= inst.operands[1].reg << 3;
11880 inst.instruction |= inst.operands[1].imm << 6;
11881}
90e4755a 11882
c19d1205
ZW
11883static void
11884do_t_ldstd (void)
11885{
11886 if (!inst.operands[1].present)
b99bd4ef 11887 {
c19d1205
ZW
11888 inst.operands[1].reg = inst.operands[0].reg + 1;
11889 constraint (inst.operands[0].reg == REG_LR,
11890 _("r14 not allowed here"));
bd340a04 11891 constraint (inst.operands[0].reg == REG_R12,
477330fc 11892 _("r12 not allowed here"));
b99bd4ef 11893 }
bd340a04
MGD
11894
11895 if (inst.operands[2].writeback
11896 && (inst.operands[0].reg == inst.operands[2].reg
11897 || inst.operands[1].reg == inst.operands[2].reg))
11898 as_warn (_("base register written back, and overlaps "
477330fc 11899 "one of transfer registers"));
bd340a04 11900
c19d1205
ZW
11901 inst.instruction |= inst.operands[0].reg << 12;
11902 inst.instruction |= inst.operands[1].reg << 8;
11903 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11904}
11905
c19d1205
ZW
11906static void
11907do_t_ldstt (void)
11908{
11909 inst.instruction |= inst.operands[0].reg << 12;
11910 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11911}
a737bd4d 11912
b99bd4ef 11913static void
c19d1205 11914do_t_mla (void)
b99bd4ef 11915{
fdfde340 11916 unsigned Rd, Rn, Rm, Ra;
c921be7d 11917
fdfde340
JM
11918 Rd = inst.operands[0].reg;
11919 Rn = inst.operands[1].reg;
11920 Rm = inst.operands[2].reg;
11921 Ra = inst.operands[3].reg;
11922
11923 reject_bad_reg (Rd);
11924 reject_bad_reg (Rn);
11925 reject_bad_reg (Rm);
11926 reject_bad_reg (Ra);
11927
11928 inst.instruction |= Rd << 8;
11929 inst.instruction |= Rn << 16;
11930 inst.instruction |= Rm;
11931 inst.instruction |= Ra << 12;
c19d1205 11932}
b99bd4ef 11933
c19d1205
ZW
11934static void
11935do_t_mlal (void)
11936{
fdfde340
JM
11937 unsigned RdLo, RdHi, Rn, Rm;
11938
11939 RdLo = inst.operands[0].reg;
11940 RdHi = inst.operands[1].reg;
11941 Rn = inst.operands[2].reg;
11942 Rm = inst.operands[3].reg;
11943
11944 reject_bad_reg (RdLo);
11945 reject_bad_reg (RdHi);
11946 reject_bad_reg (Rn);
11947 reject_bad_reg (Rm);
11948
11949 inst.instruction |= RdLo << 12;
11950 inst.instruction |= RdHi << 8;
11951 inst.instruction |= Rn << 16;
11952 inst.instruction |= Rm;
c19d1205 11953}
b99bd4ef 11954
c19d1205
ZW
11955static void
11956do_t_mov_cmp (void)
11957{
fdfde340
JM
11958 unsigned Rn, Rm;
11959
11960 Rn = inst.operands[0].reg;
11961 Rm = inst.operands[1].reg;
11962
e07e6e58
NC
11963 if (Rn == REG_PC)
11964 set_it_insn_type_last ();
11965
c19d1205 11966 if (unified_syntax)
b99bd4ef 11967 {
c19d1205
ZW
11968 int r0off = (inst.instruction == T_MNEM_mov
11969 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11970 unsigned long opcode;
3d388997
PB
11971 bfd_boolean narrow;
11972 bfd_boolean low_regs;
11973
fdfde340 11974 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11975 opcode = inst.instruction;
e07e6e58 11976 if (in_it_block ())
0110f2b8 11977 narrow = opcode != T_MNEM_movs;
3d388997 11978 else
0110f2b8 11979 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11980 if (inst.size_req == 4
11981 || inst.operands[1].shifted)
11982 narrow = FALSE;
11983
efd81785
PB
11984 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11985 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11986 && !inst.operands[1].shifted
fdfde340
JM
11987 && Rn == REG_PC
11988 && Rm == REG_LR)
efd81785
PB
11989 {
11990 inst.instruction = T2_SUBS_PC_LR;
11991 return;
11992 }
11993
fdfde340
JM
11994 if (opcode == T_MNEM_cmp)
11995 {
11996 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11997 if (narrow)
11998 {
11999 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
12000 but valid. */
12001 warn_deprecated_sp (Rm);
12002 /* R15 was documented as a valid choice for Rm in ARMv6,
12003 but as UNPREDICTABLE in ARMv7. ARM's proprietary
12004 tools reject R15, so we do too. */
12005 constraint (Rm == REG_PC, BAD_PC);
12006 }
12007 else
12008 reject_bad_reg (Rm);
fdfde340
JM
12009 }
12010 else if (opcode == T_MNEM_mov
12011 || opcode == T_MNEM_movs)
12012 {
12013 if (inst.operands[1].isreg)
12014 {
12015 if (opcode == T_MNEM_movs)
12016 {
12017 reject_bad_reg (Rn);
12018 reject_bad_reg (Rm);
12019 }
76fa04a4
MGD
12020 else if (narrow)
12021 {
12022 /* This is mov.n. */
12023 if ((Rn == REG_SP || Rn == REG_PC)
12024 && (Rm == REG_SP || Rm == REG_PC))
12025 {
5c3696f8 12026 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
12027 "deprecated when r%u is the destination "
12028 "register."), Rm, Rn);
12029 }
12030 }
12031 else
12032 {
12033 /* This is mov.w. */
12034 constraint (Rn == REG_PC, BAD_PC);
12035 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
12036 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12037 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 12038 }
fdfde340
JM
12039 }
12040 else
12041 reject_bad_reg (Rn);
12042 }
12043
c19d1205
ZW
12044 if (!inst.operands[1].isreg)
12045 {
0110f2b8 12046 /* Immediate operand. */
e07e6e58 12047 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
12048 narrow = 0;
12049 if (low_regs && narrow)
12050 {
12051 inst.instruction = THUMB_OP16 (opcode);
fdfde340 12052 inst.instruction |= Rn << 8;
e2b0ab59
AV
12053 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12054 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 12055 {
a9f02af8 12056 if (inst.size_req == 2)
e2b0ab59 12057 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
12058 else
12059 inst.relax = opcode;
72d98d16 12060 }
0110f2b8
PB
12061 }
12062 else
12063 {
e2b0ab59
AV
12064 constraint ((inst.relocs[0].type
12065 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
12066 && (inst.relocs[0].type
12067 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8
MG
12068 THUMB1_RELOC_ONLY);
12069
0110f2b8
PB
12070 inst.instruction = THUMB_OP32 (inst.instruction);
12071 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12072 inst.instruction |= Rn << r0off;
e2b0ab59 12073 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8 12074 }
c19d1205 12075 }
728ca7c9
PB
12076 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12077 && (inst.instruction == T_MNEM_mov
12078 || inst.instruction == T_MNEM_movs))
12079 {
12080 /* Register shifts are encoded as separate shift instructions. */
12081 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
12082
e07e6e58 12083 if (in_it_block ())
728ca7c9
PB
12084 narrow = !flags;
12085 else
12086 narrow = flags;
12087
12088 if (inst.size_req == 4)
12089 narrow = FALSE;
12090
12091 if (!low_regs || inst.operands[1].imm > 7)
12092 narrow = FALSE;
12093
fdfde340 12094 if (Rn != Rm)
728ca7c9
PB
12095 narrow = FALSE;
12096
12097 switch (inst.operands[1].shift_kind)
12098 {
12099 case SHIFT_LSL:
12100 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12101 break;
12102 case SHIFT_ASR:
12103 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12104 break;
12105 case SHIFT_LSR:
12106 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12107 break;
12108 case SHIFT_ROR:
12109 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12110 break;
12111 default:
5f4273c7 12112 abort ();
728ca7c9
PB
12113 }
12114
12115 inst.instruction = opcode;
12116 if (narrow)
12117 {
fdfde340 12118 inst.instruction |= Rn;
728ca7c9
PB
12119 inst.instruction |= inst.operands[1].imm << 3;
12120 }
12121 else
12122 {
12123 if (flags)
12124 inst.instruction |= CONDS_BIT;
12125
fdfde340
JM
12126 inst.instruction |= Rn << 8;
12127 inst.instruction |= Rm << 16;
728ca7c9
PB
12128 inst.instruction |= inst.operands[1].imm;
12129 }
12130 }
3d388997 12131 else if (!narrow)
c19d1205 12132 {
728ca7c9
PB
12133 /* Some mov with immediate shift have narrow variants.
12134 Register shifts are handled above. */
12135 if (low_regs && inst.operands[1].shifted
12136 && (inst.instruction == T_MNEM_mov
12137 || inst.instruction == T_MNEM_movs))
12138 {
e07e6e58 12139 if (in_it_block ())
728ca7c9
PB
12140 narrow = (inst.instruction == T_MNEM_mov);
12141 else
12142 narrow = (inst.instruction == T_MNEM_movs);
12143 }
12144
12145 if (narrow)
12146 {
12147 switch (inst.operands[1].shift_kind)
12148 {
12149 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12150 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12151 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12152 default: narrow = FALSE; break;
12153 }
12154 }
12155
12156 if (narrow)
12157 {
fdfde340
JM
12158 inst.instruction |= Rn;
12159 inst.instruction |= Rm << 3;
e2b0ab59 12160 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
728ca7c9
PB
12161 }
12162 else
12163 {
12164 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12165 inst.instruction |= Rn << r0off;
728ca7c9
PB
12166 encode_thumb32_shifted_operand (1);
12167 }
c19d1205
ZW
12168 }
12169 else
12170 switch (inst.instruction)
12171 {
12172 case T_MNEM_mov:
837b3435 12173 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12174 results. Don't allow this. */
12175 if (low_regs)
12176 {
12177 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12178 "MOV Rd, Rs with two low registers is not "
12179 "permitted on this architecture");
fa94de6b 12180 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12181 arm_ext_v6);
12182 }
12183
c19d1205 12184 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12185 inst.instruction |= (Rn & 0x8) << 4;
12186 inst.instruction |= (Rn & 0x7);
12187 inst.instruction |= Rm << 3;
c19d1205 12188 break;
b99bd4ef 12189
c19d1205
ZW
12190 case T_MNEM_movs:
12191 /* We know we have low registers at this point.
941a8a52
MGD
12192 Generate LSLS Rd, Rs, #0. */
12193 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12194 inst.instruction |= Rn;
12195 inst.instruction |= Rm << 3;
c19d1205
ZW
12196 break;
12197
12198 case T_MNEM_cmp:
3d388997 12199 if (low_regs)
c19d1205
ZW
12200 {
12201 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12202 inst.instruction |= Rn;
12203 inst.instruction |= Rm << 3;
c19d1205
ZW
12204 }
12205 else
12206 {
12207 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12208 inst.instruction |= (Rn & 0x8) << 4;
12209 inst.instruction |= (Rn & 0x7);
12210 inst.instruction |= Rm << 3;
c19d1205
ZW
12211 }
12212 break;
12213 }
b99bd4ef
NC
12214 return;
12215 }
12216
c19d1205 12217 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12218
12219 /* PR 10443: Do not silently ignore shifted operands. */
12220 constraint (inst.operands[1].shifted,
12221 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12222
c19d1205 12223 if (inst.operands[1].isreg)
b99bd4ef 12224 {
fdfde340 12225 if (Rn < 8 && Rm < 8)
b99bd4ef 12226 {
c19d1205
ZW
12227 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12228 since a MOV instruction produces unpredictable results. */
12229 if (inst.instruction == T_OPCODE_MOV_I8)
12230 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12231 else
c19d1205 12232 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12233
fdfde340
JM
12234 inst.instruction |= Rn;
12235 inst.instruction |= Rm << 3;
b99bd4ef
NC
12236 }
12237 else
12238 {
c19d1205
ZW
12239 if (inst.instruction == T_OPCODE_MOV_I8)
12240 inst.instruction = T_OPCODE_MOV_HR;
12241 else
12242 inst.instruction = T_OPCODE_CMP_HR;
12243 do_t_cpy ();
b99bd4ef
NC
12244 }
12245 }
c19d1205 12246 else
b99bd4ef 12247 {
fdfde340 12248 constraint (Rn > 7,
c19d1205 12249 _("only lo regs allowed with immediate"));
fdfde340 12250 inst.instruction |= Rn << 8;
e2b0ab59 12251 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
c19d1205
ZW
12252 }
12253}
b99bd4ef 12254
c19d1205
ZW
12255static void
12256do_t_mov16 (void)
12257{
fdfde340 12258 unsigned Rd;
b6895b4f
PB
12259 bfd_vma imm;
12260 bfd_boolean top;
12261
12262 top = (inst.instruction & 0x00800000) != 0;
e2b0ab59 12263 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
b6895b4f 12264 {
33eaf5de 12265 constraint (top, _(":lower16: not allowed in this instruction"));
e2b0ab59 12266 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
b6895b4f 12267 }
e2b0ab59 12268 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
b6895b4f 12269 {
33eaf5de 12270 constraint (!top, _(":upper16: not allowed in this instruction"));
e2b0ab59 12271 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
b6895b4f
PB
12272 }
12273
fdfde340
JM
12274 Rd = inst.operands[0].reg;
12275 reject_bad_reg (Rd);
12276
12277 inst.instruction |= Rd << 8;
e2b0ab59 12278 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 12279 {
e2b0ab59 12280 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
12281 inst.instruction |= (imm & 0xf000) << 4;
12282 inst.instruction |= (imm & 0x0800) << 15;
12283 inst.instruction |= (imm & 0x0700) << 4;
12284 inst.instruction |= (imm & 0x00ff);
12285 }
c19d1205 12286}
b99bd4ef 12287
c19d1205
ZW
12288static void
12289do_t_mvn_tst (void)
12290{
fdfde340 12291 unsigned Rn, Rm;
c921be7d 12292
fdfde340
JM
12293 Rn = inst.operands[0].reg;
12294 Rm = inst.operands[1].reg;
12295
12296 if (inst.instruction == T_MNEM_cmp
12297 || inst.instruction == T_MNEM_cmn)
12298 constraint (Rn == REG_PC, BAD_PC);
12299 else
12300 reject_bad_reg (Rn);
12301 reject_bad_reg (Rm);
12302
c19d1205
ZW
12303 if (unified_syntax)
12304 {
12305 int r0off = (inst.instruction == T_MNEM_mvn
12306 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12307 bfd_boolean narrow;
12308
12309 if (inst.size_req == 4
12310 || inst.instruction > 0xffff
12311 || inst.operands[1].shifted
fdfde340 12312 || Rn > 7 || Rm > 7)
3d388997 12313 narrow = FALSE;
fe8b4cc3
KT
12314 else if (inst.instruction == T_MNEM_cmn
12315 || inst.instruction == T_MNEM_tst)
3d388997
PB
12316 narrow = TRUE;
12317 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12318 narrow = !in_it_block ();
3d388997 12319 else
e07e6e58 12320 narrow = in_it_block ();
3d388997 12321
c19d1205 12322 if (!inst.operands[1].isreg)
b99bd4ef 12323 {
c19d1205
ZW
12324 /* For an immediate, we always generate a 32-bit opcode;
12325 section relaxation will shrink it later if possible. */
12326 if (inst.instruction < 0xffff)
12327 inst.instruction = THUMB_OP32 (inst.instruction);
12328 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12329 inst.instruction |= Rn << r0off;
e2b0ab59 12330 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12331 }
c19d1205 12332 else
b99bd4ef 12333 {
c19d1205 12334 /* See if we can do this with a 16-bit instruction. */
3d388997 12335 if (narrow)
b99bd4ef 12336 {
c19d1205 12337 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12338 inst.instruction |= Rn;
12339 inst.instruction |= Rm << 3;
b99bd4ef 12340 }
c19d1205 12341 else
b99bd4ef 12342 {
c19d1205
ZW
12343 constraint (inst.operands[1].shifted
12344 && inst.operands[1].immisreg,
12345 _("shift must be constant"));
12346 if (inst.instruction < 0xffff)
12347 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12348 inst.instruction |= Rn << r0off;
c19d1205 12349 encode_thumb32_shifted_operand (1);
b99bd4ef 12350 }
b99bd4ef
NC
12351 }
12352 }
12353 else
12354 {
c19d1205
ZW
12355 constraint (inst.instruction > 0xffff
12356 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12357 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12358 _("unshifted register required"));
fdfde340 12359 constraint (Rn > 7 || Rm > 7,
c19d1205 12360 BAD_HIREG);
b99bd4ef 12361
c19d1205 12362 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12363 inst.instruction |= Rn;
12364 inst.instruction |= Rm << 3;
b99bd4ef 12365 }
b99bd4ef
NC
12366}
12367
b05fe5cf 12368static void
c19d1205 12369do_t_mrs (void)
b05fe5cf 12370{
fdfde340 12371 unsigned Rd;
037e8744
JB
12372
12373 if (do_vfp_nsyn_mrs () == SUCCESS)
12374 return;
12375
90ec0d68
MGD
12376 Rd = inst.operands[0].reg;
12377 reject_bad_reg (Rd);
12378 inst.instruction |= Rd << 8;
12379
12380 if (inst.operands[1].isreg)
62b3e311 12381 {
90ec0d68
MGD
12382 unsigned br = inst.operands[1].reg;
12383 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12384 as_bad (_("bad register for mrs"));
12385
12386 inst.instruction |= br & (0xf << 16);
12387 inst.instruction |= (br & 0x300) >> 4;
12388 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12389 }
12390 else
12391 {
90ec0d68 12392 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12393
d2cd1205 12394 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12395 {
12396 /* PR gas/12698: The constraint is only applied for m_profile.
12397 If the user has specified -march=all, we want to ignore it as
12398 we are building for any CPU type, including non-m variants. */
823d2571
TG
12399 bfd_boolean m_profile =
12400 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12401 constraint ((flags != 0) && m_profile, _("selected processor does "
12402 "not support requested special purpose register"));
12403 }
90ec0d68 12404 else
d2cd1205
JB
12405 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12406 devices). */
12407 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12408 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12409
90ec0d68
MGD
12410 inst.instruction |= (flags & SPSR_BIT) >> 2;
12411 inst.instruction |= inst.operands[1].imm & 0xff;
12412 inst.instruction |= 0xf0000;
12413 }
c19d1205 12414}
b05fe5cf 12415
c19d1205
ZW
12416static void
12417do_t_msr (void)
12418{
62b3e311 12419 int flags;
fdfde340 12420 unsigned Rn;
62b3e311 12421
037e8744
JB
12422 if (do_vfp_nsyn_msr () == SUCCESS)
12423 return;
12424
c19d1205
ZW
12425 constraint (!inst.operands[1].isreg,
12426 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12427
12428 if (inst.operands[0].isreg)
12429 flags = (int)(inst.operands[0].reg);
12430 else
12431 flags = inst.operands[0].imm;
12432
d2cd1205 12433 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12434 {
d2cd1205
JB
12435 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12436
1a43faaf 12437 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12438 If the user has specified -march=all, we want to ignore it as
12439 we are building for any CPU type, including non-m variants. */
823d2571
TG
12440 bfd_boolean m_profile =
12441 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12442 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12443 && (bits & ~(PSR_s | PSR_f)) != 0)
12444 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12445 && bits != PSR_f)) && m_profile,
12446 _("selected processor does not support requested special "
12447 "purpose register"));
62b3e311
PB
12448 }
12449 else
d2cd1205
JB
12450 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12451 "requested special purpose register"));
c921be7d 12452
fdfde340
JM
12453 Rn = inst.operands[1].reg;
12454 reject_bad_reg (Rn);
12455
62b3e311 12456 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12457 inst.instruction |= (flags & 0xf0000) >> 8;
12458 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12459 inst.instruction |= (flags & 0xff);
fdfde340 12460 inst.instruction |= Rn << 16;
c19d1205 12461}
b05fe5cf 12462
c19d1205
ZW
12463static void
12464do_t_mul (void)
12465{
17828f45 12466 bfd_boolean narrow;
fdfde340 12467 unsigned Rd, Rn, Rm;
17828f45 12468
c19d1205
ZW
12469 if (!inst.operands[2].present)
12470 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12471
fdfde340
JM
12472 Rd = inst.operands[0].reg;
12473 Rn = inst.operands[1].reg;
12474 Rm = inst.operands[2].reg;
12475
17828f45 12476 if (unified_syntax)
b05fe5cf 12477 {
17828f45 12478 if (inst.size_req == 4
fdfde340
JM
12479 || (Rd != Rn
12480 && Rd != Rm)
12481 || Rn > 7
12482 || Rm > 7)
17828f45
JM
12483 narrow = FALSE;
12484 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12485 narrow = !in_it_block ();
17828f45 12486 else
e07e6e58 12487 narrow = in_it_block ();
b05fe5cf 12488 }
c19d1205 12489 else
b05fe5cf 12490 {
17828f45 12491 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12492 constraint (Rn > 7 || Rm > 7,
c19d1205 12493 BAD_HIREG);
17828f45
JM
12494 narrow = TRUE;
12495 }
b05fe5cf 12496
17828f45
JM
12497 if (narrow)
12498 {
12499 /* 16-bit MULS/Conditional MUL. */
c19d1205 12500 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12501 inst.instruction |= Rd;
b05fe5cf 12502
fdfde340
JM
12503 if (Rd == Rn)
12504 inst.instruction |= Rm << 3;
12505 else if (Rd == Rm)
12506 inst.instruction |= Rn << 3;
c19d1205
ZW
12507 else
12508 constraint (1, _("dest must overlap one source register"));
12509 }
17828f45
JM
12510 else
12511 {
e07e6e58
NC
12512 constraint (inst.instruction != T_MNEM_mul,
12513 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12514 /* 32-bit MUL. */
12515 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12516 inst.instruction |= Rd << 8;
12517 inst.instruction |= Rn << 16;
12518 inst.instruction |= Rm << 0;
12519
12520 reject_bad_reg (Rd);
12521 reject_bad_reg (Rn);
12522 reject_bad_reg (Rm);
17828f45 12523 }
c19d1205 12524}
b05fe5cf 12525
c19d1205
ZW
12526static void
12527do_t_mull (void)
12528{
fdfde340 12529 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12530
fdfde340
JM
12531 RdLo = inst.operands[0].reg;
12532 RdHi = inst.operands[1].reg;
12533 Rn = inst.operands[2].reg;
12534 Rm = inst.operands[3].reg;
12535
12536 reject_bad_reg (RdLo);
12537 reject_bad_reg (RdHi);
12538 reject_bad_reg (Rn);
12539 reject_bad_reg (Rm);
12540
12541 inst.instruction |= RdLo << 12;
12542 inst.instruction |= RdHi << 8;
12543 inst.instruction |= Rn << 16;
12544 inst.instruction |= Rm;
12545
12546 if (RdLo == RdHi)
c19d1205
ZW
12547 as_tsktsk (_("rdhi and rdlo must be different"));
12548}
b05fe5cf 12549
c19d1205
ZW
12550static void
12551do_t_nop (void)
12552{
e07e6e58
NC
12553 set_it_insn_type (NEUTRAL_IT_INSN);
12554
c19d1205
ZW
12555 if (unified_syntax)
12556 {
12557 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12558 {
c19d1205
ZW
12559 inst.instruction = THUMB_OP32 (inst.instruction);
12560 inst.instruction |= inst.operands[0].imm;
12561 }
12562 else
12563 {
bc2d1808
NC
12564 /* PR9722: Check for Thumb2 availability before
12565 generating a thumb2 nop instruction. */
afa62d5e 12566 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12567 {
12568 inst.instruction = THUMB_OP16 (inst.instruction);
12569 inst.instruction |= inst.operands[0].imm << 4;
12570 }
12571 else
12572 inst.instruction = 0x46c0;
c19d1205
ZW
12573 }
12574 }
12575 else
12576 {
12577 constraint (inst.operands[0].present,
12578 _("Thumb does not support NOP with hints"));
12579 inst.instruction = 0x46c0;
12580 }
12581}
b05fe5cf 12582
c19d1205
ZW
12583static void
12584do_t_neg (void)
12585{
12586 if (unified_syntax)
12587 {
3d388997
PB
12588 bfd_boolean narrow;
12589
12590 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12591 narrow = !in_it_block ();
3d388997 12592 else
e07e6e58 12593 narrow = in_it_block ();
3d388997
PB
12594 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12595 narrow = FALSE;
12596 if (inst.size_req == 4)
12597 narrow = FALSE;
12598
12599 if (!narrow)
c19d1205
ZW
12600 {
12601 inst.instruction = THUMB_OP32 (inst.instruction);
12602 inst.instruction |= inst.operands[0].reg << 8;
12603 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12604 }
12605 else
12606 {
c19d1205
ZW
12607 inst.instruction = THUMB_OP16 (inst.instruction);
12608 inst.instruction |= inst.operands[0].reg;
12609 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12610 }
12611 }
12612 else
12613 {
c19d1205
ZW
12614 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12615 BAD_HIREG);
12616 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12617
12618 inst.instruction = THUMB_OP16 (inst.instruction);
12619 inst.instruction |= inst.operands[0].reg;
12620 inst.instruction |= inst.operands[1].reg << 3;
12621 }
12622}
12623
1c444d06
JM
12624static void
12625do_t_orn (void)
12626{
12627 unsigned Rd, Rn;
12628
12629 Rd = inst.operands[0].reg;
12630 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12631
fdfde340
JM
12632 reject_bad_reg (Rd);
12633 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12634 reject_bad_reg (Rn);
12635
1c444d06
JM
12636 inst.instruction |= Rd << 8;
12637 inst.instruction |= Rn << 16;
12638
12639 if (!inst.operands[2].isreg)
12640 {
12641 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 12642 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
1c444d06
JM
12643 }
12644 else
12645 {
12646 unsigned Rm;
12647
12648 Rm = inst.operands[2].reg;
fdfde340 12649 reject_bad_reg (Rm);
1c444d06
JM
12650
12651 constraint (inst.operands[2].shifted
12652 && inst.operands[2].immisreg,
12653 _("shift must be constant"));
12654 encode_thumb32_shifted_operand (2);
12655 }
12656}
12657
c19d1205
ZW
12658static void
12659do_t_pkhbt (void)
12660{
fdfde340
JM
12661 unsigned Rd, Rn, Rm;
12662
12663 Rd = inst.operands[0].reg;
12664 Rn = inst.operands[1].reg;
12665 Rm = inst.operands[2].reg;
12666
12667 reject_bad_reg (Rd);
12668 reject_bad_reg (Rn);
12669 reject_bad_reg (Rm);
12670
12671 inst.instruction |= Rd << 8;
12672 inst.instruction |= Rn << 16;
12673 inst.instruction |= Rm;
c19d1205
ZW
12674 if (inst.operands[3].present)
12675 {
e2b0ab59
AV
12676 unsigned int val = inst.relocs[0].exp.X_add_number;
12677 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
12678 _("expression too complex"));
12679 inst.instruction |= (val & 0x1c) << 10;
12680 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12681 }
c19d1205 12682}
b05fe5cf 12683
c19d1205
ZW
12684static void
12685do_t_pkhtb (void)
12686{
12687 if (!inst.operands[3].present)
1ef52f49
NC
12688 {
12689 unsigned Rtmp;
12690
12691 inst.instruction &= ~0x00000020;
12692
12693 /* PR 10168. Swap the Rm and Rn registers. */
12694 Rtmp = inst.operands[1].reg;
12695 inst.operands[1].reg = inst.operands[2].reg;
12696 inst.operands[2].reg = Rtmp;
12697 }
c19d1205 12698 do_t_pkhbt ();
b05fe5cf
ZW
12699}
12700
c19d1205
ZW
12701static void
12702do_t_pld (void)
12703{
fdfde340
JM
12704 if (inst.operands[0].immisreg)
12705 reject_bad_reg (inst.operands[0].imm);
12706
c19d1205
ZW
12707 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12708}
b05fe5cf 12709
c19d1205
ZW
12710static void
12711do_t_push_pop (void)
b99bd4ef 12712{
e9f89963 12713 unsigned mask;
5f4273c7 12714
c19d1205
ZW
12715 constraint (inst.operands[0].writeback,
12716 _("push/pop do not support {reglist}^"));
e2b0ab59 12717 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205 12718 _("expression too complex"));
b99bd4ef 12719
e9f89963 12720 mask = inst.operands[0].imm;
d3bfe16e 12721 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12722 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12723 else if (inst.size_req != 4
c6025a80 12724 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12725 ? REG_LR : REG_PC)))
b99bd4ef 12726 {
c19d1205
ZW
12727 inst.instruction = THUMB_OP16 (inst.instruction);
12728 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12729 inst.instruction |= mask & 0xff;
c19d1205
ZW
12730 }
12731 else if (unified_syntax)
12732 {
3c707909 12733 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12734 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12735 }
12736 else
12737 {
12738 inst.error = _("invalid register list to push/pop instruction");
12739 return;
12740 }
c19d1205 12741}
b99bd4ef 12742
c19d1205
ZW
12743static void
12744do_t_rbit (void)
12745{
fdfde340
JM
12746 unsigned Rd, Rm;
12747
12748 Rd = inst.operands[0].reg;
12749 Rm = inst.operands[1].reg;
12750
12751 reject_bad_reg (Rd);
12752 reject_bad_reg (Rm);
12753
12754 inst.instruction |= Rd << 8;
12755 inst.instruction |= Rm << 16;
12756 inst.instruction |= Rm;
c19d1205 12757}
b99bd4ef 12758
c19d1205
ZW
12759static void
12760do_t_rev (void)
12761{
fdfde340
JM
12762 unsigned Rd, Rm;
12763
12764 Rd = inst.operands[0].reg;
12765 Rm = inst.operands[1].reg;
12766
12767 reject_bad_reg (Rd);
12768 reject_bad_reg (Rm);
12769
12770 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12771 && inst.size_req != 4)
12772 {
12773 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12774 inst.instruction |= Rd;
12775 inst.instruction |= Rm << 3;
c19d1205
ZW
12776 }
12777 else if (unified_syntax)
12778 {
12779 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12780 inst.instruction |= Rd << 8;
12781 inst.instruction |= Rm << 16;
12782 inst.instruction |= Rm;
c19d1205
ZW
12783 }
12784 else
12785 inst.error = BAD_HIREG;
12786}
b99bd4ef 12787
1c444d06
JM
12788static void
12789do_t_rrx (void)
12790{
12791 unsigned Rd, Rm;
12792
12793 Rd = inst.operands[0].reg;
12794 Rm = inst.operands[1].reg;
12795
fdfde340
JM
12796 reject_bad_reg (Rd);
12797 reject_bad_reg (Rm);
c921be7d 12798
1c444d06
JM
12799 inst.instruction |= Rd << 8;
12800 inst.instruction |= Rm;
12801}
12802
c19d1205
ZW
12803static void
12804do_t_rsb (void)
12805{
fdfde340 12806 unsigned Rd, Rs;
b99bd4ef 12807
c19d1205
ZW
12808 Rd = inst.operands[0].reg;
12809 Rs = (inst.operands[1].present
12810 ? inst.operands[1].reg /* Rd, Rs, foo */
12811 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12812
fdfde340
JM
12813 reject_bad_reg (Rd);
12814 reject_bad_reg (Rs);
12815 if (inst.operands[2].isreg)
12816 reject_bad_reg (inst.operands[2].reg);
12817
c19d1205
ZW
12818 inst.instruction |= Rd << 8;
12819 inst.instruction |= Rs << 16;
12820 if (!inst.operands[2].isreg)
12821 {
026d3abb
PB
12822 bfd_boolean narrow;
12823
12824 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12825 narrow = !in_it_block ();
026d3abb 12826 else
e07e6e58 12827 narrow = in_it_block ();
026d3abb
PB
12828
12829 if (Rd > 7 || Rs > 7)
12830 narrow = FALSE;
12831
12832 if (inst.size_req == 4 || !unified_syntax)
12833 narrow = FALSE;
12834
e2b0ab59
AV
12835 if (inst.relocs[0].exp.X_op != O_constant
12836 || inst.relocs[0].exp.X_add_number != 0)
026d3abb
PB
12837 narrow = FALSE;
12838
12839 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12840 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12841 if (narrow)
12842 {
e2b0ab59 12843 inst.relocs[0].type = BFD_RELOC_UNUSED;
026d3abb
PB
12844 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12845 inst.instruction |= Rs << 3;
12846 inst.instruction |= Rd;
12847 }
12848 else
12849 {
12850 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 12851 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
026d3abb 12852 }
c19d1205
ZW
12853 }
12854 else
12855 encode_thumb32_shifted_operand (2);
12856}
b99bd4ef 12857
c19d1205
ZW
12858static void
12859do_t_setend (void)
12860{
12e37cbc
MGD
12861 if (warn_on_deprecated
12862 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12863 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12864
e07e6e58 12865 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12866 if (inst.operands[0].imm)
12867 inst.instruction |= 0x8;
12868}
b99bd4ef 12869
c19d1205
ZW
12870static void
12871do_t_shift (void)
12872{
12873 if (!inst.operands[1].present)
12874 inst.operands[1].reg = inst.operands[0].reg;
12875
12876 if (unified_syntax)
12877 {
3d388997
PB
12878 bfd_boolean narrow;
12879 int shift_kind;
12880
12881 switch (inst.instruction)
12882 {
12883 case T_MNEM_asr:
12884 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12885 case T_MNEM_lsl:
12886 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12887 case T_MNEM_lsr:
12888 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12889 case T_MNEM_ror:
12890 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12891 default: abort ();
12892 }
12893
12894 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12895 narrow = !in_it_block ();
3d388997 12896 else
e07e6e58 12897 narrow = in_it_block ();
3d388997
PB
12898 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12899 narrow = FALSE;
12900 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12901 narrow = FALSE;
12902 if (inst.operands[2].isreg
12903 && (inst.operands[1].reg != inst.operands[0].reg
12904 || inst.operands[2].reg > 7))
12905 narrow = FALSE;
12906 if (inst.size_req == 4)
12907 narrow = FALSE;
12908
fdfde340
JM
12909 reject_bad_reg (inst.operands[0].reg);
12910 reject_bad_reg (inst.operands[1].reg);
c921be7d 12911
3d388997 12912 if (!narrow)
c19d1205
ZW
12913 {
12914 if (inst.operands[2].isreg)
b99bd4ef 12915 {
fdfde340 12916 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12917 inst.instruction = THUMB_OP32 (inst.instruction);
12918 inst.instruction |= inst.operands[0].reg << 8;
12919 inst.instruction |= inst.operands[1].reg << 16;
12920 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12921
12922 /* PR 12854: Error on extraneous shifts. */
12923 constraint (inst.operands[2].shifted,
12924 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12925 }
12926 else
12927 {
12928 inst.operands[1].shifted = 1;
3d388997 12929 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12930 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12931 ? T_MNEM_movs : T_MNEM_mov);
12932 inst.instruction |= inst.operands[0].reg << 8;
12933 encode_thumb32_shifted_operand (1);
12934 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
e2b0ab59 12935 inst.relocs[0].type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12936 }
12937 }
12938 else
12939 {
c19d1205 12940 if (inst.operands[2].isreg)
b99bd4ef 12941 {
3d388997 12942 switch (shift_kind)
b99bd4ef 12943 {
3d388997
PB
12944 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12945 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12946 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12947 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12948 default: abort ();
b99bd4ef 12949 }
5f4273c7 12950
c19d1205
ZW
12951 inst.instruction |= inst.operands[0].reg;
12952 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12953
12954 /* PR 12854: Error on extraneous shifts. */
12955 constraint (inst.operands[2].shifted,
12956 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12957 }
12958 else
12959 {
3d388997 12960 switch (shift_kind)
b99bd4ef 12961 {
3d388997
PB
12962 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12963 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12964 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12965 default: abort ();
b99bd4ef 12966 }
e2b0ab59 12967 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
12968 inst.instruction |= inst.operands[0].reg;
12969 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12970 }
12971 }
c19d1205
ZW
12972 }
12973 else
12974 {
12975 constraint (inst.operands[0].reg > 7
12976 || inst.operands[1].reg > 7, BAD_HIREG);
12977 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12978
c19d1205
ZW
12979 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12980 {
12981 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12982 constraint (inst.operands[0].reg != inst.operands[1].reg,
12983 _("source1 and dest must be same register"));
b99bd4ef 12984
c19d1205
ZW
12985 switch (inst.instruction)
12986 {
12987 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12988 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12989 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12990 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12991 default: abort ();
12992 }
5f4273c7 12993
c19d1205
ZW
12994 inst.instruction |= inst.operands[0].reg;
12995 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12996
12997 /* PR 12854: Error on extraneous shifts. */
12998 constraint (inst.operands[2].shifted,
12999 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
13000 }
13001 else
b99bd4ef 13002 {
c19d1205
ZW
13003 switch (inst.instruction)
13004 {
13005 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
13006 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
13007 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
13008 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
13009 default: abort ();
13010 }
e2b0ab59 13011 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
13012 inst.instruction |= inst.operands[0].reg;
13013 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
13014 }
13015 }
b99bd4ef
NC
13016}
13017
13018static void
c19d1205 13019do_t_simd (void)
b99bd4ef 13020{
fdfde340
JM
13021 unsigned Rd, Rn, Rm;
13022
13023 Rd = inst.operands[0].reg;
13024 Rn = inst.operands[1].reg;
13025 Rm = inst.operands[2].reg;
13026
13027 reject_bad_reg (Rd);
13028 reject_bad_reg (Rn);
13029 reject_bad_reg (Rm);
13030
13031 inst.instruction |= Rd << 8;
13032 inst.instruction |= Rn << 16;
13033 inst.instruction |= Rm;
c19d1205 13034}
b99bd4ef 13035
03ee1b7f
NC
13036static void
13037do_t_simd2 (void)
13038{
13039 unsigned Rd, Rn, Rm;
13040
13041 Rd = inst.operands[0].reg;
13042 Rm = inst.operands[1].reg;
13043 Rn = inst.operands[2].reg;
13044
13045 reject_bad_reg (Rd);
13046 reject_bad_reg (Rn);
13047 reject_bad_reg (Rm);
13048
13049 inst.instruction |= Rd << 8;
13050 inst.instruction |= Rn << 16;
13051 inst.instruction |= Rm;
13052}
13053
c19d1205 13054static void
3eb17e6b 13055do_t_smc (void)
c19d1205 13056{
e2b0ab59 13057 unsigned int value = inst.relocs[0].exp.X_add_number;
f4c65163
MGD
13058 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
13059 _("SMC is not permitted on this architecture"));
e2b0ab59 13060 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 13061 _("expression too complex"));
e2b0ab59 13062 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205
ZW
13063 inst.instruction |= (value & 0xf000) >> 12;
13064 inst.instruction |= (value & 0x0ff0);
13065 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
13066 /* PR gas/15623: SMC instructions must be last in an IT block. */
13067 set_it_insn_type_last ();
c19d1205 13068}
b99bd4ef 13069
90ec0d68
MGD
13070static void
13071do_t_hvc (void)
13072{
e2b0ab59 13073 unsigned int value = inst.relocs[0].exp.X_add_number;
90ec0d68 13074
e2b0ab59 13075 inst.relocs[0].type = BFD_RELOC_UNUSED;
90ec0d68
MGD
13076 inst.instruction |= (value & 0x0fff);
13077 inst.instruction |= (value & 0xf000) << 4;
13078}
13079
c19d1205 13080static void
3a21c15a 13081do_t_ssat_usat (int bias)
c19d1205 13082{
fdfde340
JM
13083 unsigned Rd, Rn;
13084
13085 Rd = inst.operands[0].reg;
13086 Rn = inst.operands[2].reg;
13087
13088 reject_bad_reg (Rd);
13089 reject_bad_reg (Rn);
13090
13091 inst.instruction |= Rd << 8;
3a21c15a 13092 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 13093 inst.instruction |= Rn << 16;
b99bd4ef 13094
c19d1205 13095 if (inst.operands[3].present)
b99bd4ef 13096 {
e2b0ab59 13097 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
3a21c15a 13098
e2b0ab59 13099 inst.relocs[0].type = BFD_RELOC_UNUSED;
3a21c15a 13100
e2b0ab59 13101 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 13102 _("expression too complex"));
b99bd4ef 13103
3a21c15a 13104 if (shift_amount != 0)
6189168b 13105 {
3a21c15a
NC
13106 constraint (shift_amount > 31,
13107 _("shift expression is too large"));
13108
c19d1205 13109 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
13110 inst.instruction |= 0x00200000; /* sh bit. */
13111
13112 inst.instruction |= (shift_amount & 0x1c) << 10;
13113 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
13114 }
13115 }
b99bd4ef 13116}
c921be7d 13117
3a21c15a
NC
13118static void
13119do_t_ssat (void)
13120{
13121 do_t_ssat_usat (1);
13122}
b99bd4ef 13123
0dd132b6 13124static void
c19d1205 13125do_t_ssat16 (void)
0dd132b6 13126{
fdfde340
JM
13127 unsigned Rd, Rn;
13128
13129 Rd = inst.operands[0].reg;
13130 Rn = inst.operands[2].reg;
13131
13132 reject_bad_reg (Rd);
13133 reject_bad_reg (Rn);
13134
13135 inst.instruction |= Rd << 8;
c19d1205 13136 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 13137 inst.instruction |= Rn << 16;
c19d1205 13138}
0dd132b6 13139
c19d1205
ZW
13140static void
13141do_t_strex (void)
13142{
13143 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13144 || inst.operands[2].postind || inst.operands[2].writeback
13145 || inst.operands[2].immisreg || inst.operands[2].shifted
13146 || inst.operands[2].negative,
01cfc07f 13147 BAD_ADDR_MODE);
0dd132b6 13148
5be8be5d
DG
13149 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13150
c19d1205
ZW
13151 inst.instruction |= inst.operands[0].reg << 8;
13152 inst.instruction |= inst.operands[1].reg << 12;
13153 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 13154 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13155}
13156
b99bd4ef 13157static void
c19d1205 13158do_t_strexd (void)
b99bd4ef 13159{
c19d1205
ZW
13160 if (!inst.operands[2].present)
13161 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13162
c19d1205
ZW
13163 constraint (inst.operands[0].reg == inst.operands[1].reg
13164 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13165 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13166 BAD_OVERLAP);
b99bd4ef 13167
c19d1205
ZW
13168 inst.instruction |= inst.operands[0].reg;
13169 inst.instruction |= inst.operands[1].reg << 12;
13170 inst.instruction |= inst.operands[2].reg << 8;
13171 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13172}
13173
13174static void
c19d1205 13175do_t_sxtah (void)
b99bd4ef 13176{
fdfde340
JM
13177 unsigned Rd, Rn, Rm;
13178
13179 Rd = inst.operands[0].reg;
13180 Rn = inst.operands[1].reg;
13181 Rm = inst.operands[2].reg;
13182
13183 reject_bad_reg (Rd);
13184 reject_bad_reg (Rn);
13185 reject_bad_reg (Rm);
13186
13187 inst.instruction |= Rd << 8;
13188 inst.instruction |= Rn << 16;
13189 inst.instruction |= Rm;
c19d1205
ZW
13190 inst.instruction |= inst.operands[3].imm << 4;
13191}
b99bd4ef 13192
c19d1205
ZW
13193static void
13194do_t_sxth (void)
13195{
fdfde340
JM
13196 unsigned Rd, Rm;
13197
13198 Rd = inst.operands[0].reg;
13199 Rm = inst.operands[1].reg;
13200
13201 reject_bad_reg (Rd);
13202 reject_bad_reg (Rm);
c921be7d
NC
13203
13204 if (inst.instruction <= 0xffff
13205 && inst.size_req != 4
fdfde340 13206 && Rd <= 7 && Rm <= 7
c19d1205 13207 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13208 {
c19d1205 13209 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13210 inst.instruction |= Rd;
13211 inst.instruction |= Rm << 3;
b99bd4ef 13212 }
c19d1205 13213 else if (unified_syntax)
b99bd4ef 13214 {
c19d1205
ZW
13215 if (inst.instruction <= 0xffff)
13216 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13217 inst.instruction |= Rd << 8;
13218 inst.instruction |= Rm;
c19d1205 13219 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13220 }
c19d1205 13221 else
b99bd4ef 13222 {
c19d1205
ZW
13223 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13224 _("Thumb encoding does not support rotation"));
13225 constraint (1, BAD_HIREG);
b99bd4ef 13226 }
c19d1205 13227}
b99bd4ef 13228
c19d1205
ZW
13229static void
13230do_t_swi (void)
13231{
e2b0ab59 13232 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
c19d1205 13233}
b99bd4ef 13234
92e90b6e
PB
13235static void
13236do_t_tb (void)
13237{
fdfde340 13238 unsigned Rn, Rm;
92e90b6e
PB
13239 int half;
13240
13241 half = (inst.instruction & 0x10) != 0;
e07e6e58 13242 set_it_insn_type_last ();
dfa9f0d5
PB
13243 constraint (inst.operands[0].immisreg,
13244 _("instruction requires register index"));
fdfde340
JM
13245
13246 Rn = inst.operands[0].reg;
13247 Rm = inst.operands[0].imm;
c921be7d 13248
5c8ed6a4
JW
13249 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13250 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
13251 reject_bad_reg (Rm);
13252
92e90b6e
PB
13253 constraint (!half && inst.operands[0].shifted,
13254 _("instruction does not allow shifted index"));
fdfde340 13255 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13256}
13257
74db7efb
NC
13258static void
13259do_t_udf (void)
13260{
13261 if (!inst.operands[0].present)
13262 inst.operands[0].imm = 0;
13263
13264 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13265 {
13266 constraint (inst.size_req == 2,
13267 _("immediate value out of range"));
13268 inst.instruction = THUMB_OP32 (inst.instruction);
13269 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13270 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13271 }
13272 else
13273 {
13274 inst.instruction = THUMB_OP16 (inst.instruction);
13275 inst.instruction |= inst.operands[0].imm;
13276 }
13277
13278 set_it_insn_type (NEUTRAL_IT_INSN);
13279}
13280
13281
c19d1205
ZW
13282static void
13283do_t_usat (void)
13284{
3a21c15a 13285 do_t_ssat_usat (0);
b99bd4ef
NC
13286}
13287
13288static void
c19d1205 13289do_t_usat16 (void)
b99bd4ef 13290{
fdfde340
JM
13291 unsigned Rd, Rn;
13292
13293 Rd = inst.operands[0].reg;
13294 Rn = inst.operands[2].reg;
13295
13296 reject_bad_reg (Rd);
13297 reject_bad_reg (Rn);
13298
13299 inst.instruction |= Rd << 8;
c19d1205 13300 inst.instruction |= inst.operands[1].imm;
fdfde340 13301 inst.instruction |= Rn << 16;
b99bd4ef 13302}
c19d1205 13303
e12437dc
AV
13304/* Checking the range of the branch offset (VAL) with NBITS bits
13305 and IS_SIGNED signedness. Also checks the LSB to be 0. */
13306static int
13307v8_1_branch_value_check (int val, int nbits, int is_signed)
13308{
13309 gas_assert (nbits > 0 && nbits <= 32);
13310 if (is_signed)
13311 {
13312 int cmp = (1 << (nbits - 1));
13313 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
13314 return FAIL;
13315 }
13316 else
13317 {
13318 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
13319 return FAIL;
13320 }
13321 return SUCCESS;
13322}
13323
4389b29a
AV
13324/* For branches in Armv8.1-M Mainline. */
13325static void
13326do_t_branch_future (void)
13327{
13328 unsigned long insn = inst.instruction;
13329
13330 inst.instruction = THUMB_OP32 (inst.instruction);
13331 if (inst.operands[0].hasreloc == 0)
13332 {
13333 if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL)
13334 as_bad (BAD_BRANCH_OFF);
13335
13336 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
13337 }
13338 else
13339 {
13340 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
13341 inst.relocs[0].pc_rel = 1;
13342 }
13343
13344 switch (insn)
13345 {
13346 case T_MNEM_bf:
13347 if (inst.operands[1].hasreloc == 0)
13348 {
13349 int val = inst.operands[1].imm;
13350 if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL)
13351 as_bad (BAD_BRANCH_OFF);
13352
13353 int immA = (val & 0x0001f000) >> 12;
13354 int immB = (val & 0x00000ffc) >> 2;
13355 int immC = (val & 0x00000002) >> 1;
13356 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
13357 }
13358 else
13359 {
13360 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
13361 inst.relocs[1].pc_rel = 1;
13362 }
13363 break;
13364
13365 default: abort ();
13366 }
13367}
13368
5287ad62 13369/* Neon instruction encoder helpers. */
5f4273c7 13370
5287ad62 13371/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13372
5287ad62
JB
13373/* An "invalid" code for the following tables. */
13374#define N_INV -1u
13375
13376struct neon_tab_entry
b99bd4ef 13377{
5287ad62
JB
13378 unsigned integer;
13379 unsigned float_or_poly;
13380 unsigned scalar_or_imm;
13381};
5f4273c7 13382
5287ad62
JB
13383/* Map overloaded Neon opcodes to their respective encodings. */
13384#define NEON_ENC_TAB \
13385 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13386 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13387 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13388 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13389 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13390 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13391 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13392 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13393 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13394 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13395 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13396 /* Register variants of the following two instructions are encoded as
e07e6e58 13397 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13398 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13399 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13400 X(vfma, N_INV, 0x0000c10, N_INV), \
13401 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13402 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13403 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13404 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13405 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13406 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13407 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13408 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13409 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13410 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13411 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13412 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13413 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13414 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13415 X(vshl, 0x0000400, N_INV, 0x0800510), \
13416 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13417 X(vand, 0x0000110, N_INV, 0x0800030), \
13418 X(vbic, 0x0100110, N_INV, 0x0800030), \
13419 X(veor, 0x1000110, N_INV, N_INV), \
13420 X(vorn, 0x0300110, N_INV, 0x0800010), \
13421 X(vorr, 0x0200110, N_INV, 0x0800010), \
13422 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13423 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13424 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13425 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13426 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13427 X(vst1, 0x0000000, 0x0800000, N_INV), \
13428 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13429 X(vst2, 0x0000100, 0x0800100, N_INV), \
13430 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13431 X(vst3, 0x0000200, 0x0800200, N_INV), \
13432 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13433 X(vst4, 0x0000300, 0x0800300, N_INV), \
13434 X(vmovn, 0x1b20200, N_INV, N_INV), \
13435 X(vtrn, 0x1b20080, N_INV, N_INV), \
13436 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13437 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13438 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13439 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13440 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13441 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13442 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13443 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13444 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13445 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13446 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13447 X(vseleq, 0xe000a00, N_INV, N_INV), \
13448 X(vselvs, 0xe100a00, N_INV, N_INV), \
13449 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13450 X(vselgt, 0xe300a00, N_INV, N_INV), \
13451 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13452 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13453 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13454 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13455 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13456 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13457 X(sha3op, 0x2000c00, N_INV, N_INV), \
13458 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13459 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13460
13461enum neon_opc
13462{
13463#define X(OPC,I,F,S) N_MNEM_##OPC
13464NEON_ENC_TAB
13465#undef X
13466};
b99bd4ef 13467
5287ad62
JB
13468static const struct neon_tab_entry neon_enc_tab[] =
13469{
13470#define X(OPC,I,F,S) { (I), (F), (S) }
13471NEON_ENC_TAB
13472#undef X
13473};
b99bd4ef 13474
88714cb8
DG
13475/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13476#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13477#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13478#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13479#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13480#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13481#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13482#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13483#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13484#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13485#define NEON_ENC_SINGLE_(X) \
037e8744 13486 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13487#define NEON_ENC_DOUBLE_(X) \
037e8744 13488 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13489#define NEON_ENC_FPV8_(X) \
13490 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13491
88714cb8
DG
13492#define NEON_ENCODE(type, inst) \
13493 do \
13494 { \
13495 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13496 inst.is_neon = 1; \
13497 } \
13498 while (0)
13499
13500#define check_neon_suffixes \
13501 do \
13502 { \
13503 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13504 { \
13505 as_bad (_("invalid neon suffix for non neon instruction")); \
13506 return; \
13507 } \
13508 } \
13509 while (0)
13510
037e8744
JB
13511/* Define shapes for instruction operands. The following mnemonic characters
13512 are used in this table:
5287ad62 13513
037e8744 13514 F - VFP S<n> register
5287ad62
JB
13515 D - Neon D<n> register
13516 Q - Neon Q<n> register
13517 I - Immediate
13518 S - Scalar
13519 R - ARM register
13520 L - D<n> register list
5f4273c7 13521
037e8744
JB
13522 This table is used to generate various data:
13523 - enumerations of the form NS_DDR to be used as arguments to
13524 neon_select_shape.
13525 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13526 - a table used to drive neon_select_shape. */
b99bd4ef 13527
037e8744
JB
13528#define NEON_SHAPE_DEF \
13529 X(3, (D, D, D), DOUBLE), \
13530 X(3, (Q, Q, Q), QUAD), \
13531 X(3, (D, D, I), DOUBLE), \
13532 X(3, (Q, Q, I), QUAD), \
13533 X(3, (D, D, S), DOUBLE), \
13534 X(3, (Q, Q, S), QUAD), \
13535 X(2, (D, D), DOUBLE), \
13536 X(2, (Q, Q), QUAD), \
13537 X(2, (D, S), DOUBLE), \
13538 X(2, (Q, S), QUAD), \
13539 X(2, (D, R), DOUBLE), \
13540 X(2, (Q, R), QUAD), \
13541 X(2, (D, I), DOUBLE), \
13542 X(2, (Q, I), QUAD), \
13543 X(3, (D, L, D), DOUBLE), \
13544 X(2, (D, Q), MIXED), \
13545 X(2, (Q, D), MIXED), \
13546 X(3, (D, Q, I), MIXED), \
13547 X(3, (Q, D, I), MIXED), \
13548 X(3, (Q, D, D), MIXED), \
13549 X(3, (D, Q, Q), MIXED), \
13550 X(3, (Q, Q, D), MIXED), \
13551 X(3, (Q, D, S), MIXED), \
13552 X(3, (D, Q, S), MIXED), \
13553 X(4, (D, D, D, I), DOUBLE), \
13554 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
13555 X(4, (D, D, S, I), DOUBLE), \
13556 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
13557 X(2, (F, F), SINGLE), \
13558 X(3, (F, F, F), SINGLE), \
13559 X(2, (F, I), SINGLE), \
13560 X(2, (F, D), MIXED), \
13561 X(2, (D, F), MIXED), \
13562 X(3, (F, F, I), MIXED), \
13563 X(4, (R, R, F, F), SINGLE), \
13564 X(4, (F, F, R, R), SINGLE), \
13565 X(3, (D, R, R), DOUBLE), \
13566 X(3, (R, R, D), DOUBLE), \
13567 X(2, (S, R), SINGLE), \
13568 X(2, (R, S), SINGLE), \
13569 X(2, (F, R), SINGLE), \
d54af2d0
RL
13570 X(2, (R, F), SINGLE), \
13571/* Half float shape supported so far. */\
13572 X (2, (H, D), MIXED), \
13573 X (2, (D, H), MIXED), \
13574 X (2, (H, F), MIXED), \
13575 X (2, (F, H), MIXED), \
13576 X (2, (H, H), HALF), \
13577 X (2, (H, R), HALF), \
13578 X (2, (R, H), HALF), \
13579 X (2, (H, I), HALF), \
13580 X (3, (H, H, H), HALF), \
13581 X (3, (H, F, I), MIXED), \
dec41383
JW
13582 X (3, (F, H, I), MIXED), \
13583 X (3, (D, H, H), MIXED), \
13584 X (3, (D, H, S), MIXED)
037e8744
JB
13585
13586#define S2(A,B) NS_##A##B
13587#define S3(A,B,C) NS_##A##B##C
13588#define S4(A,B,C,D) NS_##A##B##C##D
13589
13590#define X(N, L, C) S##N L
13591
5287ad62
JB
13592enum neon_shape
13593{
037e8744
JB
13594 NEON_SHAPE_DEF,
13595 NS_NULL
5287ad62 13596};
b99bd4ef 13597
037e8744
JB
13598#undef X
13599#undef S2
13600#undef S3
13601#undef S4
13602
13603enum neon_shape_class
13604{
d54af2d0 13605 SC_HALF,
037e8744
JB
13606 SC_SINGLE,
13607 SC_DOUBLE,
13608 SC_QUAD,
13609 SC_MIXED
13610};
13611
13612#define X(N, L, C) SC_##C
13613
13614static enum neon_shape_class neon_shape_class[] =
13615{
13616 NEON_SHAPE_DEF
13617};
13618
13619#undef X
13620
13621enum neon_shape_el
13622{
d54af2d0 13623 SE_H,
037e8744
JB
13624 SE_F,
13625 SE_D,
13626 SE_Q,
13627 SE_I,
13628 SE_S,
13629 SE_R,
13630 SE_L
13631};
13632
13633/* Register widths of above. */
13634static unsigned neon_shape_el_size[] =
13635{
d54af2d0 13636 16,
037e8744
JB
13637 32,
13638 64,
13639 128,
13640 0,
13641 32,
13642 32,
13643 0
13644};
13645
13646struct neon_shape_info
13647{
13648 unsigned els;
13649 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13650};
13651
13652#define S2(A,B) { SE_##A, SE_##B }
13653#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13654#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13655
13656#define X(N, L, C) { N, S##N L }
13657
13658static struct neon_shape_info neon_shape_tab[] =
13659{
13660 NEON_SHAPE_DEF
13661};
13662
13663#undef X
13664#undef S2
13665#undef S3
13666#undef S4
13667
5287ad62
JB
13668/* Bit masks used in type checking given instructions.
13669 'N_EQK' means the type must be the same as (or based on in some way) the key
13670 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13671 set, various other bits can be set as well in order to modify the meaning of
13672 the type constraint. */
13673
13674enum neon_type_mask
13675{
8e79c3df
CM
13676 N_S8 = 0x0000001,
13677 N_S16 = 0x0000002,
13678 N_S32 = 0x0000004,
13679 N_S64 = 0x0000008,
13680 N_U8 = 0x0000010,
13681 N_U16 = 0x0000020,
13682 N_U32 = 0x0000040,
13683 N_U64 = 0x0000080,
13684 N_I8 = 0x0000100,
13685 N_I16 = 0x0000200,
13686 N_I32 = 0x0000400,
13687 N_I64 = 0x0000800,
13688 N_8 = 0x0001000,
13689 N_16 = 0x0002000,
13690 N_32 = 0x0004000,
13691 N_64 = 0x0008000,
13692 N_P8 = 0x0010000,
13693 N_P16 = 0x0020000,
13694 N_F16 = 0x0040000,
13695 N_F32 = 0x0080000,
13696 N_F64 = 0x0100000,
4f51b4bd 13697 N_P64 = 0x0200000,
c921be7d
NC
13698 N_KEY = 0x1000000, /* Key element (main type specifier). */
13699 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13700 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13701 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13702 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13703 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13704 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13705 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13706 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13707 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13708 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13709 N_UTYP = 0,
4f51b4bd 13710 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13711};
13712
dcbf9037
JB
13713#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13714
5287ad62
JB
13715#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13716#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13717#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13718#define N_S_32 (N_S8 | N_S16 | N_S32)
13719#define N_F_16_32 (N_F16 | N_F32)
13720#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13721#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13722#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13723#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13724
13725/* Pass this as the first type argument to neon_check_type to ignore types
13726 altogether. */
13727#define N_IGNORE_TYPE (N_KEY | N_EQK)
13728
037e8744
JB
13729/* Select a "shape" for the current instruction (describing register types or
13730 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13731 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13732 function of operand parsing, so this function doesn't need to be called.
13733 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13734
13735static enum neon_shape
037e8744 13736neon_select_shape (enum neon_shape shape, ...)
5287ad62 13737{
037e8744
JB
13738 va_list ap;
13739 enum neon_shape first_shape = shape;
5287ad62
JB
13740
13741 /* Fix missing optional operands. FIXME: we don't know at this point how
13742 many arguments we should have, so this makes the assumption that we have
13743 > 1. This is true of all current Neon opcodes, I think, but may not be
13744 true in the future. */
13745 if (!inst.operands[1].present)
13746 inst.operands[1] = inst.operands[0];
13747
037e8744 13748 va_start (ap, shape);
5f4273c7 13749
21d799b5 13750 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13751 {
13752 unsigned j;
13753 int matches = 1;
13754
13755 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13756 {
13757 if (!inst.operands[j].present)
13758 {
13759 matches = 0;
13760 break;
13761 }
13762
13763 switch (neon_shape_tab[shape].el[j])
13764 {
d54af2d0
RL
13765 /* If a .f16, .16, .u16, .s16 type specifier is given over
13766 a VFP single precision register operand, it's essentially
13767 means only half of the register is used.
13768
13769 If the type specifier is given after the mnemonics, the
13770 information is stored in inst.vectype. If the type specifier
13771 is given after register operand, the information is stored
13772 in inst.operands[].vectype.
13773
13774 When there is only one type specifier, and all the register
13775 operands are the same type of hardware register, the type
13776 specifier applies to all register operands.
13777
13778 If no type specifier is given, the shape is inferred from
13779 operand information.
13780
13781 for example:
13782 vadd.f16 s0, s1, s2: NS_HHH
13783 vabs.f16 s0, s1: NS_HH
13784 vmov.f16 s0, r1: NS_HR
13785 vmov.f16 r0, s1: NS_RH
13786 vcvt.f16 r0, s1: NS_RH
13787 vcvt.f16.s32 s2, s2, #29: NS_HFI
13788 vcvt.f16.s32 s2, s2: NS_HF
13789 */
13790 case SE_H:
13791 if (!(inst.operands[j].isreg
13792 && inst.operands[j].isvec
13793 && inst.operands[j].issingle
13794 && !inst.operands[j].isquad
13795 && ((inst.vectype.elems == 1
13796 && inst.vectype.el[0].size == 16)
13797 || (inst.vectype.elems > 1
13798 && inst.vectype.el[j].size == 16)
13799 || (inst.vectype.elems == 0
13800 && inst.operands[j].vectype.type != NT_invtype
13801 && inst.operands[j].vectype.size == 16))))
13802 matches = 0;
13803 break;
13804
477330fc
RM
13805 case SE_F:
13806 if (!(inst.operands[j].isreg
13807 && inst.operands[j].isvec
13808 && inst.operands[j].issingle
d54af2d0
RL
13809 && !inst.operands[j].isquad
13810 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13811 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13812 || (inst.vectype.elems == 0
13813 && (inst.operands[j].vectype.size == 32
13814 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13815 matches = 0;
13816 break;
13817
13818 case SE_D:
13819 if (!(inst.operands[j].isreg
13820 && inst.operands[j].isvec
13821 && !inst.operands[j].isquad
13822 && !inst.operands[j].issingle))
13823 matches = 0;
13824 break;
13825
13826 case SE_R:
13827 if (!(inst.operands[j].isreg
13828 && !inst.operands[j].isvec))
13829 matches = 0;
13830 break;
13831
13832 case SE_Q:
13833 if (!(inst.operands[j].isreg
13834 && inst.operands[j].isvec
13835 && inst.operands[j].isquad
13836 && !inst.operands[j].issingle))
13837 matches = 0;
13838 break;
13839
13840 case SE_I:
13841 if (!(!inst.operands[j].isreg
13842 && !inst.operands[j].isscalar))
13843 matches = 0;
13844 break;
13845
13846 case SE_S:
13847 if (!(!inst.operands[j].isreg
13848 && inst.operands[j].isscalar))
13849 matches = 0;
13850 break;
13851
13852 case SE_L:
13853 break;
13854 }
3fde54a2
JZ
13855 if (!matches)
13856 break;
477330fc 13857 }
ad6cec43
MGD
13858 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13859 /* We've matched all the entries in the shape table, and we don't
13860 have any left over operands which have not been matched. */
477330fc 13861 break;
037e8744 13862 }
5f4273c7 13863
037e8744 13864 va_end (ap);
5287ad62 13865
037e8744
JB
13866 if (shape == NS_NULL && first_shape != NS_NULL)
13867 first_error (_("invalid instruction shape"));
5287ad62 13868
037e8744
JB
13869 return shape;
13870}
5287ad62 13871
037e8744
JB
13872/* True if SHAPE is predominantly a quadword operation (most of the time, this
13873 means the Q bit should be set). */
13874
13875static int
13876neon_quad (enum neon_shape shape)
13877{
13878 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13879}
037e8744 13880
5287ad62
JB
13881static void
13882neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13883 unsigned *g_size)
5287ad62
JB
13884{
13885 /* Allow modification to be made to types which are constrained to be
13886 based on the key element, based on bits set alongside N_EQK. */
13887 if ((typebits & N_EQK) != 0)
13888 {
13889 if ((typebits & N_HLF) != 0)
13890 *g_size /= 2;
13891 else if ((typebits & N_DBL) != 0)
13892 *g_size *= 2;
13893 if ((typebits & N_SGN) != 0)
13894 *g_type = NT_signed;
13895 else if ((typebits & N_UNS) != 0)
477330fc 13896 *g_type = NT_unsigned;
5287ad62 13897 else if ((typebits & N_INT) != 0)
477330fc 13898 *g_type = NT_integer;
5287ad62 13899 else if ((typebits & N_FLT) != 0)
477330fc 13900 *g_type = NT_float;
dcbf9037 13901 else if ((typebits & N_SIZ) != 0)
477330fc 13902 *g_type = NT_untyped;
5287ad62
JB
13903 }
13904}
5f4273c7 13905
5287ad62
JB
13906/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13907 operand type, i.e. the single type specified in a Neon instruction when it
13908 is the only one given. */
13909
13910static struct neon_type_el
13911neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13912{
13913 struct neon_type_el dest = *key;
5f4273c7 13914
9c2799c2 13915 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13916
5287ad62
JB
13917 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13918
13919 return dest;
13920}
13921
13922/* Convert Neon type and size into compact bitmask representation. */
13923
13924static enum neon_type_mask
13925type_chk_of_el_type (enum neon_el_type type, unsigned size)
13926{
13927 switch (type)
13928 {
13929 case NT_untyped:
13930 switch (size)
477330fc
RM
13931 {
13932 case 8: return N_8;
13933 case 16: return N_16;
13934 case 32: return N_32;
13935 case 64: return N_64;
13936 default: ;
13937 }
5287ad62
JB
13938 break;
13939
13940 case NT_integer:
13941 switch (size)
477330fc
RM
13942 {
13943 case 8: return N_I8;
13944 case 16: return N_I16;
13945 case 32: return N_I32;
13946 case 64: return N_I64;
13947 default: ;
13948 }
5287ad62
JB
13949 break;
13950
13951 case NT_float:
037e8744 13952 switch (size)
477330fc 13953 {
8e79c3df 13954 case 16: return N_F16;
477330fc
RM
13955 case 32: return N_F32;
13956 case 64: return N_F64;
13957 default: ;
13958 }
5287ad62
JB
13959 break;
13960
13961 case NT_poly:
13962 switch (size)
477330fc
RM
13963 {
13964 case 8: return N_P8;
13965 case 16: return N_P16;
4f51b4bd 13966 case 64: return N_P64;
477330fc
RM
13967 default: ;
13968 }
5287ad62
JB
13969 break;
13970
13971 case NT_signed:
13972 switch (size)
477330fc
RM
13973 {
13974 case 8: return N_S8;
13975 case 16: return N_S16;
13976 case 32: return N_S32;
13977 case 64: return N_S64;
13978 default: ;
13979 }
5287ad62
JB
13980 break;
13981
13982 case NT_unsigned:
13983 switch (size)
477330fc
RM
13984 {
13985 case 8: return N_U8;
13986 case 16: return N_U16;
13987 case 32: return N_U32;
13988 case 64: return N_U64;
13989 default: ;
13990 }
5287ad62
JB
13991 break;
13992
13993 default: ;
13994 }
5f4273c7 13995
5287ad62
JB
13996 return N_UTYP;
13997}
13998
13999/* Convert compact Neon bitmask type representation to a type and size. Only
14000 handles the case where a single bit is set in the mask. */
14001
dcbf9037 14002static int
5287ad62 14003el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 14004 enum neon_type_mask mask)
5287ad62 14005{
dcbf9037
JB
14006 if ((mask & N_EQK) != 0)
14007 return FAIL;
14008
5287ad62
JB
14009 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
14010 *size = 8;
c70a8987 14011 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 14012 *size = 16;
dcbf9037 14013 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 14014 *size = 32;
4f51b4bd 14015 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 14016 *size = 64;
dcbf9037
JB
14017 else
14018 return FAIL;
14019
5287ad62
JB
14020 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
14021 *type = NT_signed;
dcbf9037 14022 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 14023 *type = NT_unsigned;
dcbf9037 14024 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 14025 *type = NT_integer;
dcbf9037 14026 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 14027 *type = NT_untyped;
4f51b4bd 14028 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 14029 *type = NT_poly;
d54af2d0 14030 else if ((mask & (N_F_ALL)) != 0)
5287ad62 14031 *type = NT_float;
dcbf9037
JB
14032 else
14033 return FAIL;
5f4273c7 14034
dcbf9037 14035 return SUCCESS;
5287ad62
JB
14036}
14037
14038/* Modify a bitmask of allowed types. This is only needed for type
14039 relaxation. */
14040
14041static unsigned
14042modify_types_allowed (unsigned allowed, unsigned mods)
14043{
14044 unsigned size;
14045 enum neon_el_type type;
14046 unsigned destmask;
14047 int i;
5f4273c7 14048
5287ad62 14049 destmask = 0;
5f4273c7 14050
5287ad62
JB
14051 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
14052 {
21d799b5 14053 if (el_type_of_type_chk (&type, &size,
477330fc
RM
14054 (enum neon_type_mask) (allowed & i)) == SUCCESS)
14055 {
14056 neon_modify_type_size (mods, &type, &size);
14057 destmask |= type_chk_of_el_type (type, size);
14058 }
5287ad62 14059 }
5f4273c7 14060
5287ad62
JB
14061 return destmask;
14062}
14063
14064/* Check type and return type classification.
14065 The manual states (paraphrase): If one datatype is given, it indicates the
14066 type given in:
14067 - the second operand, if there is one
14068 - the operand, if there is no second operand
14069 - the result, if there are no operands.
14070 This isn't quite good enough though, so we use a concept of a "key" datatype
14071 which is set on a per-instruction basis, which is the one which matters when
14072 only one data type is written.
14073 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 14074 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
14075
14076static struct neon_type_el
14077neon_check_type (unsigned els, enum neon_shape ns, ...)
14078{
14079 va_list ap;
14080 unsigned i, pass, key_el = 0;
14081 unsigned types[NEON_MAX_TYPE_ELS];
14082 enum neon_el_type k_type = NT_invtype;
14083 unsigned k_size = -1u;
14084 struct neon_type_el badtype = {NT_invtype, -1};
14085 unsigned key_allowed = 0;
14086
14087 /* Optional registers in Neon instructions are always (not) in operand 1.
14088 Fill in the missing operand here, if it was omitted. */
14089 if (els > 1 && !inst.operands[1].present)
14090 inst.operands[1] = inst.operands[0];
14091
14092 /* Suck up all the varargs. */
14093 va_start (ap, ns);
14094 for (i = 0; i < els; i++)
14095 {
14096 unsigned thisarg = va_arg (ap, unsigned);
14097 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
14098 {
14099 va_end (ap);
14100 return badtype;
14101 }
5287ad62
JB
14102 types[i] = thisarg;
14103 if ((thisarg & N_KEY) != 0)
477330fc 14104 key_el = i;
5287ad62
JB
14105 }
14106 va_end (ap);
14107
dcbf9037
JB
14108 if (inst.vectype.elems > 0)
14109 for (i = 0; i < els; i++)
14110 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
14111 {
14112 first_error (_("types specified in both the mnemonic and operands"));
14113 return badtype;
14114 }
dcbf9037 14115
5287ad62
JB
14116 /* Duplicate inst.vectype elements here as necessary.
14117 FIXME: No idea if this is exactly the same as the ARM assembler,
14118 particularly when an insn takes one register and one non-register
14119 operand. */
14120 if (inst.vectype.elems == 1 && els > 1)
14121 {
14122 unsigned j;
14123 inst.vectype.elems = els;
14124 inst.vectype.el[key_el] = inst.vectype.el[0];
14125 for (j = 0; j < els; j++)
477330fc
RM
14126 if (j != key_el)
14127 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14128 types[j]);
dcbf9037
JB
14129 }
14130 else if (inst.vectype.elems == 0 && els > 0)
14131 {
14132 unsigned j;
14133 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
14134 after each operand. We allow some flexibility here; as long as the
14135 "key" operand has a type, we can infer the others. */
dcbf9037 14136 for (j = 0; j < els; j++)
477330fc
RM
14137 if (inst.operands[j].vectype.type != NT_invtype)
14138 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
14139
14140 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
14141 {
14142 for (j = 0; j < els; j++)
14143 if (inst.operands[j].vectype.type == NT_invtype)
14144 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14145 types[j]);
14146 }
dcbf9037 14147 else
477330fc
RM
14148 {
14149 first_error (_("operand types can't be inferred"));
14150 return badtype;
14151 }
5287ad62
JB
14152 }
14153 else if (inst.vectype.elems != els)
14154 {
dcbf9037 14155 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
14156 return badtype;
14157 }
14158
14159 for (pass = 0; pass < 2; pass++)
14160 {
14161 for (i = 0; i < els; i++)
477330fc
RM
14162 {
14163 unsigned thisarg = types[i];
14164 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
14165 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
14166 enum neon_el_type g_type = inst.vectype.el[i].type;
14167 unsigned g_size = inst.vectype.el[i].size;
14168
14169 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 14170 integer types if sign-specific variants are unavailable. */
477330fc 14171 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
14172 && (types_allowed & N_SU_ALL) == 0)
14173 g_type = NT_integer;
14174
477330fc 14175 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
14176 them. Some instructions only care about signs for some element
14177 sizes, so handle that properly. */
477330fc 14178 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
14179 && ((g_size == 8 && (types_allowed & N_8) != 0)
14180 || (g_size == 16 && (types_allowed & N_16) != 0)
14181 || (g_size == 32 && (types_allowed & N_32) != 0)
14182 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
14183 g_type = NT_untyped;
14184
477330fc
RM
14185 if (pass == 0)
14186 {
14187 if ((thisarg & N_KEY) != 0)
14188 {
14189 k_type = g_type;
14190 k_size = g_size;
14191 key_allowed = thisarg & ~N_KEY;
cc933301
JW
14192
14193 /* Check architecture constraint on FP16 extension. */
14194 if (k_size == 16
14195 && k_type == NT_float
14196 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14197 {
14198 inst.error = _(BAD_FP16);
14199 return badtype;
14200 }
477330fc
RM
14201 }
14202 }
14203 else
14204 {
14205 if ((thisarg & N_VFP) != 0)
14206 {
14207 enum neon_shape_el regshape;
14208 unsigned regwidth, match;
99b253c5
NC
14209
14210 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14211 if (ns == NS_NULL)
14212 {
14213 first_error (_("invalid instruction shape"));
14214 return badtype;
14215 }
477330fc
RM
14216 regshape = neon_shape_tab[ns].el[i];
14217 regwidth = neon_shape_el_size[regshape];
14218
14219 /* In VFP mode, operands must match register widths. If we
14220 have a key operand, use its width, else use the width of
14221 the current operand. */
14222 if (k_size != -1u)
14223 match = k_size;
14224 else
14225 match = g_size;
14226
9db2f6b4
RL
14227 /* FP16 will use a single precision register. */
14228 if (regwidth == 32 && match == 16)
14229 {
14230 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14231 match = regwidth;
14232 else
14233 {
14234 inst.error = _(BAD_FP16);
14235 return badtype;
14236 }
14237 }
14238
477330fc
RM
14239 if (regwidth != match)
14240 {
14241 first_error (_("operand size must match register width"));
14242 return badtype;
14243 }
14244 }
14245
14246 if ((thisarg & N_EQK) == 0)
14247 {
14248 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14249
14250 if ((given_type & types_allowed) == 0)
14251 {
14252 first_error (_("bad type in Neon instruction"));
14253 return badtype;
14254 }
14255 }
14256 else
14257 {
14258 enum neon_el_type mod_k_type = k_type;
14259 unsigned mod_k_size = k_size;
14260 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14261 if (g_type != mod_k_type || g_size != mod_k_size)
14262 {
14263 first_error (_("inconsistent types in Neon instruction"));
14264 return badtype;
14265 }
14266 }
14267 }
14268 }
5287ad62
JB
14269 }
14270
14271 return inst.vectype.el[key_el];
14272}
14273
037e8744 14274/* Neon-style VFP instruction forwarding. */
5287ad62 14275
037e8744
JB
14276/* Thumb VFP instructions have 0xE in the condition field. */
14277
14278static void
14279do_vfp_cond_or_thumb (void)
5287ad62 14280{
88714cb8
DG
14281 inst.is_neon = 1;
14282
5287ad62 14283 if (thumb_mode)
037e8744 14284 inst.instruction |= 0xe0000000;
5287ad62 14285 else
037e8744 14286 inst.instruction |= inst.cond << 28;
5287ad62
JB
14287}
14288
037e8744
JB
14289/* Look up and encode a simple mnemonic, for use as a helper function for the
14290 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14291 etc. It is assumed that operand parsing has already been done, and that the
14292 operands are in the form expected by the given opcode (this isn't necessarily
14293 the same as the form in which they were parsed, hence some massaging must
14294 take place before this function is called).
14295 Checks current arch version against that in the looked-up opcode. */
5287ad62 14296
037e8744
JB
14297static void
14298do_vfp_nsyn_opcode (const char *opname)
5287ad62 14299{
037e8744 14300 const struct asm_opcode *opcode;
5f4273c7 14301
21d799b5 14302 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14303
037e8744
JB
14304 if (!opcode)
14305 abort ();
5287ad62 14306
037e8744 14307 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14308 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14309 _(BAD_FPU));
5287ad62 14310
88714cb8
DG
14311 inst.is_neon = 1;
14312
037e8744
JB
14313 if (thumb_mode)
14314 {
14315 inst.instruction = opcode->tvalue;
14316 opcode->tencode ();
14317 }
14318 else
14319 {
14320 inst.instruction = (inst.cond << 28) | opcode->avalue;
14321 opcode->aencode ();
14322 }
14323}
5287ad62
JB
14324
14325static void
037e8744 14326do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14327{
037e8744
JB
14328 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14329
9db2f6b4 14330 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14331 {
14332 if (is_add)
477330fc 14333 do_vfp_nsyn_opcode ("fadds");
037e8744 14334 else
477330fc 14335 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14336
14337 /* ARMv8.2 fp16 instruction. */
14338 if (rs == NS_HHH)
14339 do_scalar_fp16_v82_encode ();
037e8744
JB
14340 }
14341 else
14342 {
14343 if (is_add)
477330fc 14344 do_vfp_nsyn_opcode ("faddd");
037e8744 14345 else
477330fc 14346 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14347 }
14348}
14349
14350/* Check operand types to see if this is a VFP instruction, and if so call
14351 PFN (). */
14352
14353static int
14354try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14355{
14356 enum neon_shape rs;
14357 struct neon_type_el et;
14358
14359 switch (args)
14360 {
14361 case 2:
9db2f6b4
RL
14362 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14363 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14364 break;
5f4273c7 14365
037e8744 14366 case 3:
9db2f6b4
RL
14367 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14368 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14369 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14370 break;
14371
14372 default:
14373 abort ();
14374 }
14375
14376 if (et.type != NT_invtype)
14377 {
14378 pfn (rs);
14379 return SUCCESS;
14380 }
037e8744 14381
99b253c5 14382 inst.error = NULL;
037e8744
JB
14383 return FAIL;
14384}
14385
14386static void
14387do_vfp_nsyn_mla_mls (enum neon_shape rs)
14388{
14389 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14390
9db2f6b4 14391 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14392 {
14393 if (is_mla)
477330fc 14394 do_vfp_nsyn_opcode ("fmacs");
037e8744 14395 else
477330fc 14396 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14397
14398 /* ARMv8.2 fp16 instruction. */
14399 if (rs == NS_HHH)
14400 do_scalar_fp16_v82_encode ();
037e8744
JB
14401 }
14402 else
14403 {
14404 if (is_mla)
477330fc 14405 do_vfp_nsyn_opcode ("fmacd");
037e8744 14406 else
477330fc 14407 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14408 }
14409}
14410
62f3b8c8
PB
14411static void
14412do_vfp_nsyn_fma_fms (enum neon_shape rs)
14413{
14414 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14415
9db2f6b4 14416 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14417 {
14418 if (is_fma)
477330fc 14419 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14420 else
477330fc 14421 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14422
14423 /* ARMv8.2 fp16 instruction. */
14424 if (rs == NS_HHH)
14425 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14426 }
14427 else
14428 {
14429 if (is_fma)
477330fc 14430 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14431 else
477330fc 14432 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14433 }
14434}
14435
037e8744
JB
14436static void
14437do_vfp_nsyn_mul (enum neon_shape rs)
14438{
9db2f6b4
RL
14439 if (rs == NS_FFF || rs == NS_HHH)
14440 {
14441 do_vfp_nsyn_opcode ("fmuls");
14442
14443 /* ARMv8.2 fp16 instruction. */
14444 if (rs == NS_HHH)
14445 do_scalar_fp16_v82_encode ();
14446 }
037e8744
JB
14447 else
14448 do_vfp_nsyn_opcode ("fmuld");
14449}
14450
14451static void
14452do_vfp_nsyn_abs_neg (enum neon_shape rs)
14453{
14454 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14455 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14456
9db2f6b4 14457 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14458 {
14459 if (is_neg)
477330fc 14460 do_vfp_nsyn_opcode ("fnegs");
037e8744 14461 else
477330fc 14462 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14463
14464 /* ARMv8.2 fp16 instruction. */
14465 if (rs == NS_HH)
14466 do_scalar_fp16_v82_encode ();
037e8744
JB
14467 }
14468 else
14469 {
14470 if (is_neg)
477330fc 14471 do_vfp_nsyn_opcode ("fnegd");
037e8744 14472 else
477330fc 14473 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14474 }
14475}
14476
14477/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14478 insns belong to Neon, and are handled elsewhere. */
14479
14480static void
14481do_vfp_nsyn_ldm_stm (int is_dbmode)
14482{
14483 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14484 if (is_ldm)
14485 {
14486 if (is_dbmode)
477330fc 14487 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14488 else
477330fc 14489 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14490 }
14491 else
14492 {
14493 if (is_dbmode)
477330fc 14494 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14495 else
477330fc 14496 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14497 }
14498}
14499
037e8744
JB
14500static void
14501do_vfp_nsyn_sqrt (void)
14502{
9db2f6b4
RL
14503 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14504 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14505
9db2f6b4
RL
14506 if (rs == NS_FF || rs == NS_HH)
14507 {
14508 do_vfp_nsyn_opcode ("fsqrts");
14509
14510 /* ARMv8.2 fp16 instruction. */
14511 if (rs == NS_HH)
14512 do_scalar_fp16_v82_encode ();
14513 }
037e8744
JB
14514 else
14515 do_vfp_nsyn_opcode ("fsqrtd");
14516}
14517
14518static void
14519do_vfp_nsyn_div (void)
14520{
9db2f6b4 14521 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14522 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14523 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14524
9db2f6b4
RL
14525 if (rs == NS_FFF || rs == NS_HHH)
14526 {
14527 do_vfp_nsyn_opcode ("fdivs");
14528
14529 /* ARMv8.2 fp16 instruction. */
14530 if (rs == NS_HHH)
14531 do_scalar_fp16_v82_encode ();
14532 }
037e8744
JB
14533 else
14534 do_vfp_nsyn_opcode ("fdivd");
14535}
14536
14537static void
14538do_vfp_nsyn_nmul (void)
14539{
9db2f6b4 14540 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14541 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14542 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14543
9db2f6b4 14544 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14545 {
88714cb8 14546 NEON_ENCODE (SINGLE, inst);
037e8744 14547 do_vfp_sp_dyadic ();
9db2f6b4
RL
14548
14549 /* ARMv8.2 fp16 instruction. */
14550 if (rs == NS_HHH)
14551 do_scalar_fp16_v82_encode ();
037e8744
JB
14552 }
14553 else
14554 {
88714cb8 14555 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14556 do_vfp_dp_rd_rn_rm ();
14557 }
14558 do_vfp_cond_or_thumb ();
9db2f6b4 14559
037e8744
JB
14560}
14561
14562static void
14563do_vfp_nsyn_cmp (void)
14564{
9db2f6b4 14565 enum neon_shape rs;
037e8744
JB
14566 if (inst.operands[1].isreg)
14567 {
9db2f6b4
RL
14568 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14569 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14570
9db2f6b4 14571 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14572 {
14573 NEON_ENCODE (SINGLE, inst);
14574 do_vfp_sp_monadic ();
14575 }
037e8744 14576 else
477330fc
RM
14577 {
14578 NEON_ENCODE (DOUBLE, inst);
14579 do_vfp_dp_rd_rm ();
14580 }
037e8744
JB
14581 }
14582 else
14583 {
9db2f6b4
RL
14584 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14585 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14586
14587 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14588 {
14589 case N_MNEM_vcmp:
14590 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14591 break;
14592 case N_MNEM_vcmpe:
14593 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14594 break;
14595 default:
14596 abort ();
14597 }
5f4273c7 14598
9db2f6b4 14599 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14600 {
14601 NEON_ENCODE (SINGLE, inst);
14602 do_vfp_sp_compare_z ();
14603 }
037e8744 14604 else
477330fc
RM
14605 {
14606 NEON_ENCODE (DOUBLE, inst);
14607 do_vfp_dp_rd ();
14608 }
037e8744
JB
14609 }
14610 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14611
14612 /* ARMv8.2 fp16 instruction. */
14613 if (rs == NS_HI || rs == NS_HH)
14614 do_scalar_fp16_v82_encode ();
037e8744
JB
14615}
14616
14617static void
14618nsyn_insert_sp (void)
14619{
14620 inst.operands[1] = inst.operands[0];
14621 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14622 inst.operands[0].reg = REG_SP;
037e8744
JB
14623 inst.operands[0].isreg = 1;
14624 inst.operands[0].writeback = 1;
14625 inst.operands[0].present = 1;
14626}
14627
14628static void
14629do_vfp_nsyn_push (void)
14630{
14631 nsyn_insert_sp ();
b126985e
NC
14632
14633 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14634 _("register list must contain at least 1 and at most 16 "
14635 "registers"));
14636
037e8744
JB
14637 if (inst.operands[1].issingle)
14638 do_vfp_nsyn_opcode ("fstmdbs");
14639 else
14640 do_vfp_nsyn_opcode ("fstmdbd");
14641}
14642
14643static void
14644do_vfp_nsyn_pop (void)
14645{
14646 nsyn_insert_sp ();
b126985e
NC
14647
14648 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14649 _("register list must contain at least 1 and at most 16 "
14650 "registers"));
14651
037e8744 14652 if (inst.operands[1].issingle)
22b5b651 14653 do_vfp_nsyn_opcode ("fldmias");
037e8744 14654 else
22b5b651 14655 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14656}
14657
14658/* Fix up Neon data-processing instructions, ORing in the correct bits for
14659 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14660
88714cb8
DG
14661static void
14662neon_dp_fixup (struct arm_it* insn)
037e8744 14663{
88714cb8
DG
14664 unsigned int i = insn->instruction;
14665 insn->is_neon = 1;
14666
037e8744
JB
14667 if (thumb_mode)
14668 {
14669 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14670 if (i & (1 << 24))
477330fc 14671 i |= 1 << 28;
5f4273c7 14672
037e8744 14673 i &= ~(1 << 24);
5f4273c7 14674
037e8744
JB
14675 i |= 0xef000000;
14676 }
14677 else
14678 i |= 0xf2000000;
5f4273c7 14679
88714cb8 14680 insn->instruction = i;
037e8744
JB
14681}
14682
14683/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14684 (0, 1, 2, 3). */
14685
14686static unsigned
14687neon_logbits (unsigned x)
14688{
14689 return ffs (x) - 4;
14690}
14691
14692#define LOW4(R) ((R) & 0xf)
14693#define HI1(R) (((R) >> 4) & 1)
14694
14695/* Encode insns with bit pattern:
14696
14697 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14698 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14699
037e8744
JB
14700 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14701 different meaning for some instruction. */
14702
14703static void
14704neon_three_same (int isquad, int ubit, int size)
14705{
14706 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14707 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14708 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14709 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14710 inst.instruction |= LOW4 (inst.operands[2].reg);
14711 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14712 inst.instruction |= (isquad != 0) << 6;
14713 inst.instruction |= (ubit != 0) << 24;
14714 if (size != -1)
14715 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14716
88714cb8 14717 neon_dp_fixup (&inst);
037e8744
JB
14718}
14719
14720/* Encode instructions of the form:
14721
14722 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14723 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14724
14725 Don't write size if SIZE == -1. */
14726
14727static void
14728neon_two_same (int qbit, int ubit, int size)
14729{
14730 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14731 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14732 inst.instruction |= LOW4 (inst.operands[1].reg);
14733 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14734 inst.instruction |= (qbit != 0) << 6;
14735 inst.instruction |= (ubit != 0) << 24;
14736
14737 if (size != -1)
14738 inst.instruction |= neon_logbits (size) << 18;
14739
88714cb8 14740 neon_dp_fixup (&inst);
5287ad62
JB
14741}
14742
14743/* Neon instruction encoders, in approximate order of appearance. */
14744
14745static void
14746do_neon_dyadic_i_su (void)
14747{
037e8744 14748 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14749 struct neon_type_el et = neon_check_type (3, rs,
14750 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14751 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14752}
14753
14754static void
14755do_neon_dyadic_i64_su (void)
14756{
037e8744 14757 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14758 struct neon_type_el et = neon_check_type (3, rs,
14759 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14760 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14761}
14762
14763static void
14764neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14765 unsigned immbits)
5287ad62
JB
14766{
14767 unsigned size = et.size >> 3;
14768 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14769 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14770 inst.instruction |= LOW4 (inst.operands[1].reg);
14771 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14772 inst.instruction |= (isquad != 0) << 6;
14773 inst.instruction |= immbits << 16;
14774 inst.instruction |= (size >> 3) << 7;
14775 inst.instruction |= (size & 0x7) << 19;
14776 if (write_ubit)
14777 inst.instruction |= (uval != 0) << 24;
14778
88714cb8 14779 neon_dp_fixup (&inst);
5287ad62
JB
14780}
14781
14782static void
14783do_neon_shl_imm (void)
14784{
14785 if (!inst.operands[2].isreg)
14786 {
037e8744 14787 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14788 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14789 int imm = inst.operands[2].imm;
14790
14791 constraint (imm < 0 || (unsigned)imm >= et.size,
14792 _("immediate out of range for shift"));
88714cb8 14793 NEON_ENCODE (IMMED, inst);
cb3b1e65 14794 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14795 }
14796 else
14797 {
037e8744 14798 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14799 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14800 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14801 unsigned int tmp;
14802
14803 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14804 vshl.xx Dd, Dm, Dn
14805 whereas other 3-register operations encoded by neon_three_same have
14806 syntax like:
14807 vadd.xx Dd, Dn, Dm
14808 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14809 here. */
627907b7
JB
14810 tmp = inst.operands[2].reg;
14811 inst.operands[2].reg = inst.operands[1].reg;
14812 inst.operands[1].reg = tmp;
88714cb8 14813 NEON_ENCODE (INTEGER, inst);
037e8744 14814 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14815 }
14816}
14817
14818static void
14819do_neon_qshl_imm (void)
14820{
14821 if (!inst.operands[2].isreg)
14822 {
037e8744 14823 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14824 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14825 int imm = inst.operands[2].imm;
627907b7 14826
cb3b1e65
JB
14827 constraint (imm < 0 || (unsigned)imm >= et.size,
14828 _("immediate out of range for shift"));
88714cb8 14829 NEON_ENCODE (IMMED, inst);
cb3b1e65 14830 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14831 }
14832 else
14833 {
037e8744 14834 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14835 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14836 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14837 unsigned int tmp;
14838
14839 /* See note in do_neon_shl_imm. */
14840 tmp = inst.operands[2].reg;
14841 inst.operands[2].reg = inst.operands[1].reg;
14842 inst.operands[1].reg = tmp;
88714cb8 14843 NEON_ENCODE (INTEGER, inst);
037e8744 14844 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14845 }
14846}
14847
627907b7
JB
14848static void
14849do_neon_rshl (void)
14850{
14851 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14852 struct neon_type_el et = neon_check_type (3, rs,
14853 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14854 unsigned int tmp;
14855
14856 tmp = inst.operands[2].reg;
14857 inst.operands[2].reg = inst.operands[1].reg;
14858 inst.operands[1].reg = tmp;
14859 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14860}
14861
5287ad62
JB
14862static int
14863neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14864{
036dc3f7
PB
14865 /* Handle .I8 pseudo-instructions. */
14866 if (size == 8)
5287ad62 14867 {
5287ad62 14868 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14869 FIXME is this the intended semantics? There doesn't seem much point in
14870 accepting .I8 if so. */
5287ad62
JB
14871 immediate |= immediate << 8;
14872 size = 16;
036dc3f7
PB
14873 }
14874
14875 if (size >= 32)
14876 {
14877 if (immediate == (immediate & 0x000000ff))
14878 {
14879 *immbits = immediate;
14880 return 0x1;
14881 }
14882 else if (immediate == (immediate & 0x0000ff00))
14883 {
14884 *immbits = immediate >> 8;
14885 return 0x3;
14886 }
14887 else if (immediate == (immediate & 0x00ff0000))
14888 {
14889 *immbits = immediate >> 16;
14890 return 0x5;
14891 }
14892 else if (immediate == (immediate & 0xff000000))
14893 {
14894 *immbits = immediate >> 24;
14895 return 0x7;
14896 }
14897 if ((immediate & 0xffff) != (immediate >> 16))
14898 goto bad_immediate;
14899 immediate &= 0xffff;
5287ad62
JB
14900 }
14901
14902 if (immediate == (immediate & 0x000000ff))
14903 {
14904 *immbits = immediate;
036dc3f7 14905 return 0x9;
5287ad62
JB
14906 }
14907 else if (immediate == (immediate & 0x0000ff00))
14908 {
14909 *immbits = immediate >> 8;
036dc3f7 14910 return 0xb;
5287ad62
JB
14911 }
14912
14913 bad_immediate:
dcbf9037 14914 first_error (_("immediate value out of range"));
5287ad62
JB
14915 return FAIL;
14916}
14917
5287ad62
JB
14918static void
14919do_neon_logic (void)
14920{
14921 if (inst.operands[2].present && inst.operands[2].isreg)
14922 {
037e8744 14923 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14924 neon_check_type (3, rs, N_IGNORE_TYPE);
14925 /* U bit and size field were set as part of the bitmask. */
88714cb8 14926 NEON_ENCODE (INTEGER, inst);
037e8744 14927 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14928 }
14929 else
14930 {
4316f0d2
DG
14931 const int three_ops_form = (inst.operands[2].present
14932 && !inst.operands[2].isreg);
14933 const int immoperand = (three_ops_form ? 2 : 1);
14934 enum neon_shape rs = (three_ops_form
14935 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14936 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14937 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14938 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14939 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14940 unsigned immbits;
14941 int cmode;
5f4273c7 14942
5287ad62 14943 if (et.type == NT_invtype)
477330fc 14944 return;
5f4273c7 14945
4316f0d2
DG
14946 if (three_ops_form)
14947 constraint (inst.operands[0].reg != inst.operands[1].reg,
14948 _("first and second operands shall be the same register"));
14949
88714cb8 14950 NEON_ENCODE (IMMED, inst);
5287ad62 14951
4316f0d2 14952 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14953 if (et.size == 64)
14954 {
14955 /* .i64 is a pseudo-op, so the immediate must be a repeating
14956 pattern. */
4316f0d2
DG
14957 if (immbits != (inst.operands[immoperand].regisimm ?
14958 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14959 {
14960 /* Set immbits to an invalid constant. */
14961 immbits = 0xdeadbeef;
14962 }
14963 }
14964
5287ad62 14965 switch (opcode)
477330fc
RM
14966 {
14967 case N_MNEM_vbic:
14968 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14969 break;
14970
14971 case N_MNEM_vorr:
14972 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14973 break;
14974
14975 case N_MNEM_vand:
14976 /* Pseudo-instruction for VBIC. */
14977 neon_invert_size (&immbits, 0, et.size);
14978 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14979 break;
14980
14981 case N_MNEM_vorn:
14982 /* Pseudo-instruction for VORR. */
14983 neon_invert_size (&immbits, 0, et.size);
14984 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14985 break;
14986
14987 default:
14988 abort ();
14989 }
5287ad62
JB
14990
14991 if (cmode == FAIL)
477330fc 14992 return;
5287ad62 14993
037e8744 14994 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14995 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14996 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14997 inst.instruction |= cmode << 8;
14998 neon_write_immbits (immbits);
5f4273c7 14999
88714cb8 15000 neon_dp_fixup (&inst);
5287ad62
JB
15001 }
15002}
15003
15004static void
15005do_neon_bitfield (void)
15006{
037e8744 15007 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 15008 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 15009 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
15010}
15011
15012static void
dcbf9037 15013neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 15014 unsigned destbits)
5287ad62 15015{
037e8744 15016 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 15017 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 15018 types | N_KEY);
5287ad62
JB
15019 if (et.type == NT_float)
15020 {
88714cb8 15021 NEON_ENCODE (FLOAT, inst);
cc933301 15022 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15023 }
15024 else
15025 {
88714cb8 15026 NEON_ENCODE (INTEGER, inst);
037e8744 15027 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
15028 }
15029}
15030
15031static void
15032do_neon_dyadic_if_su (void)
15033{
dcbf9037 15034 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
15035}
15036
15037static void
15038do_neon_dyadic_if_su_d (void)
15039{
15040 /* This version only allow D registers, but that constraint is enforced during
15041 operand parsing so we don't need to do anything extra here. */
dcbf9037 15042 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
15043}
15044
5287ad62
JB
15045static void
15046do_neon_dyadic_if_i_d (void)
15047{
428e3f1f
PB
15048 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15049 affected if we specify unsigned args. */
15050 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
15051}
15052
037e8744
JB
15053enum vfp_or_neon_is_neon_bits
15054{
15055 NEON_CHECK_CC = 1,
73924fbc
MGD
15056 NEON_CHECK_ARCH = 2,
15057 NEON_CHECK_ARCH8 = 4
037e8744
JB
15058};
15059
15060/* Call this function if an instruction which may have belonged to the VFP or
15061 Neon instruction sets, but turned out to be a Neon instruction (due to the
15062 operand types involved, etc.). We have to check and/or fix-up a couple of
15063 things:
15064
15065 - Make sure the user hasn't attempted to make a Neon instruction
15066 conditional.
15067 - Alter the value in the condition code field if necessary.
15068 - Make sure that the arch supports Neon instructions.
15069
15070 Which of these operations take place depends on bits from enum
15071 vfp_or_neon_is_neon_bits.
15072
15073 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
15074 current instruction's condition is COND_ALWAYS, the condition field is
15075 changed to inst.uncond_value. This is necessary because instructions shared
15076 between VFP and Neon may be conditional for the VFP variants only, and the
15077 unconditional Neon version must have, e.g., 0xF in the condition field. */
15078
15079static int
15080vfp_or_neon_is_neon (unsigned check)
15081{
15082 /* Conditions are always legal in Thumb mode (IT blocks). */
15083 if (!thumb_mode && (check & NEON_CHECK_CC))
15084 {
15085 if (inst.cond != COND_ALWAYS)
477330fc
RM
15086 {
15087 first_error (_(BAD_COND));
15088 return FAIL;
15089 }
037e8744 15090 if (inst.uncond_value != -1)
477330fc 15091 inst.instruction |= inst.uncond_value << 28;
037e8744 15092 }
5f4273c7 15093
037e8744 15094 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
15095 && !mark_feature_used (&fpu_neon_ext_v1))
15096 {
15097 first_error (_(BAD_FPU));
15098 return FAIL;
15099 }
15100
15101 if ((check & NEON_CHECK_ARCH8)
15102 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
15103 {
15104 first_error (_(BAD_FPU));
15105 return FAIL;
15106 }
5f4273c7 15107
037e8744
JB
15108 return SUCCESS;
15109}
15110
5287ad62
JB
15111static void
15112do_neon_addsub_if_i (void)
15113{
037e8744
JB
15114 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
15115 return;
15116
15117 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15118 return;
15119
5287ad62
JB
15120 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15121 affected if we specify unsigned args. */
dcbf9037 15122 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
15123}
15124
15125/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
15126 result to be:
15127 V<op> A,B (A is operand 0, B is operand 2)
15128 to mean:
15129 V<op> A,B,A
15130 not:
15131 V<op> A,B,B
15132 so handle that case specially. */
15133
15134static void
15135neon_exchange_operands (void)
15136{
5287ad62
JB
15137 if (inst.operands[1].present)
15138 {
e1fa0163
NC
15139 void *scratch = xmalloc (sizeof (inst.operands[0]));
15140
5287ad62
JB
15141 /* Swap operands[1] and operands[2]. */
15142 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
15143 inst.operands[1] = inst.operands[2];
15144 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 15145 free (scratch);
5287ad62
JB
15146 }
15147 else
15148 {
15149 inst.operands[1] = inst.operands[2];
15150 inst.operands[2] = inst.operands[0];
15151 }
15152}
15153
15154static void
15155neon_compare (unsigned regtypes, unsigned immtypes, int invert)
15156{
15157 if (inst.operands[2].isreg)
15158 {
15159 if (invert)
477330fc 15160 neon_exchange_operands ();
dcbf9037 15161 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
15162 }
15163 else
15164 {
037e8744 15165 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 15166 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15167 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 15168
88714cb8 15169 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15170 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15171 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15172 inst.instruction |= LOW4 (inst.operands[1].reg);
15173 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15174 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15175 inst.instruction |= (et.type == NT_float) << 10;
15176 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15177
88714cb8 15178 neon_dp_fixup (&inst);
5287ad62
JB
15179 }
15180}
15181
15182static void
15183do_neon_cmp (void)
15184{
cc933301 15185 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
15186}
15187
15188static void
15189do_neon_cmp_inv (void)
15190{
cc933301 15191 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
15192}
15193
15194static void
15195do_neon_ceq (void)
15196{
15197 neon_compare (N_IF_32, N_IF_32, FALSE);
15198}
15199
15200/* For multiply instructions, we have the possibility of 16-bit or 32-bit
15201 scalars, which are encoded in 5 bits, M : Rm.
15202 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15203 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
15204 index in M.
15205
15206 Dot Product instructions are similar to multiply instructions except elsize
15207 should always be 32.
15208
15209 This function translates SCALAR, which is GAS's internal encoding of indexed
15210 scalar register, to raw encoding. There is also register and index range
15211 check based on ELSIZE. */
5287ad62
JB
15212
15213static unsigned
15214neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15215{
dcbf9037
JB
15216 unsigned regno = NEON_SCALAR_REG (scalar);
15217 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
15218
15219 switch (elsize)
15220 {
15221 case 16:
15222 if (regno > 7 || elno > 3)
477330fc 15223 goto bad_scalar;
5287ad62 15224 return regno | (elno << 3);
5f4273c7 15225
5287ad62
JB
15226 case 32:
15227 if (regno > 15 || elno > 1)
477330fc 15228 goto bad_scalar;
5287ad62
JB
15229 return regno | (elno << 4);
15230
15231 default:
15232 bad_scalar:
dcbf9037 15233 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15234 }
15235
15236 return 0;
15237}
15238
15239/* Encode multiply / multiply-accumulate scalar instructions. */
15240
15241static void
15242neon_mul_mac (struct neon_type_el et, int ubit)
15243{
dcbf9037
JB
15244 unsigned scalar;
15245
15246 /* Give a more helpful error message if we have an invalid type. */
15247 if (et.type == NT_invtype)
15248 return;
5f4273c7 15249
dcbf9037 15250 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15251 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15252 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15253 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15254 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15255 inst.instruction |= LOW4 (scalar);
15256 inst.instruction |= HI1 (scalar) << 5;
15257 inst.instruction |= (et.type == NT_float) << 8;
15258 inst.instruction |= neon_logbits (et.size) << 20;
15259 inst.instruction |= (ubit != 0) << 24;
15260
88714cb8 15261 neon_dp_fixup (&inst);
5287ad62
JB
15262}
15263
15264static void
15265do_neon_mac_maybe_scalar (void)
15266{
037e8744
JB
15267 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15268 return;
15269
15270 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15271 return;
15272
5287ad62
JB
15273 if (inst.operands[2].isscalar)
15274 {
037e8744 15275 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15276 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15277 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15278 NEON_ENCODE (SCALAR, inst);
037e8744 15279 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15280 }
15281 else
428e3f1f
PB
15282 {
15283 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15284 affected if we specify unsigned args. */
15285 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15286 }
5287ad62
JB
15287}
15288
62f3b8c8
PB
15289static void
15290do_neon_fmac (void)
15291{
15292 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15293 return;
15294
15295 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15296 return;
15297
15298 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15299}
15300
5287ad62
JB
15301static void
15302do_neon_tst (void)
15303{
037e8744 15304 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15305 struct neon_type_el et = neon_check_type (3, rs,
15306 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15307 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15308}
15309
15310/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15311 same types as the MAC equivalents. The polynomial type for this instruction
15312 is encoded the same as the integer type. */
15313
15314static void
15315do_neon_mul (void)
15316{
037e8744
JB
15317 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15318 return;
15319
15320 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15321 return;
15322
5287ad62
JB
15323 if (inst.operands[2].isscalar)
15324 do_neon_mac_maybe_scalar ();
15325 else
cc933301 15326 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15327}
15328
15329static void
15330do_neon_qdmulh (void)
15331{
15332 if (inst.operands[2].isscalar)
15333 {
037e8744 15334 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15335 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15336 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15337 NEON_ENCODE (SCALAR, inst);
037e8744 15338 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15339 }
15340 else
15341 {
037e8744 15342 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15343 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15344 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15345 NEON_ENCODE (INTEGER, inst);
5287ad62 15346 /* The U bit (rounding) comes from bit mask. */
037e8744 15347 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15348 }
15349}
15350
643afb90
MW
15351static void
15352do_neon_qrdmlah (void)
15353{
15354 /* Check we're on the correct architecture. */
15355 if (!mark_feature_used (&fpu_neon_ext_armv8))
15356 inst.error =
15357 _("instruction form not available on this architecture.");
15358 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15359 {
15360 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15361 record_feature_use (&fpu_neon_ext_v8_1);
15362 }
15363
15364 if (inst.operands[2].isscalar)
15365 {
15366 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15367 struct neon_type_el et = neon_check_type (3, rs,
15368 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15369 NEON_ENCODE (SCALAR, inst);
15370 neon_mul_mac (et, neon_quad (rs));
15371 }
15372 else
15373 {
15374 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15375 struct neon_type_el et = neon_check_type (3, rs,
15376 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15377 NEON_ENCODE (INTEGER, inst);
15378 /* The U bit (rounding) comes from bit mask. */
15379 neon_three_same (neon_quad (rs), 0, et.size);
15380 }
15381}
15382
5287ad62
JB
15383static void
15384do_neon_fcmp_absolute (void)
15385{
037e8744 15386 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15387 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15388 N_F_16_32 | N_KEY);
5287ad62 15389 /* Size field comes from bit mask. */
cc933301 15390 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15391}
15392
15393static void
15394do_neon_fcmp_absolute_inv (void)
15395{
15396 neon_exchange_operands ();
15397 do_neon_fcmp_absolute ();
15398}
15399
15400static void
15401do_neon_step (void)
15402{
037e8744 15403 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15404 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15405 N_F_16_32 | N_KEY);
15406 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15407}
15408
15409static void
15410do_neon_abs_neg (void)
15411{
037e8744
JB
15412 enum neon_shape rs;
15413 struct neon_type_el et;
5f4273c7 15414
037e8744
JB
15415 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15416 return;
15417
15418 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15419 return;
15420
15421 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15422 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15423
5287ad62
JB
15424 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15425 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15426 inst.instruction |= LOW4 (inst.operands[1].reg);
15427 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15428 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15429 inst.instruction |= (et.type == NT_float) << 10;
15430 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15431
88714cb8 15432 neon_dp_fixup (&inst);
5287ad62
JB
15433}
15434
15435static void
15436do_neon_sli (void)
15437{
037e8744 15438 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15439 struct neon_type_el et = neon_check_type (2, rs,
15440 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15441 int imm = inst.operands[2].imm;
15442 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15443 _("immediate out of range for insert"));
037e8744 15444 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15445}
15446
15447static void
15448do_neon_sri (void)
15449{
037e8744 15450 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15451 struct neon_type_el et = neon_check_type (2, rs,
15452 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15453 int imm = inst.operands[2].imm;
15454 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15455 _("immediate out of range for insert"));
037e8744 15456 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15457}
15458
15459static void
15460do_neon_qshlu_imm (void)
15461{
037e8744 15462 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15463 struct neon_type_el et = neon_check_type (2, rs,
15464 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15465 int imm = inst.operands[2].imm;
15466 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15467 _("immediate out of range for shift"));
5287ad62
JB
15468 /* Only encodes the 'U present' variant of the instruction.
15469 In this case, signed types have OP (bit 8) set to 0.
15470 Unsigned types have OP set to 1. */
15471 inst.instruction |= (et.type == NT_unsigned) << 8;
15472 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15473 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15474}
15475
15476static void
15477do_neon_qmovn (void)
15478{
15479 struct neon_type_el et = neon_check_type (2, NS_DQ,
15480 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15481 /* Saturating move where operands can be signed or unsigned, and the
15482 destination has the same signedness. */
88714cb8 15483 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15484 if (et.type == NT_unsigned)
15485 inst.instruction |= 0xc0;
15486 else
15487 inst.instruction |= 0x80;
15488 neon_two_same (0, 1, et.size / 2);
15489}
15490
15491static void
15492do_neon_qmovun (void)
15493{
15494 struct neon_type_el et = neon_check_type (2, NS_DQ,
15495 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15496 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15497 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15498 neon_two_same (0, 1, et.size / 2);
15499}
15500
15501static void
15502do_neon_rshift_sat_narrow (void)
15503{
15504 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15505 or unsigned. If operands are unsigned, results must also be unsigned. */
15506 struct neon_type_el et = neon_check_type (2, NS_DQI,
15507 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15508 int imm = inst.operands[2].imm;
15509 /* This gets the bounds check, size encoding and immediate bits calculation
15510 right. */
15511 et.size /= 2;
5f4273c7 15512
5287ad62
JB
15513 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15514 VQMOVN.I<size> <Dd>, <Qm>. */
15515 if (imm == 0)
15516 {
15517 inst.operands[2].present = 0;
15518 inst.instruction = N_MNEM_vqmovn;
15519 do_neon_qmovn ();
15520 return;
15521 }
5f4273c7 15522
5287ad62 15523 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15524 _("immediate out of range"));
5287ad62
JB
15525 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15526}
15527
15528static void
15529do_neon_rshift_sat_narrow_u (void)
15530{
15531 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15532 or unsigned. If operands are unsigned, results must also be unsigned. */
15533 struct neon_type_el et = neon_check_type (2, NS_DQI,
15534 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15535 int imm = inst.operands[2].imm;
15536 /* This gets the bounds check, size encoding and immediate bits calculation
15537 right. */
15538 et.size /= 2;
15539
15540 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15541 VQMOVUN.I<size> <Dd>, <Qm>. */
15542 if (imm == 0)
15543 {
15544 inst.operands[2].present = 0;
15545 inst.instruction = N_MNEM_vqmovun;
15546 do_neon_qmovun ();
15547 return;
15548 }
15549
15550 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15551 _("immediate out of range"));
5287ad62
JB
15552 /* FIXME: The manual is kind of unclear about what value U should have in
15553 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15554 must be 1. */
15555 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15556}
15557
15558static void
15559do_neon_movn (void)
15560{
15561 struct neon_type_el et = neon_check_type (2, NS_DQ,
15562 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15563 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15564 neon_two_same (0, 1, et.size / 2);
15565}
15566
15567static void
15568do_neon_rshift_narrow (void)
15569{
15570 struct neon_type_el et = neon_check_type (2, NS_DQI,
15571 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15572 int imm = inst.operands[2].imm;
15573 /* This gets the bounds check, size encoding and immediate bits calculation
15574 right. */
15575 et.size /= 2;
5f4273c7 15576
5287ad62
JB
15577 /* If immediate is zero then we are a pseudo-instruction for
15578 VMOVN.I<size> <Dd>, <Qm> */
15579 if (imm == 0)
15580 {
15581 inst.operands[2].present = 0;
15582 inst.instruction = N_MNEM_vmovn;
15583 do_neon_movn ();
15584 return;
15585 }
5f4273c7 15586
5287ad62 15587 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15588 _("immediate out of range for narrowing operation"));
5287ad62
JB
15589 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15590}
15591
15592static void
15593do_neon_shll (void)
15594{
15595 /* FIXME: Type checking when lengthening. */
15596 struct neon_type_el et = neon_check_type (2, NS_QDI,
15597 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15598 unsigned imm = inst.operands[2].imm;
15599
15600 if (imm == et.size)
15601 {
15602 /* Maximum shift variant. */
88714cb8 15603 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15604 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15605 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15606 inst.instruction |= LOW4 (inst.operands[1].reg);
15607 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15608 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15609
88714cb8 15610 neon_dp_fixup (&inst);
5287ad62
JB
15611 }
15612 else
15613 {
15614 /* A more-specific type check for non-max versions. */
15615 et = neon_check_type (2, NS_QDI,
477330fc 15616 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15617 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15618 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15619 }
15620}
15621
037e8744 15622/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15623 the current instruction is. */
15624
6b9a8b67
MGD
15625#define CVT_FLAVOUR_VAR \
15626 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15627 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15628 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15629 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15630 /* Half-precision conversions. */ \
cc933301
JW
15631 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15632 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15633 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15634 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15635 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15636 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15637 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15638 Compared with single/double precision variants, only the co-processor \
15639 field is different, so the encoding flow is reused here. */ \
15640 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15641 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15642 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15643 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15644 /* VFP instructions. */ \
15645 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15646 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15647 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15648 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15649 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15650 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15651 /* VFP instructions with bitshift. */ \
15652 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15653 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15654 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15655 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15656 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15657 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15658 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15659 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15660
15661#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15662 neon_cvt_flavour_##C,
15663
15664/* The different types of conversions we can do. */
15665enum neon_cvt_flavour
15666{
15667 CVT_FLAVOUR_VAR
15668 neon_cvt_flavour_invalid,
15669 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15670};
15671
15672#undef CVT_VAR
15673
15674static enum neon_cvt_flavour
15675get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15676{
6b9a8b67
MGD
15677#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15678 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15679 if (et.type != NT_invtype) \
15680 { \
15681 inst.error = NULL; \
15682 return (neon_cvt_flavour_##C); \
5287ad62 15683 }
6b9a8b67 15684
5287ad62 15685 struct neon_type_el et;
037e8744 15686 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15687 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15688 /* The instruction versions which take an immediate take one register
15689 argument, which is extended to the width of the full register. Thus the
15690 "source" and "destination" registers must have the same width. Hack that
15691 here by making the size equal to the key (wider, in this case) operand. */
15692 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15693
6b9a8b67
MGD
15694 CVT_FLAVOUR_VAR;
15695
15696 return neon_cvt_flavour_invalid;
5287ad62
JB
15697#undef CVT_VAR
15698}
15699
7e8e6784
MGD
15700enum neon_cvt_mode
15701{
15702 neon_cvt_mode_a,
15703 neon_cvt_mode_n,
15704 neon_cvt_mode_p,
15705 neon_cvt_mode_m,
15706 neon_cvt_mode_z,
30bdf752
MGD
15707 neon_cvt_mode_x,
15708 neon_cvt_mode_r
7e8e6784
MGD
15709};
15710
037e8744
JB
15711/* Neon-syntax VFP conversions. */
15712
5287ad62 15713static void
6b9a8b67 15714do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15715{
037e8744 15716 const char *opname = 0;
5f4273c7 15717
d54af2d0
RL
15718 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15719 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15720 {
037e8744
JB
15721 /* Conversions with immediate bitshift. */
15722 const char *enc[] =
477330fc 15723 {
6b9a8b67
MGD
15724#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15725 CVT_FLAVOUR_VAR
15726 NULL
15727#undef CVT_VAR
477330fc 15728 };
037e8744 15729
6b9a8b67 15730 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15731 {
15732 opname = enc[flavour];
15733 constraint (inst.operands[0].reg != inst.operands[1].reg,
15734 _("operands 0 and 1 must be the same register"));
15735 inst.operands[1] = inst.operands[2];
15736 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15737 }
5287ad62
JB
15738 }
15739 else
15740 {
037e8744
JB
15741 /* Conversions without bitshift. */
15742 const char *enc[] =
477330fc 15743 {
6b9a8b67
MGD
15744#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15745 CVT_FLAVOUR_VAR
15746 NULL
15747#undef CVT_VAR
477330fc 15748 };
037e8744 15749
6b9a8b67 15750 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15751 opname = enc[flavour];
037e8744
JB
15752 }
15753
15754 if (opname)
15755 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15756
15757 /* ARMv8.2 fp16 VCVT instruction. */
15758 if (flavour == neon_cvt_flavour_s32_f16
15759 || flavour == neon_cvt_flavour_u32_f16
15760 || flavour == neon_cvt_flavour_f16_u32
15761 || flavour == neon_cvt_flavour_f16_s32)
15762 do_scalar_fp16_v82_encode ();
037e8744
JB
15763}
15764
15765static void
15766do_vfp_nsyn_cvtz (void)
15767{
d54af2d0 15768 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15769 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15770 const char *enc[] =
15771 {
6b9a8b67
MGD
15772#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15773 CVT_FLAVOUR_VAR
15774 NULL
15775#undef CVT_VAR
037e8744
JB
15776 };
15777
6b9a8b67 15778 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15779 do_vfp_nsyn_opcode (enc[flavour]);
15780}
f31fef98 15781
037e8744 15782static void
bacebabc 15783do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15784 enum neon_cvt_mode mode)
15785{
15786 int sz, op;
15787 int rm;
15788
a715796b
TG
15789 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15790 D register operands. */
15791 if (flavour == neon_cvt_flavour_s32_f64
15792 || flavour == neon_cvt_flavour_u32_f64)
15793 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15794 _(BAD_FPU));
15795
9db2f6b4
RL
15796 if (flavour == neon_cvt_flavour_s32_f16
15797 || flavour == neon_cvt_flavour_u32_f16)
15798 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15799 _(BAD_FP16));
15800
7e8e6784
MGD
15801 set_it_insn_type (OUTSIDE_IT_INSN);
15802
15803 switch (flavour)
15804 {
15805 case neon_cvt_flavour_s32_f64:
15806 sz = 1;
827f64ff 15807 op = 1;
7e8e6784
MGD
15808 break;
15809 case neon_cvt_flavour_s32_f32:
15810 sz = 0;
15811 op = 1;
15812 break;
9db2f6b4
RL
15813 case neon_cvt_flavour_s32_f16:
15814 sz = 0;
15815 op = 1;
15816 break;
7e8e6784
MGD
15817 case neon_cvt_flavour_u32_f64:
15818 sz = 1;
15819 op = 0;
15820 break;
15821 case neon_cvt_flavour_u32_f32:
15822 sz = 0;
15823 op = 0;
15824 break;
9db2f6b4
RL
15825 case neon_cvt_flavour_u32_f16:
15826 sz = 0;
15827 op = 0;
15828 break;
7e8e6784
MGD
15829 default:
15830 first_error (_("invalid instruction shape"));
15831 return;
15832 }
15833
15834 switch (mode)
15835 {
15836 case neon_cvt_mode_a: rm = 0; break;
15837 case neon_cvt_mode_n: rm = 1; break;
15838 case neon_cvt_mode_p: rm = 2; break;
15839 case neon_cvt_mode_m: rm = 3; break;
15840 default: first_error (_("invalid rounding mode")); return;
15841 }
15842
15843 NEON_ENCODE (FPV8, inst);
15844 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15845 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15846 inst.instruction |= sz << 8;
9db2f6b4
RL
15847
15848 /* ARMv8.2 fp16 VCVT instruction. */
15849 if (flavour == neon_cvt_flavour_s32_f16
15850 ||flavour == neon_cvt_flavour_u32_f16)
15851 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15852 inst.instruction |= op << 7;
15853 inst.instruction |= rm << 16;
15854 inst.instruction |= 0xf0000000;
15855 inst.is_neon = TRUE;
15856}
15857
15858static void
15859do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15860{
15861 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15862 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15863 NS_FH, NS_HF, NS_FHI, NS_HFI,
15864 NS_NULL);
6b9a8b67 15865 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15866
cc933301
JW
15867 if (flavour == neon_cvt_flavour_invalid)
15868 return;
15869
e3e535bc 15870 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15871 if (mode == neon_cvt_mode_z
e3e535bc 15872 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15873 && (flavour == neon_cvt_flavour_s16_f16
15874 || flavour == neon_cvt_flavour_u16_f16
15875 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15876 || flavour == neon_cvt_flavour_u32_f32
15877 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15878 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15879 && (rs == NS_FD || rs == NS_FF))
15880 {
15881 do_vfp_nsyn_cvtz ();
15882 return;
15883 }
15884
9db2f6b4
RL
15885 /* ARMv8.2 fp16 VCVT conversions. */
15886 if (mode == neon_cvt_mode_z
15887 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15888 && (flavour == neon_cvt_flavour_s32_f16
15889 || flavour == neon_cvt_flavour_u32_f16)
15890 && (rs == NS_FH))
15891 {
15892 do_vfp_nsyn_cvtz ();
15893 do_scalar_fp16_v82_encode ();
15894 return;
15895 }
15896
037e8744 15897 /* VFP rather than Neon conversions. */
6b9a8b67 15898 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15899 {
7e8e6784
MGD
15900 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15901 do_vfp_nsyn_cvt (rs, flavour);
15902 else
15903 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15904
037e8744
JB
15905 return;
15906 }
15907
15908 switch (rs)
15909 {
15910 case NS_DDI:
15911 case NS_QQI:
15912 {
477330fc 15913 unsigned immbits;
cc933301
JW
15914 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15915 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15916
477330fc
RM
15917 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15918 return;
037e8744 15919
477330fc
RM
15920 /* Fixed-point conversion with #0 immediate is encoded as an
15921 integer conversion. */
15922 if (inst.operands[2].present && inst.operands[2].imm == 0)
15923 goto int_encode;
477330fc
RM
15924 NEON_ENCODE (IMMED, inst);
15925 if (flavour != neon_cvt_flavour_invalid)
15926 inst.instruction |= enctab[flavour];
15927 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15928 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15929 inst.instruction |= LOW4 (inst.operands[1].reg);
15930 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15931 inst.instruction |= neon_quad (rs) << 6;
15932 inst.instruction |= 1 << 21;
cc933301
JW
15933 if (flavour < neon_cvt_flavour_s16_f16)
15934 {
15935 inst.instruction |= 1 << 21;
15936 immbits = 32 - inst.operands[2].imm;
15937 inst.instruction |= immbits << 16;
15938 }
15939 else
15940 {
15941 inst.instruction |= 3 << 20;
15942 immbits = 16 - inst.operands[2].imm;
15943 inst.instruction |= immbits << 16;
15944 inst.instruction &= ~(1 << 9);
15945 }
477330fc
RM
15946
15947 neon_dp_fixup (&inst);
037e8744
JB
15948 }
15949 break;
15950
15951 case NS_DD:
15952 case NS_QQ:
7e8e6784
MGD
15953 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15954 {
15955 NEON_ENCODE (FLOAT, inst);
15956 set_it_insn_type (OUTSIDE_IT_INSN);
15957
15958 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15959 return;
15960
15961 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15962 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15963 inst.instruction |= LOW4 (inst.operands[1].reg);
15964 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15965 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15966 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15967 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15968 inst.instruction |= mode << 8;
cc933301
JW
15969 if (flavour == neon_cvt_flavour_u16_f16
15970 || flavour == neon_cvt_flavour_s16_f16)
15971 /* Mask off the original size bits and reencode them. */
15972 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15973
7e8e6784
MGD
15974 if (thumb_mode)
15975 inst.instruction |= 0xfc000000;
15976 else
15977 inst.instruction |= 0xf0000000;
15978 }
15979 else
15980 {
037e8744 15981 int_encode:
7e8e6784 15982 {
cc933301
JW
15983 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15984 0x100, 0x180, 0x0, 0x080};
037e8744 15985
7e8e6784 15986 NEON_ENCODE (INTEGER, inst);
037e8744 15987
7e8e6784
MGD
15988 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15989 return;
037e8744 15990
7e8e6784
MGD
15991 if (flavour != neon_cvt_flavour_invalid)
15992 inst.instruction |= enctab[flavour];
037e8744 15993
7e8e6784
MGD
15994 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15995 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15996 inst.instruction |= LOW4 (inst.operands[1].reg);
15997 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15998 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15999 if (flavour >= neon_cvt_flavour_s16_f16
16000 && flavour <= neon_cvt_flavour_f16_u16)
16001 /* Half precision. */
16002 inst.instruction |= 1 << 18;
16003 else
16004 inst.instruction |= 2 << 18;
037e8744 16005
7e8e6784
MGD
16006 neon_dp_fixup (&inst);
16007 }
16008 }
16009 break;
037e8744 16010
8e79c3df
CM
16011 /* Half-precision conversions for Advanced SIMD -- neon. */
16012 case NS_QD:
16013 case NS_DQ:
bc52d49c
MM
16014 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16015 return;
8e79c3df
CM
16016
16017 if ((rs == NS_DQ)
16018 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
16019 {
16020 as_bad (_("operand size must match register width"));
16021 break;
16022 }
16023
16024 if ((rs == NS_QD)
16025 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
16026 {
16027 as_bad (_("operand size must match register width"));
16028 break;
16029 }
16030
16031 if (rs == NS_DQ)
477330fc 16032 inst.instruction = 0x3b60600;
8e79c3df
CM
16033 else
16034 inst.instruction = 0x3b60700;
16035
16036 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16037 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16038 inst.instruction |= LOW4 (inst.operands[1].reg);
16039 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 16040 neon_dp_fixup (&inst);
8e79c3df
CM
16041 break;
16042
037e8744
JB
16043 default:
16044 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
16045 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
16046 do_vfp_nsyn_cvt (rs, flavour);
16047 else
16048 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 16049 }
5287ad62
JB
16050}
16051
e3e535bc
NC
16052static void
16053do_neon_cvtr (void)
16054{
7e8e6784 16055 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
16056}
16057
16058static void
16059do_neon_cvt (void)
16060{
7e8e6784
MGD
16061 do_neon_cvt_1 (neon_cvt_mode_z);
16062}
16063
16064static void
16065do_neon_cvta (void)
16066{
16067 do_neon_cvt_1 (neon_cvt_mode_a);
16068}
16069
16070static void
16071do_neon_cvtn (void)
16072{
16073 do_neon_cvt_1 (neon_cvt_mode_n);
16074}
16075
16076static void
16077do_neon_cvtp (void)
16078{
16079 do_neon_cvt_1 (neon_cvt_mode_p);
16080}
16081
16082static void
16083do_neon_cvtm (void)
16084{
16085 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
16086}
16087
8e79c3df 16088static void
c70a8987 16089do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 16090{
c70a8987
MGD
16091 if (is_double)
16092 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 16093
c70a8987
MGD
16094 encode_arm_vfp_reg (inst.operands[0].reg,
16095 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
16096 encode_arm_vfp_reg (inst.operands[1].reg,
16097 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
16098 inst.instruction |= to ? 0x10000 : 0;
16099 inst.instruction |= t ? 0x80 : 0;
16100 inst.instruction |= is_double ? 0x100 : 0;
16101 do_vfp_cond_or_thumb ();
16102}
8e79c3df 16103
c70a8987
MGD
16104static void
16105do_neon_cvttb_1 (bfd_boolean t)
16106{
d54af2d0
RL
16107 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
16108 NS_DF, NS_DH, NS_NULL);
8e79c3df 16109
c70a8987
MGD
16110 if (rs == NS_NULL)
16111 return;
16112 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
16113 {
16114 inst.error = NULL;
16115 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
16116 }
16117 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
16118 {
16119 inst.error = NULL;
16120 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
16121 }
16122 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
16123 {
a715796b
TG
16124 /* The VCVTB and VCVTT instructions with D-register operands
16125 don't work for SP only targets. */
16126 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16127 _(BAD_FPU));
16128
c70a8987
MGD
16129 inst.error = NULL;
16130 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
16131 }
16132 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
16133 {
a715796b
TG
16134 /* The VCVTB and VCVTT instructions with D-register operands
16135 don't work for SP only targets. */
16136 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16137 _(BAD_FPU));
16138
c70a8987
MGD
16139 inst.error = NULL;
16140 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
16141 }
16142 else
16143 return;
16144}
16145
16146static void
16147do_neon_cvtb (void)
16148{
16149 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
16150}
16151
16152
16153static void
16154do_neon_cvtt (void)
16155{
c70a8987 16156 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
16157}
16158
5287ad62
JB
16159static void
16160neon_move_immediate (void)
16161{
037e8744
JB
16162 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
16163 struct neon_type_el et = neon_check_type (2, rs,
16164 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 16165 unsigned immlo, immhi = 0, immbits;
c96612cc 16166 int op, cmode, float_p;
5287ad62 16167
037e8744 16168 constraint (et.type == NT_invtype,
477330fc 16169 _("operand size must be specified for immediate VMOV"));
037e8744 16170
5287ad62
JB
16171 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
16172 op = (inst.instruction & (1 << 5)) != 0;
16173
16174 immlo = inst.operands[1].imm;
16175 if (inst.operands[1].regisimm)
16176 immhi = inst.operands[1].reg;
16177
16178 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 16179 _("immediate has bits set outside the operand size"));
5287ad62 16180
c96612cc
JB
16181 float_p = inst.operands[1].immisfloat;
16182
16183 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 16184 et.size, et.type)) == FAIL)
5287ad62
JB
16185 {
16186 /* Invert relevant bits only. */
16187 neon_invert_size (&immlo, &immhi, et.size);
16188 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
16189 with one or the other; those cases are caught by
16190 neon_cmode_for_move_imm. */
5287ad62 16191 op = !op;
c96612cc
JB
16192 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16193 &op, et.size, et.type)) == FAIL)
477330fc
RM
16194 {
16195 first_error (_("immediate out of range"));
16196 return;
16197 }
5287ad62
JB
16198 }
16199
16200 inst.instruction &= ~(1 << 5);
16201 inst.instruction |= op << 5;
16202
16203 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16204 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 16205 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16206 inst.instruction |= cmode << 8;
16207
16208 neon_write_immbits (immbits);
16209}
16210
16211static void
16212do_neon_mvn (void)
16213{
16214 if (inst.operands[1].isreg)
16215 {
037e8744 16216 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16217
88714cb8 16218 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16219 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16220 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16221 inst.instruction |= LOW4 (inst.operands[1].reg);
16222 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16223 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16224 }
16225 else
16226 {
88714cb8 16227 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16228 neon_move_immediate ();
16229 }
16230
88714cb8 16231 neon_dp_fixup (&inst);
5287ad62
JB
16232}
16233
16234/* Encode instructions of form:
16235
16236 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16237 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16238
16239static void
16240neon_mixed_length (struct neon_type_el et, unsigned size)
16241{
16242 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16243 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16244 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16245 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16246 inst.instruction |= LOW4 (inst.operands[2].reg);
16247 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16248 inst.instruction |= (et.type == NT_unsigned) << 24;
16249 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16250
88714cb8 16251 neon_dp_fixup (&inst);
5287ad62
JB
16252}
16253
16254static void
16255do_neon_dyadic_long (void)
16256{
16257 /* FIXME: Type checking for lengthening op. */
16258 struct neon_type_el et = neon_check_type (3, NS_QDD,
16259 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16260 neon_mixed_length (et, et.size);
16261}
16262
16263static void
16264do_neon_abal (void)
16265{
16266 struct neon_type_el et = neon_check_type (3, NS_QDD,
16267 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16268 neon_mixed_length (et, et.size);
16269}
16270
16271static void
16272neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16273{
16274 if (inst.operands[2].isscalar)
16275 {
dcbf9037 16276 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16277 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16278 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16279 neon_mul_mac (et, et.type == NT_unsigned);
16280 }
16281 else
16282 {
16283 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16284 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16285 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16286 neon_mixed_length (et, et.size);
16287 }
16288}
16289
16290static void
16291do_neon_mac_maybe_scalar_long (void)
16292{
16293 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16294}
16295
dec41383
JW
16296/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
16297 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
16298
16299static unsigned
16300neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
16301{
16302 unsigned regno = NEON_SCALAR_REG (scalar);
16303 unsigned elno = NEON_SCALAR_INDEX (scalar);
16304
16305 if (quad_p)
16306 {
16307 if (regno > 7 || elno > 3)
16308 goto bad_scalar;
16309
16310 return ((regno & 0x7)
16311 | ((elno & 0x1) << 3)
16312 | (((elno >> 1) & 0x1) << 5));
16313 }
16314 else
16315 {
16316 if (regno > 15 || elno > 1)
16317 goto bad_scalar;
16318
16319 return (((regno & 0x1) << 5)
16320 | ((regno >> 1) & 0x7)
16321 | ((elno & 0x1) << 3));
16322 }
16323
16324bad_scalar:
16325 first_error (_("scalar out of range for multiply instruction"));
16326 return 0;
16327}
16328
16329static void
16330do_neon_fmac_maybe_scalar_long (int subtype)
16331{
16332 enum neon_shape rs;
16333 int high8;
16334 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
16335 field (bits[21:20]) has different meaning. For scalar index variant, it's
16336 used to differentiate add and subtract, otherwise it's with fixed value
16337 0x2. */
16338 int size = -1;
16339
16340 if (inst.cond != COND_ALWAYS)
16341 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
16342 "behaviour is UNPREDICTABLE"));
16343
01f48020 16344 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
dec41383
JW
16345 _(BAD_FP16));
16346
16347 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
16348 _(BAD_FPU));
16349
16350 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
16351 be a scalar index register. */
16352 if (inst.operands[2].isscalar)
16353 {
16354 high8 = 0xfe000000;
16355 if (subtype)
16356 size = 16;
16357 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
16358 }
16359 else
16360 {
16361 high8 = 0xfc000000;
16362 size = 32;
16363 if (subtype)
16364 inst.instruction |= (0x1 << 23);
16365 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
16366 }
16367
16368 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
16369
16370 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
16371 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
16372 so we simply pass -1 as size. */
16373 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
16374 neon_three_same (quad_p, 0, size);
16375
16376 /* Undo neon_dp_fixup. Redo the high eight bits. */
16377 inst.instruction &= 0x00ffffff;
16378 inst.instruction |= high8;
16379
16380#define LOW1(R) ((R) & 0x1)
16381#define HI4(R) (((R) >> 1) & 0xf)
16382 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
16383 whether the instruction is in Q form and whether Vm is a scalar indexed
16384 operand. */
16385 if (inst.operands[2].isscalar)
16386 {
16387 unsigned rm
16388 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
16389 inst.instruction &= 0xffffffd0;
16390 inst.instruction |= rm;
16391
16392 if (!quad_p)
16393 {
16394 /* Redo Rn as well. */
16395 inst.instruction &= 0xfff0ff7f;
16396 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16397 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16398 }
16399 }
16400 else if (!quad_p)
16401 {
16402 /* Redo Rn and Rm. */
16403 inst.instruction &= 0xfff0ff50;
16404 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16405 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16406 inst.instruction |= HI4 (inst.operands[2].reg);
16407 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
16408 }
16409}
16410
16411static void
16412do_neon_vfmal (void)
16413{
16414 return do_neon_fmac_maybe_scalar_long (0);
16415}
16416
16417static void
16418do_neon_vfmsl (void)
16419{
16420 return do_neon_fmac_maybe_scalar_long (1);
16421}
16422
5287ad62
JB
16423static void
16424do_neon_dyadic_wide (void)
16425{
16426 struct neon_type_el et = neon_check_type (3, NS_QQD,
16427 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16428 neon_mixed_length (et, et.size);
16429}
16430
16431static void
16432do_neon_dyadic_narrow (void)
16433{
16434 struct neon_type_el et = neon_check_type (3, NS_QDD,
16435 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16436 /* Operand sign is unimportant, and the U bit is part of the opcode,
16437 so force the operand type to integer. */
16438 et.type = NT_integer;
5287ad62
JB
16439 neon_mixed_length (et, et.size / 2);
16440}
16441
16442static void
16443do_neon_mul_sat_scalar_long (void)
16444{
16445 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16446}
16447
16448static void
16449do_neon_vmull (void)
16450{
16451 if (inst.operands[2].isscalar)
16452 do_neon_mac_maybe_scalar_long ();
16453 else
16454 {
16455 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16456 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16457
5287ad62 16458 if (et.type == NT_poly)
477330fc 16459 NEON_ENCODE (POLY, inst);
5287ad62 16460 else
477330fc 16461 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16462
16463 /* For polynomial encoding the U bit must be zero, and the size must
16464 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16465 obviously, as 0b10). */
16466 if (et.size == 64)
16467 {
16468 /* Check we're on the correct architecture. */
16469 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16470 inst.error =
16471 _("Instruction form not available on this architecture.");
16472
16473 et.size = 32;
16474 }
16475
5287ad62
JB
16476 neon_mixed_length (et, et.size);
16477 }
16478}
16479
16480static void
16481do_neon_ext (void)
16482{
037e8744 16483 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16484 struct neon_type_el et = neon_check_type (3, rs,
16485 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16486 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16487
16488 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16489 _("shift out of range"));
5287ad62
JB
16490 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16491 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16492 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16493 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16494 inst.instruction |= LOW4 (inst.operands[2].reg);
16495 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16496 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16497 inst.instruction |= imm << 8;
5f4273c7 16498
88714cb8 16499 neon_dp_fixup (&inst);
5287ad62
JB
16500}
16501
16502static void
16503do_neon_rev (void)
16504{
037e8744 16505 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16506 struct neon_type_el et = neon_check_type (2, rs,
16507 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16508 unsigned op = (inst.instruction >> 7) & 3;
16509 /* N (width of reversed regions) is encoded as part of the bitmask. We
16510 extract it here to check the elements to be reversed are smaller.
16511 Otherwise we'd get a reserved instruction. */
16512 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16513 gas_assert (elsize != 0);
5287ad62 16514 constraint (et.size >= elsize,
477330fc 16515 _("elements must be smaller than reversal region"));
037e8744 16516 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16517}
16518
16519static void
16520do_neon_dup (void)
16521{
16522 if (inst.operands[1].isscalar)
16523 {
037e8744 16524 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16525 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16526 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16527 unsigned sizebits = et.size >> 3;
dcbf9037 16528 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16529 int logsize = neon_logbits (et.size);
dcbf9037 16530 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16531
16532 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16533 return;
037e8744 16534
88714cb8 16535 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16536 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16537 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16538 inst.instruction |= LOW4 (dm);
16539 inst.instruction |= HI1 (dm) << 5;
037e8744 16540 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16541 inst.instruction |= x << 17;
16542 inst.instruction |= sizebits << 16;
5f4273c7 16543
88714cb8 16544 neon_dp_fixup (&inst);
5287ad62
JB
16545 }
16546 else
16547 {
037e8744
JB
16548 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16549 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16550 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16551 /* Duplicate ARM register to lanes of vector. */
88714cb8 16552 NEON_ENCODE (ARMREG, inst);
5287ad62 16553 switch (et.size)
477330fc
RM
16554 {
16555 case 8: inst.instruction |= 0x400000; break;
16556 case 16: inst.instruction |= 0x000020; break;
16557 case 32: inst.instruction |= 0x000000; break;
16558 default: break;
16559 }
5287ad62
JB
16560 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16561 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16562 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16563 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16564 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16565 variants, except for the condition field. */
037e8744 16566 do_vfp_cond_or_thumb ();
5287ad62
JB
16567 }
16568}
16569
16570/* VMOV has particularly many variations. It can be one of:
16571 0. VMOV<c><q> <Qd>, <Qm>
16572 1. VMOV<c><q> <Dd>, <Dm>
16573 (Register operations, which are VORR with Rm = Rn.)
16574 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16575 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16576 (Immediate loads.)
16577 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16578 (ARM register to scalar.)
16579 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16580 (Two ARM registers to vector.)
16581 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16582 (Scalar to ARM register.)
16583 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16584 (Vector to two ARM registers.)
037e8744
JB
16585 8. VMOV.F32 <Sd>, <Sm>
16586 9. VMOV.F64 <Dd>, <Dm>
16587 (VFP register moves.)
16588 10. VMOV.F32 <Sd>, #imm
16589 11. VMOV.F64 <Dd>, #imm
16590 (VFP float immediate load.)
16591 12. VMOV <Rd>, <Sm>
16592 (VFP single to ARM reg.)
16593 13. VMOV <Sd>, <Rm>
16594 (ARM reg to VFP single.)
16595 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16596 (Two ARM regs to two VFP singles.)
16597 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16598 (Two VFP singles to two ARM regs.)
5f4273c7 16599
037e8744
JB
16600 These cases can be disambiguated using neon_select_shape, except cases 1/9
16601 and 3/11 which depend on the operand type too.
5f4273c7 16602
5287ad62 16603 All the encoded bits are hardcoded by this function.
5f4273c7 16604
b7fc2769
JB
16605 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16606 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16607
5287ad62 16608 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16609 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16610
16611static void
16612do_neon_mov (void)
16613{
037e8744 16614 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16615 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16616 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16617 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16618 struct neon_type_el et;
16619 const char *ldconst = 0;
5287ad62 16620
037e8744 16621 switch (rs)
5287ad62 16622 {
037e8744
JB
16623 case NS_DD: /* case 1/9. */
16624 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16625 /* It is not an error here if no type is given. */
16626 inst.error = NULL;
16627 if (et.type == NT_float && et.size == 64)
477330fc
RM
16628 {
16629 do_vfp_nsyn_opcode ("fcpyd");
16630 break;
16631 }
037e8744 16632 /* fall through. */
5287ad62 16633
037e8744
JB
16634 case NS_QQ: /* case 0/1. */
16635 {
477330fc
RM
16636 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16637 return;
16638 /* The architecture manual I have doesn't explicitly state which
16639 value the U bit should have for register->register moves, but
16640 the equivalent VORR instruction has U = 0, so do that. */
16641 inst.instruction = 0x0200110;
16642 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16643 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16644 inst.instruction |= LOW4 (inst.operands[1].reg);
16645 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16646 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16647 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16648 inst.instruction |= neon_quad (rs) << 6;
16649
16650 neon_dp_fixup (&inst);
037e8744
JB
16651 }
16652 break;
5f4273c7 16653
037e8744
JB
16654 case NS_DI: /* case 3/11. */
16655 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16656 inst.error = NULL;
16657 if (et.type == NT_float && et.size == 64)
477330fc
RM
16658 {
16659 /* case 11 (fconstd). */
16660 ldconst = "fconstd";
16661 goto encode_fconstd;
16662 }
037e8744
JB
16663 /* fall through. */
16664
16665 case NS_QI: /* case 2/3. */
16666 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16667 return;
037e8744
JB
16668 inst.instruction = 0x0800010;
16669 neon_move_immediate ();
88714cb8 16670 neon_dp_fixup (&inst);
5287ad62 16671 break;
5f4273c7 16672
037e8744
JB
16673 case NS_SR: /* case 4. */
16674 {
477330fc
RM
16675 unsigned bcdebits = 0;
16676 int logsize;
16677 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16678 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16679
05ac0ffb
JB
16680 /* .<size> is optional here, defaulting to .32. */
16681 if (inst.vectype.elems == 0
16682 && inst.operands[0].vectype.type == NT_invtype
16683 && inst.operands[1].vectype.type == NT_invtype)
16684 {
16685 inst.vectype.el[0].type = NT_untyped;
16686 inst.vectype.el[0].size = 32;
16687 inst.vectype.elems = 1;
16688 }
16689
477330fc
RM
16690 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16691 logsize = neon_logbits (et.size);
16692
16693 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16694 _(BAD_FPU));
16695 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16696 && et.size != 32, _(BAD_FPU));
16697 constraint (et.type == NT_invtype, _("bad type for scalar"));
16698 constraint (x >= 64 / et.size, _("scalar index out of range"));
16699
16700 switch (et.size)
16701 {
16702 case 8: bcdebits = 0x8; break;
16703 case 16: bcdebits = 0x1; break;
16704 case 32: bcdebits = 0x0; break;
16705 default: ;
16706 }
16707
16708 bcdebits |= x << logsize;
16709
16710 inst.instruction = 0xe000b10;
16711 do_vfp_cond_or_thumb ();
16712 inst.instruction |= LOW4 (dn) << 16;
16713 inst.instruction |= HI1 (dn) << 7;
16714 inst.instruction |= inst.operands[1].reg << 12;
16715 inst.instruction |= (bcdebits & 3) << 5;
16716 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16717 }
16718 break;
5f4273c7 16719
037e8744 16720 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16721 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16722 _(BAD_FPU));
b7fc2769 16723
037e8744
JB
16724 inst.instruction = 0xc400b10;
16725 do_vfp_cond_or_thumb ();
16726 inst.instruction |= LOW4 (inst.operands[0].reg);
16727 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16728 inst.instruction |= inst.operands[1].reg << 12;
16729 inst.instruction |= inst.operands[2].reg << 16;
16730 break;
5f4273c7 16731
037e8744
JB
16732 case NS_RS: /* case 6. */
16733 {
477330fc
RM
16734 unsigned logsize;
16735 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16736 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16737 unsigned abcdebits = 0;
037e8744 16738
05ac0ffb
JB
16739 /* .<dt> is optional here, defaulting to .32. */
16740 if (inst.vectype.elems == 0
16741 && inst.operands[0].vectype.type == NT_invtype
16742 && inst.operands[1].vectype.type == NT_invtype)
16743 {
16744 inst.vectype.el[0].type = NT_untyped;
16745 inst.vectype.el[0].size = 32;
16746 inst.vectype.elems = 1;
16747 }
16748
91d6fa6a
NC
16749 et = neon_check_type (2, NS_NULL,
16750 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16751 logsize = neon_logbits (et.size);
16752
16753 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16754 _(BAD_FPU));
16755 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16756 && et.size != 32, _(BAD_FPU));
16757 constraint (et.type == NT_invtype, _("bad type for scalar"));
16758 constraint (x >= 64 / et.size, _("scalar index out of range"));
16759
16760 switch (et.size)
16761 {
16762 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16763 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16764 case 32: abcdebits = 0x00; break;
16765 default: ;
16766 }
16767
16768 abcdebits |= x << logsize;
16769 inst.instruction = 0xe100b10;
16770 do_vfp_cond_or_thumb ();
16771 inst.instruction |= LOW4 (dn) << 16;
16772 inst.instruction |= HI1 (dn) << 7;
16773 inst.instruction |= inst.operands[0].reg << 12;
16774 inst.instruction |= (abcdebits & 3) << 5;
16775 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16776 }
16777 break;
5f4273c7 16778
037e8744
JB
16779 case NS_RRD: /* case 7 (fmrrd). */
16780 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16781 _(BAD_FPU));
037e8744
JB
16782
16783 inst.instruction = 0xc500b10;
16784 do_vfp_cond_or_thumb ();
16785 inst.instruction |= inst.operands[0].reg << 12;
16786 inst.instruction |= inst.operands[1].reg << 16;
16787 inst.instruction |= LOW4 (inst.operands[2].reg);
16788 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16789 break;
5f4273c7 16790
037e8744
JB
16791 case NS_FF: /* case 8 (fcpys). */
16792 do_vfp_nsyn_opcode ("fcpys");
16793 break;
5f4273c7 16794
9db2f6b4 16795 case NS_HI:
037e8744
JB
16796 case NS_FI: /* case 10 (fconsts). */
16797 ldconst = "fconsts";
4ef4710f 16798 encode_fconstd:
58ed5c38
TC
16799 if (!inst.operands[1].immisfloat)
16800 {
4ef4710f 16801 unsigned new_imm;
58ed5c38 16802 /* Immediate has to fit in 8 bits so float is enough. */
4ef4710f
NC
16803 float imm = (float) inst.operands[1].imm;
16804 memcpy (&new_imm, &imm, sizeof (float));
16805 /* But the assembly may have been written to provide an integer
16806 bit pattern that equates to a float, so check that the
16807 conversion has worked. */
16808 if (is_quarter_float (new_imm))
16809 {
16810 if (is_quarter_float (inst.operands[1].imm))
16811 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
16812
16813 inst.operands[1].imm = new_imm;
16814 inst.operands[1].immisfloat = 1;
16815 }
58ed5c38
TC
16816 }
16817
037e8744 16818 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16819 {
16820 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16821 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16822
16823 /* ARMv8.2 fp16 vmov.f16 instruction. */
16824 if (rs == NS_HI)
16825 do_scalar_fp16_v82_encode ();
477330fc 16826 }
5287ad62 16827 else
477330fc 16828 first_error (_("immediate out of range"));
037e8744 16829 break;
5f4273c7 16830
9db2f6b4 16831 case NS_RH:
037e8744
JB
16832 case NS_RF: /* case 12 (fmrs). */
16833 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16834 /* ARMv8.2 fp16 vmov.f16 instruction. */
16835 if (rs == NS_RH)
16836 do_scalar_fp16_v82_encode ();
037e8744 16837 break;
5f4273c7 16838
9db2f6b4 16839 case NS_HR:
037e8744
JB
16840 case NS_FR: /* case 13 (fmsr). */
16841 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16842 /* ARMv8.2 fp16 vmov.f16 instruction. */
16843 if (rs == NS_HR)
16844 do_scalar_fp16_v82_encode ();
037e8744 16845 break;
5f4273c7 16846
037e8744
JB
16847 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16848 (one of which is a list), but we have parsed four. Do some fiddling to
16849 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16850 expect. */
16851 case NS_RRFF: /* case 14 (fmrrs). */
16852 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16853 _("VFP registers must be adjacent"));
037e8744
JB
16854 inst.operands[2].imm = 2;
16855 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16856 do_vfp_nsyn_opcode ("fmrrs");
16857 break;
5f4273c7 16858
037e8744
JB
16859 case NS_FFRR: /* case 15 (fmsrr). */
16860 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16861 _("VFP registers must be adjacent"));
037e8744
JB
16862 inst.operands[1] = inst.operands[2];
16863 inst.operands[2] = inst.operands[3];
16864 inst.operands[0].imm = 2;
16865 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16866 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16867 break;
5f4273c7 16868
4c261dff
NC
16869 case NS_NULL:
16870 /* neon_select_shape has determined that the instruction
16871 shape is wrong and has already set the error message. */
16872 break;
16873
5287ad62
JB
16874 default:
16875 abort ();
16876 }
16877}
16878
16879static void
16880do_neon_rshift_round_imm (void)
16881{
037e8744 16882 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16883 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16884 int imm = inst.operands[2].imm;
16885
16886 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16887 if (imm == 0)
16888 {
16889 inst.operands[2].present = 0;
16890 do_neon_mov ();
16891 return;
16892 }
16893
16894 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16895 _("immediate out of range for shift"));
037e8744 16896 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16897 et.size - imm);
5287ad62
JB
16898}
16899
9db2f6b4
RL
16900static void
16901do_neon_movhf (void)
16902{
16903 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16904 constraint (rs != NS_HH, _("invalid suffix"));
16905
7bdf778b
ASDV
16906 if (inst.cond != COND_ALWAYS)
16907 {
16908 if (thumb_mode)
16909 {
16910 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
16911 " the behaviour is UNPREDICTABLE"));
16912 }
16913 else
16914 {
16915 inst.error = BAD_COND;
16916 return;
16917 }
16918 }
16919
9db2f6b4
RL
16920 do_vfp_sp_monadic ();
16921
16922 inst.is_neon = 1;
16923 inst.instruction |= 0xf0000000;
16924}
16925
5287ad62
JB
16926static void
16927do_neon_movl (void)
16928{
16929 struct neon_type_el et = neon_check_type (2, NS_QD,
16930 N_EQK | N_DBL, N_SU_32 | N_KEY);
16931 unsigned sizebits = et.size >> 3;
16932 inst.instruction |= sizebits << 19;
16933 neon_two_same (0, et.type == NT_unsigned, -1);
16934}
16935
16936static void
16937do_neon_trn (void)
16938{
037e8744 16939 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16940 struct neon_type_el et = neon_check_type (2, rs,
16941 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16942 NEON_ENCODE (INTEGER, inst);
037e8744 16943 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16944}
16945
16946static void
16947do_neon_zip_uzp (void)
16948{
037e8744 16949 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16950 struct neon_type_el et = neon_check_type (2, rs,
16951 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16952 if (rs == NS_DD && et.size == 32)
16953 {
16954 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16955 inst.instruction = N_MNEM_vtrn;
16956 do_neon_trn ();
16957 return;
16958 }
037e8744 16959 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16960}
16961
16962static void
16963do_neon_sat_abs_neg (void)
16964{
037e8744 16965 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16966 struct neon_type_el et = neon_check_type (2, rs,
16967 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16968 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16969}
16970
16971static void
16972do_neon_pair_long (void)
16973{
037e8744 16974 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16975 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16976 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16977 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16978 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16979}
16980
16981static void
16982do_neon_recip_est (void)
16983{
037e8744 16984 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16985 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16986 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16987 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16988 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16989}
16990
16991static void
16992do_neon_cls (void)
16993{
037e8744 16994 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16995 struct neon_type_el et = neon_check_type (2, rs,
16996 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16997 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16998}
16999
17000static void
17001do_neon_clz (void)
17002{
037e8744 17003 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17004 struct neon_type_el et = neon_check_type (2, rs,
17005 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 17006 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17007}
17008
17009static void
17010do_neon_cnt (void)
17011{
037e8744 17012 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17013 struct neon_type_el et = neon_check_type (2, rs,
17014 N_EQK | N_INT, N_8 | N_KEY);
037e8744 17015 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17016}
17017
17018static void
17019do_neon_swp (void)
17020{
037e8744
JB
17021 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
17022 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
17023}
17024
17025static void
17026do_neon_tbl_tbx (void)
17027{
17028 unsigned listlenbits;
dcbf9037 17029 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 17030
5287ad62
JB
17031 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
17032 {
dcbf9037 17033 first_error (_("bad list length for table lookup"));
5287ad62
JB
17034 return;
17035 }
5f4273c7 17036
5287ad62
JB
17037 listlenbits = inst.operands[1].imm - 1;
17038 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17039 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17040 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17041 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17042 inst.instruction |= LOW4 (inst.operands[2].reg);
17043 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
17044 inst.instruction |= listlenbits << 8;
5f4273c7 17045
88714cb8 17046 neon_dp_fixup (&inst);
5287ad62
JB
17047}
17048
17049static void
17050do_neon_ldm_stm (void)
17051{
17052 /* P, U and L bits are part of bitmask. */
17053 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
17054 unsigned offsetbits = inst.operands[1].imm * 2;
17055
037e8744
JB
17056 if (inst.operands[1].issingle)
17057 {
17058 do_vfp_nsyn_ldm_stm (is_dbmode);
17059 return;
17060 }
17061
5287ad62 17062 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 17063 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
17064
17065 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
17066 _("register list must contain at least 1 and at most 16 "
17067 "registers"));
5287ad62
JB
17068
17069 inst.instruction |= inst.operands[0].reg << 16;
17070 inst.instruction |= inst.operands[0].writeback << 21;
17071 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
17072 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
17073
17074 inst.instruction |= offsetbits;
5f4273c7 17075
037e8744 17076 do_vfp_cond_or_thumb ();
5287ad62
JB
17077}
17078
17079static void
17080do_neon_ldr_str (void)
17081{
5287ad62 17082 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 17083
6844b2c2
MGD
17084 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
17085 And is UNPREDICTABLE in thumb mode. */
fa94de6b 17086 if (!is_ldr
6844b2c2 17087 && inst.operands[1].reg == REG_PC
ba86b375 17088 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 17089 {
94dcf8bf 17090 if (thumb_mode)
6844b2c2 17091 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 17092 else if (warn_on_deprecated)
5c3696f8 17093 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
17094 }
17095
037e8744
JB
17096 if (inst.operands[0].issingle)
17097 {
cd2f129f 17098 if (is_ldr)
477330fc 17099 do_vfp_nsyn_opcode ("flds");
cd2f129f 17100 else
477330fc 17101 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
17102
17103 /* ARMv8.2 vldr.16/vstr.16 instruction. */
17104 if (inst.vectype.el[0].size == 16)
17105 do_scalar_fp16_v82_encode ();
5287ad62
JB
17106 }
17107 else
5287ad62 17108 {
cd2f129f 17109 if (is_ldr)
477330fc 17110 do_vfp_nsyn_opcode ("fldd");
5287ad62 17111 else
477330fc 17112 do_vfp_nsyn_opcode ("fstd");
5287ad62 17113 }
5287ad62
JB
17114}
17115
17116/* "interleave" version also handles non-interleaving register VLD1/VST1
17117 instructions. */
17118
17119static void
17120do_neon_ld_st_interleave (void)
17121{
037e8744 17122 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 17123 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
17124 unsigned alignbits = 0;
17125 unsigned idx;
17126 /* The bits in this table go:
17127 0: register stride of one (0) or two (1)
17128 1,2: register list length, minus one (1, 2, 3, 4).
17129 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
17130 We use -1 for invalid entries. */
17131 const int typetable[] =
17132 {
17133 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
17134 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
17135 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
17136 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
17137 };
17138 int typebits;
17139
dcbf9037
JB
17140 if (et.type == NT_invtype)
17141 return;
17142
5287ad62
JB
17143 if (inst.operands[1].immisalign)
17144 switch (inst.operands[1].imm >> 8)
17145 {
17146 case 64: alignbits = 1; break;
17147 case 128:
477330fc 17148 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 17149 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
17150 goto bad_alignment;
17151 alignbits = 2;
17152 break;
5287ad62 17153 case 256:
477330fc
RM
17154 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
17155 goto bad_alignment;
17156 alignbits = 3;
17157 break;
5287ad62
JB
17158 default:
17159 bad_alignment:
477330fc
RM
17160 first_error (_("bad alignment"));
17161 return;
5287ad62
JB
17162 }
17163
17164 inst.instruction |= alignbits << 4;
17165 inst.instruction |= neon_logbits (et.size) << 6;
17166
17167 /* Bits [4:6] of the immediate in a list specifier encode register stride
17168 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
17169 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
17170 up the right value for "type" in a table based on this value and the given
17171 list style, then stick it back. */
17172 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 17173 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
17174
17175 typebits = typetable[idx];
5f4273c7 17176
5287ad62 17177 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
17178 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
17179 _("bad element type for instruction"));
5287ad62
JB
17180
17181 inst.instruction &= ~0xf00;
17182 inst.instruction |= typebits << 8;
17183}
17184
17185/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
17186 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
17187 otherwise. The variable arguments are a list of pairs of legal (size, align)
17188 values, terminated with -1. */
17189
17190static int
aa8a0863 17191neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
17192{
17193 va_list ap;
17194 int result = FAIL, thissize, thisalign;
5f4273c7 17195
5287ad62
JB
17196 if (!inst.operands[1].immisalign)
17197 {
aa8a0863 17198 *do_alignment = 0;
5287ad62
JB
17199 return SUCCESS;
17200 }
5f4273c7 17201
aa8a0863 17202 va_start (ap, do_alignment);
5287ad62
JB
17203
17204 do
17205 {
17206 thissize = va_arg (ap, int);
17207 if (thissize == -1)
477330fc 17208 break;
5287ad62
JB
17209 thisalign = va_arg (ap, int);
17210
17211 if (size == thissize && align == thisalign)
477330fc 17212 result = SUCCESS;
5287ad62
JB
17213 }
17214 while (result != SUCCESS);
17215
17216 va_end (ap);
17217
17218 if (result == SUCCESS)
aa8a0863 17219 *do_alignment = 1;
5287ad62 17220 else
dcbf9037 17221 first_error (_("unsupported alignment for instruction"));
5f4273c7 17222
5287ad62
JB
17223 return result;
17224}
17225
17226static void
17227do_neon_ld_st_lane (void)
17228{
037e8744 17229 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17230 int align_good, do_alignment = 0;
5287ad62
JB
17231 int logsize = neon_logbits (et.size);
17232 int align = inst.operands[1].imm >> 8;
17233 int n = (inst.instruction >> 8) & 3;
17234 int max_el = 64 / et.size;
5f4273c7 17235
dcbf9037
JB
17236 if (et.type == NT_invtype)
17237 return;
5f4273c7 17238
5287ad62 17239 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 17240 _("bad list length"));
5287ad62 17241 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 17242 _("scalar index out of range"));
5287ad62 17243 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
17244 && et.size == 8,
17245 _("stride of 2 unavailable when element size is 8"));
5f4273c7 17246
5287ad62
JB
17247 switch (n)
17248 {
17249 case 0: /* VLD1 / VST1. */
aa8a0863 17250 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 17251 32, 32, -1);
5287ad62 17252 if (align_good == FAIL)
477330fc 17253 return;
aa8a0863 17254 if (do_alignment)
477330fc
RM
17255 {
17256 unsigned alignbits = 0;
17257 switch (et.size)
17258 {
17259 case 16: alignbits = 0x1; break;
17260 case 32: alignbits = 0x3; break;
17261 default: ;
17262 }
17263 inst.instruction |= alignbits << 4;
17264 }
5287ad62
JB
17265 break;
17266
17267 case 1: /* VLD2 / VST2. */
aa8a0863
TS
17268 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
17269 16, 32, 32, 64, -1);
5287ad62 17270 if (align_good == FAIL)
477330fc 17271 return;
aa8a0863 17272 if (do_alignment)
477330fc 17273 inst.instruction |= 1 << 4;
5287ad62
JB
17274 break;
17275
17276 case 2: /* VLD3 / VST3. */
17277 constraint (inst.operands[1].immisalign,
477330fc 17278 _("can't use alignment with this instruction"));
5287ad62
JB
17279 break;
17280
17281 case 3: /* VLD4 / VST4. */
aa8a0863 17282 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 17283 16, 64, 32, 64, 32, 128, -1);
5287ad62 17284 if (align_good == FAIL)
477330fc 17285 return;
aa8a0863 17286 if (do_alignment)
477330fc
RM
17287 {
17288 unsigned alignbits = 0;
17289 switch (et.size)
17290 {
17291 case 8: alignbits = 0x1; break;
17292 case 16: alignbits = 0x1; break;
17293 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
17294 default: ;
17295 }
17296 inst.instruction |= alignbits << 4;
17297 }
5287ad62
JB
17298 break;
17299
17300 default: ;
17301 }
17302
17303 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
17304 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17305 inst.instruction |= 1 << (4 + logsize);
5f4273c7 17306
5287ad62
JB
17307 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
17308 inst.instruction |= logsize << 10;
17309}
17310
17311/* Encode single n-element structure to all lanes VLD<n> instructions. */
17312
17313static void
17314do_neon_ld_dup (void)
17315{
037e8744 17316 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17317 int align_good, do_alignment = 0;
5287ad62 17318
dcbf9037
JB
17319 if (et.type == NT_invtype)
17320 return;
17321
5287ad62
JB
17322 switch ((inst.instruction >> 8) & 3)
17323 {
17324 case 0: /* VLD1. */
9c2799c2 17325 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 17326 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 17327 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 17328 if (align_good == FAIL)
477330fc 17329 return;
5287ad62 17330 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
17331 {
17332 case 1: break;
17333 case 2: inst.instruction |= 1 << 5; break;
17334 default: first_error (_("bad list length")); return;
17335 }
5287ad62
JB
17336 inst.instruction |= neon_logbits (et.size) << 6;
17337 break;
17338
17339 case 1: /* VLD2. */
17340 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
17341 &do_alignment, 8, 16, 16, 32, 32, 64,
17342 -1);
5287ad62 17343 if (align_good == FAIL)
477330fc 17344 return;
5287ad62 17345 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 17346 _("bad list length"));
5287ad62 17347 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17348 inst.instruction |= 1 << 5;
5287ad62
JB
17349 inst.instruction |= neon_logbits (et.size) << 6;
17350 break;
17351
17352 case 2: /* VLD3. */
17353 constraint (inst.operands[1].immisalign,
477330fc 17354 _("can't use alignment with this instruction"));
5287ad62 17355 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 17356 _("bad list length"));
5287ad62 17357 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17358 inst.instruction |= 1 << 5;
5287ad62
JB
17359 inst.instruction |= neon_logbits (et.size) << 6;
17360 break;
17361
17362 case 3: /* VLD4. */
17363 {
477330fc 17364 int align = inst.operands[1].imm >> 8;
aa8a0863 17365 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17366 16, 64, 32, 64, 32, 128, -1);
17367 if (align_good == FAIL)
17368 return;
17369 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17370 _("bad list length"));
17371 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17372 inst.instruction |= 1 << 5;
17373 if (et.size == 32 && align == 128)
17374 inst.instruction |= 0x3 << 6;
17375 else
17376 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
17377 }
17378 break;
17379
17380 default: ;
17381 }
17382
aa8a0863 17383 inst.instruction |= do_alignment << 4;
5287ad62
JB
17384}
17385
17386/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17387 apart from bits [11:4]. */
17388
17389static void
17390do_neon_ldx_stx (void)
17391{
b1a769ed
DG
17392 if (inst.operands[1].isreg)
17393 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17394
5287ad62
JB
17395 switch (NEON_LANE (inst.operands[0].imm))
17396 {
17397 case NEON_INTERLEAVE_LANES:
88714cb8 17398 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
17399 do_neon_ld_st_interleave ();
17400 break;
5f4273c7 17401
5287ad62 17402 case NEON_ALL_LANES:
88714cb8 17403 NEON_ENCODE (DUP, inst);
2d51fb74
JB
17404 if (inst.instruction == N_INV)
17405 {
17406 first_error ("only loads support such operands");
17407 break;
17408 }
5287ad62
JB
17409 do_neon_ld_dup ();
17410 break;
5f4273c7 17411
5287ad62 17412 default:
88714cb8 17413 NEON_ENCODE (LANE, inst);
5287ad62
JB
17414 do_neon_ld_st_lane ();
17415 }
17416
17417 /* L bit comes from bit mask. */
17418 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17419 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17420 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17421
5287ad62
JB
17422 if (inst.operands[1].postind)
17423 {
17424 int postreg = inst.operands[1].imm & 0xf;
17425 constraint (!inst.operands[1].immisreg,
477330fc 17426 _("post-index must be a register"));
5287ad62 17427 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17428 _("bad register for post-index"));
5287ad62
JB
17429 inst.instruction |= postreg;
17430 }
4f2374c7 17431 else
5287ad62 17432 {
4f2374c7 17433 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
e2b0ab59
AV
17434 constraint (inst.relocs[0].exp.X_op != O_constant
17435 || inst.relocs[0].exp.X_add_number != 0,
4f2374c7
WN
17436 BAD_ADDR_MODE);
17437
17438 if (inst.operands[1].writeback)
17439 {
17440 inst.instruction |= 0xd;
17441 }
17442 else
17443 inst.instruction |= 0xf;
5287ad62 17444 }
5f4273c7 17445
5287ad62
JB
17446 if (thumb_mode)
17447 inst.instruction |= 0xf9000000;
17448 else
17449 inst.instruction |= 0xf4000000;
17450}
33399f07
MGD
17451
17452/* FP v8. */
17453static void
17454do_vfp_nsyn_fpv8 (enum neon_shape rs)
17455{
a715796b
TG
17456 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17457 D register operands. */
17458 if (neon_shape_class[rs] == SC_DOUBLE)
17459 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17460 _(BAD_FPU));
17461
33399f07
MGD
17462 NEON_ENCODE (FPV8, inst);
17463
9db2f6b4
RL
17464 if (rs == NS_FFF || rs == NS_HHH)
17465 {
17466 do_vfp_sp_dyadic ();
17467
17468 /* ARMv8.2 fp16 instruction. */
17469 if (rs == NS_HHH)
17470 do_scalar_fp16_v82_encode ();
17471 }
33399f07
MGD
17472 else
17473 do_vfp_dp_rd_rn_rm ();
17474
17475 if (rs == NS_DDD)
17476 inst.instruction |= 0x100;
17477
17478 inst.instruction |= 0xf0000000;
17479}
17480
17481static void
17482do_vsel (void)
17483{
17484 set_it_insn_type (OUTSIDE_IT_INSN);
17485
17486 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17487 first_error (_("invalid instruction shape"));
17488}
17489
73924fbc
MGD
17490static void
17491do_vmaxnm (void)
17492{
17493 set_it_insn_type (OUTSIDE_IT_INSN);
17494
17495 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17496 return;
17497
17498 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17499 return;
17500
cc933301 17501 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17502}
17503
30bdf752
MGD
17504static void
17505do_vrint_1 (enum neon_cvt_mode mode)
17506{
9db2f6b4 17507 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17508 struct neon_type_el et;
17509
17510 if (rs == NS_NULL)
17511 return;
17512
a715796b
TG
17513 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17514 D register operands. */
17515 if (neon_shape_class[rs] == SC_DOUBLE)
17516 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17517 _(BAD_FPU));
17518
9db2f6b4
RL
17519 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17520 | N_VFP);
30bdf752
MGD
17521 if (et.type != NT_invtype)
17522 {
17523 /* VFP encodings. */
17524 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17525 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17526 set_it_insn_type (OUTSIDE_IT_INSN);
17527
17528 NEON_ENCODE (FPV8, inst);
9db2f6b4 17529 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17530 do_vfp_sp_monadic ();
17531 else
17532 do_vfp_dp_rd_rm ();
17533
17534 switch (mode)
17535 {
17536 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17537 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17538 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17539 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17540 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17541 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17542 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17543 default: abort ();
17544 }
17545
17546 inst.instruction |= (rs == NS_DD) << 8;
17547 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17548
17549 /* ARMv8.2 fp16 vrint instruction. */
17550 if (rs == NS_HH)
17551 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17552 }
17553 else
17554 {
17555 /* Neon encodings (or something broken...). */
17556 inst.error = NULL;
cc933301 17557 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17558
17559 if (et.type == NT_invtype)
17560 return;
17561
17562 set_it_insn_type (OUTSIDE_IT_INSN);
17563 NEON_ENCODE (FLOAT, inst);
17564
17565 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17566 return;
17567
17568 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17569 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17570 inst.instruction |= LOW4 (inst.operands[1].reg);
17571 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17572 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17573 /* Mask off the original size bits and reencode them. */
17574 inst.instruction = ((inst.instruction & 0xfff3ffff)
17575 | neon_logbits (et.size) << 18);
17576
30bdf752
MGD
17577 switch (mode)
17578 {
17579 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17580 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17581 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17582 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17583 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17584 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17585 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17586 default: abort ();
17587 }
17588
17589 if (thumb_mode)
17590 inst.instruction |= 0xfc000000;
17591 else
17592 inst.instruction |= 0xf0000000;
17593 }
17594}
17595
17596static void
17597do_vrintx (void)
17598{
17599 do_vrint_1 (neon_cvt_mode_x);
17600}
17601
17602static void
17603do_vrintz (void)
17604{
17605 do_vrint_1 (neon_cvt_mode_z);
17606}
17607
17608static void
17609do_vrintr (void)
17610{
17611 do_vrint_1 (neon_cvt_mode_r);
17612}
17613
17614static void
17615do_vrinta (void)
17616{
17617 do_vrint_1 (neon_cvt_mode_a);
17618}
17619
17620static void
17621do_vrintn (void)
17622{
17623 do_vrint_1 (neon_cvt_mode_n);
17624}
17625
17626static void
17627do_vrintp (void)
17628{
17629 do_vrint_1 (neon_cvt_mode_p);
17630}
17631
17632static void
17633do_vrintm (void)
17634{
17635 do_vrint_1 (neon_cvt_mode_m);
17636}
17637
c28eeff2
SN
17638static unsigned
17639neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17640{
17641 unsigned regno = NEON_SCALAR_REG (opnd);
17642 unsigned elno = NEON_SCALAR_INDEX (opnd);
17643
17644 if (elsize == 16 && elno < 2 && regno < 16)
17645 return regno | (elno << 4);
17646 else if (elsize == 32 && elno == 0)
17647 return regno;
17648
17649 first_error (_("scalar out of range"));
17650 return 0;
17651}
17652
17653static void
17654do_vcmla (void)
17655{
17656 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17657 _(BAD_FPU));
e2b0ab59
AV
17658 constraint (inst.relocs[0].exp.X_op != O_constant,
17659 _("expression too complex"));
17660 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
17661 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17662 _("immediate out of range"));
17663 rot /= 90;
17664 if (inst.operands[2].isscalar)
17665 {
17666 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17667 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17668 N_KEY | N_F16 | N_F32).size;
17669 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17670 inst.is_neon = 1;
17671 inst.instruction = 0xfe000800;
17672 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17673 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17674 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17675 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17676 inst.instruction |= LOW4 (m);
17677 inst.instruction |= HI1 (m) << 5;
17678 inst.instruction |= neon_quad (rs) << 6;
17679 inst.instruction |= rot << 20;
17680 inst.instruction |= (size == 32) << 23;
17681 }
17682 else
17683 {
17684 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17685 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17686 N_KEY | N_F16 | N_F32).size;
17687 neon_three_same (neon_quad (rs), 0, -1);
17688 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17689 inst.instruction |= 0xfc200800;
17690 inst.instruction |= rot << 23;
17691 inst.instruction |= (size == 32) << 20;
17692 }
17693}
17694
17695static void
17696do_vcadd (void)
17697{
17698 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17699 _(BAD_FPU));
e2b0ab59
AV
17700 constraint (inst.relocs[0].exp.X_op != O_constant,
17701 _("expression too complex"));
17702 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
17703 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17704 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17705 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17706 N_KEY | N_F16 | N_F32).size;
17707 neon_three_same (neon_quad (rs), 0, -1);
17708 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17709 inst.instruction |= 0xfc800800;
17710 inst.instruction |= (rot == 270) << 24;
17711 inst.instruction |= (size == 32) << 20;
17712}
17713
c604a79a
JW
17714/* Dot Product instructions encoding support. */
17715
17716static void
17717do_neon_dotproduct (int unsigned_p)
17718{
17719 enum neon_shape rs;
17720 unsigned scalar_oprd2 = 0;
17721 int high8;
17722
17723 if (inst.cond != COND_ALWAYS)
17724 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
17725 "is UNPREDICTABLE"));
17726
17727 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17728 _(BAD_FPU));
17729
17730 /* Dot Product instructions are in three-same D/Q register format or the third
17731 operand can be a scalar index register. */
17732 if (inst.operands[2].isscalar)
17733 {
17734 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
17735 high8 = 0xfe000000;
17736 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17737 }
17738 else
17739 {
17740 high8 = 0xfc000000;
17741 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17742 }
17743
17744 if (unsigned_p)
17745 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
17746 else
17747 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
17748
17749 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
17750 Product instruction, so we pass 0 as the "ubit" parameter. And the
17751 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
17752 neon_three_same (neon_quad (rs), 0, 32);
17753
17754 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
17755 different NEON three-same encoding. */
17756 inst.instruction &= 0x00ffffff;
17757 inst.instruction |= high8;
17758 /* Encode 'U' bit which indicates signedness. */
17759 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
17760 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
17761 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
17762 the instruction encoding. */
17763 if (inst.operands[2].isscalar)
17764 {
17765 inst.instruction &= 0xffffffd0;
17766 inst.instruction |= LOW4 (scalar_oprd2);
17767 inst.instruction |= HI1 (scalar_oprd2) << 5;
17768 }
17769}
17770
17771/* Dot Product instructions for signed integer. */
17772
17773static void
17774do_neon_dotproduct_s (void)
17775{
17776 return do_neon_dotproduct (0);
17777}
17778
17779/* Dot Product instructions for unsigned integer. */
17780
17781static void
17782do_neon_dotproduct_u (void)
17783{
17784 return do_neon_dotproduct (1);
17785}
17786
91ff7894
MGD
17787/* Crypto v1 instructions. */
17788static void
17789do_crypto_2op_1 (unsigned elttype, int op)
17790{
17791 set_it_insn_type (OUTSIDE_IT_INSN);
17792
17793 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17794 == NT_invtype)
17795 return;
17796
17797 inst.error = NULL;
17798
17799 NEON_ENCODE (INTEGER, inst);
17800 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17801 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17802 inst.instruction |= LOW4 (inst.operands[1].reg);
17803 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17804 if (op != -1)
17805 inst.instruction |= op << 6;
17806
17807 if (thumb_mode)
17808 inst.instruction |= 0xfc000000;
17809 else
17810 inst.instruction |= 0xf0000000;
17811}
17812
48adcd8e
MGD
17813static void
17814do_crypto_3op_1 (int u, int op)
17815{
17816 set_it_insn_type (OUTSIDE_IT_INSN);
17817
17818 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17819 N_32 | N_UNT | N_KEY).type == NT_invtype)
17820 return;
17821
17822 inst.error = NULL;
17823
17824 NEON_ENCODE (INTEGER, inst);
17825 neon_three_same (1, u, 8 << op);
17826}
17827
91ff7894
MGD
17828static void
17829do_aese (void)
17830{
17831 do_crypto_2op_1 (N_8, 0);
17832}
17833
17834static void
17835do_aesd (void)
17836{
17837 do_crypto_2op_1 (N_8, 1);
17838}
17839
17840static void
17841do_aesmc (void)
17842{
17843 do_crypto_2op_1 (N_8, 2);
17844}
17845
17846static void
17847do_aesimc (void)
17848{
17849 do_crypto_2op_1 (N_8, 3);
17850}
17851
48adcd8e
MGD
17852static void
17853do_sha1c (void)
17854{
17855 do_crypto_3op_1 (0, 0);
17856}
17857
17858static void
17859do_sha1p (void)
17860{
17861 do_crypto_3op_1 (0, 1);
17862}
17863
17864static void
17865do_sha1m (void)
17866{
17867 do_crypto_3op_1 (0, 2);
17868}
17869
17870static void
17871do_sha1su0 (void)
17872{
17873 do_crypto_3op_1 (0, 3);
17874}
91ff7894 17875
48adcd8e
MGD
17876static void
17877do_sha256h (void)
17878{
17879 do_crypto_3op_1 (1, 0);
17880}
17881
17882static void
17883do_sha256h2 (void)
17884{
17885 do_crypto_3op_1 (1, 1);
17886}
17887
17888static void
17889do_sha256su1 (void)
17890{
17891 do_crypto_3op_1 (1, 2);
17892}
3c9017d2
MGD
17893
17894static void
17895do_sha1h (void)
17896{
17897 do_crypto_2op_1 (N_32, -1);
17898}
17899
17900static void
17901do_sha1su1 (void)
17902{
17903 do_crypto_2op_1 (N_32, 0);
17904}
17905
17906static void
17907do_sha256su0 (void)
17908{
17909 do_crypto_2op_1 (N_32, 1);
17910}
dd5181d5
KT
17911
17912static void
17913do_crc32_1 (unsigned int poly, unsigned int sz)
17914{
17915 unsigned int Rd = inst.operands[0].reg;
17916 unsigned int Rn = inst.operands[1].reg;
17917 unsigned int Rm = inst.operands[2].reg;
17918
17919 set_it_insn_type (OUTSIDE_IT_INSN);
17920 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17921 inst.instruction |= LOW4 (Rn) << 16;
17922 inst.instruction |= LOW4 (Rm);
17923 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17924 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17925
17926 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17927 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
17928}
17929
17930static void
17931do_crc32b (void)
17932{
17933 do_crc32_1 (0, 0);
17934}
17935
17936static void
17937do_crc32h (void)
17938{
17939 do_crc32_1 (0, 1);
17940}
17941
17942static void
17943do_crc32w (void)
17944{
17945 do_crc32_1 (0, 2);
17946}
17947
17948static void
17949do_crc32cb (void)
17950{
17951 do_crc32_1 (1, 0);
17952}
17953
17954static void
17955do_crc32ch (void)
17956{
17957 do_crc32_1 (1, 1);
17958}
17959
17960static void
17961do_crc32cw (void)
17962{
17963 do_crc32_1 (1, 2);
17964}
17965
49e8a725
SN
17966static void
17967do_vjcvt (void)
17968{
17969 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17970 _(BAD_FPU));
17971 neon_check_type (2, NS_FD, N_S32, N_F64);
17972 do_vfp_sp_dp_cvt ();
17973 do_vfp_cond_or_thumb ();
17974}
17975
5287ad62
JB
17976\f
17977/* Overall per-instruction processing. */
17978
17979/* We need to be able to fix up arbitrary expressions in some statements.
17980 This is so that we can handle symbols that are an arbitrary distance from
17981 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17982 which returns part of an address in a form which will be valid for
17983 a data instruction. We do this by pushing the expression into a symbol
17984 in the expr_section, and creating a fix for that. */
17985
17986static void
17987fix_new_arm (fragS * frag,
17988 int where,
17989 short int size,
17990 expressionS * exp,
17991 int pc_rel,
17992 int reloc)
17993{
17994 fixS * new_fix;
17995
17996 switch (exp->X_op)
17997 {
17998 case O_constant:
6e7ce2cd
PB
17999 if (pc_rel)
18000 {
18001 /* Create an absolute valued symbol, so we have something to
477330fc
RM
18002 refer to in the object file. Unfortunately for us, gas's
18003 generic expression parsing will already have folded out
18004 any use of .set foo/.type foo %function that may have
18005 been used to set type information of the target location,
18006 that's being specified symbolically. We have to presume
18007 the user knows what they are doing. */
6e7ce2cd
PB
18008 char name[16 + 8];
18009 symbolS *symbol;
18010
18011 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
18012
18013 symbol = symbol_find_or_make (name);
18014 S_SET_SEGMENT (symbol, absolute_section);
18015 symbol_set_frag (symbol, &zero_address_frag);
18016 S_SET_VALUE (symbol, exp->X_add_number);
18017 exp->X_op = O_symbol;
18018 exp->X_add_symbol = symbol;
18019 exp->X_add_number = 0;
18020 }
18021 /* FALLTHROUGH */
5287ad62
JB
18022 case O_symbol:
18023 case O_add:
18024 case O_subtract:
21d799b5 18025 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 18026 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
18027 break;
18028
18029 default:
21d799b5 18030 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 18031 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
18032 break;
18033 }
18034
18035 /* Mark whether the fix is to a THUMB instruction, or an ARM
18036 instruction. */
18037 new_fix->tc_fix_data = thumb_mode;
18038}
18039
18040/* Create a frg for an instruction requiring relaxation. */
18041static void
18042output_relax_insn (void)
18043{
18044 char * to;
18045 symbolS *sym;
0110f2b8
PB
18046 int offset;
18047
6e1cb1a6
PB
18048 /* The size of the instruction is unknown, so tie the debug info to the
18049 start of the instruction. */
18050 dwarf2_emit_insn (0);
6e1cb1a6 18051
e2b0ab59 18052 switch (inst.relocs[0].exp.X_op)
0110f2b8
PB
18053 {
18054 case O_symbol:
e2b0ab59
AV
18055 sym = inst.relocs[0].exp.X_add_symbol;
18056 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
18057 break;
18058 case O_constant:
18059 sym = NULL;
e2b0ab59 18060 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
18061 break;
18062 default:
e2b0ab59 18063 sym = make_expr_symbol (&inst.relocs[0].exp);
0110f2b8
PB
18064 offset = 0;
18065 break;
18066 }
18067 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
18068 inst.relax, sym, offset, NULL/*offset, opcode*/);
18069 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
18070}
18071
18072/* Write a 32-bit thumb instruction to buf. */
18073static void
18074put_thumb32_insn (char * buf, unsigned long insn)
18075{
18076 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
18077 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
18078}
18079
b99bd4ef 18080static void
c19d1205 18081output_inst (const char * str)
b99bd4ef 18082{
c19d1205 18083 char * to = NULL;
b99bd4ef 18084
c19d1205 18085 if (inst.error)
b99bd4ef 18086 {
c19d1205 18087 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
18088 return;
18089 }
5f4273c7
NC
18090 if (inst.relax)
18091 {
18092 output_relax_insn ();
0110f2b8 18093 return;
5f4273c7 18094 }
c19d1205
ZW
18095 if (inst.size == 0)
18096 return;
b99bd4ef 18097
c19d1205 18098 to = frag_more (inst.size);
8dc2430f
NC
18099 /* PR 9814: Record the thumb mode into the current frag so that we know
18100 what type of NOP padding to use, if necessary. We override any previous
18101 setting so that if the mode has changed then the NOPS that we use will
18102 match the encoding of the last instruction in the frag. */
cd000bff 18103 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
18104
18105 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 18106 {
9c2799c2 18107 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 18108 put_thumb32_insn (to, inst.instruction);
b99bd4ef 18109 }
c19d1205 18110 else if (inst.size > INSN_SIZE)
b99bd4ef 18111 {
9c2799c2 18112 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
18113 md_number_to_chars (to, inst.instruction, INSN_SIZE);
18114 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 18115 }
c19d1205
ZW
18116 else
18117 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 18118
e2b0ab59
AV
18119 int r;
18120 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
18121 {
18122 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
18123 fix_new_arm (frag_now, to - frag_now->fr_literal,
18124 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
18125 inst.relocs[r].type);
18126 }
b99bd4ef 18127
c19d1205 18128 dwarf2_emit_insn (inst.size);
c19d1205 18129}
b99bd4ef 18130
e07e6e58
NC
18131static char *
18132output_it_inst (int cond, int mask, char * to)
18133{
18134 unsigned long instruction = 0xbf00;
18135
18136 mask &= 0xf;
18137 instruction |= mask;
18138 instruction |= cond << 4;
18139
18140 if (to == NULL)
18141 {
18142 to = frag_more (2);
18143#ifdef OBJ_ELF
18144 dwarf2_emit_insn (2);
18145#endif
18146 }
18147
18148 md_number_to_chars (to, instruction, 2);
18149
18150 return to;
18151}
18152
c19d1205
ZW
18153/* Tag values used in struct asm_opcode's tag field. */
18154enum opcode_tag
18155{
18156 OT_unconditional, /* Instruction cannot be conditionalized.
18157 The ARM condition field is still 0xE. */
18158 OT_unconditionalF, /* Instruction cannot be conditionalized
18159 and carries 0xF in its ARM condition field. */
18160 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 18161 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
18162 suffix, others place 0xF where the condition field
18163 would be. */
c19d1205
ZW
18164 OT_cinfix3, /* Instruction takes a conditional infix,
18165 beginning at character index 3. (In
18166 unified mode, it becomes a suffix.) */
088fa78e
KH
18167 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
18168 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
18169 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
18170 character index 3, even in unified mode. Used for
18171 legacy instructions where suffix and infix forms
18172 may be ambiguous. */
c19d1205 18173 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 18174 suffix or an infix at character index 3. */
c19d1205
ZW
18175 OT_odd_infix_unc, /* This is the unconditional variant of an
18176 instruction that takes a conditional infix
18177 at an unusual position. In unified mode,
18178 this variant will accept a suffix. */
18179 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
18180 are the conditional variants of instructions that
18181 take conditional infixes in unusual positions.
18182 The infix appears at character index
18183 (tag - OT_odd_infix_0). These are not accepted
18184 in unified mode. */
18185};
b99bd4ef 18186
c19d1205
ZW
18187/* Subroutine of md_assemble, responsible for looking up the primary
18188 opcode from the mnemonic the user wrote. STR points to the
18189 beginning of the mnemonic.
18190
18191 This is not simply a hash table lookup, because of conditional
18192 variants. Most instructions have conditional variants, which are
18193 expressed with a _conditional affix_ to the mnemonic. If we were
18194 to encode each conditional variant as a literal string in the opcode
18195 table, it would have approximately 20,000 entries.
18196
18197 Most mnemonics take this affix as a suffix, and in unified syntax,
18198 'most' is upgraded to 'all'. However, in the divided syntax, some
18199 instructions take the affix as an infix, notably the s-variants of
18200 the arithmetic instructions. Of those instructions, all but six
18201 have the infix appear after the third character of the mnemonic.
18202
18203 Accordingly, the algorithm for looking up primary opcodes given
18204 an identifier is:
18205
18206 1. Look up the identifier in the opcode table.
18207 If we find a match, go to step U.
18208
18209 2. Look up the last two characters of the identifier in the
18210 conditions table. If we find a match, look up the first N-2
18211 characters of the identifier in the opcode table. If we
18212 find a match, go to step CE.
18213
18214 3. Look up the fourth and fifth characters of the identifier in
18215 the conditions table. If we find a match, extract those
18216 characters from the identifier, and look up the remaining
18217 characters in the opcode table. If we find a match, go
18218 to step CM.
18219
18220 4. Fail.
18221
18222 U. Examine the tag field of the opcode structure, in case this is
18223 one of the six instructions with its conditional infix in an
18224 unusual place. If it is, the tag tells us where to find the
18225 infix; look it up in the conditions table and set inst.cond
18226 accordingly. Otherwise, this is an unconditional instruction.
18227 Again set inst.cond accordingly. Return the opcode structure.
18228
18229 CE. Examine the tag field to make sure this is an instruction that
18230 should receive a conditional suffix. If it is not, fail.
18231 Otherwise, set inst.cond from the suffix we already looked up,
18232 and return the opcode structure.
18233
18234 CM. Examine the tag field to make sure this is an instruction that
18235 should receive a conditional infix after the third character.
18236 If it is not, fail. Otherwise, undo the edits to the current
18237 line of input and proceed as for case CE. */
18238
18239static const struct asm_opcode *
18240opcode_lookup (char **str)
18241{
18242 char *end, *base;
18243 char *affix;
18244 const struct asm_opcode *opcode;
18245 const struct asm_cond *cond;
e3cb604e 18246 char save[2];
c19d1205
ZW
18247
18248 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 18249 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 18250 for (base = end = *str; *end != '\0'; end++)
721a8186 18251 if (*end == ' ' || *end == '.')
c19d1205 18252 break;
b99bd4ef 18253
c19d1205 18254 if (end == base)
c921be7d 18255 return NULL;
b99bd4ef 18256
5287ad62 18257 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 18258 if (end[0] == '.')
b99bd4ef 18259 {
5287ad62 18260 int offset = 2;
5f4273c7 18261
267d2029 18262 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 18263 use. */
267d2029 18264 if (unified_syntax && end[1] == 'w')
c19d1205 18265 inst.size_req = 4;
267d2029 18266 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
18267 inst.size_req = 2;
18268 else
477330fc 18269 offset = 0;
5287ad62
JB
18270
18271 inst.vectype.elems = 0;
18272
18273 *str = end + offset;
b99bd4ef 18274
5f4273c7 18275 if (end[offset] == '.')
5287ad62 18276 {
267d2029 18277 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
18278 non-unified ARM syntax mode). */
18279 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 18280 return NULL;
477330fc 18281 }
5287ad62 18282 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 18283 return NULL;
b99bd4ef 18284 }
c19d1205
ZW
18285 else
18286 *str = end;
b99bd4ef 18287
c19d1205 18288 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 18289 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18290 end - base);
c19d1205 18291 if (opcode)
b99bd4ef 18292 {
c19d1205
ZW
18293 /* step U */
18294 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 18295 {
c19d1205
ZW
18296 inst.cond = COND_ALWAYS;
18297 return opcode;
b99bd4ef 18298 }
b99bd4ef 18299
278df34e 18300 if (warn_on_deprecated && unified_syntax)
5c3696f8 18301 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 18302 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 18303 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 18304 gas_assert (cond);
b99bd4ef 18305
c19d1205
ZW
18306 inst.cond = cond->value;
18307 return opcode;
18308 }
b99bd4ef 18309
c19d1205
ZW
18310 /* Cannot have a conditional suffix on a mnemonic of less than two
18311 characters. */
18312 if (end - base < 3)
c921be7d 18313 return NULL;
b99bd4ef 18314
c19d1205
ZW
18315 /* Look for suffixed mnemonic. */
18316 affix = end - 2;
21d799b5
NC
18317 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18318 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18319 affix - base);
c19d1205
ZW
18320 if (opcode && cond)
18321 {
18322 /* step CE */
18323 switch (opcode->tag)
18324 {
e3cb604e
PB
18325 case OT_cinfix3_legacy:
18326 /* Ignore conditional suffixes matched on infix only mnemonics. */
18327 break;
18328
c19d1205 18329 case OT_cinfix3:
088fa78e 18330 case OT_cinfix3_deprecated:
c19d1205
ZW
18331 case OT_odd_infix_unc:
18332 if (!unified_syntax)
0198d5e6 18333 return NULL;
1a0670f3 18334 /* Fall through. */
c19d1205
ZW
18335
18336 case OT_csuffix:
477330fc 18337 case OT_csuffixF:
c19d1205
ZW
18338 case OT_csuf_or_in3:
18339 inst.cond = cond->value;
18340 return opcode;
18341
18342 case OT_unconditional:
18343 case OT_unconditionalF:
dfa9f0d5 18344 if (thumb_mode)
c921be7d 18345 inst.cond = cond->value;
dfa9f0d5
PB
18346 else
18347 {
c921be7d 18348 /* Delayed diagnostic. */
dfa9f0d5
PB
18349 inst.error = BAD_COND;
18350 inst.cond = COND_ALWAYS;
18351 }
c19d1205 18352 return opcode;
b99bd4ef 18353
c19d1205 18354 default:
c921be7d 18355 return NULL;
c19d1205
ZW
18356 }
18357 }
b99bd4ef 18358
c19d1205
ZW
18359 /* Cannot have a usual-position infix on a mnemonic of less than
18360 six characters (five would be a suffix). */
18361 if (end - base < 6)
c921be7d 18362 return NULL;
b99bd4ef 18363
c19d1205
ZW
18364 /* Look for infixed mnemonic in the usual position. */
18365 affix = base + 3;
21d799b5 18366 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 18367 if (!cond)
c921be7d 18368 return NULL;
e3cb604e
PB
18369
18370 memcpy (save, affix, 2);
18371 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 18372 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18373 (end - base) - 2);
e3cb604e
PB
18374 memmove (affix + 2, affix, (end - affix) - 2);
18375 memcpy (affix, save, 2);
18376
088fa78e
KH
18377 if (opcode
18378 && (opcode->tag == OT_cinfix3
18379 || opcode->tag == OT_cinfix3_deprecated
18380 || opcode->tag == OT_csuf_or_in3
18381 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 18382 {
c921be7d 18383 /* Step CM. */
278df34e 18384 if (warn_on_deprecated && unified_syntax
088fa78e
KH
18385 && (opcode->tag == OT_cinfix3
18386 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 18387 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
18388
18389 inst.cond = cond->value;
18390 return opcode;
b99bd4ef
NC
18391 }
18392
c921be7d 18393 return NULL;
b99bd4ef
NC
18394}
18395
e07e6e58
NC
18396/* This function generates an initial IT instruction, leaving its block
18397 virtually open for the new instructions. Eventually,
18398 the mask will be updated by now_it_add_mask () each time
18399 a new instruction needs to be included in the IT block.
18400 Finally, the block is closed with close_automatic_it_block ().
18401 The block closure can be requested either from md_assemble (),
18402 a tencode (), or due to a label hook. */
18403
18404static void
18405new_automatic_it_block (int cond)
18406{
18407 now_it.state = AUTOMATIC_IT_BLOCK;
18408 now_it.mask = 0x18;
18409 now_it.cc = cond;
18410 now_it.block_length = 1;
cd000bff 18411 mapping_state (MAP_THUMB);
e07e6e58 18412 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
18413 now_it.warn_deprecated = FALSE;
18414 now_it.insn_cond = TRUE;
e07e6e58
NC
18415}
18416
18417/* Close an automatic IT block.
18418 See comments in new_automatic_it_block (). */
18419
18420static void
18421close_automatic_it_block (void)
18422{
18423 now_it.mask = 0x10;
18424 now_it.block_length = 0;
18425}
18426
18427/* Update the mask of the current automatically-generated IT
18428 instruction. See comments in new_automatic_it_block (). */
18429
18430static void
18431now_it_add_mask (int cond)
18432{
18433#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
18434#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 18435 | ((bitvalue) << (nbit)))
e07e6e58 18436 const int resulting_bit = (cond & 1);
c921be7d 18437
e07e6e58
NC
18438 now_it.mask &= 0xf;
18439 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18440 resulting_bit,
18441 (5 - now_it.block_length));
e07e6e58 18442 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18443 1,
18444 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
18445 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18446
18447#undef CLEAR_BIT
18448#undef SET_BIT_VALUE
e07e6e58
NC
18449}
18450
18451/* The IT blocks handling machinery is accessed through the these functions:
18452 it_fsm_pre_encode () from md_assemble ()
18453 set_it_insn_type () optional, from the tencode functions
18454 set_it_insn_type_last () ditto
18455 in_it_block () ditto
18456 it_fsm_post_encode () from md_assemble ()
33eaf5de 18457 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
18458
18459 Rationale:
18460 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
18461 initializing the IT insn type with a generic initial value depending
18462 on the inst.condition.
e07e6e58 18463 2) During the tencode function, two things may happen:
477330fc
RM
18464 a) The tencode function overrides the IT insn type by
18465 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18466 b) The tencode function queries the IT block state by
18467 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18468
18469 Both set_it_insn_type and in_it_block run the internal FSM state
18470 handling function (handle_it_state), because: a) setting the IT insn
18471 type may incur in an invalid state (exiting the function),
18472 and b) querying the state requires the FSM to be updated.
18473 Specifically we want to avoid creating an IT block for conditional
18474 branches, so it_fsm_pre_encode is actually a guess and we can't
18475 determine whether an IT block is required until the tencode () routine
18476 has decided what type of instruction this actually it.
18477 Because of this, if set_it_insn_type and in_it_block have to be used,
18478 set_it_insn_type has to be called first.
18479
18480 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18481 determines the insn IT type depending on the inst.cond code.
18482 When a tencode () routine encodes an instruction that can be
18483 either outside an IT block, or, in the case of being inside, has to be
18484 the last one, set_it_insn_type_last () will determine the proper
18485 IT instruction type based on the inst.cond code. Otherwise,
18486 set_it_insn_type can be called for overriding that logic or
18487 for covering other cases.
18488
18489 Calling handle_it_state () may not transition the IT block state to
2b0f3761 18490 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
477330fc
RM
18491 still queried. Instead, if the FSM determines that the state should
18492 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18493 after the tencode () function: that's what it_fsm_post_encode () does.
18494
18495 Since in_it_block () calls the state handling function to get an
18496 updated state, an error may occur (due to invalid insns combination).
18497 In that case, inst.error is set.
18498 Therefore, inst.error has to be checked after the execution of
18499 the tencode () routine.
e07e6e58
NC
18500
18501 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
18502 any pending state change (if any) that didn't take place in
18503 handle_it_state () as explained above. */
e07e6e58
NC
18504
18505static void
18506it_fsm_pre_encode (void)
18507{
18508 if (inst.cond != COND_ALWAYS)
18509 inst.it_insn_type = INSIDE_IT_INSN;
18510 else
18511 inst.it_insn_type = OUTSIDE_IT_INSN;
18512
18513 now_it.state_handled = 0;
18514}
18515
18516/* IT state FSM handling function. */
18517
18518static int
18519handle_it_state (void)
18520{
18521 now_it.state_handled = 1;
5a01bb1d 18522 now_it.insn_cond = FALSE;
e07e6e58
NC
18523
18524 switch (now_it.state)
18525 {
18526 case OUTSIDE_IT_BLOCK:
18527 switch (inst.it_insn_type)
18528 {
18529 case OUTSIDE_IT_INSN:
18530 break;
18531
18532 case INSIDE_IT_INSN:
18533 case INSIDE_IT_LAST_INSN:
18534 if (thumb_mode == 0)
18535 {
c921be7d 18536 if (unified_syntax
e07e6e58
NC
18537 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18538 as_tsktsk (_("Warning: conditional outside an IT block"\
18539 " for Thumb."));
18540 }
18541 else
18542 {
18543 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 18544 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
18545 {
18546 /* Automatically generate the IT instruction. */
18547 new_automatic_it_block (inst.cond);
18548 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18549 close_automatic_it_block ();
18550 }
18551 else
18552 {
18553 inst.error = BAD_OUT_IT;
18554 return FAIL;
18555 }
18556 }
18557 break;
18558
18559 case IF_INSIDE_IT_LAST_INSN:
18560 case NEUTRAL_IT_INSN:
18561 break;
18562
18563 case IT_INSN:
18564 now_it.state = MANUAL_IT_BLOCK;
18565 now_it.block_length = 0;
18566 break;
18567 }
18568 break;
18569
18570 case AUTOMATIC_IT_BLOCK:
18571 /* Three things may happen now:
18572 a) We should increment current it block size;
18573 b) We should close current it block (closing insn or 4 insns);
18574 c) We should close current it block and start a new one (due
18575 to incompatible conditions or
18576 4 insns-length block reached). */
18577
18578 switch (inst.it_insn_type)
18579 {
18580 case OUTSIDE_IT_INSN:
2b0f3761 18581 /* The closure of the block shall happen immediately,
e07e6e58
NC
18582 so any in_it_block () call reports the block as closed. */
18583 force_automatic_it_block_close ();
18584 break;
18585
18586 case INSIDE_IT_INSN:
18587 case INSIDE_IT_LAST_INSN:
18588 case IF_INSIDE_IT_LAST_INSN:
18589 now_it.block_length++;
18590
18591 if (now_it.block_length > 4
18592 || !now_it_compatible (inst.cond))
18593 {
18594 force_automatic_it_block_close ();
18595 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18596 new_automatic_it_block (inst.cond);
18597 }
18598 else
18599 {
5a01bb1d 18600 now_it.insn_cond = TRUE;
e07e6e58
NC
18601 now_it_add_mask (inst.cond);
18602 }
18603
18604 if (now_it.state == AUTOMATIC_IT_BLOCK
18605 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18606 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18607 close_automatic_it_block ();
18608 break;
18609
18610 case NEUTRAL_IT_INSN:
18611 now_it.block_length++;
5a01bb1d 18612 now_it.insn_cond = TRUE;
e07e6e58
NC
18613
18614 if (now_it.block_length > 4)
18615 force_automatic_it_block_close ();
18616 else
18617 now_it_add_mask (now_it.cc & 1);
18618 break;
18619
18620 case IT_INSN:
18621 close_automatic_it_block ();
18622 now_it.state = MANUAL_IT_BLOCK;
18623 break;
18624 }
18625 break;
18626
18627 case MANUAL_IT_BLOCK:
18628 {
18629 /* Check conditional suffixes. */
18630 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18631 int is_last;
18632 now_it.mask <<= 1;
18633 now_it.mask &= 0x1f;
18634 is_last = (now_it.mask == 0x10);
5a01bb1d 18635 now_it.insn_cond = TRUE;
e07e6e58
NC
18636
18637 switch (inst.it_insn_type)
18638 {
18639 case OUTSIDE_IT_INSN:
18640 inst.error = BAD_NOT_IT;
18641 return FAIL;
18642
18643 case INSIDE_IT_INSN:
18644 if (cond != inst.cond)
18645 {
18646 inst.error = BAD_IT_COND;
18647 return FAIL;
18648 }
18649 break;
18650
18651 case INSIDE_IT_LAST_INSN:
18652 case IF_INSIDE_IT_LAST_INSN:
18653 if (cond != inst.cond)
18654 {
18655 inst.error = BAD_IT_COND;
18656 return FAIL;
18657 }
18658 if (!is_last)
18659 {
18660 inst.error = BAD_BRANCH;
18661 return FAIL;
18662 }
18663 break;
18664
18665 case NEUTRAL_IT_INSN:
18666 /* The BKPT instruction is unconditional even in an IT block. */
18667 break;
18668
18669 case IT_INSN:
18670 inst.error = BAD_IT_IT;
18671 return FAIL;
18672 }
18673 }
18674 break;
18675 }
18676
18677 return SUCCESS;
18678}
18679
5a01bb1d
MGD
18680struct depr_insn_mask
18681{
18682 unsigned long pattern;
18683 unsigned long mask;
18684 const char* description;
18685};
18686
18687/* List of 16-bit instruction patterns deprecated in an IT block in
18688 ARMv8. */
18689static const struct depr_insn_mask depr_it_insns[] = {
18690 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18691 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18692 { 0xa000, 0xb800, N_("ADR") },
18693 { 0x4800, 0xf800, N_("Literal loads") },
18694 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18695 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18696 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18697 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18698 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18699 { 0, 0, NULL }
18700};
18701
e07e6e58
NC
18702static void
18703it_fsm_post_encode (void)
18704{
18705 int is_last;
18706
18707 if (!now_it.state_handled)
18708 handle_it_state ();
18709
5a01bb1d
MGD
18710 if (now_it.insn_cond
18711 && !now_it.warn_deprecated
18712 && warn_on_deprecated
df9909b8
TP
18713 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
18714 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
5a01bb1d
MGD
18715 {
18716 if (inst.instruction >= 0x10000)
18717 {
5c3696f8 18718 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
df9909b8 18719 "performance deprecated in ARMv8-A and ARMv8-R"));
5a01bb1d
MGD
18720 now_it.warn_deprecated = TRUE;
18721 }
18722 else
18723 {
18724 const struct depr_insn_mask *p = depr_it_insns;
18725
18726 while (p->mask != 0)
18727 {
18728 if ((inst.instruction & p->mask) == p->pattern)
18729 {
df9909b8
TP
18730 as_tsktsk (_("IT blocks containing 16-bit Thumb "
18731 "instructions of the following class are "
18732 "performance deprecated in ARMv8-A and "
18733 "ARMv8-R: %s"), p->description);
5a01bb1d
MGD
18734 now_it.warn_deprecated = TRUE;
18735 break;
18736 }
18737
18738 ++p;
18739 }
18740 }
18741
18742 if (now_it.block_length > 1)
18743 {
5c3696f8 18744 as_tsktsk (_("IT blocks containing more than one conditional "
df9909b8
TP
18745 "instruction are performance deprecated in ARMv8-A and "
18746 "ARMv8-R"));
5a01bb1d
MGD
18747 now_it.warn_deprecated = TRUE;
18748 }
18749 }
18750
e07e6e58
NC
18751 is_last = (now_it.mask == 0x10);
18752 if (is_last)
18753 {
18754 now_it.state = OUTSIDE_IT_BLOCK;
18755 now_it.mask = 0;
18756 }
18757}
18758
18759static void
18760force_automatic_it_block_close (void)
18761{
18762 if (now_it.state == AUTOMATIC_IT_BLOCK)
18763 {
18764 close_automatic_it_block ();
18765 now_it.state = OUTSIDE_IT_BLOCK;
18766 now_it.mask = 0;
18767 }
18768}
18769
18770static int
18771in_it_block (void)
18772{
18773 if (!now_it.state_handled)
18774 handle_it_state ();
18775
18776 return now_it.state != OUTSIDE_IT_BLOCK;
18777}
18778
ff8646ee
TP
18779/* Whether OPCODE only has T32 encoding. Since this function is only used by
18780 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18781 here, hence the "known" in the function name. */
fc289b0a
TP
18782
18783static bfd_boolean
ff8646ee 18784known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18785{
18786 /* Original Thumb-1 wide instruction. */
18787 if (opcode->tencode == do_t_blx
18788 || opcode->tencode == do_t_branch23
18789 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18790 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18791 return TRUE;
18792
16a1fa25
TP
18793 /* Wide-only instruction added to ARMv8-M Baseline. */
18794 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18795 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18796 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18797 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18798 return TRUE;
18799
18800 return FALSE;
18801}
18802
18803/* Whether wide instruction variant can be used if available for a valid OPCODE
18804 in ARCH. */
18805
18806static bfd_boolean
18807t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18808{
18809 if (known_t32_only_insn (opcode))
18810 return TRUE;
18811
18812 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18813 of variant T3 of B.W is checked in do_t_branch. */
18814 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18815 && opcode->tencode == do_t_branch)
18816 return TRUE;
18817
bada4342
JW
18818 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18819 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18820 && opcode->tencode == do_t_mov_cmp
18821 /* Make sure CMP instruction is not affected. */
18822 && opcode->aencode == do_mov)
18823 return TRUE;
18824
ff8646ee
TP
18825 /* Wide instruction variants of all instructions with narrow *and* wide
18826 variants become available with ARMv6t2. Other opcodes are either
18827 narrow-only or wide-only and are thus available if OPCODE is valid. */
18828 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18829 return TRUE;
18830
18831 /* OPCODE with narrow only instruction variant or wide variant not
18832 available. */
fc289b0a
TP
18833 return FALSE;
18834}
18835
c19d1205
ZW
18836void
18837md_assemble (char *str)
b99bd4ef 18838{
c19d1205
ZW
18839 char *p = str;
18840 const struct asm_opcode * opcode;
b99bd4ef 18841
c19d1205
ZW
18842 /* Align the previous label if needed. */
18843 if (last_label_seen != NULL)
b99bd4ef 18844 {
c19d1205
ZW
18845 symbol_set_frag (last_label_seen, frag_now);
18846 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18847 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18848 }
18849
c19d1205 18850 memset (&inst, '\0', sizeof (inst));
e2b0ab59
AV
18851 int r;
18852 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
18853 inst.relocs[r].type = BFD_RELOC_UNUSED;
b99bd4ef 18854
c19d1205
ZW
18855 opcode = opcode_lookup (&p);
18856 if (!opcode)
b99bd4ef 18857 {
c19d1205 18858 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18859 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18860 if (! create_register_alias (str, p)
477330fc 18861 && ! create_neon_reg_alias (str, p))
c19d1205 18862 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18863
b99bd4ef
NC
18864 return;
18865 }
18866
278df34e 18867 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18868 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18869
037e8744
JB
18870 /* The value which unconditional instructions should have in place of the
18871 condition field. */
18872 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18873
c19d1205 18874 if (thumb_mode)
b99bd4ef 18875 {
e74cfd16 18876 arm_feature_set variant;
8f06b2d8
PB
18877
18878 variant = cpu_variant;
18879 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18880 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18881 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18882 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18883 if (!opcode->tvariant
18884 || (thumb_mode == 1
18885 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18886 {
173205ca
TP
18887 if (opcode->tencode == do_t_swi)
18888 as_bad (_("SVC is not permitted on this architecture"));
18889 else
18890 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18891 return;
18892 }
c19d1205
ZW
18893 if (inst.cond != COND_ALWAYS && !unified_syntax
18894 && opcode->tencode != do_t_branch)
b99bd4ef 18895 {
c19d1205 18896 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18897 return;
18898 }
18899
fc289b0a
TP
18900 /* Two things are addressed here:
18901 1) Implicit require narrow instructions on Thumb-1.
18902 This avoids relaxation accidentally introducing Thumb-2
18903 instructions.
18904 2) Reject wide instructions in non Thumb-2 cores.
18905
18906 Only instructions with narrow and wide variants need to be handled
18907 but selecting all non wide-only instructions is easier. */
18908 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18909 && !t32_insn_ok (variant, opcode))
076d447c 18910 {
fc289b0a
TP
18911 if (inst.size_req == 0)
18912 inst.size_req = 2;
18913 else if (inst.size_req == 4)
752d5da4 18914 {
ff8646ee
TP
18915 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18916 as_bad (_("selected processor does not support 32bit wide "
18917 "variant of instruction `%s'"), str);
18918 else
18919 as_bad (_("selected processor does not support `%s' in "
18920 "Thumb-2 mode"), str);
fc289b0a 18921 return;
752d5da4 18922 }
076d447c
PB
18923 }
18924
c19d1205
ZW
18925 inst.instruction = opcode->tvalue;
18926
5be8be5d 18927 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18928 {
18929 /* Prepare the it_insn_type for those encodings that don't set
18930 it. */
18931 it_fsm_pre_encode ();
c19d1205 18932
477330fc 18933 opcode->tencode ();
e07e6e58 18934
477330fc
RM
18935 it_fsm_post_encode ();
18936 }
e27ec89e 18937
0110f2b8 18938 if (!(inst.error || inst.relax))
b99bd4ef 18939 {
9c2799c2 18940 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18941 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18942 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18943 {
c19d1205 18944 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18945 return;
18946 }
18947 }
076d447c
PB
18948
18949 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18950 instruction. */
9c2799c2 18951 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18952
e74cfd16
PB
18953 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18954 *opcode->tvariant);
ee065d83 18955 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18956 set those bits when Thumb-2 32-bit instructions are seen. The impact
18957 of relaxable instructions will be considered later after we finish all
18958 relaxation. */
ff8646ee
TP
18959 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18960 variant = arm_arch_none;
18961 else
18962 variant = cpu_variant;
18963 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18964 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18965 arm_ext_v6t2);
cd000bff 18966
88714cb8
DG
18967 check_neon_suffixes;
18968
cd000bff 18969 if (!inst.error)
c877a2f2
NC
18970 {
18971 mapping_state (MAP_THUMB);
18972 }
c19d1205 18973 }
3e9e4fcf 18974 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18975 {
845b51d6
PB
18976 bfd_boolean is_bx;
18977
18978 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18979 is_bx = (opcode->aencode == do_bx);
18980
c19d1205 18981 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18982 if (!(is_bx && fix_v4bx)
18983 && !(opcode->avariant &&
18984 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18985 {
84b52b66 18986 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18987 return;
b99bd4ef 18988 }
c19d1205 18989 if (inst.size_req)
b99bd4ef 18990 {
c19d1205
ZW
18991 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18992 return;
b99bd4ef
NC
18993 }
18994
c19d1205
ZW
18995 inst.instruction = opcode->avalue;
18996 if (opcode->tag == OT_unconditionalF)
eff0bc54 18997 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18998 else
18999 inst.instruction |= inst.cond << 28;
19000 inst.size = INSN_SIZE;
5be8be5d 19001 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
19002 {
19003 it_fsm_pre_encode ();
19004 opcode->aencode ();
19005 it_fsm_post_encode ();
19006 }
ee065d83 19007 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 19008 on a hypothetical non-thumb v5 core. */
845b51d6 19009 if (is_bx)
e74cfd16 19010 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 19011 else
e74cfd16
PB
19012 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
19013 *opcode->avariant);
88714cb8
DG
19014
19015 check_neon_suffixes;
19016
cd000bff 19017 if (!inst.error)
c877a2f2
NC
19018 {
19019 mapping_state (MAP_ARM);
19020 }
b99bd4ef 19021 }
3e9e4fcf
JB
19022 else
19023 {
19024 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
19025 "-- `%s'"), str);
19026 return;
19027 }
c19d1205
ZW
19028 output_inst (str);
19029}
b99bd4ef 19030
e07e6e58
NC
19031static void
19032check_it_blocks_finished (void)
19033{
19034#ifdef OBJ_ELF
19035 asection *sect;
19036
19037 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
19038 if (seg_info (sect)->tc_segment_info_data.current_it.state
19039 == MANUAL_IT_BLOCK)
19040 {
19041 as_warn (_("section '%s' finished with an open IT block."),
19042 sect->name);
19043 }
19044#else
19045 if (now_it.state == MANUAL_IT_BLOCK)
19046 as_warn (_("file finished with an open IT block."));
19047#endif
19048}
19049
c19d1205
ZW
19050/* Various frobbings of labels and their addresses. */
19051
19052void
19053arm_start_line_hook (void)
19054{
19055 last_label_seen = NULL;
b99bd4ef
NC
19056}
19057
c19d1205
ZW
19058void
19059arm_frob_label (symbolS * sym)
b99bd4ef 19060{
c19d1205 19061 last_label_seen = sym;
b99bd4ef 19062
c19d1205 19063 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 19064
c19d1205
ZW
19065#if defined OBJ_COFF || defined OBJ_ELF
19066 ARM_SET_INTERWORK (sym, support_interwork);
19067#endif
b99bd4ef 19068
e07e6e58
NC
19069 force_automatic_it_block_close ();
19070
5f4273c7 19071 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
19072 as Thumb functions. This is because these labels, whilst
19073 they exist inside Thumb code, are not the entry points for
19074 possible ARM->Thumb calls. Also, these labels can be used
19075 as part of a computed goto or switch statement. eg gcc
19076 can generate code that looks like this:
b99bd4ef 19077
c19d1205
ZW
19078 ldr r2, [pc, .Laaa]
19079 lsl r3, r3, #2
19080 ldr r2, [r3, r2]
19081 mov pc, r2
b99bd4ef 19082
c19d1205
ZW
19083 .Lbbb: .word .Lxxx
19084 .Lccc: .word .Lyyy
19085 ..etc...
19086 .Laaa: .word Lbbb
b99bd4ef 19087
c19d1205
ZW
19088 The first instruction loads the address of the jump table.
19089 The second instruction converts a table index into a byte offset.
19090 The third instruction gets the jump address out of the table.
19091 The fourth instruction performs the jump.
b99bd4ef 19092
c19d1205
ZW
19093 If the address stored at .Laaa is that of a symbol which has the
19094 Thumb_Func bit set, then the linker will arrange for this address
19095 to have the bottom bit set, which in turn would mean that the
19096 address computation performed by the third instruction would end
19097 up with the bottom bit set. Since the ARM is capable of unaligned
19098 word loads, the instruction would then load the incorrect address
19099 out of the jump table, and chaos would ensue. */
19100 if (label_is_thumb_function_name
19101 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
19102 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 19103 {
c19d1205
ZW
19104 /* When the address of a Thumb function is taken the bottom
19105 bit of that address should be set. This will allow
19106 interworking between Arm and Thumb functions to work
19107 correctly. */
b99bd4ef 19108
c19d1205 19109 THUMB_SET_FUNC (sym, 1);
b99bd4ef 19110
c19d1205 19111 label_is_thumb_function_name = FALSE;
b99bd4ef 19112 }
07a53e5c 19113
07a53e5c 19114 dwarf2_emit_label (sym);
b99bd4ef
NC
19115}
19116
c921be7d 19117bfd_boolean
c19d1205 19118arm_data_in_code (void)
b99bd4ef 19119{
c19d1205 19120 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 19121 {
c19d1205
ZW
19122 *input_line_pointer = '/';
19123 input_line_pointer += 5;
19124 *input_line_pointer = 0;
c921be7d 19125 return TRUE;
b99bd4ef
NC
19126 }
19127
c921be7d 19128 return FALSE;
b99bd4ef
NC
19129}
19130
c19d1205
ZW
19131char *
19132arm_canonicalize_symbol_name (char * name)
b99bd4ef 19133{
c19d1205 19134 int len;
b99bd4ef 19135
c19d1205
ZW
19136 if (thumb_mode && (len = strlen (name)) > 5
19137 && streq (name + len - 5, "/data"))
19138 *(name + len - 5) = 0;
b99bd4ef 19139
c19d1205 19140 return name;
b99bd4ef 19141}
c19d1205
ZW
19142\f
19143/* Table of all register names defined by default. The user can
19144 define additional names with .req. Note that all register names
19145 should appear in both upper and lowercase variants. Some registers
19146 also have mixed-case names. */
b99bd4ef 19147
dcbf9037 19148#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 19149#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 19150#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
19151#define REGSET(p,t) \
19152 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
19153 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
19154 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
19155 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
19156#define REGSETH(p,t) \
19157 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
19158 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
19159 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
19160 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
19161#define REGSET2(p,t) \
19162 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
19163 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
19164 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
19165 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
19166#define SPLRBANK(base,bank,t) \
19167 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
19168 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
19169 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
19170 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
19171 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
19172 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 19173
c19d1205 19174static const struct reg_entry reg_names[] =
7ed4c4c5 19175{
c19d1205
ZW
19176 /* ARM integer registers. */
19177 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 19178
c19d1205
ZW
19179 /* ATPCS synonyms. */
19180 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
19181 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
19182 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 19183
c19d1205
ZW
19184 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
19185 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
19186 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 19187
c19d1205
ZW
19188 /* Well-known aliases. */
19189 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
19190 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
19191
19192 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
19193 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
19194
19195 /* Coprocessor numbers. */
19196 REGSET(p, CP), REGSET(P, CP),
19197
19198 /* Coprocessor register numbers. The "cr" variants are for backward
19199 compatibility. */
19200 REGSET(c, CN), REGSET(C, CN),
19201 REGSET(cr, CN), REGSET(CR, CN),
19202
90ec0d68
MGD
19203 /* ARM banked registers. */
19204 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
19205 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
19206 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
19207 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
19208 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
19209 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
19210 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
19211
19212 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
19213 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
19214 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
19215 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
19216 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 19217 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
19218 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
19219 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
19220
19221 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
19222 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
19223 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
19224 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
19225 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
19226 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
19227 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 19228 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
19229 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
19230
c19d1205
ZW
19231 /* FPA registers. */
19232 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
19233 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
19234
19235 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
19236 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
19237
19238 /* VFP SP registers. */
5287ad62
JB
19239 REGSET(s,VFS), REGSET(S,VFS),
19240 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
19241
19242 /* VFP DP Registers. */
5287ad62
JB
19243 REGSET(d,VFD), REGSET(D,VFD),
19244 /* Extra Neon DP registers. */
19245 REGSETH(d,VFD), REGSETH(D,VFD),
19246
19247 /* Neon QP registers. */
19248 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
19249
19250 /* VFP control registers. */
19251 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
19252 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
19253 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
19254 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
19255 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
19256 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 19257 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
c19d1205
ZW
19258
19259 /* Maverick DSP coprocessor registers. */
19260 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
19261 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
19262
19263 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
19264 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
19265 REGDEF(dspsc,0,DSPSC),
19266
19267 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
19268 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
19269 REGDEF(DSPSC,0,DSPSC),
19270
19271 /* iWMMXt data registers - p0, c0-15. */
19272 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
19273
19274 /* iWMMXt control registers - p1, c0-3. */
19275 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
19276 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
19277 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
19278 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
19279
19280 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
19281 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
19282 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
19283 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
19284 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
19285
19286 /* XScale accumulator registers. */
19287 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
19288};
19289#undef REGDEF
19290#undef REGNUM
19291#undef REGSET
7ed4c4c5 19292
c19d1205
ZW
19293/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
19294 within psr_required_here. */
19295static const struct asm_psr psrs[] =
19296{
19297 /* Backward compatibility notation. Note that "all" is no longer
19298 truly all possible PSR bits. */
19299 {"all", PSR_c | PSR_f},
19300 {"flg", PSR_f},
19301 {"ctl", PSR_c},
19302
19303 /* Individual flags. */
19304 {"f", PSR_f},
19305 {"c", PSR_c},
19306 {"x", PSR_x},
19307 {"s", PSR_s},
59b42a0d 19308
c19d1205
ZW
19309 /* Combinations of flags. */
19310 {"fs", PSR_f | PSR_s},
19311 {"fx", PSR_f | PSR_x},
19312 {"fc", PSR_f | PSR_c},
19313 {"sf", PSR_s | PSR_f},
19314 {"sx", PSR_s | PSR_x},
19315 {"sc", PSR_s | PSR_c},
19316 {"xf", PSR_x | PSR_f},
19317 {"xs", PSR_x | PSR_s},
19318 {"xc", PSR_x | PSR_c},
19319 {"cf", PSR_c | PSR_f},
19320 {"cs", PSR_c | PSR_s},
19321 {"cx", PSR_c | PSR_x},
19322 {"fsx", PSR_f | PSR_s | PSR_x},
19323 {"fsc", PSR_f | PSR_s | PSR_c},
19324 {"fxs", PSR_f | PSR_x | PSR_s},
19325 {"fxc", PSR_f | PSR_x | PSR_c},
19326 {"fcs", PSR_f | PSR_c | PSR_s},
19327 {"fcx", PSR_f | PSR_c | PSR_x},
19328 {"sfx", PSR_s | PSR_f | PSR_x},
19329 {"sfc", PSR_s | PSR_f | PSR_c},
19330 {"sxf", PSR_s | PSR_x | PSR_f},
19331 {"sxc", PSR_s | PSR_x | PSR_c},
19332 {"scf", PSR_s | PSR_c | PSR_f},
19333 {"scx", PSR_s | PSR_c | PSR_x},
19334 {"xfs", PSR_x | PSR_f | PSR_s},
19335 {"xfc", PSR_x | PSR_f | PSR_c},
19336 {"xsf", PSR_x | PSR_s | PSR_f},
19337 {"xsc", PSR_x | PSR_s | PSR_c},
19338 {"xcf", PSR_x | PSR_c | PSR_f},
19339 {"xcs", PSR_x | PSR_c | PSR_s},
19340 {"cfs", PSR_c | PSR_f | PSR_s},
19341 {"cfx", PSR_c | PSR_f | PSR_x},
19342 {"csf", PSR_c | PSR_s | PSR_f},
19343 {"csx", PSR_c | PSR_s | PSR_x},
19344 {"cxf", PSR_c | PSR_x | PSR_f},
19345 {"cxs", PSR_c | PSR_x | PSR_s},
19346 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
19347 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
19348 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
19349 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
19350 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
19351 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
19352 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
19353 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
19354 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
19355 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
19356 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
19357 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
19358 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
19359 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
19360 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
19361 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
19362 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
19363 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
19364 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
19365 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
19366 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
19367 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
19368 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
19369 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
19370};
19371
62b3e311
PB
19372/* Table of V7M psr names. */
19373static const struct asm_psr v7m_psrs[] =
19374{
1a336194
TP
19375 {"apsr", 0x0 }, {"APSR", 0x0 },
19376 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
19377 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
19378 {"psr", 0x3 }, {"PSR", 0x3 },
19379 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
19380 {"ipsr", 0x5 }, {"IPSR", 0x5 },
19381 {"epsr", 0x6 }, {"EPSR", 0x6 },
19382 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
19383 {"msp", 0x8 }, {"MSP", 0x8 },
19384 {"psp", 0x9 }, {"PSP", 0x9 },
19385 {"msplim", 0xa }, {"MSPLIM", 0xa },
19386 {"psplim", 0xb }, {"PSPLIM", 0xb },
19387 {"primask", 0x10}, {"PRIMASK", 0x10},
19388 {"basepri", 0x11}, {"BASEPRI", 0x11},
19389 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
19390 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
19391 {"control", 0x14}, {"CONTROL", 0x14},
19392 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
19393 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
19394 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
19395 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
19396 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
19397 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
19398 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
19399 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
19400 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
19401};
19402
c19d1205
ZW
19403/* Table of all shift-in-operand names. */
19404static const struct asm_shift_name shift_names [] =
b99bd4ef 19405{
c19d1205
ZW
19406 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
19407 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
19408 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
19409 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
19410 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
19411 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
19412};
b99bd4ef 19413
c19d1205
ZW
19414/* Table of all explicit relocation names. */
19415#ifdef OBJ_ELF
19416static struct reloc_entry reloc_names[] =
19417{
19418 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
19419 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
19420 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
19421 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
19422 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
19423 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
19424 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
19425 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
19426 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
19427 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 19428 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
19429 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
19430 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 19431 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 19432 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 19433 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 19434 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
188fd7ae
CL
19435 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
19436 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
19437 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
19438 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
19439 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
19440 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
5c5a4843
CL
19441 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
19442 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
19443 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
19444 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
c19d1205
ZW
19445};
19446#endif
b99bd4ef 19447
c19d1205
ZW
19448/* Table of all conditional affixes. 0xF is not defined as a condition code. */
19449static const struct asm_cond conds[] =
19450{
19451 {"eq", 0x0},
19452 {"ne", 0x1},
19453 {"cs", 0x2}, {"hs", 0x2},
19454 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
19455 {"mi", 0x4},
19456 {"pl", 0x5},
19457 {"vs", 0x6},
19458 {"vc", 0x7},
19459 {"hi", 0x8},
19460 {"ls", 0x9},
19461 {"ge", 0xa},
19462 {"lt", 0xb},
19463 {"gt", 0xc},
19464 {"le", 0xd},
19465 {"al", 0xe}
19466};
bfae80f2 19467
e797f7e0 19468#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
19469 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19470 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 19471
62b3e311
PB
19472static struct asm_barrier_opt barrier_opt_names[] =
19473{
e797f7e0
MGD
19474 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19475 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19476 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19477 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19478 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19479 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19480 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19481 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19482 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19483 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19484 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19485 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19486 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19487 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19488 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19489 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
19490};
19491
e797f7e0
MGD
19492#undef UL_BARRIER
19493
c19d1205
ZW
19494/* Table of ARM-format instructions. */
19495
19496/* Macros for gluing together operand strings. N.B. In all cases
19497 other than OPS0, the trailing OP_stop comes from default
19498 zero-initialization of the unspecified elements of the array. */
19499#define OPS0() { OP_stop, }
19500#define OPS1(a) { OP_##a, }
19501#define OPS2(a,b) { OP_##a,OP_##b, }
19502#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19503#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19504#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19505#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19506
5be8be5d
DG
19507/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19508 This is useful when mixing operands for ARM and THUMB, i.e. using the
19509 MIX_ARM_THUMB_OPERANDS macro.
19510 In order to use these macros, prefix the number of operands with _
19511 e.g. _3. */
19512#define OPS_1(a) { a, }
19513#define OPS_2(a,b) { a,b, }
19514#define OPS_3(a,b,c) { a,b,c, }
19515#define OPS_4(a,b,c,d) { a,b,c,d, }
19516#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19517#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19518
c19d1205
ZW
19519/* These macros abstract out the exact format of the mnemonic table and
19520 save some repeated characters. */
19521
19522/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19523#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19524 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 19525 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19526
19527/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19528 a T_MNEM_xyz enumerator. */
19529#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19530 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19531#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19532 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
19533
19534/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19535 infix after the third character. */
19536#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 19537 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 19538 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 19539#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 19540 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 19541 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19542#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19543 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 19544#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19545 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19546#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19547 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 19548#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19549 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 19550
c19d1205 19551/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
19552 field is still 0xE. Many of the Thumb variants can be executed
19553 conditionally, so this is checked separately. */
c19d1205 19554#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19555 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19556 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19557
dd5181d5
KT
19558/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19559 Used by mnemonics that have very minimal differences in the encoding for
19560 ARM and Thumb variants and can be handled in a common function. */
19561#define TUEc(mnem, op, top, nops, ops, en) \
19562 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19563 THUMB_VARIANT, do_##en, do_##en }
19564
c19d1205
ZW
19565/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19566 condition code field. */
19567#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 19568 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19569 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19570
19571/* ARM-only variants of all the above. */
6a86118a 19572#define CE(mnem, op, nops, ops, ae) \
21d799b5 19573 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
19574
19575#define C3(mnem, op, nops, ops, ae) \
19576 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19577
cf3cf39d
TP
19578/* Thumb-only variants of TCE and TUE. */
19579#define ToC(mnem, top, nops, ops, te) \
19580 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
19581 do_##te }
cf3cf39d
TP
19582
19583#define ToU(mnem, top, nops, ops, te) \
19584 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
19585 NULL, do_##te }
cf3cf39d 19586
4389b29a
AV
19587/* T_MNEM_xyz enumerator variants of ToC. */
19588#define toC(mnem, top, nops, ops, te) \
19589 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
19590 do_##te }
19591
e3cb604e
PB
19592/* Legacy mnemonics that always have conditional infix after the third
19593 character. */
19594#define CL(mnem, op, nops, ops, ae) \
21d799b5 19595 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19596 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19597
8f06b2d8
PB
19598/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19599#define cCE(mnem, op, nops, ops, ae) \
21d799b5 19600 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19601
e3cb604e
PB
19602/* Legacy coprocessor instructions where conditional infix and conditional
19603 suffix are ambiguous. For consistency this includes all FPA instructions,
19604 not just the potentially ambiguous ones. */
19605#define cCL(mnem, op, nops, ops, ae) \
21d799b5 19606 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19607 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19608
19609/* Coprocessor, takes either a suffix or a position-3 infix
19610 (for an FPA corner case). */
19611#define C3E(mnem, op, nops, ops, ae) \
21d799b5 19612 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19613 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19614
6a86118a 19615#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19616 { m1 #m2 m3, OPS##nops ops, \
19617 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19618 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19619
19620#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19621 xCM_ (m1, , m2, op, nops, ops, ae), \
19622 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19623 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19624 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19625 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19626 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19627 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19628 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19629 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19630 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19631 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19632 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19633 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19634 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19635 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19636 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19637 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19638 xCM_ (m1, le, m2, op, nops, ops, ae), \
19639 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19640
19641#define UE(mnem, op, nops, ops, ae) \
19642 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19643
19644#define UF(mnem, op, nops, ops, ae) \
19645 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19646
5287ad62
JB
19647/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19648 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19649 use the same encoding function for each. */
19650#define NUF(mnem, op, nops, ops, enc) \
19651 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19652 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19653
19654/* Neon data processing, version which indirects through neon_enc_tab for
19655 the various overloaded versions of opcodes. */
19656#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19657 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19658 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19659
19660/* Neon insn with conditional suffix for the ARM version, non-overloaded
19661 version. */
037e8744
JB
19662#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19663 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19664 THUMB_VARIANT, do_##enc, do_##enc }
19665
037e8744 19666#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19667 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19668
19669#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19670 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19671
5287ad62 19672/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19673#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19674 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19675 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19676
037e8744 19677#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19678 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19679
19680#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19681 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19682
c19d1205
ZW
19683#define do_0 0
19684
c19d1205 19685static const struct asm_opcode insns[] =
bfae80f2 19686{
74db7efb
NC
19687#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19688#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19689 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19690 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19691 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19692 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19693 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19694 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19695 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19696 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19697 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19698 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19699 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19700 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19701 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19702 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19703 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19704 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19705
19706 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19707 for setting PSR flag bits. They are obsolete in V6 and do not
19708 have Thumb equivalents. */
21d799b5
NC
19709 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19710 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19711 CL("tstp", 110f000, 2, (RR, SH), cmp),
19712 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19713 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19714 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19715 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19716 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19717 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19718
19719 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19720 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19721 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19722 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19723
19724 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19725 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19726 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19727 OP_RRnpc),
19728 OP_ADDRGLDR),ldst, t_ldst),
19729 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19730
19731 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19732 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19733 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19734 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19735 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19736 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19737
21d799b5
NC
19738 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19739 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19740
c19d1205 19741 /* Pseudo ops. */
21d799b5 19742 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19743 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19744 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19745 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19746
19747 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19748 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19749 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19750 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19751 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19752 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19753 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19754 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19755 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19756 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19757 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19758 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19759 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19760
16a4cf17 19761 /* These may simplify to neg. */
21d799b5
NC
19762 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19763 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19764
173205ca
TP
19765#undef THUMB_VARIANT
19766#define THUMB_VARIANT & arm_ext_os
19767
19768 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19769 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19770
c921be7d
NC
19771#undef THUMB_VARIANT
19772#define THUMB_VARIANT & arm_ext_v6
19773
21d799b5 19774 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19775
19776 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19777#undef THUMB_VARIANT
19778#define THUMB_VARIANT & arm_ext_v6t2
19779
21d799b5
NC
19780 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19781 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19782 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19783
5be8be5d
DG
19784 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19785 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19786 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19787 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19788
21d799b5
NC
19789 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19790 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19791
21d799b5
NC
19792 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19793 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19794
19795 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19796 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19797 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19798
19799 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19800 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19801 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19802 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19803 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19804 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19805 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19806 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19807
c921be7d
NC
19808#undef ARM_VARIANT
19809#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19810#undef THUMB_VARIANT
19811#define THUMB_VARIANT & arm_ext_v4t
19812
21d799b5
NC
19813 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19814 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19815
c921be7d
NC
19816#undef THUMB_VARIANT
19817#define THUMB_VARIANT & arm_ext_v6t2
19818
21d799b5 19819 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19820 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19821
19822 /* Generic coprocessor instructions. */
21d799b5
NC
19823 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19824 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19825 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19826 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19827 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19828 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19829 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19830
c921be7d
NC
19831#undef ARM_VARIANT
19832#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19833
21d799b5 19834 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19835 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19836
c921be7d
NC
19837#undef ARM_VARIANT
19838#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19839#undef THUMB_VARIANT
19840#define THUMB_VARIANT & arm_ext_msr
19841
d2cd1205
JB
19842 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19843 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19844
c921be7d
NC
19845#undef ARM_VARIANT
19846#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19847#undef THUMB_VARIANT
19848#define THUMB_VARIANT & arm_ext_v6t2
19849
21d799b5
NC
19850 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19851 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19852 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19853 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19854 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19855 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19856 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19857 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19858
c921be7d
NC
19859#undef ARM_VARIANT
19860#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19861#undef THUMB_VARIANT
19862#define THUMB_VARIANT & arm_ext_v4t
19863
5be8be5d
DG
19864 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19865 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19866 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19867 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19868 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19869 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19870
c921be7d
NC
19871#undef ARM_VARIANT
19872#define ARM_VARIANT & arm_ext_v4t_5
19873
c19d1205
ZW
19874 /* ARM Architecture 4T. */
19875 /* Note: bx (and blx) are required on V5, even if the processor does
19876 not support Thumb. */
21d799b5 19877 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19878
c921be7d
NC
19879#undef ARM_VARIANT
19880#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19881#undef THUMB_VARIANT
19882#define THUMB_VARIANT & arm_ext_v5t
19883
c19d1205
ZW
19884 /* Note: blx has 2 variants; the .value coded here is for
19885 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19886 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19887 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19888
c921be7d
NC
19889#undef THUMB_VARIANT
19890#define THUMB_VARIANT & arm_ext_v6t2
19891
21d799b5
NC
19892 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19893 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19894 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19895 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19896 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19897 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19898 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19899 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19900
c921be7d 19901#undef ARM_VARIANT
74db7efb
NC
19902#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19903#undef THUMB_VARIANT
19904#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19905
21d799b5
NC
19906 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19907 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19908 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19909 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19910
21d799b5
NC
19911 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19912 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19913
21d799b5
NC
19914 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19915 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19916 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19917 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19918
21d799b5
NC
19919 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19920 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19921 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19922 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19923
21d799b5
NC
19924 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19925 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19926
03ee1b7f
NC
19927 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19928 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19929 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19930 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19931
c921be7d 19932#undef ARM_VARIANT
74db7efb
NC
19933#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19934#undef THUMB_VARIANT
19935#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19936
21d799b5 19937 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19938 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19939 ldrd, t_ldstd),
19940 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19941 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19942
21d799b5
NC
19943 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19944 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19945
c921be7d
NC
19946#undef ARM_VARIANT
19947#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19948
21d799b5 19949 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19950
c921be7d
NC
19951#undef ARM_VARIANT
19952#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19953#undef THUMB_VARIANT
19954#define THUMB_VARIANT & arm_ext_v6
19955
21d799b5
NC
19956 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19957 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19958 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19959 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19960 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19961 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19962 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19963 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19964 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19965 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19966
c921be7d 19967#undef THUMB_VARIANT
ff8646ee 19968#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19969
5be8be5d
DG
19970 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19971 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19972 strex, t_strex),
ff8646ee
TP
19973#undef THUMB_VARIANT
19974#define THUMB_VARIANT & arm_ext_v6t2
19975
21d799b5
NC
19976 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19977 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19978
21d799b5
NC
19979 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19980 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19981
9e3c6df6 19982/* ARM V6 not included in V7M. */
c921be7d
NC
19983#undef THUMB_VARIANT
19984#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19985 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19986 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19987 UF(rfeib, 9900a00, 1, (RRw), rfe),
19988 UF(rfeda, 8100a00, 1, (RRw), rfe),
19989 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19990 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19991 UF(rfefa, 8100a00, 1, (RRw), rfe),
19992 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19993 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19994 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19995 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19996 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19997 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19998 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19999 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 20000 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 20001 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 20002 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 20003 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 20004
9e3c6df6
PB
20005/* ARM V6 not included in V7M (eg. integer SIMD). */
20006#undef THUMB_VARIANT
20007#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
20008 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
20009 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
20010 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20011 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20012 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20013 /* Old name for QASX. */
74db7efb 20014 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 20015 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20016 /* Old name for QSAX. */
74db7efb 20017 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20018 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20019 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20020 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20021 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20022 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20023 /* Old name for SASX. */
74db7efb 20024 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20025 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20026 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20027 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20028 /* Old name for SHASX. */
21d799b5 20029 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20030 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20031 /* Old name for SHSAX. */
21d799b5
NC
20032 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20033 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20034 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20035 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20036 /* Old name for SSAX. */
74db7efb 20037 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20038 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20039 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20040 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20041 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20042 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20043 /* Old name for UASX. */
74db7efb 20044 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20045 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20046 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20047 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20048 /* Old name for UHASX. */
21d799b5
NC
20049 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20050 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20051 /* Old name for UHSAX. */
21d799b5
NC
20052 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20053 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20054 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20055 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20056 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20057 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20058 /* Old name for UQASX. */
21d799b5
NC
20059 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20060 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20061 /* Old name for UQSAX. */
21d799b5
NC
20062 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20063 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20064 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20065 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20066 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20067 /* Old name for USAX. */
74db7efb 20068 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 20069 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20070 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20071 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20072 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20073 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20074 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20075 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20076 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20077 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20078 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20079 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20080 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20081 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
20082 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
20083 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20084 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20085 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
20086 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
20087 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20088 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20089 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20090 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20091 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20092 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20093 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20094 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20095 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20096 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
20097 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
20098 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
20099 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20100 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20101 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 20102
c921be7d 20103#undef ARM_VARIANT
55e8aae7 20104#define ARM_VARIANT & arm_ext_v6k_v6t2
c921be7d 20105#undef THUMB_VARIANT
55e8aae7 20106#define THUMB_VARIANT & arm_ext_v6k_v6t2
c921be7d 20107
21d799b5
NC
20108 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
20109 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
20110 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
20111 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 20112
c921be7d
NC
20113#undef THUMB_VARIANT
20114#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
20115 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
20116 ldrexd, t_ldrexd),
20117 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
20118 RRnpcb), strexd, t_strexd),
ebdca51a 20119
c921be7d 20120#undef THUMB_VARIANT
ff8646ee 20121#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
20122 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
20123 rd_rn, rd_rn),
20124 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
20125 rd_rn, rd_rn),
20126 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 20127 strex, t_strexbh),
5be8be5d 20128 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 20129 strex, t_strexbh),
21d799b5 20130 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 20131
c921be7d 20132#undef ARM_VARIANT
f4c65163 20133#define ARM_VARIANT & arm_ext_sec
74db7efb 20134#undef THUMB_VARIANT
f4c65163 20135#define THUMB_VARIANT & arm_ext_sec
c921be7d 20136
21d799b5 20137 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 20138
90ec0d68
MGD
20139#undef ARM_VARIANT
20140#define ARM_VARIANT & arm_ext_virt
20141#undef THUMB_VARIANT
20142#define THUMB_VARIANT & arm_ext_virt
20143
20144 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
20145 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
20146
ddfded2f
MW
20147#undef ARM_VARIANT
20148#define ARM_VARIANT & arm_ext_pan
20149#undef THUMB_VARIANT
20150#define THUMB_VARIANT & arm_ext_pan
20151
20152 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
20153
c921be7d 20154#undef ARM_VARIANT
74db7efb 20155#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
20156#undef THUMB_VARIANT
20157#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 20158
21d799b5
NC
20159 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
20160 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
20161 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
20162 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 20163
21d799b5 20164 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 20165 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 20166
5be8be5d
DG
20167 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20168 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20169 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20170 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 20171
91d8b670
JG
20172#undef ARM_VARIANT
20173#define ARM_VARIANT & arm_ext_v3
20174#undef THUMB_VARIANT
20175#define THUMB_VARIANT & arm_ext_v6t2
20176
20177 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
c597cc3d
SD
20178 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
20179 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
91d8b670
JG
20180
20181#undef ARM_VARIANT
20182#define ARM_VARIANT & arm_ext_v6t2
ff8646ee
TP
20183#undef THUMB_VARIANT
20184#define THUMB_VARIANT & arm_ext_v6t2_v8m
20185 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
20186 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
20187
bf3eeda7 20188 /* Thumb-only instructions. */
74db7efb 20189#undef ARM_VARIANT
bf3eeda7
NS
20190#define ARM_VARIANT NULL
20191 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
20192 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
20193
20194 /* ARM does not really have an IT instruction, so always allow it.
20195 The opcode is copied from Thumb in order to allow warnings in
20196 -mimplicit-it=[never | arm] modes. */
20197#undef ARM_VARIANT
20198#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
20199#undef THUMB_VARIANT
20200#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 20201
21d799b5
NC
20202 TUE("it", bf08, bf08, 1, (COND), it, t_it),
20203 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
20204 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
20205 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
20206 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
20207 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
20208 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
20209 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
20210 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
20211 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
20212 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
20213 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
20214 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
20215 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
20216 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 20217 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
20218 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
20219 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 20220
92e90b6e 20221 /* Thumb2 only instructions. */
c921be7d
NC
20222#undef ARM_VARIANT
20223#define ARM_VARIANT NULL
92e90b6e 20224
21d799b5
NC
20225 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20226 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20227 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
20228 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
20229 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
20230 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 20231
eea54501
MGD
20232 /* Hardware division instructions. */
20233#undef ARM_VARIANT
20234#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
20235#undef THUMB_VARIANT
20236#define THUMB_VARIANT & arm_ext_div
20237
eea54501
MGD
20238 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
20239 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 20240
7e806470 20241 /* ARM V6M/V7 instructions. */
c921be7d
NC
20242#undef ARM_VARIANT
20243#define ARM_VARIANT & arm_ext_barrier
20244#undef THUMB_VARIANT
20245#define THUMB_VARIANT & arm_ext_barrier
20246
ccb84d65
JB
20247 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
20248 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
20249 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 20250
62b3e311 20251 /* ARM V7 instructions. */
c921be7d
NC
20252#undef ARM_VARIANT
20253#define ARM_VARIANT & arm_ext_v7
20254#undef THUMB_VARIANT
20255#define THUMB_VARIANT & arm_ext_v7
20256
21d799b5
NC
20257 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
20258 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 20259
74db7efb 20260#undef ARM_VARIANT
60e5ef9f 20261#define ARM_VARIANT & arm_ext_mp
74db7efb 20262#undef THUMB_VARIANT
60e5ef9f
MGD
20263#define THUMB_VARIANT & arm_ext_mp
20264
20265 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
20266
53c4b28b
MGD
20267 /* AArchv8 instructions. */
20268#undef ARM_VARIANT
20269#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
20270
20271/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 20272#undef THUMB_VARIANT
4ed7ed8d 20273#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 20274
4ed7ed8d
TP
20275 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20276 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20277 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20278 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20279 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20280 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 20281 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
20282 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
20283 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20284 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
20285 stlex, t_stlex),
4b8c8c02
RE
20286 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
20287 stlex, t_stlex),
20288 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
20289 stlex, t_stlex),
4ed7ed8d
TP
20290#undef THUMB_VARIANT
20291#define THUMB_VARIANT & arm_ext_v8
53c4b28b 20292
4ed7ed8d 20293 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
4ed7ed8d
TP
20294 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
20295 ldrexd, t_ldrexd),
20296 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
20297 strexd, t_strexd),
f7dd2fb2
TC
20298
20299/* Defined in V8 but is in undefined encoding space for earlier
20300 architectures. However earlier architectures are required to treat
20301 this instuction as a semihosting trap as well. Hence while not explicitly
20302 defined as such, it is in fact correct to define the instruction for all
20303 architectures. */
20304#undef THUMB_VARIANT
20305#define THUMB_VARIANT & arm_ext_v1
20306#undef ARM_VARIANT
20307#define ARM_VARIANT & arm_ext_v1
20308 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
20309
8884b720 20310 /* ARMv8 T32 only. */
74db7efb 20311#undef ARM_VARIANT
b79f7053
MGD
20312#define ARM_VARIANT NULL
20313 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
20314 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
20315 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
20316
33399f07
MGD
20317 /* FP for ARMv8. */
20318#undef ARM_VARIANT
a715796b 20319#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 20320#undef THUMB_VARIANT
a715796b 20321#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
20322
20323 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
20324 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
20325 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
20326 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
20327 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
20328 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
20329 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
20330 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
20331 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
20332 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
20333 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
20334 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
20335 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
20336 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
20337 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
20338 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
20339 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 20340
91ff7894
MGD
20341 /* Crypto v1 extensions. */
20342#undef ARM_VARIANT
20343#define ARM_VARIANT & fpu_crypto_ext_armv8
20344#undef THUMB_VARIANT
20345#define THUMB_VARIANT & fpu_crypto_ext_armv8
20346
20347 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
20348 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
20349 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
20350 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
20351 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
20352 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
20353 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
20354 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
20355 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
20356 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
20357 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
20358 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
20359 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
20360 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 20361
dd5181d5 20362#undef ARM_VARIANT
74db7efb 20363#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
20364#undef THUMB_VARIANT
20365#define THUMB_VARIANT & crc_ext_armv8
20366 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
20367 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
20368 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
20369 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
20370 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
20371 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
20372
105bde57
MW
20373 /* ARMv8.2 RAS extension. */
20374#undef ARM_VARIANT
4d1464f2 20375#define ARM_VARIANT & arm_ext_ras
105bde57 20376#undef THUMB_VARIANT
4d1464f2 20377#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
20378 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
20379
49e8a725
SN
20380#undef ARM_VARIANT
20381#define ARM_VARIANT & arm_ext_v8_3
20382#undef THUMB_VARIANT
20383#define THUMB_VARIANT & arm_ext_v8_3
20384 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
20385 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
20386 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 20387
c604a79a
JW
20388#undef ARM_VARIANT
20389#define ARM_VARIANT & fpu_neon_ext_dotprod
20390#undef THUMB_VARIANT
20391#define THUMB_VARIANT & fpu_neon_ext_dotprod
20392 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
20393 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
20394
c921be7d
NC
20395#undef ARM_VARIANT
20396#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
20397#undef THUMB_VARIANT
20398#define THUMB_VARIANT NULL
c921be7d 20399
21d799b5
NC
20400 cCE("wfs", e200110, 1, (RR), rd),
20401 cCE("rfs", e300110, 1, (RR), rd),
20402 cCE("wfc", e400110, 1, (RR), rd),
20403 cCE("rfc", e500110, 1, (RR), rd),
20404
20405 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
20406 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
20407 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
20408 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
20409
20410 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
20411 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
20412 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
20413 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
20414
20415 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
20416 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
20417 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
20418 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
20419 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
20420 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
20421 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
20422 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
20423 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
20424 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
20425 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
20426 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
20427
20428 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
20429 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
20430 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
20431 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
20432 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
20433 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
20434 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
20435 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
20436 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
20437 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
20438 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
20439 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
20440
20441 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
20442 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
20443 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
20444 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
20445 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
20446 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
20447 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
20448 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
20449 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
20450 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
20451 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
20452 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
20453
20454 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
20455 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
20456 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
20457 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
20458 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
20459 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
20460 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
20461 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
20462 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
20463 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
20464 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
20465 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
20466
20467 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
20468 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
20469 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
20470 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
20471 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
20472 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
20473 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
20474 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
20475 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
20476 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
20477 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
20478 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
20479
20480 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
20481 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
20482 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
20483 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
20484 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
20485 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
20486 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
20487 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
20488 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
20489 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
20490 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
20491 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
20492
20493 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
20494 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
20495 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
20496 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
20497 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
20498 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
20499 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
20500 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
20501 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
20502 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
20503 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
20504 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
20505
20506 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
20507 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20508 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20509 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20510 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20511 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20512 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20513 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20514 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20515 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20516 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20517 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20518
20519 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20520 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20521 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20522 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20523 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20524 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20525 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20526 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20527 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20528 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20529 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20530 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20531
20532 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20533 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20534 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20535 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20536 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20537 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20538 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20539 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20540 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20541 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20542 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20543 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20544
20545 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20546 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20547 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20548 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20549 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20550 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20551 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20552 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20553 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20554 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20555 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20556 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20557
20558 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20559 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20560 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20561 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20562 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20563 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20564 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20565 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20566 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20567 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20568 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20569 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20570
20571 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20572 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20573 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20574 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20575 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20576 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20577 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20578 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20579 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20580 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20581 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20582 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20583
20584 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20585 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20586 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20587 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20588 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20589 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20590 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20591 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20592 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20593 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20594 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20595 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20596
20597 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20598 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20599 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20600 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20601 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20602 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20603 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20604 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20605 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20606 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20607 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20608 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20609
20610 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20611 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20612 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20613 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20614 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20615 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20616 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20617 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20618 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20619 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20620 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20621 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20622
20623 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20624 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20625 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20626 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20627 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20628 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20629 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20630 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20631 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20632 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20633 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20634 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20635
20636 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20637 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20638 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20639 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20640 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20641 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20642 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20643 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20644 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20645 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20646 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20647 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20648
20649 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20650 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20651 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20652 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20653 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20654 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20655 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20656 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20657 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20658 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20659 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20660 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20661
20662 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20663 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20664 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20665 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20666 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20667 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20668 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20669 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20670 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20671 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20672 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20673 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20674
20675 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20676 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20677 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20678 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20679 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20680 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20681 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20682 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20683 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20684 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20685 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20686 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20687
20688 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20689 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20690 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20691 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20692 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20693 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20694 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20695 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20696 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20697 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20698 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20699 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20700
20701 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20702 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20703 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20704 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20705 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20706 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20707 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20708 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20709 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20710 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20711 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20712 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20713
20714 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20715 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20716 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20717 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20718 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20719 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20720 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20721 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20722 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20723 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20724 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20725 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20726
20727 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20728 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20729 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20730 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20731 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20732 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20733 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20734 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20735 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20736 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20737 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20738 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20739
20740 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20741 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20742 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20743 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20744 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20745 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20746 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20747 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20748 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20749 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20750 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20751 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20752
20753 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20754 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20755 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20756 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20757 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20758 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20759 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20760 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20761 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20762 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20763 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20764 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20765
20766 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20767 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20768 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20769 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20770 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20771 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20772 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20773 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20774 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20775 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20776 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20777 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20778
20779 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20780 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20781 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20782 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20783 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20784 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20785 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20786 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20787 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20788 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20789 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20790 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20791
20792 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20793 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20794 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20795 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20796
20797 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20798 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20799 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20800 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20801 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20802 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20803 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20804 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20805 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20806 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20807 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20808 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20809
c19d1205
ZW
20810 /* The implementation of the FIX instruction is broken on some
20811 assemblers, in that it accepts a precision specifier as well as a
20812 rounding specifier, despite the fact that this is meaningless.
20813 To be more compatible, we accept it as well, though of course it
20814 does not set any bits. */
21d799b5
NC
20815 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20816 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20817 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20818 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20819 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20820 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20821 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20822 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20823 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20824 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20825 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20826 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20827 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20828
c19d1205 20829 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20830#undef ARM_VARIANT
20831#define ARM_VARIANT & fpu_fpa_ext_v2
20832
21d799b5
NC
20833 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20834 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20835 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20836 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20837 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20838 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20839
c921be7d
NC
20840#undef ARM_VARIANT
20841#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20842
c19d1205 20843 /* Moves and type conversions. */
21d799b5
NC
20844 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20845 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20846 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20847 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20848 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20849 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20850 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20851 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20852 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20853 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20854 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20855 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20856 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20857 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20858
20859 /* Memory operations. */
21d799b5
NC
20860 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20861 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20862 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20863 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20864 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20865 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20866 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20867 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20868 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20869 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20870 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20871 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20872 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20873 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20874 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20875 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20876 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20877 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20878
c19d1205 20879 /* Monadic operations. */
21d799b5
NC
20880 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20881 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20882 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20883
20884 /* Dyadic operations. */
21d799b5
NC
20885 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20886 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20887 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20888 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20889 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20890 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20891 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20892 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20893 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20894
c19d1205 20895 /* Comparisons. */
21d799b5
NC
20896 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20897 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20898 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20899 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20900
62f3b8c8
PB
20901 /* Double precision load/store are still present on single precision
20902 implementations. */
20903 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20904 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20905 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20906 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20907 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20908 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20909 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20910 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20911 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20912 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20913
c921be7d
NC
20914#undef ARM_VARIANT
20915#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20916
c19d1205 20917 /* Moves and type conversions. */
21d799b5
NC
20918 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20919 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20920 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20921 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20922 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20923 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20924 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20925 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20926 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20927 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20928 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20929 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20930 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20931
c19d1205 20932 /* Monadic operations. */
21d799b5
NC
20933 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20934 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20935 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20936
20937 /* Dyadic operations. */
21d799b5
NC
20938 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20939 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20940 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20941 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20942 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20943 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20944 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20945 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20946 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20947
c19d1205 20948 /* Comparisons. */
21d799b5
NC
20949 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20950 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20951 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20952 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20953
c921be7d
NC
20954#undef ARM_VARIANT
20955#define ARM_VARIANT & fpu_vfp_ext_v2
20956
21d799b5
NC
20957 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20958 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20959 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20960 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20961
037e8744
JB
20962/* Instructions which may belong to either the Neon or VFP instruction sets.
20963 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20964#undef ARM_VARIANT
20965#define ARM_VARIANT & fpu_vfp_ext_v1xd
20966#undef THUMB_VARIANT
20967#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20968
037e8744
JB
20969 /* These mnemonics are unique to VFP. */
20970 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20971 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20972 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20973 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20974 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20975 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20976 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20977 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20978 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20979 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20980
20981 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20982 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20983 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20984 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20985
21d799b5
NC
20986 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20987 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20988
20989 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20990 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20991
55881a11
MGD
20992 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20993 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20994 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20995 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20996 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20997 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20998 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20999 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 21000
5f1af56b 21001 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 21002 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
21003 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
21004 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 21005
037e8744
JB
21006
21007 /* NOTE: All VMOV encoding is special-cased! */
21008 NCE(vmov, 0, 1, (VMOV), neon_mov),
21009 NCE(vmovq, 0, 1, (VMOV), neon_mov),
21010
9db2f6b4
RL
21011#undef ARM_VARIANT
21012#define ARM_VARIANT & arm_ext_fp16
21013#undef THUMB_VARIANT
21014#define THUMB_VARIANT & arm_ext_fp16
21015 /* New instructions added from v8.2, allowing the extraction and insertion of
21016 the upper 16 bits of a 32-bit vector register. */
21017 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
21018 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
21019
dec41383
JW
21020 /* New backported fma/fms instructions optional in v8.2. */
21021 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
21022 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
21023
c921be7d
NC
21024#undef THUMB_VARIANT
21025#define THUMB_VARIANT & fpu_neon_ext_v1
21026#undef ARM_VARIANT
21027#define ARM_VARIANT & fpu_neon_ext_v1
21028
5287ad62
JB
21029 /* Data processing with three registers of the same length. */
21030 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
21031 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
21032 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
21033 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21034 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21035 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21036 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21037 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21038 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21039 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
21040 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
21041 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
21042 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
21043 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
21044 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
21045 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
21046 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
21047 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
21048 /* If not immediate, fall back to neon_dyadic_i64_su.
21049 shl_imm should accept I8 I16 I32 I64,
21050 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
21051 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
21052 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
21053 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
21054 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 21055 /* Logic ops, types optional & ignored. */
4316f0d2
DG
21056 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21057 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21058 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21059 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21060 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21061 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21062 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21063 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21064 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
21065 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
21066 /* Bitfield ops, untyped. */
21067 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
21068 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
21069 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
21070 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
21071 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
21072 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 21073 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
21074 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
21075 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21076 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
21077 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21078 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
21079 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
21080 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
21081 back to neon_dyadic_if_su. */
21d799b5
NC
21082 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
21083 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
21084 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
21085 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
21086 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
21087 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
21088 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
21089 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 21090 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
21091 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
21092 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 21093 /* As above, D registers only. */
21d799b5
NC
21094 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
21095 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 21096 /* Int and float variants, signedness unimportant. */
21d799b5
NC
21097 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
21098 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
21099 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 21100 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
21101 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
21102 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
21103 /* vtst takes sizes 8, 16, 32. */
21104 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
21105 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
21106 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 21107 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 21108 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
21109 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
21110 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
21111 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
21112 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
21113 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
21114 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
21115 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
21116 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
21117 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
21118 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
21119 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
21120 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
21121 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
21122 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
21123 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
21124 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 21125 /* ARM v8.1 extension. */
643afb90
MW
21126 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
21127 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
21128 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
21129 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
21130
21131 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 21132 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
21133 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
21134
21135 /* Data processing with two registers and a shift amount. */
21136 /* Right shifts, and variants with rounding.
21137 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
21138 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
21139 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
21140 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
21141 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
21142 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
21143 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
21144 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
21145 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
21146 /* Shift and insert. Sizes accepted 8 16 32 64. */
21147 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
21148 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
21149 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
21150 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
21151 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
21152 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
21153 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
21154 /* Right shift immediate, saturating & narrowing, with rounding variants.
21155 Types accepted S16 S32 S64 U16 U32 U64. */
21156 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
21157 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
21158 /* As above, unsigned. Types accepted S16 S32 S64. */
21159 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
21160 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
21161 /* Right shift narrowing. Types accepted I16 I32 I64. */
21162 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
21163 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
21164 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 21165 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 21166 /* CVT with optional immediate for fixed-point variant. */
21d799b5 21167 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 21168
4316f0d2
DG
21169 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
21170 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
21171
21172 /* Data processing, three registers of different lengths. */
21173 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
21174 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
21175 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
21176 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
21177 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
21178 /* If not scalar, fall back to neon_dyadic_long.
21179 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
21180 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
21181 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
21182 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
21183 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
21184 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
21185 /* Dyadic, narrowing insns. Types I16 I32 I64. */
21186 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21187 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21188 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21189 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21190 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
21191 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21192 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21193 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
21194 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
21195 S16 S32 U16 U32. */
21d799b5 21196 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
21197
21198 /* Extract. Size 8. */
3b8d421e
PB
21199 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
21200 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
21201
21202 /* Two registers, miscellaneous. */
21203 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
21204 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
21205 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
21206 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
21207 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
21208 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
21209 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
21210 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
21211 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
21212 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
21213 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
21214 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
21215 /* VMOVN. Types I16 I32 I64. */
21d799b5 21216 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 21217 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 21218 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 21219 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 21220 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
21221 /* VZIP / VUZP. Sizes 8 16 32. */
21222 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
21223 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
21224 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
21225 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
21226 /* VQABS / VQNEG. Types S8 S16 S32. */
21227 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21228 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
21229 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21230 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
21231 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
21232 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
21233 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
21234 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
21235 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 21236 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
21237 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
21238 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
21239 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
21240 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
21241 /* VCLS. Types S8 S16 S32. */
21242 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
21243 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
21244 /* VCLZ. Types I8 I16 I32. */
21245 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
21246 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
21247 /* VCNT. Size 8. */
21248 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
21249 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
21250 /* Two address, untyped. */
21251 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
21252 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
21253 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
21254 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
21255 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
21256
21257 /* Table lookup. Size 8. */
21258 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21259 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21260
c921be7d
NC
21261#undef THUMB_VARIANT
21262#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
21263#undef ARM_VARIANT
21264#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
21265
5287ad62 21266 /* Neon element/structure load/store. */
21d799b5
NC
21267 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21268 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21269 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21270 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21271 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21272 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21273 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
21274 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 21275
c921be7d 21276#undef THUMB_VARIANT
74db7efb
NC
21277#define THUMB_VARIANT & fpu_vfp_ext_v3xd
21278#undef ARM_VARIANT
21279#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
21280 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
21281 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21282 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21283 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21284 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21285 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21286 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21287 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21288 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21289
74db7efb 21290#undef THUMB_VARIANT
c921be7d
NC
21291#define THUMB_VARIANT & fpu_vfp_ext_v3
21292#undef ARM_VARIANT
21293#define ARM_VARIANT & fpu_vfp_ext_v3
21294
21d799b5 21295 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 21296 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21297 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21298 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21299 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21300 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21301 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21302 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21303 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 21304
74db7efb
NC
21305#undef ARM_VARIANT
21306#define ARM_VARIANT & fpu_vfp_ext_fma
21307#undef THUMB_VARIANT
21308#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
21309 /* Mnemonics shared by Neon and VFP. These are included in the
21310 VFP FMA variant; NEON and VFP FMA always includes the NEON
21311 FMA instructions. */
21312 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21313 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21314 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
21315 the v form should always be used. */
21316 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21317 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21318 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21319 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21320 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21321 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21322
5287ad62 21323#undef THUMB_VARIANT
c921be7d
NC
21324#undef ARM_VARIANT
21325#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
21326
21d799b5
NC
21327 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21328 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21329 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21330 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21331 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21332 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21333 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
21334 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 21335
c921be7d
NC
21336#undef ARM_VARIANT
21337#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
21338
21d799b5
NC
21339 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
21340 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
21341 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
21342 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
21343 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
21344 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
21345 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
21346 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
21347 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
21348 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21349 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21350 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21351 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21352 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21353 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
21354 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21355 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21356 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21357 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
21358 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
21359 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21360 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21361 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21362 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21363 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21364 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
21365 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
21366 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
21367 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
21368 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
21369 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
21370 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
21371 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
21372 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
21373 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
21374 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
21375 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
21376 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21377 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21378 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21379 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21380 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21381 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21382 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21383 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21384 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21385 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
21386 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21387 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21388 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21389 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21390 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21391 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21392 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21393 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21394 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21395 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21396 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21397 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21398 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21399 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21400 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21401 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21402 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21403 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21404 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21405 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21406 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21407 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21408 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21409 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21410 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21411 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21412 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21413 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21414 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21415 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21416 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21417 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21418 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21419 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21420 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21421 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21422 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21423 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21424 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21425 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21426 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21427 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
21428 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21429 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21430 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21431 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21432 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21433 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21434 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21435 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21436 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21437 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21438 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21439 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21440 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21441 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21442 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21443 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21444 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21445 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21446 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21447 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21448 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21449 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
21450 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21451 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21452 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21453 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21454 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21455 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21456 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21457 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21458 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21459 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21460 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21461 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21462 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21463 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21464 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21465 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21466 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21467 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21468 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21469 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21470 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21471 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21472 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21473 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21474 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21475 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21476 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21477 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21478 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21479 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21480 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21481 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
21482 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
21483 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
21484 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
21485 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
21486 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
21487 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21488 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21489 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21490 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
21491 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
21492 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
21493 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
21494 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
21495 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
21496 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21497 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21498 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21499 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21500 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 21501
c921be7d
NC
21502#undef ARM_VARIANT
21503#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
21504
21d799b5
NC
21505 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
21506 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
21507 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
21508 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
21509 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
21510 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
21511 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21512 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21513 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21514 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21515 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21516 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21517 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21518 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21519 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21520 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21521 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21522 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21523 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21524 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21525 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21526 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21527 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21528 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21529 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21530 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21531 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21532 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21533 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21534 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21535 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21536 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21537 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21538 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21539 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21540 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21541 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21542 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21543 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21544 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21545 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21546 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21547 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21548 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21549 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21550 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21551 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21552 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21553 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21554 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21555 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21556 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21557 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21558 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21559 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21560 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21561 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 21562
c921be7d
NC
21563#undef ARM_VARIANT
21564#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21565
21d799b5
NC
21566 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21567 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21568 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21569 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21570 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21571 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21572 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21573 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21574 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21575 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21576 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21577 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21578 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21579 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
21580 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21581 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21582 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21583 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21584 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21585 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21586 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21587 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21588 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21589 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
21590 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21591 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21592 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21593 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
21594 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21595 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
21596 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21597 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21598 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21599 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
21600 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21601 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21602 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21603 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21604 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21605 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
21606 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21607 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
21608 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21609 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
21610 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21611 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21612 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21613 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21614 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21615 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21616 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21617 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21618 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21619 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21620 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21621 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21622 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21623 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21624 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21625 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21626 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21627 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21628 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21629 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21630 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21631 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21632 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21633 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21634 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21635 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21636 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21637 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
21638 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21639 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
21640 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21641 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 21642
7fadb25d
SD
21643 /* ARMv8.5-A instructions. */
21644#undef ARM_VARIANT
21645#define ARM_VARIANT & arm_ext_sb
21646#undef THUMB_VARIANT
21647#define THUMB_VARIANT & arm_ext_sb
21648 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
21649
dad0c3bf
SD
21650#undef ARM_VARIANT
21651#define ARM_VARIANT & arm_ext_predres
21652#undef THUMB_VARIANT
21653#define THUMB_VARIANT & arm_ext_predres
21654 CE("cfprctx", e070f93, 1, (RRnpc), rd),
21655 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
21656 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
21657
16a1fa25 21658 /* ARMv8-M instructions. */
4ed7ed8d
TP
21659#undef ARM_VARIANT
21660#define ARM_VARIANT NULL
21661#undef THUMB_VARIANT
21662#define THUMB_VARIANT & arm_ext_v8m
cf3cf39d
TP
21663 ToU("sg", e97fe97f, 0, (), noargs),
21664 ToC("blxns", 4784, 1, (RRnpc), t_blx),
21665 ToC("bxns", 4704, 1, (RRnpc), t_bx),
21666 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
21667 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
21668 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
21669 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
16a1fa25
TP
21670
21671 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21672 instructions behave as nop if no VFP is present. */
21673#undef THUMB_VARIANT
21674#define THUMB_VARIANT & arm_ext_v8m_main
cf3cf39d
TP
21675 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
21676 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
4389b29a
AV
21677
21678 /* Armv8.1-M Mainline instructions. */
21679#undef THUMB_VARIANT
21680#define THUMB_VARIANT & arm_ext_v8_1m_main
21681 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
c19d1205
ZW
21682};
21683#undef ARM_VARIANT
21684#undef THUMB_VARIANT
21685#undef TCE
c19d1205
ZW
21686#undef TUE
21687#undef TUF
21688#undef TCC
8f06b2d8 21689#undef cCE
e3cb604e
PB
21690#undef cCL
21691#undef C3E
4389b29a 21692#undef C3
c19d1205
ZW
21693#undef CE
21694#undef CM
4389b29a 21695#undef CL
c19d1205
ZW
21696#undef UE
21697#undef UF
21698#undef UT
5287ad62
JB
21699#undef NUF
21700#undef nUF
21701#undef NCE
21702#undef nCE
c19d1205
ZW
21703#undef OPS0
21704#undef OPS1
21705#undef OPS2
21706#undef OPS3
21707#undef OPS4
21708#undef OPS5
21709#undef OPS6
21710#undef do_0
4389b29a
AV
21711#undef ToC
21712#undef toC
21713#undef ToU
c19d1205
ZW
21714\f
21715/* MD interface: bits in the object file. */
bfae80f2 21716
c19d1205
ZW
21717/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21718 for use in the a.out file, and stores them in the array pointed to by buf.
21719 This knows about the endian-ness of the target machine and does
21720 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21721 2 (short) and 4 (long) Floating numbers are put out as a series of
21722 LITTLENUMS (shorts, here at least). */
b99bd4ef 21723
c19d1205
ZW
21724void
21725md_number_to_chars (char * buf, valueT val, int n)
21726{
21727 if (target_big_endian)
21728 number_to_chars_bigendian (buf, val, n);
21729 else
21730 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21731}
21732
c19d1205
ZW
21733static valueT
21734md_chars_to_number (char * buf, int n)
bfae80f2 21735{
c19d1205
ZW
21736 valueT result = 0;
21737 unsigned char * where = (unsigned char *) buf;
bfae80f2 21738
c19d1205 21739 if (target_big_endian)
b99bd4ef 21740 {
c19d1205
ZW
21741 while (n--)
21742 {
21743 result <<= 8;
21744 result |= (*where++ & 255);
21745 }
b99bd4ef 21746 }
c19d1205 21747 else
b99bd4ef 21748 {
c19d1205
ZW
21749 while (n--)
21750 {
21751 result <<= 8;
21752 result |= (where[n] & 255);
21753 }
bfae80f2 21754 }
b99bd4ef 21755
c19d1205 21756 return result;
bfae80f2 21757}
b99bd4ef 21758
c19d1205 21759/* MD interface: Sections. */
b99bd4ef 21760
fa94de6b
RM
21761/* Calculate the maximum variable size (i.e., excluding fr_fix)
21762 that an rs_machine_dependent frag may reach. */
21763
21764unsigned int
21765arm_frag_max_var (fragS *fragp)
21766{
21767 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21768 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21769
21770 Note that we generate relaxable instructions even for cases that don't
21771 really need it, like an immediate that's a trivial constant. So we're
21772 overestimating the instruction size for some of those cases. Rather
21773 than putting more intelligence here, it would probably be better to
21774 avoid generating a relaxation frag in the first place when it can be
21775 determined up front that a short instruction will suffice. */
21776
21777 gas_assert (fragp->fr_type == rs_machine_dependent);
21778 return INSN_SIZE;
21779}
21780
0110f2b8
PB
21781/* Estimate the size of a frag before relaxing. Assume everything fits in
21782 2 bytes. */
21783
c19d1205 21784int
0110f2b8 21785md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21786 segT segtype ATTRIBUTE_UNUSED)
21787{
0110f2b8
PB
21788 fragp->fr_var = 2;
21789 return 2;
21790}
21791
21792/* Convert a machine dependent frag. */
21793
21794void
21795md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21796{
21797 unsigned long insn;
21798 unsigned long old_op;
21799 char *buf;
21800 expressionS exp;
21801 fixS *fixp;
21802 int reloc_type;
21803 int pc_rel;
21804 int opcode;
21805
21806 buf = fragp->fr_literal + fragp->fr_fix;
21807
21808 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21809 if (fragp->fr_symbol)
21810 {
0110f2b8
PB
21811 exp.X_op = O_symbol;
21812 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21813 }
21814 else
21815 {
0110f2b8 21816 exp.X_op = O_constant;
5f4273c7 21817 }
0110f2b8
PB
21818 exp.X_add_number = fragp->fr_offset;
21819 opcode = fragp->fr_subtype;
21820 switch (opcode)
21821 {
21822 case T_MNEM_ldr_pc:
21823 case T_MNEM_ldr_pc2:
21824 case T_MNEM_ldr_sp:
21825 case T_MNEM_str_sp:
21826 case T_MNEM_ldr:
21827 case T_MNEM_ldrb:
21828 case T_MNEM_ldrh:
21829 case T_MNEM_str:
21830 case T_MNEM_strb:
21831 case T_MNEM_strh:
21832 if (fragp->fr_var == 4)
21833 {
5f4273c7 21834 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21835 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21836 {
21837 insn |= (old_op & 0x700) << 4;
21838 }
21839 else
21840 {
21841 insn |= (old_op & 7) << 12;
21842 insn |= (old_op & 0x38) << 13;
21843 }
21844 insn |= 0x00000c00;
21845 put_thumb32_insn (buf, insn);
21846 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21847 }
21848 else
21849 {
21850 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21851 }
21852 pc_rel = (opcode == T_MNEM_ldr_pc2);
21853 break;
21854 case T_MNEM_adr:
21855 if (fragp->fr_var == 4)
21856 {
21857 insn = THUMB_OP32 (opcode);
21858 insn |= (old_op & 0xf0) << 4;
21859 put_thumb32_insn (buf, insn);
21860 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21861 }
21862 else
21863 {
21864 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21865 exp.X_add_number -= 4;
21866 }
21867 pc_rel = 1;
21868 break;
21869 case T_MNEM_mov:
21870 case T_MNEM_movs:
21871 case T_MNEM_cmp:
21872 case T_MNEM_cmn:
21873 if (fragp->fr_var == 4)
21874 {
21875 int r0off = (opcode == T_MNEM_mov
21876 || opcode == T_MNEM_movs) ? 0 : 8;
21877 insn = THUMB_OP32 (opcode);
21878 insn = (insn & 0xe1ffffff) | 0x10000000;
21879 insn |= (old_op & 0x700) << r0off;
21880 put_thumb32_insn (buf, insn);
21881 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21882 }
21883 else
21884 {
21885 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21886 }
21887 pc_rel = 0;
21888 break;
21889 case T_MNEM_b:
21890 if (fragp->fr_var == 4)
21891 {
21892 insn = THUMB_OP32(opcode);
21893 put_thumb32_insn (buf, insn);
21894 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21895 }
21896 else
21897 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21898 pc_rel = 1;
21899 break;
21900 case T_MNEM_bcond:
21901 if (fragp->fr_var == 4)
21902 {
21903 insn = THUMB_OP32(opcode);
21904 insn |= (old_op & 0xf00) << 14;
21905 put_thumb32_insn (buf, insn);
21906 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21907 }
21908 else
21909 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21910 pc_rel = 1;
21911 break;
21912 case T_MNEM_add_sp:
21913 case T_MNEM_add_pc:
21914 case T_MNEM_inc_sp:
21915 case T_MNEM_dec_sp:
21916 if (fragp->fr_var == 4)
21917 {
21918 /* ??? Choose between add and addw. */
21919 insn = THUMB_OP32 (opcode);
21920 insn |= (old_op & 0xf0) << 4;
21921 put_thumb32_insn (buf, insn);
16805f35
PB
21922 if (opcode == T_MNEM_add_pc)
21923 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21924 else
21925 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21926 }
21927 else
21928 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21929 pc_rel = 0;
21930 break;
21931
21932 case T_MNEM_addi:
21933 case T_MNEM_addis:
21934 case T_MNEM_subi:
21935 case T_MNEM_subis:
21936 if (fragp->fr_var == 4)
21937 {
21938 insn = THUMB_OP32 (opcode);
21939 insn |= (old_op & 0xf0) << 4;
21940 insn |= (old_op & 0xf) << 16;
21941 put_thumb32_insn (buf, insn);
16805f35
PB
21942 if (insn & (1 << 20))
21943 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21944 else
21945 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21946 }
21947 else
21948 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21949 pc_rel = 0;
21950 break;
21951 default:
5f4273c7 21952 abort ();
0110f2b8
PB
21953 }
21954 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21955 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21956 fixp->fx_file = fragp->fr_file;
21957 fixp->fx_line = fragp->fr_line;
21958 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21959
21960 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21961 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21962 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21963 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21964}
21965
21966/* Return the size of a relaxable immediate operand instruction.
21967 SHIFT and SIZE specify the form of the allowable immediate. */
21968static int
21969relax_immediate (fragS *fragp, int size, int shift)
21970{
21971 offsetT offset;
21972 offsetT mask;
21973 offsetT low;
21974
21975 /* ??? Should be able to do better than this. */
21976 if (fragp->fr_symbol)
21977 return 4;
21978
21979 low = (1 << shift) - 1;
21980 mask = (1 << (shift + size)) - (1 << shift);
21981 offset = fragp->fr_offset;
21982 /* Force misaligned offsets to 32-bit variant. */
21983 if (offset & low)
5e77afaa 21984 return 4;
0110f2b8
PB
21985 if (offset & ~mask)
21986 return 4;
21987 return 2;
21988}
21989
5e77afaa
PB
21990/* Get the address of a symbol during relaxation. */
21991static addressT
5f4273c7 21992relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21993{
21994 fragS *sym_frag;
21995 addressT addr;
21996 symbolS *sym;
21997
21998 sym = fragp->fr_symbol;
21999 sym_frag = symbol_get_frag (sym);
22000 know (S_GET_SEGMENT (sym) != absolute_section
22001 || sym_frag == &zero_address_frag);
22002 addr = S_GET_VALUE (sym) + fragp->fr_offset;
22003
22004 /* If frag has yet to be reached on this pass, assume it will
22005 move by STRETCH just as we did. If this is not so, it will
22006 be because some frag between grows, and that will force
22007 another pass. */
22008
22009 if (stretch != 0
22010 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
22011 {
22012 fragS *f;
22013
22014 /* Adjust stretch for any alignment frag. Note that if have
22015 been expanding the earlier code, the symbol may be
22016 defined in what appears to be an earlier frag. FIXME:
22017 This doesn't handle the fr_subtype field, which specifies
22018 a maximum number of bytes to skip when doing an
22019 alignment. */
22020 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
22021 {
22022 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
22023 {
22024 if (stretch < 0)
22025 stretch = - ((- stretch)
22026 & ~ ((1 << (int) f->fr_offset) - 1));
22027 else
22028 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
22029 if (stretch == 0)
22030 break;
22031 }
22032 }
22033 if (f != NULL)
22034 addr += stretch;
22035 }
5e77afaa
PB
22036
22037 return addr;
22038}
22039
0110f2b8
PB
22040/* Return the size of a relaxable adr pseudo-instruction or PC-relative
22041 load. */
22042static int
5e77afaa 22043relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
22044{
22045 addressT addr;
22046 offsetT val;
22047
22048 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
22049 if (fragp->fr_symbol == NULL
22050 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
22051 || sec != S_GET_SEGMENT (fragp->fr_symbol)
22052 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
22053 return 4;
22054
5f4273c7 22055 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
22056 addr = fragp->fr_address + fragp->fr_fix;
22057 addr = (addr + 4) & ~3;
5e77afaa 22058 /* Force misaligned targets to 32-bit variant. */
0110f2b8 22059 if (val & 3)
5e77afaa 22060 return 4;
0110f2b8
PB
22061 val -= addr;
22062 if (val < 0 || val > 1020)
22063 return 4;
22064 return 2;
22065}
22066
22067/* Return the size of a relaxable add/sub immediate instruction. */
22068static int
22069relax_addsub (fragS *fragp, asection *sec)
22070{
22071 char *buf;
22072 int op;
22073
22074 buf = fragp->fr_literal + fragp->fr_fix;
22075 op = bfd_get_16(sec->owner, buf);
22076 if ((op & 0xf) == ((op >> 4) & 0xf))
22077 return relax_immediate (fragp, 8, 0);
22078 else
22079 return relax_immediate (fragp, 3, 0);
22080}
22081
e83a675f
RE
22082/* Return TRUE iff the definition of symbol S could be pre-empted
22083 (overridden) at link or load time. */
22084static bfd_boolean
22085symbol_preemptible (symbolS *s)
22086{
22087 /* Weak symbols can always be pre-empted. */
22088 if (S_IS_WEAK (s))
22089 return TRUE;
22090
22091 /* Non-global symbols cannot be pre-empted. */
22092 if (! S_IS_EXTERNAL (s))
22093 return FALSE;
22094
22095#ifdef OBJ_ELF
22096 /* In ELF, a global symbol can be marked protected, or private. In that
22097 case it can't be pre-empted (other definitions in the same link unit
22098 would violate the ODR). */
22099 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
22100 return FALSE;
22101#endif
22102
22103 /* Other global symbols might be pre-empted. */
22104 return TRUE;
22105}
0110f2b8
PB
22106
22107/* Return the size of a relaxable branch instruction. BITS is the
22108 size of the offset field in the narrow instruction. */
22109
22110static int
5e77afaa 22111relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
22112{
22113 addressT addr;
22114 offsetT val;
22115 offsetT limit;
22116
22117 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 22118 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
22119 || sec != S_GET_SEGMENT (fragp->fr_symbol)
22120 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
22121 return 4;
22122
267bf995 22123#ifdef OBJ_ELF
e83a675f 22124 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
22125 if (S_IS_DEFINED (fragp->fr_symbol)
22126 && ARM_IS_FUNC (fragp->fr_symbol))
22127 return 4;
e83a675f 22128#endif
0d9b4b55 22129
e83a675f 22130 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 22131 return 4;
267bf995 22132
5f4273c7 22133 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
22134 addr = fragp->fr_address + fragp->fr_fix + 4;
22135 val -= addr;
22136
22137 /* Offset is a signed value *2 */
22138 limit = 1 << bits;
22139 if (val >= limit || val < -limit)
22140 return 4;
22141 return 2;
22142}
22143
22144
22145/* Relax a machine dependent frag. This returns the amount by which
22146 the current size of the frag should change. */
22147
22148int
5e77afaa 22149arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
22150{
22151 int oldsize;
22152 int newsize;
22153
22154 oldsize = fragp->fr_var;
22155 switch (fragp->fr_subtype)
22156 {
22157 case T_MNEM_ldr_pc2:
5f4273c7 22158 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
22159 break;
22160 case T_MNEM_ldr_pc:
22161 case T_MNEM_ldr_sp:
22162 case T_MNEM_str_sp:
5f4273c7 22163 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
22164 break;
22165 case T_MNEM_ldr:
22166 case T_MNEM_str:
5f4273c7 22167 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
22168 break;
22169 case T_MNEM_ldrh:
22170 case T_MNEM_strh:
5f4273c7 22171 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
22172 break;
22173 case T_MNEM_ldrb:
22174 case T_MNEM_strb:
5f4273c7 22175 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
22176 break;
22177 case T_MNEM_adr:
5f4273c7 22178 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
22179 break;
22180 case T_MNEM_mov:
22181 case T_MNEM_movs:
22182 case T_MNEM_cmp:
22183 case T_MNEM_cmn:
5f4273c7 22184 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
22185 break;
22186 case T_MNEM_b:
5f4273c7 22187 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
22188 break;
22189 case T_MNEM_bcond:
5f4273c7 22190 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
22191 break;
22192 case T_MNEM_add_sp:
22193 case T_MNEM_add_pc:
22194 newsize = relax_immediate (fragp, 8, 2);
22195 break;
22196 case T_MNEM_inc_sp:
22197 case T_MNEM_dec_sp:
22198 newsize = relax_immediate (fragp, 7, 2);
22199 break;
22200 case T_MNEM_addi:
22201 case T_MNEM_addis:
22202 case T_MNEM_subi:
22203 case T_MNEM_subis:
22204 newsize = relax_addsub (fragp, sec);
22205 break;
22206 default:
5f4273c7 22207 abort ();
0110f2b8 22208 }
5e77afaa
PB
22209
22210 fragp->fr_var = newsize;
22211 /* Freeze wide instructions that are at or before the same location as
22212 in the previous pass. This avoids infinite loops.
5f4273c7
NC
22213 Don't freeze them unconditionally because targets may be artificially
22214 misaligned by the expansion of preceding frags. */
5e77afaa 22215 if (stretch <= 0 && newsize > 2)
0110f2b8 22216 {
0110f2b8 22217 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 22218 frag_wane (fragp);
0110f2b8 22219 }
5e77afaa 22220
0110f2b8 22221 return newsize - oldsize;
c19d1205 22222}
b99bd4ef 22223
c19d1205 22224/* Round up a section size to the appropriate boundary. */
b99bd4ef 22225
c19d1205
ZW
22226valueT
22227md_section_align (segT segment ATTRIBUTE_UNUSED,
22228 valueT size)
22229{
6844c0cc 22230 return size;
bfae80f2 22231}
b99bd4ef 22232
c19d1205
ZW
22233/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
22234 of an rs_align_code fragment. */
22235
22236void
22237arm_handle_align (fragS * fragP)
bfae80f2 22238{
d9235011 22239 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
22240 {
22241 { /* ARMv1 */
22242 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
22243 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
22244 },
22245 { /* ARMv6k */
22246 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
22247 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
22248 },
22249 };
d9235011 22250 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
22251 {
22252 { /* Thumb-1 */
22253 {0xc0, 0x46}, /* LE */
22254 {0x46, 0xc0}, /* BE */
22255 },
22256 { /* Thumb-2 */
22257 {0x00, 0xbf}, /* LE */
22258 {0xbf, 0x00} /* BE */
22259 }
22260 };
d9235011 22261 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
22262 { /* Wide Thumb-2 */
22263 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
22264 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
22265 };
c921be7d 22266
e7495e45 22267 unsigned bytes, fix, noop_size;
c19d1205 22268 char * p;
d9235011
TS
22269 const unsigned char * noop;
22270 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
22271#ifdef OBJ_ELF
22272 enum mstate state;
22273#endif
bfae80f2 22274
c19d1205 22275 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
22276 return;
22277
c19d1205
ZW
22278 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
22279 p = fragP->fr_literal + fragP->fr_fix;
22280 fix = 0;
bfae80f2 22281
c19d1205
ZW
22282 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
22283 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 22284
cd000bff 22285 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 22286
cd000bff 22287 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 22288 {
7f78eb34
JW
22289 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22290 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
22291 {
22292 narrow_noop = thumb_noop[1][target_big_endian];
22293 noop = wide_thumb_noop[target_big_endian];
22294 }
c19d1205 22295 else
e7495e45
NS
22296 noop = thumb_noop[0][target_big_endian];
22297 noop_size = 2;
cd000bff
DJ
22298#ifdef OBJ_ELF
22299 state = MAP_THUMB;
22300#endif
7ed4c4c5
NC
22301 }
22302 else
22303 {
7f78eb34
JW
22304 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22305 ? selected_cpu : arm_arch_none,
22306 arm_ext_v6k) != 0]
e7495e45
NS
22307 [target_big_endian];
22308 noop_size = 4;
cd000bff
DJ
22309#ifdef OBJ_ELF
22310 state = MAP_ARM;
22311#endif
7ed4c4c5 22312 }
c921be7d 22313
e7495e45 22314 fragP->fr_var = noop_size;
c921be7d 22315
c19d1205 22316 if (bytes & (noop_size - 1))
7ed4c4c5 22317 {
c19d1205 22318 fix = bytes & (noop_size - 1);
cd000bff
DJ
22319#ifdef OBJ_ELF
22320 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
22321#endif
c19d1205
ZW
22322 memset (p, 0, fix);
22323 p += fix;
22324 bytes -= fix;
a737bd4d 22325 }
a737bd4d 22326
e7495e45
NS
22327 if (narrow_noop)
22328 {
22329 if (bytes & noop_size)
22330 {
22331 /* Insert a narrow noop. */
22332 memcpy (p, narrow_noop, noop_size);
22333 p += noop_size;
22334 bytes -= noop_size;
22335 fix += noop_size;
22336 }
22337
22338 /* Use wide noops for the remainder */
22339 noop_size = 4;
22340 }
22341
c19d1205 22342 while (bytes >= noop_size)
a737bd4d 22343 {
c19d1205
ZW
22344 memcpy (p, noop, noop_size);
22345 p += noop_size;
22346 bytes -= noop_size;
22347 fix += noop_size;
a737bd4d
NC
22348 }
22349
c19d1205 22350 fragP->fr_fix += fix;
a737bd4d
NC
22351}
22352
c19d1205
ZW
22353/* Called from md_do_align. Used to create an alignment
22354 frag in a code section. */
22355
22356void
22357arm_frag_align_code (int n, int max)
bfae80f2 22358{
c19d1205 22359 char * p;
7ed4c4c5 22360
c19d1205 22361 /* We assume that there will never be a requirement
6ec8e702 22362 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 22363 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
22364 {
22365 char err_msg[128];
22366
fa94de6b 22367 sprintf (err_msg,
477330fc
RM
22368 _("alignments greater than %d bytes not supported in .text sections."),
22369 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 22370 as_fatal ("%s", err_msg);
6ec8e702 22371 }
bfae80f2 22372
c19d1205
ZW
22373 p = frag_var (rs_align_code,
22374 MAX_MEM_FOR_RS_ALIGN_CODE,
22375 1,
22376 (relax_substateT) max,
22377 (symbolS *) NULL,
22378 (offsetT) n,
22379 (char *) NULL);
22380 *p = 0;
22381}
bfae80f2 22382
8dc2430f
NC
22383/* Perform target specific initialisation of a frag.
22384 Note - despite the name this initialisation is not done when the frag
22385 is created, but only when its type is assigned. A frag can be created
22386 and used a long time before its type is set, so beware of assuming that
33eaf5de 22387 this initialisation is performed first. */
bfae80f2 22388
cd000bff
DJ
22389#ifndef OBJ_ELF
22390void
22391arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
22392{
22393 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 22394 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
22395}
22396
22397#else /* OBJ_ELF is defined. */
c19d1205 22398void
cd000bff 22399arm_init_frag (fragS * fragP, int max_chars)
c19d1205 22400{
e8d84ca1 22401 bfd_boolean frag_thumb_mode;
b968d18a 22402
8dc2430f
NC
22403 /* If the current ARM vs THUMB mode has not already
22404 been recorded into this frag then do so now. */
cd000bff 22405 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
22406 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22407
e8d84ca1
NC
22408 /* PR 21809: Do not set a mapping state for debug sections
22409 - it just confuses other tools. */
22410 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
22411 return;
22412
b968d18a 22413 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 22414
f9c1b181
RL
22415 /* Record a mapping symbol for alignment frags. We will delete this
22416 later if the alignment ends up empty. */
22417 switch (fragP->fr_type)
22418 {
22419 case rs_align:
22420 case rs_align_test:
22421 case rs_fill:
22422 mapping_state_2 (MAP_DATA, max_chars);
22423 break;
22424 case rs_align_code:
b968d18a 22425 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
22426 break;
22427 default:
22428 break;
cd000bff 22429 }
bfae80f2
RE
22430}
22431
c19d1205
ZW
22432/* When we change sections we need to issue a new mapping symbol. */
22433
22434void
22435arm_elf_change_section (void)
bfae80f2 22436{
c19d1205
ZW
22437 /* Link an unlinked unwind index table section to the .text section. */
22438 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
22439 && elf_linked_to_section (now_seg) == NULL)
22440 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
22441}
22442
c19d1205
ZW
22443int
22444arm_elf_section_type (const char * str, size_t len)
e45d0630 22445{
c19d1205
ZW
22446 if (len == 5 && strncmp (str, "exidx", 5) == 0)
22447 return SHT_ARM_EXIDX;
e45d0630 22448
c19d1205
ZW
22449 return -1;
22450}
22451\f
22452/* Code to deal with unwinding tables. */
e45d0630 22453
c19d1205 22454static void add_unwind_adjustsp (offsetT);
e45d0630 22455
5f4273c7 22456/* Generate any deferred unwind frame offset. */
e45d0630 22457
bfae80f2 22458static void
c19d1205 22459flush_pending_unwind (void)
bfae80f2 22460{
c19d1205 22461 offsetT offset;
bfae80f2 22462
c19d1205
ZW
22463 offset = unwind.pending_offset;
22464 unwind.pending_offset = 0;
22465 if (offset != 0)
22466 add_unwind_adjustsp (offset);
bfae80f2
RE
22467}
22468
c19d1205
ZW
22469/* Add an opcode to this list for this function. Two-byte opcodes should
22470 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
22471 order. */
22472
bfae80f2 22473static void
c19d1205 22474add_unwind_opcode (valueT op, int length)
bfae80f2 22475{
c19d1205
ZW
22476 /* Add any deferred stack adjustment. */
22477 if (unwind.pending_offset)
22478 flush_pending_unwind ();
bfae80f2 22479
c19d1205 22480 unwind.sp_restored = 0;
bfae80f2 22481
c19d1205 22482 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 22483 {
c19d1205
ZW
22484 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
22485 if (unwind.opcodes)
325801bd
TS
22486 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
22487 unwind.opcode_alloc);
c19d1205 22488 else
325801bd 22489 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 22490 }
c19d1205 22491 while (length > 0)
bfae80f2 22492 {
c19d1205
ZW
22493 length--;
22494 unwind.opcodes[unwind.opcode_count] = op & 0xff;
22495 op >>= 8;
22496 unwind.opcode_count++;
bfae80f2 22497 }
bfae80f2
RE
22498}
22499
c19d1205
ZW
22500/* Add unwind opcodes to adjust the stack pointer. */
22501
bfae80f2 22502static void
c19d1205 22503add_unwind_adjustsp (offsetT offset)
bfae80f2 22504{
c19d1205 22505 valueT op;
bfae80f2 22506
c19d1205 22507 if (offset > 0x200)
bfae80f2 22508 {
c19d1205
ZW
22509 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
22510 char bytes[5];
22511 int n;
22512 valueT o;
bfae80f2 22513
c19d1205
ZW
22514 /* Long form: 0xb2, uleb128. */
22515 /* This might not fit in a word so add the individual bytes,
22516 remembering the list is built in reverse order. */
22517 o = (valueT) ((offset - 0x204) >> 2);
22518 if (o == 0)
22519 add_unwind_opcode (0, 1);
bfae80f2 22520
c19d1205
ZW
22521 /* Calculate the uleb128 encoding of the offset. */
22522 n = 0;
22523 while (o)
22524 {
22525 bytes[n] = o & 0x7f;
22526 o >>= 7;
22527 if (o)
22528 bytes[n] |= 0x80;
22529 n++;
22530 }
22531 /* Add the insn. */
22532 for (; n; n--)
22533 add_unwind_opcode (bytes[n - 1], 1);
22534 add_unwind_opcode (0xb2, 1);
22535 }
22536 else if (offset > 0x100)
bfae80f2 22537 {
c19d1205
ZW
22538 /* Two short opcodes. */
22539 add_unwind_opcode (0x3f, 1);
22540 op = (offset - 0x104) >> 2;
22541 add_unwind_opcode (op, 1);
bfae80f2 22542 }
c19d1205
ZW
22543 else if (offset > 0)
22544 {
22545 /* Short opcode. */
22546 op = (offset - 4) >> 2;
22547 add_unwind_opcode (op, 1);
22548 }
22549 else if (offset < 0)
bfae80f2 22550 {
c19d1205
ZW
22551 offset = -offset;
22552 while (offset > 0x100)
bfae80f2 22553 {
c19d1205
ZW
22554 add_unwind_opcode (0x7f, 1);
22555 offset -= 0x100;
bfae80f2 22556 }
c19d1205
ZW
22557 op = ((offset - 4) >> 2) | 0x40;
22558 add_unwind_opcode (op, 1);
bfae80f2 22559 }
bfae80f2
RE
22560}
22561
c19d1205 22562/* Finish the list of unwind opcodes for this function. */
0198d5e6 22563
c19d1205
ZW
22564static void
22565finish_unwind_opcodes (void)
bfae80f2 22566{
c19d1205 22567 valueT op;
bfae80f2 22568
c19d1205 22569 if (unwind.fp_used)
bfae80f2 22570 {
708587a4 22571 /* Adjust sp as necessary. */
c19d1205
ZW
22572 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22573 flush_pending_unwind ();
bfae80f2 22574
c19d1205
ZW
22575 /* After restoring sp from the frame pointer. */
22576 op = 0x90 | unwind.fp_reg;
22577 add_unwind_opcode (op, 1);
22578 }
22579 else
22580 flush_pending_unwind ();
bfae80f2
RE
22581}
22582
bfae80f2 22583
c19d1205
ZW
22584/* Start an exception table entry. If idx is nonzero this is an index table
22585 entry. */
bfae80f2
RE
22586
22587static void
c19d1205 22588start_unwind_section (const segT text_seg, int idx)
bfae80f2 22589{
c19d1205
ZW
22590 const char * text_name;
22591 const char * prefix;
22592 const char * prefix_once;
22593 const char * group_name;
c19d1205 22594 char * sec_name;
c19d1205
ZW
22595 int type;
22596 int flags;
22597 int linkonce;
bfae80f2 22598
c19d1205 22599 if (idx)
bfae80f2 22600 {
c19d1205
ZW
22601 prefix = ELF_STRING_ARM_unwind;
22602 prefix_once = ELF_STRING_ARM_unwind_once;
22603 type = SHT_ARM_EXIDX;
bfae80f2 22604 }
c19d1205 22605 else
bfae80f2 22606 {
c19d1205
ZW
22607 prefix = ELF_STRING_ARM_unwind_info;
22608 prefix_once = ELF_STRING_ARM_unwind_info_once;
22609 type = SHT_PROGBITS;
bfae80f2
RE
22610 }
22611
c19d1205
ZW
22612 text_name = segment_name (text_seg);
22613 if (streq (text_name, ".text"))
22614 text_name = "";
22615
22616 if (strncmp (text_name, ".gnu.linkonce.t.",
22617 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 22618 {
c19d1205
ZW
22619 prefix = prefix_once;
22620 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
22621 }
22622
29a2809e 22623 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 22624
c19d1205
ZW
22625 flags = SHF_ALLOC;
22626 linkonce = 0;
22627 group_name = 0;
bfae80f2 22628
c19d1205
ZW
22629 /* Handle COMDAT group. */
22630 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 22631 {
c19d1205
ZW
22632 group_name = elf_group_name (text_seg);
22633 if (group_name == NULL)
22634 {
bd3ba5d1 22635 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
22636 segment_name (text_seg));
22637 ignore_rest_of_line ();
22638 return;
22639 }
22640 flags |= SHF_GROUP;
22641 linkonce = 1;
bfae80f2
RE
22642 }
22643
a91e1603
L
22644 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
22645 linkonce, 0);
bfae80f2 22646
5f4273c7 22647 /* Set the section link for index tables. */
c19d1205
ZW
22648 if (idx)
22649 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
22650}
22651
bfae80f2 22652
c19d1205
ZW
22653/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22654 personality routine data. Returns zero, or the index table value for
cad0da33 22655 an inline entry. */
c19d1205
ZW
22656
22657static valueT
22658create_unwind_entry (int have_data)
bfae80f2 22659{
c19d1205
ZW
22660 int size;
22661 addressT where;
22662 char *ptr;
22663 /* The current word of data. */
22664 valueT data;
22665 /* The number of bytes left in this word. */
22666 int n;
bfae80f2 22667
c19d1205 22668 finish_unwind_opcodes ();
bfae80f2 22669
c19d1205
ZW
22670 /* Remember the current text section. */
22671 unwind.saved_seg = now_seg;
22672 unwind.saved_subseg = now_subseg;
bfae80f2 22673
c19d1205 22674 start_unwind_section (now_seg, 0);
bfae80f2 22675
c19d1205 22676 if (unwind.personality_routine == NULL)
bfae80f2 22677 {
c19d1205
ZW
22678 if (unwind.personality_index == -2)
22679 {
22680 if (have_data)
5f4273c7 22681 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22682 return 1; /* EXIDX_CANTUNWIND. */
22683 }
bfae80f2 22684
c19d1205
ZW
22685 /* Use a default personality routine if none is specified. */
22686 if (unwind.personality_index == -1)
22687 {
22688 if (unwind.opcode_count > 3)
22689 unwind.personality_index = 1;
22690 else
22691 unwind.personality_index = 0;
22692 }
bfae80f2 22693
c19d1205
ZW
22694 /* Space for the personality routine entry. */
22695 if (unwind.personality_index == 0)
22696 {
22697 if (unwind.opcode_count > 3)
22698 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22699
c19d1205
ZW
22700 if (!have_data)
22701 {
22702 /* All the data is inline in the index table. */
22703 data = 0x80;
22704 n = 3;
22705 while (unwind.opcode_count > 0)
22706 {
22707 unwind.opcode_count--;
22708 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22709 n--;
22710 }
bfae80f2 22711
c19d1205
ZW
22712 /* Pad with "finish" opcodes. */
22713 while (n--)
22714 data = (data << 8) | 0xb0;
bfae80f2 22715
c19d1205
ZW
22716 return data;
22717 }
22718 size = 0;
22719 }
22720 else
22721 /* We get two opcodes "free" in the first word. */
22722 size = unwind.opcode_count - 2;
22723 }
22724 else
5011093d 22725 {
cad0da33
NC
22726 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22727 if (unwind.personality_index != -1)
22728 {
22729 as_bad (_("attempt to recreate an unwind entry"));
22730 return 1;
22731 }
5011093d
NC
22732
22733 /* An extra byte is required for the opcode count. */
22734 size = unwind.opcode_count + 1;
22735 }
bfae80f2 22736
c19d1205
ZW
22737 size = (size + 3) >> 2;
22738 if (size > 0xff)
22739 as_bad (_("too many unwind opcodes"));
bfae80f2 22740
c19d1205
ZW
22741 frag_align (2, 0, 0);
22742 record_alignment (now_seg, 2);
22743 unwind.table_entry = expr_build_dot ();
22744
22745 /* Allocate the table entry. */
22746 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22747 /* PR 13449: Zero the table entries in case some of them are not used. */
22748 memset (ptr, 0, (size << 2) + 4);
c19d1205 22749 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22750
c19d1205 22751 switch (unwind.personality_index)
bfae80f2 22752 {
c19d1205
ZW
22753 case -1:
22754 /* ??? Should this be a PLT generating relocation? */
22755 /* Custom personality routine. */
22756 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22757 BFD_RELOC_ARM_PREL31);
bfae80f2 22758
c19d1205
ZW
22759 where += 4;
22760 ptr += 4;
bfae80f2 22761
c19d1205 22762 /* Set the first byte to the number of additional words. */
5011093d 22763 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22764 n = 3;
22765 break;
bfae80f2 22766
c19d1205
ZW
22767 /* ABI defined personality routines. */
22768 case 0:
22769 /* Three opcodes bytes are packed into the first word. */
22770 data = 0x80;
22771 n = 3;
22772 break;
bfae80f2 22773
c19d1205
ZW
22774 case 1:
22775 case 2:
22776 /* The size and first two opcode bytes go in the first word. */
22777 data = ((0x80 + unwind.personality_index) << 8) | size;
22778 n = 2;
22779 break;
bfae80f2 22780
c19d1205
ZW
22781 default:
22782 /* Should never happen. */
22783 abort ();
22784 }
bfae80f2 22785
c19d1205
ZW
22786 /* Pack the opcodes into words (MSB first), reversing the list at the same
22787 time. */
22788 while (unwind.opcode_count > 0)
22789 {
22790 if (n == 0)
22791 {
22792 md_number_to_chars (ptr, data, 4);
22793 ptr += 4;
22794 n = 4;
22795 data = 0;
22796 }
22797 unwind.opcode_count--;
22798 n--;
22799 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22800 }
22801
22802 /* Finish off the last word. */
22803 if (n < 4)
22804 {
22805 /* Pad with "finish" opcodes. */
22806 while (n--)
22807 data = (data << 8) | 0xb0;
22808
22809 md_number_to_chars (ptr, data, 4);
22810 }
22811
22812 if (!have_data)
22813 {
22814 /* Add an empty descriptor if there is no user-specified data. */
22815 ptr = frag_more (4);
22816 md_number_to_chars (ptr, 0, 4);
22817 }
22818
22819 return 0;
bfae80f2
RE
22820}
22821
f0927246
NC
22822
22823/* Initialize the DWARF-2 unwind information for this procedure. */
22824
22825void
22826tc_arm_frame_initial_instructions (void)
22827{
22828 cfi_add_CFA_def_cfa (REG_SP, 0);
22829}
22830#endif /* OBJ_ELF */
22831
c19d1205
ZW
22832/* Convert REGNAME to a DWARF-2 register number. */
22833
22834int
1df69f4f 22835tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22836{
1df69f4f 22837 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22838 if (reg != FAIL)
22839 return reg;
c19d1205 22840
1f5afe1c
NC
22841 /* PR 16694: Allow VFP registers as well. */
22842 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22843 if (reg != FAIL)
22844 return 64 + reg;
c19d1205 22845
1f5afe1c
NC
22846 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22847 if (reg != FAIL)
22848 return reg + 256;
22849
0198d5e6 22850 return FAIL;
bfae80f2
RE
22851}
22852
f0927246 22853#ifdef TE_PE
c19d1205 22854void
f0927246 22855tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22856{
91d6fa6a 22857 expressionS exp;
bfae80f2 22858
91d6fa6a
NC
22859 exp.X_op = O_secrel;
22860 exp.X_add_symbol = symbol;
22861 exp.X_add_number = 0;
22862 emit_expr (&exp, size);
f0927246
NC
22863}
22864#endif
bfae80f2 22865
c19d1205 22866/* MD interface: Symbol and relocation handling. */
bfae80f2 22867
2fc8bdac
ZW
22868/* Return the address within the segment that a PC-relative fixup is
22869 relative to. For ARM, PC-relative fixups applied to instructions
22870 are generally relative to the location of the fixup plus 8 bytes.
22871 Thumb branches are offset by 4, and Thumb loads relative to PC
22872 require special handling. */
bfae80f2 22873
c19d1205 22874long
2fc8bdac 22875md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22876{
2fc8bdac
ZW
22877 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22878
22879 /* If this is pc-relative and we are going to emit a relocation
22880 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22881 will need. Otherwise we want to use the calculated base.
22882 For WinCE we skip the bias for externals as well, since this
22883 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22884 if (fixP->fx_pcrel
2fc8bdac 22885 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22886 || (arm_force_relocation (fixP)
22887#ifdef TE_WINCE
22888 && !S_IS_EXTERNAL (fixP->fx_addsy)
22889#endif
22890 )))
2fc8bdac 22891 base = 0;
bfae80f2 22892
267bf995 22893
c19d1205 22894 switch (fixP->fx_r_type)
bfae80f2 22895 {
2fc8bdac
ZW
22896 /* PC relative addressing on the Thumb is slightly odd as the
22897 bottom two bits of the PC are forced to zero for the
22898 calculation. This happens *after* application of the
22899 pipeline offset. However, Thumb adrl already adjusts for
22900 this, so we need not do it again. */
c19d1205 22901 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22902 return base & ~3;
c19d1205
ZW
22903
22904 case BFD_RELOC_ARM_THUMB_OFFSET:
22905 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22906 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22907 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22908 return (base + 4) & ~3;
c19d1205 22909
2fc8bdac 22910 /* Thumb branches are simply offset by +4. */
e12437dc 22911 case BFD_RELOC_THUMB_PCREL_BRANCH5:
2fc8bdac
ZW
22912 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22913 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22914 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22915 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22916 case BFD_RELOC_THUMB_PCREL_BRANCH25:
e5d6e09e 22917 case BFD_RELOC_ARM_THUMB_BF17:
2fc8bdac 22918 return base + 4;
bfae80f2 22919
267bf995 22920 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22921 if (fixP->fx_addsy
22922 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22923 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22924 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22925 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22926 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22927 return base + 4;
22928
00adf2d4
JB
22929 /* BLX is like branches above, but forces the low two bits of PC to
22930 zero. */
486499d0
CL
22931 case BFD_RELOC_THUMB_PCREL_BLX:
22932 if (fixP->fx_addsy
22933 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22934 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22935 && THUMB_IS_FUNC (fixP->fx_addsy)
22936 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22937 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22938 return (base + 4) & ~3;
22939
2fc8bdac
ZW
22940 /* ARM mode branches are offset by +8. However, the Windows CE
22941 loader expects the relocation not to take this into account. */
267bf995 22942 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22943 if (fixP->fx_addsy
22944 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22945 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22946 && ARM_IS_FUNC (fixP->fx_addsy)
22947 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22948 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22949 return base + 8;
267bf995 22950
486499d0
CL
22951 case BFD_RELOC_ARM_PCREL_CALL:
22952 if (fixP->fx_addsy
22953 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22954 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22955 && THUMB_IS_FUNC (fixP->fx_addsy)
22956 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22957 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22958 return base + 8;
267bf995 22959
2fc8bdac 22960 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22961 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22962 case BFD_RELOC_ARM_PLT32:
c19d1205 22963#ifdef TE_WINCE
5f4273c7 22964 /* When handling fixups immediately, because we have already
477330fc 22965 discovered the value of a symbol, or the address of the frag involved
53baae48 22966 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22967 see fixup_segment() in write.c
22968 The S_IS_EXTERNAL test handles the case of global symbols.
22969 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22970 if (fixP->fx_pcrel
22971 && fixP->fx_addsy != NULL
22972 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22973 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22974 return base + 8;
2fc8bdac 22975 return base;
c19d1205 22976#else
2fc8bdac 22977 return base + 8;
c19d1205 22978#endif
2fc8bdac 22979
267bf995 22980
2fc8bdac
ZW
22981 /* ARM mode loads relative to PC are also offset by +8. Unlike
22982 branches, the Windows CE loader *does* expect the relocation
22983 to take this into account. */
22984 case BFD_RELOC_ARM_OFFSET_IMM:
22985 case BFD_RELOC_ARM_OFFSET_IMM8:
22986 case BFD_RELOC_ARM_HWLITERAL:
22987 case BFD_RELOC_ARM_LITERAL:
22988 case BFD_RELOC_ARM_CP_OFF_IMM:
22989 return base + 8;
22990
22991
22992 /* Other PC-relative relocations are un-offset. */
22993 default:
22994 return base;
22995 }
bfae80f2
RE
22996}
22997
8b2d793c
NC
22998static bfd_boolean flag_warn_syms = TRUE;
22999
ae8714c2
NC
23000bfd_boolean
23001arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 23002{
8b2d793c
NC
23003 /* PR 18347 - Warn if the user attempts to create a symbol with the same
23004 name as an ARM instruction. Whilst strictly speaking it is allowed, it
23005 does mean that the resulting code might be very confusing to the reader.
23006 Also this warning can be triggered if the user omits an operand before
23007 an immediate address, eg:
23008
23009 LDR =foo
23010
23011 GAS treats this as an assignment of the value of the symbol foo to a
23012 symbol LDR, and so (without this code) it will not issue any kind of
23013 warning or error message.
23014
23015 Note - ARM instructions are case-insensitive but the strings in the hash
23016 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
23017 lower case too. */
23018 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
23019 {
23020 char * nbuf = strdup (name);
23021 char * p;
23022
23023 for (p = nbuf; *p; p++)
23024 *p = TOLOWER (*p);
23025 if (hash_find (arm_ops_hsh, nbuf) != NULL)
23026 {
23027 static struct hash_control * already_warned = NULL;
23028
23029 if (already_warned == NULL)
23030 already_warned = hash_new ();
23031 /* Only warn about the symbol once. To keep the code
23032 simple we let hash_insert do the lookup for us. */
23033 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 23034 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
23035 }
23036 else
23037 free (nbuf);
23038 }
3739860c 23039
ae8714c2
NC
23040 return FALSE;
23041}
23042
23043/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
23044 Otherwise we have no need to default values of symbols. */
23045
23046symbolS *
23047md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
23048{
23049#ifdef OBJ_ELF
23050 if (name[0] == '_' && name[1] == 'G'
23051 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
23052 {
23053 if (!GOT_symbol)
23054 {
23055 if (symbol_find (name))
23056 as_bad (_("GOT already in the symbol table"));
23057
23058 GOT_symbol = symbol_new (name, undefined_section,
23059 (valueT) 0, & zero_address_frag);
23060 }
23061
23062 return GOT_symbol;
23063 }
23064#endif
23065
c921be7d 23066 return NULL;
bfae80f2
RE
23067}
23068
55cf6793 23069/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
23070 computed as two separate immediate values, added together. We
23071 already know that this value cannot be computed by just one ARM
23072 instruction. */
23073
23074static unsigned int
23075validate_immediate_twopart (unsigned int val,
23076 unsigned int * highpart)
bfae80f2 23077{
c19d1205
ZW
23078 unsigned int a;
23079 unsigned int i;
bfae80f2 23080
c19d1205
ZW
23081 for (i = 0; i < 32; i += 2)
23082 if (((a = rotate_left (val, i)) & 0xff) != 0)
23083 {
23084 if (a & 0xff00)
23085 {
23086 if (a & ~ 0xffff)
23087 continue;
23088 * highpart = (a >> 8) | ((i + 24) << 7);
23089 }
23090 else if (a & 0xff0000)
23091 {
23092 if (a & 0xff000000)
23093 continue;
23094 * highpart = (a >> 16) | ((i + 16) << 7);
23095 }
23096 else
23097 {
9c2799c2 23098 gas_assert (a & 0xff000000);
c19d1205
ZW
23099 * highpart = (a >> 24) | ((i + 8) << 7);
23100 }
bfae80f2 23101
c19d1205
ZW
23102 return (a & 0xff) | (i << 7);
23103 }
bfae80f2 23104
c19d1205 23105 return FAIL;
bfae80f2
RE
23106}
23107
c19d1205
ZW
23108static int
23109validate_offset_imm (unsigned int val, int hwse)
23110{
23111 if ((hwse && val > 255) || val > 4095)
23112 return FAIL;
23113 return val;
23114}
bfae80f2 23115
55cf6793 23116/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
23117 negative immediate constant by altering the instruction. A bit of
23118 a hack really.
23119 MOV <-> MVN
23120 AND <-> BIC
23121 ADC <-> SBC
23122 by inverting the second operand, and
23123 ADD <-> SUB
23124 CMP <-> CMN
23125 by negating the second operand. */
bfae80f2 23126
c19d1205
ZW
23127static int
23128negate_data_op (unsigned long * instruction,
23129 unsigned long value)
bfae80f2 23130{
c19d1205
ZW
23131 int op, new_inst;
23132 unsigned long negated, inverted;
bfae80f2 23133
c19d1205
ZW
23134 negated = encode_arm_immediate (-value);
23135 inverted = encode_arm_immediate (~value);
bfae80f2 23136
c19d1205
ZW
23137 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
23138 switch (op)
bfae80f2 23139 {
c19d1205
ZW
23140 /* First negates. */
23141 case OPCODE_SUB: /* ADD <-> SUB */
23142 new_inst = OPCODE_ADD;
23143 value = negated;
23144 break;
bfae80f2 23145
c19d1205
ZW
23146 case OPCODE_ADD:
23147 new_inst = OPCODE_SUB;
23148 value = negated;
23149 break;
bfae80f2 23150
c19d1205
ZW
23151 case OPCODE_CMP: /* CMP <-> CMN */
23152 new_inst = OPCODE_CMN;
23153 value = negated;
23154 break;
bfae80f2 23155
c19d1205
ZW
23156 case OPCODE_CMN:
23157 new_inst = OPCODE_CMP;
23158 value = negated;
23159 break;
bfae80f2 23160
c19d1205
ZW
23161 /* Now Inverted ops. */
23162 case OPCODE_MOV: /* MOV <-> MVN */
23163 new_inst = OPCODE_MVN;
23164 value = inverted;
23165 break;
bfae80f2 23166
c19d1205
ZW
23167 case OPCODE_MVN:
23168 new_inst = OPCODE_MOV;
23169 value = inverted;
23170 break;
bfae80f2 23171
c19d1205
ZW
23172 case OPCODE_AND: /* AND <-> BIC */
23173 new_inst = OPCODE_BIC;
23174 value = inverted;
23175 break;
bfae80f2 23176
c19d1205
ZW
23177 case OPCODE_BIC:
23178 new_inst = OPCODE_AND;
23179 value = inverted;
23180 break;
bfae80f2 23181
c19d1205
ZW
23182 case OPCODE_ADC: /* ADC <-> SBC */
23183 new_inst = OPCODE_SBC;
23184 value = inverted;
23185 break;
bfae80f2 23186
c19d1205
ZW
23187 case OPCODE_SBC:
23188 new_inst = OPCODE_ADC;
23189 value = inverted;
23190 break;
bfae80f2 23191
c19d1205
ZW
23192 /* We cannot do anything. */
23193 default:
23194 return FAIL;
b99bd4ef
NC
23195 }
23196
c19d1205
ZW
23197 if (value == (unsigned) FAIL)
23198 return FAIL;
23199
23200 *instruction &= OPCODE_MASK;
23201 *instruction |= new_inst << DATA_OP_SHIFT;
23202 return value;
b99bd4ef
NC
23203}
23204
ef8d22e6
PB
23205/* Like negate_data_op, but for Thumb-2. */
23206
23207static unsigned int
16dd5e42 23208thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
23209{
23210 int op, new_inst;
23211 int rd;
16dd5e42 23212 unsigned int negated, inverted;
ef8d22e6
PB
23213
23214 negated = encode_thumb32_immediate (-value);
23215 inverted = encode_thumb32_immediate (~value);
23216
23217 rd = (*instruction >> 8) & 0xf;
23218 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
23219 switch (op)
23220 {
23221 /* ADD <-> SUB. Includes CMP <-> CMN. */
23222 case T2_OPCODE_SUB:
23223 new_inst = T2_OPCODE_ADD;
23224 value = negated;
23225 break;
23226
23227 case T2_OPCODE_ADD:
23228 new_inst = T2_OPCODE_SUB;
23229 value = negated;
23230 break;
23231
23232 /* ORR <-> ORN. Includes MOV <-> MVN. */
23233 case T2_OPCODE_ORR:
23234 new_inst = T2_OPCODE_ORN;
23235 value = inverted;
23236 break;
23237
23238 case T2_OPCODE_ORN:
23239 new_inst = T2_OPCODE_ORR;
23240 value = inverted;
23241 break;
23242
23243 /* AND <-> BIC. TST has no inverted equivalent. */
23244 case T2_OPCODE_AND:
23245 new_inst = T2_OPCODE_BIC;
23246 if (rd == 15)
23247 value = FAIL;
23248 else
23249 value = inverted;
23250 break;
23251
23252 case T2_OPCODE_BIC:
23253 new_inst = T2_OPCODE_AND;
23254 value = inverted;
23255 break;
23256
23257 /* ADC <-> SBC */
23258 case T2_OPCODE_ADC:
23259 new_inst = T2_OPCODE_SBC;
23260 value = inverted;
23261 break;
23262
23263 case T2_OPCODE_SBC:
23264 new_inst = T2_OPCODE_ADC;
23265 value = inverted;
23266 break;
23267
23268 /* We cannot do anything. */
23269 default:
23270 return FAIL;
23271 }
23272
16dd5e42 23273 if (value == (unsigned int)FAIL)
ef8d22e6
PB
23274 return FAIL;
23275
23276 *instruction &= T2_OPCODE_MASK;
23277 *instruction |= new_inst << T2_DATA_OP_SHIFT;
23278 return value;
23279}
23280
8f06b2d8 23281/* Read a 32-bit thumb instruction from buf. */
0198d5e6 23282
8f06b2d8
PB
23283static unsigned long
23284get_thumb32_insn (char * buf)
23285{
23286 unsigned long insn;
23287 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
23288 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23289
23290 return insn;
23291}
23292
a8bc6c78
PB
23293/* We usually want to set the low bit on the address of thumb function
23294 symbols. In particular .word foo - . should have the low bit set.
23295 Generic code tries to fold the difference of two symbols to
23296 a constant. Prevent this and force a relocation when the first symbols
23297 is a thumb function. */
c921be7d
NC
23298
23299bfd_boolean
a8bc6c78
PB
23300arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
23301{
23302 if (op == O_subtract
23303 && l->X_op == O_symbol
23304 && r->X_op == O_symbol
23305 && THUMB_IS_FUNC (l->X_add_symbol))
23306 {
23307 l->X_op = O_subtract;
23308 l->X_op_symbol = r->X_add_symbol;
23309 l->X_add_number -= r->X_add_number;
c921be7d 23310 return TRUE;
a8bc6c78 23311 }
c921be7d 23312
a8bc6c78 23313 /* Process as normal. */
c921be7d 23314 return FALSE;
a8bc6c78
PB
23315}
23316
4a42ebbc
RR
23317/* Encode Thumb2 unconditional branches and calls. The encoding
23318 for the 2 are identical for the immediate values. */
23319
23320static void
23321encode_thumb2_b_bl_offset (char * buf, offsetT value)
23322{
23323#define T2I1I2MASK ((1 << 13) | (1 << 11))
23324 offsetT newval;
23325 offsetT newval2;
23326 addressT S, I1, I2, lo, hi;
23327
23328 S = (value >> 24) & 0x01;
23329 I1 = (value >> 23) & 0x01;
23330 I2 = (value >> 22) & 0x01;
23331 hi = (value >> 12) & 0x3ff;
fa94de6b 23332 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
23333 newval = md_chars_to_number (buf, THUMB_SIZE);
23334 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23335 newval |= (S << 10) | hi;
23336 newval2 &= ~T2I1I2MASK;
23337 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
23338 md_number_to_chars (buf, newval, THUMB_SIZE);
23339 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23340}
23341
c19d1205 23342void
55cf6793 23343md_apply_fix (fixS * fixP,
c19d1205
ZW
23344 valueT * valP,
23345 segT seg)
23346{
23347 offsetT value = * valP;
23348 offsetT newval;
23349 unsigned int newimm;
23350 unsigned long temp;
23351 int sign;
23352 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 23353
9c2799c2 23354 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 23355
c19d1205 23356 /* Note whether this will delete the relocation. */
4962c51a 23357
c19d1205
ZW
23358 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
23359 fixP->fx_done = 1;
b99bd4ef 23360
adbaf948 23361 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 23362 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
23363 for emit_reloc. */
23364 value &= 0xffffffff;
23365 value ^= 0x80000000;
5f4273c7 23366 value -= 0x80000000;
adbaf948
ZW
23367
23368 *valP = value;
c19d1205 23369 fixP->fx_addnumber = value;
b99bd4ef 23370
adbaf948
ZW
23371 /* Same treatment for fixP->fx_offset. */
23372 fixP->fx_offset &= 0xffffffff;
23373 fixP->fx_offset ^= 0x80000000;
23374 fixP->fx_offset -= 0x80000000;
23375
c19d1205 23376 switch (fixP->fx_r_type)
b99bd4ef 23377 {
c19d1205
ZW
23378 case BFD_RELOC_NONE:
23379 /* This will need to go in the object file. */
23380 fixP->fx_done = 0;
23381 break;
b99bd4ef 23382
c19d1205
ZW
23383 case BFD_RELOC_ARM_IMMEDIATE:
23384 /* We claim that this fixup has been processed here,
23385 even if in fact we generate an error because we do
23386 not have a reloc for it, so tc_gen_reloc will reject it. */
23387 fixP->fx_done = 1;
b99bd4ef 23388
77db8e2e 23389 if (fixP->fx_addsy)
b99bd4ef 23390 {
77db8e2e 23391 const char *msg = 0;
b99bd4ef 23392
77db8e2e
NC
23393 if (! S_IS_DEFINED (fixP->fx_addsy))
23394 msg = _("undefined symbol %s used as an immediate value");
23395 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23396 msg = _("symbol %s is in a different section");
23397 else if (S_IS_WEAK (fixP->fx_addsy))
23398 msg = _("symbol %s is weak and may be overridden later");
23399
23400 if (msg)
23401 {
23402 as_bad_where (fixP->fx_file, fixP->fx_line,
23403 msg, S_GET_NAME (fixP->fx_addsy));
23404 break;
23405 }
42e5fcbf
AS
23406 }
23407
c19d1205
ZW
23408 temp = md_chars_to_number (buf, INSN_SIZE);
23409
5e73442d
SL
23410 /* If the offset is negative, we should use encoding A2 for ADR. */
23411 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
23412 newimm = negate_data_op (&temp, value);
23413 else
23414 {
23415 newimm = encode_arm_immediate (value);
23416
23417 /* If the instruction will fail, see if we can fix things up by
23418 changing the opcode. */
23419 if (newimm == (unsigned int) FAIL)
23420 newimm = negate_data_op (&temp, value);
bada4342
JW
23421 /* MOV accepts both ARM modified immediate (A1 encoding) and
23422 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
23423 When disassembling, MOV is preferred when there is no encoding
23424 overlap. */
23425 if (newimm == (unsigned int) FAIL
23426 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
23427 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
23428 && !((temp >> SBIT_SHIFT) & 0x1)
23429 && value >= 0 && value <= 0xffff)
23430 {
23431 /* Clear bits[23:20] to change encoding from A1 to A2. */
23432 temp &= 0xff0fffff;
23433 /* Encoding high 4bits imm. Code below will encode the remaining
23434 low 12bits. */
23435 temp |= (value & 0x0000f000) << 4;
23436 newimm = value & 0x00000fff;
23437 }
5e73442d
SL
23438 }
23439
23440 if (newimm == (unsigned int) FAIL)
b99bd4ef 23441 {
c19d1205
ZW
23442 as_bad_where (fixP->fx_file, fixP->fx_line,
23443 _("invalid constant (%lx) after fixup"),
23444 (unsigned long) value);
23445 break;
b99bd4ef 23446 }
b99bd4ef 23447
c19d1205
ZW
23448 newimm |= (temp & 0xfffff000);
23449 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
23450 break;
b99bd4ef 23451
c19d1205
ZW
23452 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23453 {
23454 unsigned int highpart = 0;
23455 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 23456
77db8e2e 23457 if (fixP->fx_addsy)
42e5fcbf 23458 {
77db8e2e 23459 const char *msg = 0;
42e5fcbf 23460
77db8e2e
NC
23461 if (! S_IS_DEFINED (fixP->fx_addsy))
23462 msg = _("undefined symbol %s used as an immediate value");
23463 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23464 msg = _("symbol %s is in a different section");
23465 else if (S_IS_WEAK (fixP->fx_addsy))
23466 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 23467
77db8e2e
NC
23468 if (msg)
23469 {
23470 as_bad_where (fixP->fx_file, fixP->fx_line,
23471 msg, S_GET_NAME (fixP->fx_addsy));
23472 break;
23473 }
23474 }
fa94de6b 23475
c19d1205
ZW
23476 newimm = encode_arm_immediate (value);
23477 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 23478
c19d1205
ZW
23479 /* If the instruction will fail, see if we can fix things up by
23480 changing the opcode. */
23481 if (newimm == (unsigned int) FAIL
23482 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
23483 {
23484 /* No ? OK - try using two ADD instructions to generate
23485 the value. */
23486 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 23487
c19d1205
ZW
23488 /* Yes - then make sure that the second instruction is
23489 also an add. */
23490 if (newimm != (unsigned int) FAIL)
23491 newinsn = temp;
23492 /* Still No ? Try using a negated value. */
23493 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
23494 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
23495 /* Otherwise - give up. */
23496 else
23497 {
23498 as_bad_where (fixP->fx_file, fixP->fx_line,
23499 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
23500 (long) value);
23501 break;
23502 }
b99bd4ef 23503
c19d1205
ZW
23504 /* Replace the first operand in the 2nd instruction (which
23505 is the PC) with the destination register. We have
23506 already added in the PC in the first instruction and we
23507 do not want to do it again. */
23508 newinsn &= ~ 0xf0000;
23509 newinsn |= ((newinsn & 0x0f000) << 4);
23510 }
b99bd4ef 23511
c19d1205
ZW
23512 newimm |= (temp & 0xfffff000);
23513 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 23514
c19d1205
ZW
23515 highpart |= (newinsn & 0xfffff000);
23516 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
23517 }
23518 break;
b99bd4ef 23519
c19d1205 23520 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23521 if (!fixP->fx_done && seg->use_rela_p)
23522 value = 0;
1a0670f3 23523 /* Fall through. */
00a97672 23524
c19d1205 23525 case BFD_RELOC_ARM_LITERAL:
26d97720 23526 sign = value > 0;
b99bd4ef 23527
c19d1205
ZW
23528 if (value < 0)
23529 value = - value;
b99bd4ef 23530
c19d1205 23531 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 23532 {
c19d1205
ZW
23533 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23534 as_bad_where (fixP->fx_file, fixP->fx_line,
23535 _("invalid literal constant: pool needs to be closer"));
23536 else
23537 as_bad_where (fixP->fx_file, fixP->fx_line,
23538 _("bad immediate value for offset (%ld)"),
23539 (long) value);
23540 break;
f03698e6
RE
23541 }
23542
c19d1205 23543 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23544 if (value == 0)
23545 newval &= 0xfffff000;
23546 else
23547 {
23548 newval &= 0xff7ff000;
23549 newval |= value | (sign ? INDEX_UP : 0);
23550 }
c19d1205
ZW
23551 md_number_to_chars (buf, newval, INSN_SIZE);
23552 break;
b99bd4ef 23553
c19d1205
ZW
23554 case BFD_RELOC_ARM_OFFSET_IMM8:
23555 case BFD_RELOC_ARM_HWLITERAL:
26d97720 23556 sign = value > 0;
b99bd4ef 23557
c19d1205
ZW
23558 if (value < 0)
23559 value = - value;
b99bd4ef 23560
c19d1205 23561 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 23562 {
c19d1205
ZW
23563 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23564 as_bad_where (fixP->fx_file, fixP->fx_line,
23565 _("invalid literal constant: pool needs to be closer"));
23566 else
427d0db6
RM
23567 as_bad_where (fixP->fx_file, fixP->fx_line,
23568 _("bad immediate value for 8-bit offset (%ld)"),
23569 (long) value);
c19d1205 23570 break;
b99bd4ef
NC
23571 }
23572
c19d1205 23573 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23574 if (value == 0)
23575 newval &= 0xfffff0f0;
23576 else
23577 {
23578 newval &= 0xff7ff0f0;
23579 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23580 }
c19d1205
ZW
23581 md_number_to_chars (buf, newval, INSN_SIZE);
23582 break;
b99bd4ef 23583
c19d1205
ZW
23584 case BFD_RELOC_ARM_T32_OFFSET_U8:
23585 if (value < 0 || value > 1020 || value % 4 != 0)
23586 as_bad_where (fixP->fx_file, fixP->fx_line,
23587 _("bad immediate value for offset (%ld)"), (long) value);
23588 value /= 4;
b99bd4ef 23589
c19d1205 23590 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
23591 newval |= value;
23592 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23593 break;
b99bd4ef 23594
c19d1205
ZW
23595 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23596 /* This is a complicated relocation used for all varieties of Thumb32
23597 load/store instruction with immediate offset:
23598
23599 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 23600 *4, optional writeback(W)
c19d1205
ZW
23601 (doubleword load/store)
23602
23603 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23604 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23605 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23606 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23607 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23608
23609 Uppercase letters indicate bits that are already encoded at
23610 this point. Lowercase letters are our problem. For the
23611 second block of instructions, the secondary opcode nybble
23612 (bits 8..11) is present, and bit 23 is zero, even if this is
23613 a PC-relative operation. */
23614 newval = md_chars_to_number (buf, THUMB_SIZE);
23615 newval <<= 16;
23616 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 23617
c19d1205 23618 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 23619 {
c19d1205
ZW
23620 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23621 if (value >= 0)
23622 newval |= (1 << 23);
23623 else
23624 value = -value;
23625 if (value % 4 != 0)
23626 {
23627 as_bad_where (fixP->fx_file, fixP->fx_line,
23628 _("offset not a multiple of 4"));
23629 break;
23630 }
23631 value /= 4;
216d22bc 23632 if (value > 0xff)
c19d1205
ZW
23633 {
23634 as_bad_where (fixP->fx_file, fixP->fx_line,
23635 _("offset out of range"));
23636 break;
23637 }
23638 newval &= ~0xff;
b99bd4ef 23639 }
c19d1205 23640 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 23641 {
c19d1205
ZW
23642 /* PC-relative, 12-bit offset. */
23643 if (value >= 0)
23644 newval |= (1 << 23);
23645 else
23646 value = -value;
216d22bc 23647 if (value > 0xfff)
c19d1205
ZW
23648 {
23649 as_bad_where (fixP->fx_file, fixP->fx_line,
23650 _("offset out of range"));
23651 break;
23652 }
23653 newval &= ~0xfff;
b99bd4ef 23654 }
c19d1205 23655 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 23656 {
c19d1205
ZW
23657 /* Writeback: 8-bit, +/- offset. */
23658 if (value >= 0)
23659 newval |= (1 << 9);
23660 else
23661 value = -value;
216d22bc 23662 if (value > 0xff)
c19d1205
ZW
23663 {
23664 as_bad_where (fixP->fx_file, fixP->fx_line,
23665 _("offset out of range"));
23666 break;
23667 }
23668 newval &= ~0xff;
b99bd4ef 23669 }
c19d1205 23670 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 23671 {
c19d1205 23672 /* T-instruction: positive 8-bit offset. */
216d22bc 23673 if (value < 0 || value > 0xff)
b99bd4ef 23674 {
c19d1205
ZW
23675 as_bad_where (fixP->fx_file, fixP->fx_line,
23676 _("offset out of range"));
23677 break;
b99bd4ef 23678 }
c19d1205
ZW
23679 newval &= ~0xff;
23680 newval |= value;
b99bd4ef
NC
23681 }
23682 else
b99bd4ef 23683 {
c19d1205
ZW
23684 /* Positive 12-bit or negative 8-bit offset. */
23685 int limit;
23686 if (value >= 0)
b99bd4ef 23687 {
c19d1205
ZW
23688 newval |= (1 << 23);
23689 limit = 0xfff;
23690 }
23691 else
23692 {
23693 value = -value;
23694 limit = 0xff;
23695 }
23696 if (value > limit)
23697 {
23698 as_bad_where (fixP->fx_file, fixP->fx_line,
23699 _("offset out of range"));
23700 break;
b99bd4ef 23701 }
c19d1205 23702 newval &= ~limit;
b99bd4ef 23703 }
b99bd4ef 23704
c19d1205
ZW
23705 newval |= value;
23706 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23707 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23708 break;
404ff6b5 23709
c19d1205
ZW
23710 case BFD_RELOC_ARM_SHIFT_IMM:
23711 newval = md_chars_to_number (buf, INSN_SIZE);
23712 if (((unsigned long) value) > 32
23713 || (value == 32
23714 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23715 {
23716 as_bad_where (fixP->fx_file, fixP->fx_line,
23717 _("shift expression is too large"));
23718 break;
23719 }
404ff6b5 23720
c19d1205
ZW
23721 if (value == 0)
23722 /* Shifts of zero must be done as lsl. */
23723 newval &= ~0x60;
23724 else if (value == 32)
23725 value = 0;
23726 newval &= 0xfffff07f;
23727 newval |= (value & 0x1f) << 7;
23728 md_number_to_chars (buf, newval, INSN_SIZE);
23729 break;
404ff6b5 23730
c19d1205 23731 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23732 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23733 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23734 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23735 /* We claim that this fixup has been processed here,
23736 even if in fact we generate an error because we do
23737 not have a reloc for it, so tc_gen_reloc will reject it. */
23738 fixP->fx_done = 1;
404ff6b5 23739
c19d1205
ZW
23740 if (fixP->fx_addsy
23741 && ! S_IS_DEFINED (fixP->fx_addsy))
23742 {
23743 as_bad_where (fixP->fx_file, fixP->fx_line,
23744 _("undefined symbol %s used as an immediate value"),
23745 S_GET_NAME (fixP->fx_addsy));
23746 break;
23747 }
404ff6b5 23748
c19d1205
ZW
23749 newval = md_chars_to_number (buf, THUMB_SIZE);
23750 newval <<= 16;
23751 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23752
16805f35 23753 newimm = FAIL;
bada4342
JW
23754 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23755 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23756 Thumb2 modified immediate encoding (T2). */
23757 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 23758 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23759 {
23760 newimm = encode_thumb32_immediate (value);
23761 if (newimm == (unsigned int) FAIL)
23762 newimm = thumb32_negate_data_op (&newval, value);
23763 }
bada4342 23764 if (newimm == (unsigned int) FAIL)
92e90b6e 23765 {
bada4342 23766 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 23767 {
bada4342
JW
23768 /* Turn add/sum into addw/subw. */
23769 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23770 newval = (newval & 0xfeffffff) | 0x02000000;
23771 /* No flat 12-bit imm encoding for addsw/subsw. */
23772 if ((newval & 0x00100000) == 0)
40f246e3 23773 {
bada4342
JW
23774 /* 12 bit immediate for addw/subw. */
23775 if (value < 0)
23776 {
23777 value = -value;
23778 newval ^= 0x00a00000;
23779 }
23780 if (value > 0xfff)
23781 newimm = (unsigned int) FAIL;
23782 else
23783 newimm = value;
23784 }
23785 }
23786 else
23787 {
23788 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23789 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23790 disassembling, MOV is preferred when there is no encoding
db7bf105 23791 overlap. */
bada4342 23792 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
db7bf105
NC
23793 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
23794 but with the Rn field [19:16] set to 1111. */
23795 && (((newval >> 16) & 0xf) == 0xf)
bada4342
JW
23796 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23797 && !((newval >> T2_SBIT_SHIFT) & 0x1)
db7bf105 23798 && value >= 0 && value <= 0xffff)
bada4342
JW
23799 {
23800 /* Toggle bit[25] to change encoding from T2 to T3. */
23801 newval ^= 1 << 25;
23802 /* Clear bits[19:16]. */
23803 newval &= 0xfff0ffff;
23804 /* Encoding high 4bits imm. Code below will encode the
23805 remaining low 12bits. */
23806 newval |= (value & 0x0000f000) << 4;
23807 newimm = value & 0x00000fff;
40f246e3 23808 }
e9f89963 23809 }
92e90b6e 23810 }
cc8a6dd0 23811
c19d1205 23812 if (newimm == (unsigned int)FAIL)
3631a3c8 23813 {
c19d1205
ZW
23814 as_bad_where (fixP->fx_file, fixP->fx_line,
23815 _("invalid constant (%lx) after fixup"),
23816 (unsigned long) value);
23817 break;
3631a3c8
NC
23818 }
23819
c19d1205
ZW
23820 newval |= (newimm & 0x800) << 15;
23821 newval |= (newimm & 0x700) << 4;
23822 newval |= (newimm & 0x0ff);
cc8a6dd0 23823
c19d1205
ZW
23824 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23825 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23826 break;
a737bd4d 23827
3eb17e6b 23828 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23829 if (((unsigned long) value) > 0xffff)
23830 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23831 _("invalid smc expression"));
2fc8bdac 23832 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23833 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23834 md_number_to_chars (buf, newval, INSN_SIZE);
23835 break;
a737bd4d 23836
90ec0d68
MGD
23837 case BFD_RELOC_ARM_HVC:
23838 if (((unsigned long) value) > 0xffff)
23839 as_bad_where (fixP->fx_file, fixP->fx_line,
23840 _("invalid hvc expression"));
23841 newval = md_chars_to_number (buf, INSN_SIZE);
23842 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23843 md_number_to_chars (buf, newval, INSN_SIZE);
23844 break;
23845
c19d1205 23846 case BFD_RELOC_ARM_SWI:
adbaf948 23847 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23848 {
23849 if (((unsigned long) value) > 0xff)
23850 as_bad_where (fixP->fx_file, fixP->fx_line,
23851 _("invalid swi expression"));
2fc8bdac 23852 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23853 newval |= value;
23854 md_number_to_chars (buf, newval, THUMB_SIZE);
23855 }
23856 else
23857 {
23858 if (((unsigned long) value) > 0x00ffffff)
23859 as_bad_where (fixP->fx_file, fixP->fx_line,
23860 _("invalid swi expression"));
2fc8bdac 23861 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23862 newval |= value;
23863 md_number_to_chars (buf, newval, INSN_SIZE);
23864 }
23865 break;
a737bd4d 23866
c19d1205
ZW
23867 case BFD_RELOC_ARM_MULTI:
23868 if (((unsigned long) value) > 0xffff)
23869 as_bad_where (fixP->fx_file, fixP->fx_line,
23870 _("invalid expression in load/store multiple"));
23871 newval = value | md_chars_to_number (buf, INSN_SIZE);
23872 md_number_to_chars (buf, newval, INSN_SIZE);
23873 break;
a737bd4d 23874
c19d1205 23875#ifdef OBJ_ELF
39b41c9c 23876 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23877
23878 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23879 && fixP->fx_addsy
34e77a92 23880 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23881 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23882 && THUMB_IS_FUNC (fixP->fx_addsy))
23883 /* Flip the bl to blx. This is a simple flip
23884 bit here because we generate PCREL_CALL for
23885 unconditional bls. */
23886 {
23887 newval = md_chars_to_number (buf, INSN_SIZE);
23888 newval = newval | 0x10000000;
23889 md_number_to_chars (buf, newval, INSN_SIZE);
23890 temp = 1;
23891 fixP->fx_done = 1;
23892 }
39b41c9c
PB
23893 else
23894 temp = 3;
23895 goto arm_branch_common;
23896
23897 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23898 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23899 && fixP->fx_addsy
34e77a92 23900 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23901 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23902 && THUMB_IS_FUNC (fixP->fx_addsy))
23903 {
23904 /* This would map to a bl<cond>, b<cond>,
23905 b<always> to a Thumb function. We
23906 need to force a relocation for this particular
23907 case. */
23908 newval = md_chars_to_number (buf, INSN_SIZE);
23909 fixP->fx_done = 0;
23910 }
1a0670f3 23911 /* Fall through. */
267bf995 23912
2fc8bdac 23913 case BFD_RELOC_ARM_PLT32:
c19d1205 23914#endif
39b41c9c
PB
23915 case BFD_RELOC_ARM_PCREL_BRANCH:
23916 temp = 3;
23917 goto arm_branch_common;
a737bd4d 23918
39b41c9c 23919 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23920
39b41c9c 23921 temp = 1;
267bf995
RR
23922 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23923 && fixP->fx_addsy
34e77a92 23924 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23925 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23926 && ARM_IS_FUNC (fixP->fx_addsy))
23927 {
23928 /* Flip the blx to a bl and warn. */
23929 const char *name = S_GET_NAME (fixP->fx_addsy);
23930 newval = 0xeb000000;
23931 as_warn_where (fixP->fx_file, fixP->fx_line,
23932 _("blx to '%s' an ARM ISA state function changed to bl"),
23933 name);
23934 md_number_to_chars (buf, newval, INSN_SIZE);
23935 temp = 3;
23936 fixP->fx_done = 1;
23937 }
23938
23939#ifdef OBJ_ELF
23940 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23941 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23942#endif
23943
39b41c9c 23944 arm_branch_common:
c19d1205 23945 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23946 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23947 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 23948 also be clear. */
39b41c9c 23949 if (value & temp)
c19d1205 23950 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23951 _("misaligned branch destination"));
23952 if ((value & (offsetT)0xfe000000) != (offsetT)0
23953 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23954 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23955
2fc8bdac 23956 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23957 {
2fc8bdac
ZW
23958 newval = md_chars_to_number (buf, INSN_SIZE);
23959 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23960 /* Set the H bit on BLX instructions. */
23961 if (temp == 1)
23962 {
23963 if (value & 2)
23964 newval |= 0x01000000;
23965 else
23966 newval &= ~0x01000000;
23967 }
2fc8bdac 23968 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23969 }
c19d1205 23970 break;
a737bd4d 23971
25fe350b
MS
23972 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23973 /* CBZ can only branch forward. */
a737bd4d 23974
738755b0 23975 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23976 (which, strictly speaking, are prohibited) will be turned into
23977 no-ops.
738755b0
MS
23978
23979 FIXME: It may be better to remove the instruction completely and
23980 perform relaxation. */
23981 if (value == -2)
2fc8bdac
ZW
23982 {
23983 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23984 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23985 md_number_to_chars (buf, newval, THUMB_SIZE);
23986 }
738755b0
MS
23987 else
23988 {
23989 if (value & ~0x7e)
08f10d51 23990 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23991
477330fc 23992 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23993 {
23994 newval = md_chars_to_number (buf, THUMB_SIZE);
23995 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23996 md_number_to_chars (buf, newval, THUMB_SIZE);
23997 }
23998 }
c19d1205 23999 break;
a737bd4d 24000
c19d1205 24001 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 24002 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 24003 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 24004
2fc8bdac
ZW
24005 if (fixP->fx_done || !seg->use_rela_p)
24006 {
24007 newval = md_chars_to_number (buf, THUMB_SIZE);
24008 newval |= (value & 0x1ff) >> 1;
24009 md_number_to_chars (buf, newval, THUMB_SIZE);
24010 }
c19d1205 24011 break;
a737bd4d 24012
c19d1205 24013 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 24014 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 24015 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 24016
2fc8bdac
ZW
24017 if (fixP->fx_done || !seg->use_rela_p)
24018 {
24019 newval = md_chars_to_number (buf, THUMB_SIZE);
24020 newval |= (value & 0xfff) >> 1;
24021 md_number_to_chars (buf, newval, THUMB_SIZE);
24022 }
c19d1205 24023 break;
a737bd4d 24024
c19d1205 24025 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
24026 if (fixP->fx_addsy
24027 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 24028 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24029 && ARM_IS_FUNC (fixP->fx_addsy)
24030 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
24031 {
24032 /* Force a relocation for a branch 20 bits wide. */
24033 fixP->fx_done = 0;
24034 }
08f10d51 24035 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
24036 as_bad_where (fixP->fx_file, fixP->fx_line,
24037 _("conditional branch out of range"));
404ff6b5 24038
2fc8bdac
ZW
24039 if (fixP->fx_done || !seg->use_rela_p)
24040 {
24041 offsetT newval2;
24042 addressT S, J1, J2, lo, hi;
404ff6b5 24043
2fc8bdac
ZW
24044 S = (value & 0x00100000) >> 20;
24045 J2 = (value & 0x00080000) >> 19;
24046 J1 = (value & 0x00040000) >> 18;
24047 hi = (value & 0x0003f000) >> 12;
24048 lo = (value & 0x00000ffe) >> 1;
6c43fab6 24049
2fc8bdac
ZW
24050 newval = md_chars_to_number (buf, THUMB_SIZE);
24051 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24052 newval |= (S << 10) | hi;
24053 newval2 |= (J1 << 13) | (J2 << 11) | lo;
24054 md_number_to_chars (buf, newval, THUMB_SIZE);
24055 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
24056 }
c19d1205 24057 break;
6c43fab6 24058
c19d1205 24059 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
24060 /* If there is a blx from a thumb state function to
24061 another thumb function flip this to a bl and warn
24062 about it. */
24063
24064 if (fixP->fx_addsy
34e77a92 24065 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24066 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24067 && THUMB_IS_FUNC (fixP->fx_addsy))
24068 {
24069 const char *name = S_GET_NAME (fixP->fx_addsy);
24070 as_warn_where (fixP->fx_file, fixP->fx_line,
24071 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
24072 name);
24073 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24074 newval = newval | 0x1000;
24075 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
24076 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
24077 fixP->fx_done = 1;
24078 }
24079
24080
24081 goto thumb_bl_common;
24082
c19d1205 24083 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
24084 /* A bl from Thumb state ISA to an internal ARM state function
24085 is converted to a blx. */
24086 if (fixP->fx_addsy
24087 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 24088 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24089 && ARM_IS_FUNC (fixP->fx_addsy)
24090 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
24091 {
24092 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24093 newval = newval & ~0x1000;
24094 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
24095 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
24096 fixP->fx_done = 1;
24097 }
24098
24099 thumb_bl_common:
24100
2fc8bdac
ZW
24101 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
24102 /* For a BLX instruction, make sure that the relocation is rounded up
24103 to a word boundary. This follows the semantics of the instruction
24104 which specifies that bit 1 of the target address will come from bit
24105 1 of the base address. */
d406f3e4
JB
24106 value = (value + 3) & ~ 3;
24107
24108#ifdef OBJ_ELF
24109 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
24110 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
24111 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
24112#endif
404ff6b5 24113
2b2f5df9
NC
24114 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
24115 {
fc289b0a 24116 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
24117 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
24118 else if ((value & ~0x1ffffff)
24119 && ((value & ~0x1ffffff) != ~0x1ffffff))
24120 as_bad_where (fixP->fx_file, fixP->fx_line,
24121 _("Thumb2 branch out of range"));
24122 }
4a42ebbc
RR
24123
24124 if (fixP->fx_done || !seg->use_rela_p)
24125 encode_thumb2_b_bl_offset (buf, value);
24126
c19d1205 24127 break;
404ff6b5 24128
c19d1205 24129 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
24130 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
24131 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 24132
2fc8bdac 24133 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 24134 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 24135
2fc8bdac 24136 break;
a737bd4d 24137
2fc8bdac
ZW
24138 case BFD_RELOC_8:
24139 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 24140 *buf = value;
c19d1205 24141 break;
a737bd4d 24142
c19d1205 24143 case BFD_RELOC_16:
2fc8bdac 24144 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 24145 md_number_to_chars (buf, value, 2);
c19d1205 24146 break;
a737bd4d 24147
c19d1205 24148#ifdef OBJ_ELF
0855e32b
NS
24149 case BFD_RELOC_ARM_TLS_CALL:
24150 case BFD_RELOC_ARM_THM_TLS_CALL:
24151 case BFD_RELOC_ARM_TLS_DESCSEQ:
24152 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 24153 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
24154 case BFD_RELOC_ARM_TLS_GD32:
24155 case BFD_RELOC_ARM_TLS_LE32:
24156 case BFD_RELOC_ARM_TLS_IE32:
24157 case BFD_RELOC_ARM_TLS_LDM32:
24158 case BFD_RELOC_ARM_TLS_LDO32:
24159 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 24160 break;
6c43fab6 24161
5c5a4843
CL
24162 /* Same handling as above, but with the arm_fdpic guard. */
24163 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
24164 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
24165 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
24166 if (arm_fdpic)
24167 {
24168 S_SET_THREAD_LOCAL (fixP->fx_addsy);
24169 }
24170 else
24171 {
24172 as_bad_where (fixP->fx_file, fixP->fx_line,
24173 _("Relocation supported only in FDPIC mode"));
24174 }
24175 break;
24176
c19d1205
ZW
24177 case BFD_RELOC_ARM_GOT32:
24178 case BFD_RELOC_ARM_GOTOFF:
c19d1205 24179 break;
b43420e6
NC
24180
24181 case BFD_RELOC_ARM_GOT_PREL:
24182 if (fixP->fx_done || !seg->use_rela_p)
477330fc 24183 md_number_to_chars (buf, value, 4);
b43420e6
NC
24184 break;
24185
9a6f4e97
NS
24186 case BFD_RELOC_ARM_TARGET2:
24187 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
24188 addend here for REL targets, because it won't be written out
24189 during reloc processing later. */
9a6f4e97
NS
24190 if (fixP->fx_done || !seg->use_rela_p)
24191 md_number_to_chars (buf, fixP->fx_offset, 4);
24192 break;
188fd7ae
CL
24193
24194 /* Relocations for FDPIC. */
24195 case BFD_RELOC_ARM_GOTFUNCDESC:
24196 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
24197 case BFD_RELOC_ARM_FUNCDESC:
24198 if (arm_fdpic)
24199 {
24200 if (fixP->fx_done || !seg->use_rela_p)
24201 md_number_to_chars (buf, 0, 4);
24202 }
24203 else
24204 {
24205 as_bad_where (fixP->fx_file, fixP->fx_line,
24206 _("Relocation supported only in FDPIC mode"));
24207 }
24208 break;
c19d1205 24209#endif
6c43fab6 24210
c19d1205
ZW
24211 case BFD_RELOC_RVA:
24212 case BFD_RELOC_32:
24213 case BFD_RELOC_ARM_TARGET1:
24214 case BFD_RELOC_ARM_ROSEGREL32:
24215 case BFD_RELOC_ARM_SBREL32:
24216 case BFD_RELOC_32_PCREL:
f0927246
NC
24217#ifdef TE_PE
24218 case BFD_RELOC_32_SECREL:
24219#endif
2fc8bdac 24220 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
24221#ifdef TE_WINCE
24222 /* For WinCE we only do this for pcrel fixups. */
24223 if (fixP->fx_done || fixP->fx_pcrel)
24224#endif
24225 md_number_to_chars (buf, value, 4);
c19d1205 24226 break;
6c43fab6 24227
c19d1205
ZW
24228#ifdef OBJ_ELF
24229 case BFD_RELOC_ARM_PREL31:
2fc8bdac 24230 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
24231 {
24232 newval = md_chars_to_number (buf, 4) & 0x80000000;
24233 if ((value ^ (value >> 1)) & 0x40000000)
24234 {
24235 as_bad_where (fixP->fx_file, fixP->fx_line,
24236 _("rel31 relocation overflow"));
24237 }
24238 newval |= value & 0x7fffffff;
24239 md_number_to_chars (buf, newval, 4);
24240 }
24241 break;
c19d1205 24242#endif
a737bd4d 24243
c19d1205 24244 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 24245 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
24246 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
24247 newval = md_chars_to_number (buf, INSN_SIZE);
24248 else
24249 newval = get_thumb32_insn (buf);
24250 if ((newval & 0x0f200f00) == 0x0d000900)
24251 {
24252 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
24253 has permitted values that are multiples of 2, in the range 0
24254 to 510. */
24255 if (value < -510 || value > 510 || (value & 1))
24256 as_bad_where (fixP->fx_file, fixP->fx_line,
24257 _("co-processor offset out of range"));
24258 }
24259 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
24260 as_bad_where (fixP->fx_file, fixP->fx_line,
24261 _("co-processor offset out of range"));
24262 cp_off_common:
26d97720 24263 sign = value > 0;
c19d1205
ZW
24264 if (value < 0)
24265 value = -value;
8f06b2d8
PB
24266 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24267 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24268 newval = md_chars_to_number (buf, INSN_SIZE);
24269 else
24270 newval = get_thumb32_insn (buf);
26d97720
NS
24271 if (value == 0)
24272 newval &= 0xffffff00;
24273 else
24274 {
24275 newval &= 0xff7fff00;
9db2f6b4
RL
24276 if ((newval & 0x0f200f00) == 0x0d000900)
24277 {
24278 /* This is a fp16 vstr/vldr.
24279
24280 It requires the immediate offset in the instruction is shifted
24281 left by 1 to be a half-word offset.
24282
24283 Here, left shift by 1 first, and later right shift by 2
24284 should get the right offset. */
24285 value <<= 1;
24286 }
26d97720
NS
24287 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
24288 }
8f06b2d8
PB
24289 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24290 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24291 md_number_to_chars (buf, newval, INSN_SIZE);
24292 else
24293 put_thumb32_insn (buf, newval);
c19d1205 24294 break;
a737bd4d 24295
c19d1205 24296 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 24297 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
24298 if (value < -255 || value > 255)
24299 as_bad_where (fixP->fx_file, fixP->fx_line,
24300 _("co-processor offset out of range"));
df7849c5 24301 value *= 4;
c19d1205 24302 goto cp_off_common;
6c43fab6 24303
c19d1205
ZW
24304 case BFD_RELOC_ARM_THUMB_OFFSET:
24305 newval = md_chars_to_number (buf, THUMB_SIZE);
24306 /* Exactly what ranges, and where the offset is inserted depends
24307 on the type of instruction, we can establish this from the
24308 top 4 bits. */
24309 switch (newval >> 12)
24310 {
24311 case 4: /* PC load. */
24312 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
24313 forced to zero for these loads; md_pcrel_from has already
24314 compensated for this. */
24315 if (value & 3)
24316 as_bad_where (fixP->fx_file, fixP->fx_line,
24317 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
24318 (((unsigned long) fixP->fx_frag->fr_address
24319 + (unsigned long) fixP->fx_where) & ~3)
24320 + (unsigned long) value);
a737bd4d 24321
c19d1205
ZW
24322 if (value & ~0x3fc)
24323 as_bad_where (fixP->fx_file, fixP->fx_line,
24324 _("invalid offset, value too big (0x%08lX)"),
24325 (long) value);
a737bd4d 24326
c19d1205
ZW
24327 newval |= value >> 2;
24328 break;
a737bd4d 24329
c19d1205
ZW
24330 case 9: /* SP load/store. */
24331 if (value & ~0x3fc)
24332 as_bad_where (fixP->fx_file, fixP->fx_line,
24333 _("invalid offset, value too big (0x%08lX)"),
24334 (long) value);
24335 newval |= value >> 2;
24336 break;
6c43fab6 24337
c19d1205
ZW
24338 case 6: /* Word load/store. */
24339 if (value & ~0x7c)
24340 as_bad_where (fixP->fx_file, fixP->fx_line,
24341 _("invalid offset, value too big (0x%08lX)"),
24342 (long) value);
24343 newval |= value << 4; /* 6 - 2. */
24344 break;
a737bd4d 24345
c19d1205
ZW
24346 case 7: /* Byte load/store. */
24347 if (value & ~0x1f)
24348 as_bad_where (fixP->fx_file, fixP->fx_line,
24349 _("invalid offset, value too big (0x%08lX)"),
24350 (long) value);
24351 newval |= value << 6;
24352 break;
a737bd4d 24353
c19d1205
ZW
24354 case 8: /* Halfword load/store. */
24355 if (value & ~0x3e)
24356 as_bad_where (fixP->fx_file, fixP->fx_line,
24357 _("invalid offset, value too big (0x%08lX)"),
24358 (long) value);
24359 newval |= value << 5; /* 6 - 1. */
24360 break;
a737bd4d 24361
c19d1205
ZW
24362 default:
24363 as_bad_where (fixP->fx_file, fixP->fx_line,
24364 "Unable to process relocation for thumb opcode: %lx",
24365 (unsigned long) newval);
24366 break;
24367 }
24368 md_number_to_chars (buf, newval, THUMB_SIZE);
24369 break;
a737bd4d 24370
c19d1205
ZW
24371 case BFD_RELOC_ARM_THUMB_ADD:
24372 /* This is a complicated relocation, since we use it for all of
24373 the following immediate relocations:
a737bd4d 24374
c19d1205
ZW
24375 3bit ADD/SUB
24376 8bit ADD/SUB
24377 9bit ADD/SUB SP word-aligned
24378 10bit ADD PC/SP word-aligned
a737bd4d 24379
c19d1205
ZW
24380 The type of instruction being processed is encoded in the
24381 instruction field:
a737bd4d 24382
c19d1205
ZW
24383 0x8000 SUB
24384 0x00F0 Rd
24385 0x000F Rs
24386 */
24387 newval = md_chars_to_number (buf, THUMB_SIZE);
24388 {
24389 int rd = (newval >> 4) & 0xf;
24390 int rs = newval & 0xf;
24391 int subtract = !!(newval & 0x8000);
a737bd4d 24392
c19d1205
ZW
24393 /* Check for HI regs, only very restricted cases allowed:
24394 Adjusting SP, and using PC or SP to get an address. */
24395 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
24396 || (rs > 7 && rs != REG_SP && rs != REG_PC))
24397 as_bad_where (fixP->fx_file, fixP->fx_line,
24398 _("invalid Hi register with immediate"));
a737bd4d 24399
c19d1205
ZW
24400 /* If value is negative, choose the opposite instruction. */
24401 if (value < 0)
24402 {
24403 value = -value;
24404 subtract = !subtract;
24405 if (value < 0)
24406 as_bad_where (fixP->fx_file, fixP->fx_line,
24407 _("immediate value out of range"));
24408 }
a737bd4d 24409
c19d1205
ZW
24410 if (rd == REG_SP)
24411 {
75c11999 24412 if (value & ~0x1fc)
c19d1205
ZW
24413 as_bad_where (fixP->fx_file, fixP->fx_line,
24414 _("invalid immediate for stack address calculation"));
24415 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
24416 newval |= value >> 2;
24417 }
24418 else if (rs == REG_PC || rs == REG_SP)
24419 {
c12d2c9d
NC
24420 /* PR gas/18541. If the addition is for a defined symbol
24421 within range of an ADR instruction then accept it. */
24422 if (subtract
24423 && value == 4
24424 && fixP->fx_addsy != NULL)
24425 {
24426 subtract = 0;
24427
24428 if (! S_IS_DEFINED (fixP->fx_addsy)
24429 || S_GET_SEGMENT (fixP->fx_addsy) != seg
24430 || S_IS_WEAK (fixP->fx_addsy))
24431 {
24432 as_bad_where (fixP->fx_file, fixP->fx_line,
24433 _("address calculation needs a strongly defined nearby symbol"));
24434 }
24435 else
24436 {
24437 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
24438
24439 /* Round up to the next 4-byte boundary. */
24440 if (v & 3)
24441 v = (v + 3) & ~ 3;
24442 else
24443 v += 4;
24444 v = S_GET_VALUE (fixP->fx_addsy) - v;
24445
24446 if (v & ~0x3fc)
24447 {
24448 as_bad_where (fixP->fx_file, fixP->fx_line,
24449 _("symbol too far away"));
24450 }
24451 else
24452 {
24453 fixP->fx_done = 1;
24454 value = v;
24455 }
24456 }
24457 }
24458
c19d1205
ZW
24459 if (subtract || value & ~0x3fc)
24460 as_bad_where (fixP->fx_file, fixP->fx_line,
24461 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 24462 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
24463 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
24464 newval |= rd << 8;
24465 newval |= value >> 2;
24466 }
24467 else if (rs == rd)
24468 {
24469 if (value & ~0xff)
24470 as_bad_where (fixP->fx_file, fixP->fx_line,
24471 _("immediate value out of range"));
24472 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
24473 newval |= (rd << 8) | value;
24474 }
24475 else
24476 {
24477 if (value & ~0x7)
24478 as_bad_where (fixP->fx_file, fixP->fx_line,
24479 _("immediate value out of range"));
24480 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
24481 newval |= rd | (rs << 3) | (value << 6);
24482 }
24483 }
24484 md_number_to_chars (buf, newval, THUMB_SIZE);
24485 break;
a737bd4d 24486
c19d1205
ZW
24487 case BFD_RELOC_ARM_THUMB_IMM:
24488 newval = md_chars_to_number (buf, THUMB_SIZE);
24489 if (value < 0 || value > 255)
24490 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 24491 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
24492 (long) value);
24493 newval |= value;
24494 md_number_to_chars (buf, newval, THUMB_SIZE);
24495 break;
a737bd4d 24496
c19d1205
ZW
24497 case BFD_RELOC_ARM_THUMB_SHIFT:
24498 /* 5bit shift value (0..32). LSL cannot take 32. */
24499 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
24500 temp = newval & 0xf800;
24501 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
24502 as_bad_where (fixP->fx_file, fixP->fx_line,
24503 _("invalid shift value: %ld"), (long) value);
24504 /* Shifts of zero must be encoded as LSL. */
24505 if (value == 0)
24506 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
24507 /* Shifts of 32 are encoded as zero. */
24508 else if (value == 32)
24509 value = 0;
24510 newval |= value << 6;
24511 md_number_to_chars (buf, newval, THUMB_SIZE);
24512 break;
a737bd4d 24513
c19d1205
ZW
24514 case BFD_RELOC_VTABLE_INHERIT:
24515 case BFD_RELOC_VTABLE_ENTRY:
24516 fixP->fx_done = 0;
24517 return;
6c43fab6 24518
b6895b4f
PB
24519 case BFD_RELOC_ARM_MOVW:
24520 case BFD_RELOC_ARM_MOVT:
24521 case BFD_RELOC_ARM_THUMB_MOVW:
24522 case BFD_RELOC_ARM_THUMB_MOVT:
24523 if (fixP->fx_done || !seg->use_rela_p)
24524 {
24525 /* REL format relocations are limited to a 16-bit addend. */
24526 if (!fixP->fx_done)
24527 {
39623e12 24528 if (value < -0x8000 || value > 0x7fff)
b6895b4f 24529 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 24530 _("offset out of range"));
b6895b4f
PB
24531 }
24532 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24533 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24534 {
24535 value >>= 16;
24536 }
24537
24538 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24539 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24540 {
24541 newval = get_thumb32_insn (buf);
24542 newval &= 0xfbf08f00;
24543 newval |= (value & 0xf000) << 4;
24544 newval |= (value & 0x0800) << 15;
24545 newval |= (value & 0x0700) << 4;
24546 newval |= (value & 0x00ff);
24547 put_thumb32_insn (buf, newval);
24548 }
24549 else
24550 {
24551 newval = md_chars_to_number (buf, 4);
24552 newval &= 0xfff0f000;
24553 newval |= value & 0x0fff;
24554 newval |= (value & 0xf000) << 4;
24555 md_number_to_chars (buf, newval, 4);
24556 }
24557 }
24558 return;
24559
72d98d16
MG
24560 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24561 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24562 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24563 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24564 gas_assert (!fixP->fx_done);
24565 {
24566 bfd_vma insn;
24567 bfd_boolean is_mov;
24568 bfd_vma encoded_addend = value;
24569
24570 /* Check that addend can be encoded in instruction. */
24571 if (!seg->use_rela_p && (value < 0 || value > 255))
24572 as_bad_where (fixP->fx_file, fixP->fx_line,
24573 _("the offset 0x%08lX is not representable"),
24574 (unsigned long) encoded_addend);
24575
24576 /* Extract the instruction. */
24577 insn = md_chars_to_number (buf, THUMB_SIZE);
24578 is_mov = (insn & 0xf800) == 0x2000;
24579
24580 /* Encode insn. */
24581 if (is_mov)
24582 {
24583 if (!seg->use_rela_p)
24584 insn |= encoded_addend;
24585 }
24586 else
24587 {
24588 int rd, rs;
24589
24590 /* Extract the instruction. */
24591 /* Encoding is the following
24592 0x8000 SUB
24593 0x00F0 Rd
24594 0x000F Rs
24595 */
24596 /* The following conditions must be true :
24597 - ADD
24598 - Rd == Rs
24599 - Rd <= 7
24600 */
24601 rd = (insn >> 4) & 0xf;
24602 rs = insn & 0xf;
24603 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24604 as_bad_where (fixP->fx_file, fixP->fx_line,
24605 _("Unable to process relocation for thumb opcode: %lx"),
24606 (unsigned long) insn);
24607
24608 /* Encode as ADD immediate8 thumb 1 code. */
24609 insn = 0x3000 | (rd << 8);
24610
24611 /* Place the encoded addend into the first 8 bits of the
24612 instruction. */
24613 if (!seg->use_rela_p)
24614 insn |= encoded_addend;
24615 }
24616
24617 /* Update the instruction. */
24618 md_number_to_chars (buf, insn, THUMB_SIZE);
24619 }
24620 break;
24621
4962c51a
MS
24622 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24623 case BFD_RELOC_ARM_ALU_PC_G0:
24624 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24625 case BFD_RELOC_ARM_ALU_PC_G1:
24626 case BFD_RELOC_ARM_ALU_PC_G2:
24627 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24628 case BFD_RELOC_ARM_ALU_SB_G0:
24629 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24630 case BFD_RELOC_ARM_ALU_SB_G1:
24631 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 24632 gas_assert (!fixP->fx_done);
4962c51a
MS
24633 if (!seg->use_rela_p)
24634 {
477330fc
RM
24635 bfd_vma insn;
24636 bfd_vma encoded_addend;
3ca4a8ec 24637 bfd_vma addend_abs = llabs (value);
477330fc
RM
24638
24639 /* Check that the absolute value of the addend can be
24640 expressed as an 8-bit constant plus a rotation. */
24641 encoded_addend = encode_arm_immediate (addend_abs);
24642 if (encoded_addend == (unsigned int) FAIL)
4962c51a 24643 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24644 _("the offset 0x%08lX is not representable"),
24645 (unsigned long) addend_abs);
24646
24647 /* Extract the instruction. */
24648 insn = md_chars_to_number (buf, INSN_SIZE);
24649
24650 /* If the addend is positive, use an ADD instruction.
24651 Otherwise use a SUB. Take care not to destroy the S bit. */
24652 insn &= 0xff1fffff;
24653 if (value < 0)
24654 insn |= 1 << 22;
24655 else
24656 insn |= 1 << 23;
24657
24658 /* Place the encoded addend into the first 12 bits of the
24659 instruction. */
24660 insn &= 0xfffff000;
24661 insn |= encoded_addend;
24662
24663 /* Update the instruction. */
24664 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
24665 }
24666 break;
24667
24668 case BFD_RELOC_ARM_LDR_PC_G0:
24669 case BFD_RELOC_ARM_LDR_PC_G1:
24670 case BFD_RELOC_ARM_LDR_PC_G2:
24671 case BFD_RELOC_ARM_LDR_SB_G0:
24672 case BFD_RELOC_ARM_LDR_SB_G1:
24673 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 24674 gas_assert (!fixP->fx_done);
4962c51a 24675 if (!seg->use_rela_p)
477330fc
RM
24676 {
24677 bfd_vma insn;
3ca4a8ec 24678 bfd_vma addend_abs = llabs (value);
4962c51a 24679
477330fc
RM
24680 /* Check that the absolute value of the addend can be
24681 encoded in 12 bits. */
24682 if (addend_abs >= 0x1000)
4962c51a 24683 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24684 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24685 (unsigned long) addend_abs);
24686
24687 /* Extract the instruction. */
24688 insn = md_chars_to_number (buf, INSN_SIZE);
24689
24690 /* If the addend is negative, clear bit 23 of the instruction.
24691 Otherwise set it. */
24692 if (value < 0)
24693 insn &= ~(1 << 23);
24694 else
24695 insn |= 1 << 23;
24696
24697 /* Place the absolute value of the addend into the first 12 bits
24698 of the instruction. */
24699 insn &= 0xfffff000;
24700 insn |= addend_abs;
24701
24702 /* Update the instruction. */
24703 md_number_to_chars (buf, insn, INSN_SIZE);
24704 }
4962c51a
MS
24705 break;
24706
24707 case BFD_RELOC_ARM_LDRS_PC_G0:
24708 case BFD_RELOC_ARM_LDRS_PC_G1:
24709 case BFD_RELOC_ARM_LDRS_PC_G2:
24710 case BFD_RELOC_ARM_LDRS_SB_G0:
24711 case BFD_RELOC_ARM_LDRS_SB_G1:
24712 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 24713 gas_assert (!fixP->fx_done);
4962c51a 24714 if (!seg->use_rela_p)
477330fc
RM
24715 {
24716 bfd_vma insn;
3ca4a8ec 24717 bfd_vma addend_abs = llabs (value);
4962c51a 24718
477330fc
RM
24719 /* Check that the absolute value of the addend can be
24720 encoded in 8 bits. */
24721 if (addend_abs >= 0x100)
4962c51a 24722 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24723 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24724 (unsigned long) addend_abs);
24725
24726 /* Extract the instruction. */
24727 insn = md_chars_to_number (buf, INSN_SIZE);
24728
24729 /* If the addend is negative, clear bit 23 of the instruction.
24730 Otherwise set it. */
24731 if (value < 0)
24732 insn &= ~(1 << 23);
24733 else
24734 insn |= 1 << 23;
24735
24736 /* Place the first four bits of the absolute value of the addend
24737 into the first 4 bits of the instruction, and the remaining
24738 four into bits 8 .. 11. */
24739 insn &= 0xfffff0f0;
24740 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24741
24742 /* Update the instruction. */
24743 md_number_to_chars (buf, insn, INSN_SIZE);
24744 }
4962c51a
MS
24745 break;
24746
24747 case BFD_RELOC_ARM_LDC_PC_G0:
24748 case BFD_RELOC_ARM_LDC_PC_G1:
24749 case BFD_RELOC_ARM_LDC_PC_G2:
24750 case BFD_RELOC_ARM_LDC_SB_G0:
24751 case BFD_RELOC_ARM_LDC_SB_G1:
24752 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 24753 gas_assert (!fixP->fx_done);
4962c51a 24754 if (!seg->use_rela_p)
477330fc
RM
24755 {
24756 bfd_vma insn;
3ca4a8ec 24757 bfd_vma addend_abs = llabs (value);
4962c51a 24758
477330fc
RM
24759 /* Check that the absolute value of the addend is a multiple of
24760 four and, when divided by four, fits in 8 bits. */
24761 if (addend_abs & 0x3)
4962c51a 24762 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24763 _("bad offset 0x%08lX (must be word-aligned)"),
24764 (unsigned long) addend_abs);
4962c51a 24765
477330fc 24766 if ((addend_abs >> 2) > 0xff)
4962c51a 24767 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24768 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24769 (unsigned long) addend_abs);
24770
24771 /* Extract the instruction. */
24772 insn = md_chars_to_number (buf, INSN_SIZE);
24773
24774 /* If the addend is negative, clear bit 23 of the instruction.
24775 Otherwise set it. */
24776 if (value < 0)
24777 insn &= ~(1 << 23);
24778 else
24779 insn |= 1 << 23;
24780
24781 /* Place the addend (divided by four) into the first eight
24782 bits of the instruction. */
24783 insn &= 0xfffffff0;
24784 insn |= addend_abs >> 2;
24785
24786 /* Update the instruction. */
24787 md_number_to_chars (buf, insn, INSN_SIZE);
24788 }
4962c51a
MS
24789 break;
24790
e12437dc
AV
24791 case BFD_RELOC_THUMB_PCREL_BRANCH5:
24792 if (fixP->fx_addsy
24793 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24794 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
24795 && ARM_IS_FUNC (fixP->fx_addsy)
24796 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
24797 {
24798 /* Force a relocation for a branch 5 bits wide. */
24799 fixP->fx_done = 0;
24800 }
24801 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
24802 as_bad_where (fixP->fx_file, fixP->fx_line,
24803 BAD_BRANCH_OFF);
24804
24805 if (fixP->fx_done || !seg->use_rela_p)
24806 {
24807 addressT boff = value >> 1;
24808
24809 newval = md_chars_to_number (buf, THUMB_SIZE);
24810 newval |= (boff << 7);
24811 md_number_to_chars (buf, newval, THUMB_SIZE);
24812 }
24813 break;
24814
e5d6e09e
AV
24815 case BFD_RELOC_ARM_THUMB_BF17:
24816 if (fixP->fx_addsy
24817 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24818 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
24819 && ARM_IS_FUNC (fixP->fx_addsy)
24820 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
24821 {
24822 /* Force a relocation for a branch 17 bits wide. */
24823 fixP->fx_done = 0;
24824 }
24825
24826 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
24827 as_bad_where (fixP->fx_file, fixP->fx_line,
24828 BAD_BRANCH_OFF);
24829
24830 if (fixP->fx_done || !seg->use_rela_p)
24831 {
24832 offsetT newval2;
24833 addressT immA, immB, immC;
24834
24835 immA = (value & 0x0001f000) >> 12;
24836 immB = (value & 0x00000ffc) >> 2;
24837 immC = (value & 0x00000002) >> 1;
24838
24839 newval = md_chars_to_number (buf, THUMB_SIZE);
24840 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24841 newval |= immA;
24842 newval2 |= (immC << 11) | (immB << 1);
24843 md_number_to_chars (buf, newval, THUMB_SIZE);
24844 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
24845 }
24846 break;
24847
845b51d6
PB
24848 case BFD_RELOC_ARM_V4BX:
24849 /* This will need to go in the object file. */
24850 fixP->fx_done = 0;
24851 break;
24852
c19d1205
ZW
24853 case BFD_RELOC_UNUSED:
24854 default:
24855 as_bad_where (fixP->fx_file, fixP->fx_line,
24856 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24857 }
6c43fab6
RE
24858}
24859
c19d1205
ZW
24860/* Translate internal representation of relocation info to BFD target
24861 format. */
a737bd4d 24862
c19d1205 24863arelent *
00a97672 24864tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24865{
c19d1205
ZW
24866 arelent * reloc;
24867 bfd_reloc_code_real_type code;
a737bd4d 24868
325801bd 24869 reloc = XNEW (arelent);
a737bd4d 24870
325801bd 24871 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24872 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24873 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24874
2fc8bdac 24875 if (fixp->fx_pcrel)
00a97672
RS
24876 {
24877 if (section->use_rela_p)
24878 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24879 else
24880 fixp->fx_offset = reloc->address;
24881 }
c19d1205 24882 reloc->addend = fixp->fx_offset;
a737bd4d 24883
c19d1205 24884 switch (fixp->fx_r_type)
a737bd4d 24885 {
c19d1205
ZW
24886 case BFD_RELOC_8:
24887 if (fixp->fx_pcrel)
24888 {
24889 code = BFD_RELOC_8_PCREL;
24890 break;
24891 }
1a0670f3 24892 /* Fall through. */
a737bd4d 24893
c19d1205
ZW
24894 case BFD_RELOC_16:
24895 if (fixp->fx_pcrel)
24896 {
24897 code = BFD_RELOC_16_PCREL;
24898 break;
24899 }
1a0670f3 24900 /* Fall through. */
6c43fab6 24901
c19d1205
ZW
24902 case BFD_RELOC_32:
24903 if (fixp->fx_pcrel)
24904 {
24905 code = BFD_RELOC_32_PCREL;
24906 break;
24907 }
1a0670f3 24908 /* Fall through. */
a737bd4d 24909
b6895b4f
PB
24910 case BFD_RELOC_ARM_MOVW:
24911 if (fixp->fx_pcrel)
24912 {
24913 code = BFD_RELOC_ARM_MOVW_PCREL;
24914 break;
24915 }
1a0670f3 24916 /* Fall through. */
b6895b4f
PB
24917
24918 case BFD_RELOC_ARM_MOVT:
24919 if (fixp->fx_pcrel)
24920 {
24921 code = BFD_RELOC_ARM_MOVT_PCREL;
24922 break;
24923 }
1a0670f3 24924 /* Fall through. */
b6895b4f
PB
24925
24926 case BFD_RELOC_ARM_THUMB_MOVW:
24927 if (fixp->fx_pcrel)
24928 {
24929 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24930 break;
24931 }
1a0670f3 24932 /* Fall through. */
b6895b4f
PB
24933
24934 case BFD_RELOC_ARM_THUMB_MOVT:
24935 if (fixp->fx_pcrel)
24936 {
24937 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24938 break;
24939 }
1a0670f3 24940 /* Fall through. */
b6895b4f 24941
c19d1205
ZW
24942 case BFD_RELOC_NONE:
24943 case BFD_RELOC_ARM_PCREL_BRANCH:
24944 case BFD_RELOC_ARM_PCREL_BLX:
24945 case BFD_RELOC_RVA:
24946 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24947 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24948 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24949 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24950 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24951 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24952 case BFD_RELOC_VTABLE_ENTRY:
24953 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24954#ifdef TE_PE
24955 case BFD_RELOC_32_SECREL:
24956#endif
c19d1205
ZW
24957 code = fixp->fx_r_type;
24958 break;
a737bd4d 24959
00adf2d4
JB
24960 case BFD_RELOC_THUMB_PCREL_BLX:
24961#ifdef OBJ_ELF
24962 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24963 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24964 else
24965#endif
24966 code = BFD_RELOC_THUMB_PCREL_BLX;
24967 break;
24968
c19d1205
ZW
24969 case BFD_RELOC_ARM_LITERAL:
24970 case BFD_RELOC_ARM_HWLITERAL:
24971 /* If this is called then the a literal has
24972 been referenced across a section boundary. */
24973 as_bad_where (fixp->fx_file, fixp->fx_line,
24974 _("literal referenced across section boundary"));
24975 return NULL;
a737bd4d 24976
c19d1205 24977#ifdef OBJ_ELF
0855e32b
NS
24978 case BFD_RELOC_ARM_TLS_CALL:
24979 case BFD_RELOC_ARM_THM_TLS_CALL:
24980 case BFD_RELOC_ARM_TLS_DESCSEQ:
24981 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24982 case BFD_RELOC_ARM_GOT32:
24983 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24984 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24985 case BFD_RELOC_ARM_PLT32:
24986 case BFD_RELOC_ARM_TARGET1:
24987 case BFD_RELOC_ARM_ROSEGREL32:
24988 case BFD_RELOC_ARM_SBREL32:
24989 case BFD_RELOC_ARM_PREL31:
24990 case BFD_RELOC_ARM_TARGET2:
c19d1205 24991 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24992 case BFD_RELOC_ARM_PCREL_CALL:
24993 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24994 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24995 case BFD_RELOC_ARM_ALU_PC_G0:
24996 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24997 case BFD_RELOC_ARM_ALU_PC_G1:
24998 case BFD_RELOC_ARM_ALU_PC_G2:
24999 case BFD_RELOC_ARM_LDR_PC_G0:
25000 case BFD_RELOC_ARM_LDR_PC_G1:
25001 case BFD_RELOC_ARM_LDR_PC_G2:
25002 case BFD_RELOC_ARM_LDRS_PC_G0:
25003 case BFD_RELOC_ARM_LDRS_PC_G1:
25004 case BFD_RELOC_ARM_LDRS_PC_G2:
25005 case BFD_RELOC_ARM_LDC_PC_G0:
25006 case BFD_RELOC_ARM_LDC_PC_G1:
25007 case BFD_RELOC_ARM_LDC_PC_G2:
25008 case BFD_RELOC_ARM_ALU_SB_G0_NC:
25009 case BFD_RELOC_ARM_ALU_SB_G0:
25010 case BFD_RELOC_ARM_ALU_SB_G1_NC:
25011 case BFD_RELOC_ARM_ALU_SB_G1:
25012 case BFD_RELOC_ARM_ALU_SB_G2:
25013 case BFD_RELOC_ARM_LDR_SB_G0:
25014 case BFD_RELOC_ARM_LDR_SB_G1:
25015 case BFD_RELOC_ARM_LDR_SB_G2:
25016 case BFD_RELOC_ARM_LDRS_SB_G0:
25017 case BFD_RELOC_ARM_LDRS_SB_G1:
25018 case BFD_RELOC_ARM_LDRS_SB_G2:
25019 case BFD_RELOC_ARM_LDC_SB_G0:
25020 case BFD_RELOC_ARM_LDC_SB_G1:
25021 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 25022 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
25023 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
25024 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
25025 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
25026 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
188fd7ae
CL
25027 case BFD_RELOC_ARM_GOTFUNCDESC:
25028 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
25029 case BFD_RELOC_ARM_FUNCDESC:
e5d6e09e 25030 case BFD_RELOC_ARM_THUMB_BF17:
c19d1205
ZW
25031 code = fixp->fx_r_type;
25032 break;
a737bd4d 25033
0855e32b 25034 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 25035 case BFD_RELOC_ARM_TLS_GD32:
5c5a4843 25036 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
75c11999 25037 case BFD_RELOC_ARM_TLS_LE32:
c19d1205 25038 case BFD_RELOC_ARM_TLS_IE32:
5c5a4843 25039 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
c19d1205 25040 case BFD_RELOC_ARM_TLS_LDM32:
5c5a4843 25041 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
c19d1205
ZW
25042 /* BFD will include the symbol's address in the addend.
25043 But we don't want that, so subtract it out again here. */
25044 if (!S_IS_COMMON (fixp->fx_addsy))
25045 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
25046 code = fixp->fx_r_type;
25047 break;
25048#endif
a737bd4d 25049
c19d1205
ZW
25050 case BFD_RELOC_ARM_IMMEDIATE:
25051 as_bad_where (fixp->fx_file, fixp->fx_line,
25052 _("internal relocation (type: IMMEDIATE) not fixed up"));
25053 return NULL;
a737bd4d 25054
c19d1205
ZW
25055 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
25056 as_bad_where (fixp->fx_file, fixp->fx_line,
25057 _("ADRL used for a symbol not defined in the same file"));
25058 return NULL;
a737bd4d 25059
e12437dc
AV
25060 case BFD_RELOC_THUMB_PCREL_BRANCH5:
25061 as_bad_where (fixp->fx_file, fixp->fx_line,
25062 _("%s used for a symbol not defined in the same file"),
25063 bfd_get_reloc_code_name (fixp->fx_r_type));
25064 return NULL;
25065
c19d1205 25066 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
25067 if (section->use_rela_p)
25068 {
25069 code = fixp->fx_r_type;
25070 break;
25071 }
25072
c19d1205
ZW
25073 if (fixp->fx_addsy != NULL
25074 && !S_IS_DEFINED (fixp->fx_addsy)
25075 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 25076 {
c19d1205
ZW
25077 as_bad_where (fixp->fx_file, fixp->fx_line,
25078 _("undefined local label `%s'"),
25079 S_GET_NAME (fixp->fx_addsy));
25080 return NULL;
a737bd4d
NC
25081 }
25082
c19d1205
ZW
25083 as_bad_where (fixp->fx_file, fixp->fx_line,
25084 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
25085 return NULL;
a737bd4d 25086
c19d1205
ZW
25087 default:
25088 {
e0471c16 25089 const char * type;
6c43fab6 25090
c19d1205
ZW
25091 switch (fixp->fx_r_type)
25092 {
25093 case BFD_RELOC_NONE: type = "NONE"; break;
25094 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
25095 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 25096 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
25097 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
25098 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
25099 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 25100 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 25101 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
25102 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
25103 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
25104 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
25105 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
25106 default: type = _("<unknown>"); break;
25107 }
25108 as_bad_where (fixp->fx_file, fixp->fx_line,
25109 _("cannot represent %s relocation in this object file format"),
25110 type);
25111 return NULL;
25112 }
a737bd4d 25113 }
6c43fab6 25114
c19d1205
ZW
25115#ifdef OBJ_ELF
25116 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
25117 && GOT_symbol
25118 && fixp->fx_addsy == GOT_symbol)
25119 {
25120 code = BFD_RELOC_ARM_GOTPC;
25121 reloc->addend = fixp->fx_offset = reloc->address;
25122 }
25123#endif
6c43fab6 25124
c19d1205 25125 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 25126
c19d1205
ZW
25127 if (reloc->howto == NULL)
25128 {
25129 as_bad_where (fixp->fx_file, fixp->fx_line,
25130 _("cannot represent %s relocation in this object file format"),
25131 bfd_get_reloc_code_name (code));
25132 return NULL;
25133 }
6c43fab6 25134
c19d1205
ZW
25135 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
25136 vtable entry to be used in the relocation's section offset. */
25137 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
25138 reloc->address = fixp->fx_offset;
6c43fab6 25139
c19d1205 25140 return reloc;
6c43fab6
RE
25141}
25142
c19d1205 25143/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 25144
c19d1205
ZW
25145void
25146cons_fix_new_arm (fragS * frag,
25147 int where,
25148 int size,
62ebcb5c
AM
25149 expressionS * exp,
25150 bfd_reloc_code_real_type reloc)
6c43fab6 25151{
c19d1205 25152 int pcrel = 0;
6c43fab6 25153
c19d1205
ZW
25154 /* Pick a reloc.
25155 FIXME: @@ Should look at CPU word size. */
25156 switch (size)
25157 {
25158 case 1:
62ebcb5c 25159 reloc = BFD_RELOC_8;
c19d1205
ZW
25160 break;
25161 case 2:
62ebcb5c 25162 reloc = BFD_RELOC_16;
c19d1205
ZW
25163 break;
25164 case 4:
25165 default:
62ebcb5c 25166 reloc = BFD_RELOC_32;
c19d1205
ZW
25167 break;
25168 case 8:
62ebcb5c 25169 reloc = BFD_RELOC_64;
c19d1205
ZW
25170 break;
25171 }
6c43fab6 25172
f0927246
NC
25173#ifdef TE_PE
25174 if (exp->X_op == O_secrel)
25175 {
25176 exp->X_op = O_symbol;
62ebcb5c 25177 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
25178 }
25179#endif
25180
62ebcb5c 25181 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 25182}
6c43fab6 25183
4343666d 25184#if defined (OBJ_COFF)
c19d1205
ZW
25185void
25186arm_validate_fix (fixS * fixP)
6c43fab6 25187{
c19d1205
ZW
25188 /* If the destination of the branch is a defined symbol which does not have
25189 the THUMB_FUNC attribute, then we must be calling a function which has
25190 the (interfacearm) attribute. We look for the Thumb entry point to that
25191 function and change the branch to refer to that function instead. */
25192 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
25193 && fixP->fx_addsy != NULL
25194 && S_IS_DEFINED (fixP->fx_addsy)
25195 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 25196 {
c19d1205 25197 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 25198 }
c19d1205
ZW
25199}
25200#endif
6c43fab6 25201
267bf995 25202
c19d1205
ZW
25203int
25204arm_force_relocation (struct fix * fixp)
25205{
25206#if defined (OBJ_COFF) && defined (TE_PE)
25207 if (fixp->fx_r_type == BFD_RELOC_RVA)
25208 return 1;
25209#endif
6c43fab6 25210
267bf995
RR
25211 /* In case we have a call or a branch to a function in ARM ISA mode from
25212 a thumb function or vice-versa force the relocation. These relocations
25213 are cleared off for some cores that might have blx and simple transformations
25214 are possible. */
25215
25216#ifdef OBJ_ELF
25217 switch (fixp->fx_r_type)
25218 {
25219 case BFD_RELOC_ARM_PCREL_JUMP:
25220 case BFD_RELOC_ARM_PCREL_CALL:
25221 case BFD_RELOC_THUMB_PCREL_BLX:
25222 if (THUMB_IS_FUNC (fixp->fx_addsy))
25223 return 1;
25224 break;
25225
25226 case BFD_RELOC_ARM_PCREL_BLX:
25227 case BFD_RELOC_THUMB_PCREL_BRANCH25:
25228 case BFD_RELOC_THUMB_PCREL_BRANCH20:
25229 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25230 if (ARM_IS_FUNC (fixp->fx_addsy))
25231 return 1;
25232 break;
25233
25234 default:
25235 break;
25236 }
25237#endif
25238
b5884301
PB
25239 /* Resolve these relocations even if the symbol is extern or weak.
25240 Technically this is probably wrong due to symbol preemption.
25241 In practice these relocations do not have enough range to be useful
25242 at dynamic link time, and some code (e.g. in the Linux kernel)
25243 expects these references to be resolved. */
c19d1205
ZW
25244 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
25245 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 25246 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 25247 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
25248 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
25249 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
25250 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 25251 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
25252 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
25253 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
25254 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
25255 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
25256 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
25257 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 25258 return 0;
a737bd4d 25259
4962c51a
MS
25260 /* Always leave these relocations for the linker. */
25261 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25262 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25263 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
25264 return 1;
25265
f0291e4c
PB
25266 /* Always generate relocations against function symbols. */
25267 if (fixp->fx_r_type == BFD_RELOC_32
25268 && fixp->fx_addsy
25269 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
25270 return 1;
25271
c19d1205 25272 return generic_force_reloc (fixp);
404ff6b5
AH
25273}
25274
0ffdc86c 25275#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
25276/* Relocations against function names must be left unadjusted,
25277 so that the linker can use this information to generate interworking
25278 stubs. The MIPS version of this function
c19d1205
ZW
25279 also prevents relocations that are mips-16 specific, but I do not
25280 know why it does this.
404ff6b5 25281
c19d1205
ZW
25282 FIXME:
25283 There is one other problem that ought to be addressed here, but
25284 which currently is not: Taking the address of a label (rather
25285 than a function) and then later jumping to that address. Such
25286 addresses also ought to have their bottom bit set (assuming that
25287 they reside in Thumb code), but at the moment they will not. */
404ff6b5 25288
c19d1205
ZW
25289bfd_boolean
25290arm_fix_adjustable (fixS * fixP)
404ff6b5 25291{
c19d1205
ZW
25292 if (fixP->fx_addsy == NULL)
25293 return 1;
404ff6b5 25294
e28387c3
PB
25295 /* Preserve relocations against symbols with function type. */
25296 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 25297 return FALSE;
e28387c3 25298
c19d1205
ZW
25299 if (THUMB_IS_FUNC (fixP->fx_addsy)
25300 && fixP->fx_subsy == NULL)
c921be7d 25301 return FALSE;
a737bd4d 25302
c19d1205
ZW
25303 /* We need the symbol name for the VTABLE entries. */
25304 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
25305 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 25306 return FALSE;
404ff6b5 25307
c19d1205
ZW
25308 /* Don't allow symbols to be discarded on GOT related relocs. */
25309 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
25310 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
25311 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
25312 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
5c5a4843 25313 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
c19d1205
ZW
25314 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
25315 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
5c5a4843 25316 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
c19d1205 25317 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
5c5a4843 25318 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
c19d1205 25319 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
25320 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
25321 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
25322 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
25323 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
25324 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 25325 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 25326 return FALSE;
a737bd4d 25327
4962c51a
MS
25328 /* Similarly for group relocations. */
25329 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25330 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25331 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 25332 return FALSE;
4962c51a 25333
79947c54
CD
25334 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
25335 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
25336 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
25337 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
25338 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
25339 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
25340 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
25341 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
25342 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 25343 return FALSE;
79947c54 25344
72d98d16
MG
25345 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
25346 offsets, so keep these symbols. */
25347 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
25348 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
25349 return FALSE;
25350
c921be7d 25351 return TRUE;
a737bd4d 25352}
0ffdc86c
NC
25353#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
25354
25355#ifdef OBJ_ELF
c19d1205
ZW
25356const char *
25357elf32_arm_target_format (void)
404ff6b5 25358{
c19d1205
ZW
25359#ifdef TE_SYMBIAN
25360 return (target_big_endian
25361 ? "elf32-bigarm-symbian"
25362 : "elf32-littlearm-symbian");
25363#elif defined (TE_VXWORKS)
25364 return (target_big_endian
25365 ? "elf32-bigarm-vxworks"
25366 : "elf32-littlearm-vxworks");
b38cadfb
NC
25367#elif defined (TE_NACL)
25368 return (target_big_endian
25369 ? "elf32-bigarm-nacl"
25370 : "elf32-littlearm-nacl");
c19d1205 25371#else
18a20338
CL
25372 if (arm_fdpic)
25373 {
25374 if (target_big_endian)
25375 return "elf32-bigarm-fdpic";
25376 else
25377 return "elf32-littlearm-fdpic";
25378 }
c19d1205 25379 else
18a20338
CL
25380 {
25381 if (target_big_endian)
25382 return "elf32-bigarm";
25383 else
25384 return "elf32-littlearm";
25385 }
c19d1205 25386#endif
404ff6b5
AH
25387}
25388
c19d1205
ZW
25389void
25390armelf_frob_symbol (symbolS * symp,
25391 int * puntp)
404ff6b5 25392{
c19d1205
ZW
25393 elf_frob_symbol (symp, puntp);
25394}
25395#endif
404ff6b5 25396
c19d1205 25397/* MD interface: Finalization. */
a737bd4d 25398
c19d1205
ZW
25399void
25400arm_cleanup (void)
25401{
25402 literal_pool * pool;
a737bd4d 25403
e07e6e58
NC
25404 /* Ensure that all the IT blocks are properly closed. */
25405 check_it_blocks_finished ();
25406
c19d1205
ZW
25407 for (pool = list_of_pools; pool; pool = pool->next)
25408 {
5f4273c7 25409 /* Put it at the end of the relevant section. */
c19d1205
ZW
25410 subseg_set (pool->section, pool->sub_section);
25411#ifdef OBJ_ELF
25412 arm_elf_change_section ();
25413#endif
25414 s_ltorg (0);
25415 }
404ff6b5
AH
25416}
25417
cd000bff
DJ
25418#ifdef OBJ_ELF
25419/* Remove any excess mapping symbols generated for alignment frags in
25420 SEC. We may have created a mapping symbol before a zero byte
25421 alignment; remove it if there's a mapping symbol after the
25422 alignment. */
25423static void
25424check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
25425 void *dummy ATTRIBUTE_UNUSED)
25426{
25427 segment_info_type *seginfo = seg_info (sec);
25428 fragS *fragp;
25429
25430 if (seginfo == NULL || seginfo->frchainP == NULL)
25431 return;
25432
25433 for (fragp = seginfo->frchainP->frch_root;
25434 fragp != NULL;
25435 fragp = fragp->fr_next)
25436 {
25437 symbolS *sym = fragp->tc_frag_data.last_map;
25438 fragS *next = fragp->fr_next;
25439
25440 /* Variable-sized frags have been converted to fixed size by
25441 this point. But if this was variable-sized to start with,
25442 there will be a fixed-size frag after it. So don't handle
25443 next == NULL. */
25444 if (sym == NULL || next == NULL)
25445 continue;
25446
25447 if (S_GET_VALUE (sym) < next->fr_address)
25448 /* Not at the end of this frag. */
25449 continue;
25450 know (S_GET_VALUE (sym) == next->fr_address);
25451
25452 do
25453 {
25454 if (next->tc_frag_data.first_map != NULL)
25455 {
25456 /* Next frag starts with a mapping symbol. Discard this
25457 one. */
25458 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25459 break;
25460 }
25461
25462 if (next->fr_next == NULL)
25463 {
25464 /* This mapping symbol is at the end of the section. Discard
25465 it. */
25466 know (next->fr_fix == 0 && next->fr_var == 0);
25467 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25468 break;
25469 }
25470
25471 /* As long as we have empty frags without any mapping symbols,
25472 keep looking. */
25473 /* If the next frag is non-empty and does not start with a
25474 mapping symbol, then this mapping symbol is required. */
25475 if (next->fr_address != next->fr_next->fr_address)
25476 break;
25477
25478 next = next->fr_next;
25479 }
25480 while (next != NULL);
25481 }
25482}
25483#endif
25484
c19d1205
ZW
25485/* Adjust the symbol table. This marks Thumb symbols as distinct from
25486 ARM ones. */
404ff6b5 25487
c19d1205
ZW
25488void
25489arm_adjust_symtab (void)
404ff6b5 25490{
c19d1205
ZW
25491#ifdef OBJ_COFF
25492 symbolS * sym;
404ff6b5 25493
c19d1205
ZW
25494 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
25495 {
25496 if (ARM_IS_THUMB (sym))
25497 {
25498 if (THUMB_IS_FUNC (sym))
25499 {
25500 /* Mark the symbol as a Thumb function. */
25501 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
25502 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
25503 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 25504
c19d1205
ZW
25505 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
25506 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
25507 else
25508 as_bad (_("%s: unexpected function type: %d"),
25509 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
25510 }
25511 else switch (S_GET_STORAGE_CLASS (sym))
25512 {
25513 case C_EXT:
25514 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
25515 break;
25516 case C_STAT:
25517 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
25518 break;
25519 case C_LABEL:
25520 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
25521 break;
25522 default:
25523 /* Do nothing. */
25524 break;
25525 }
25526 }
a737bd4d 25527
c19d1205
ZW
25528 if (ARM_IS_INTERWORK (sym))
25529 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 25530 }
c19d1205
ZW
25531#endif
25532#ifdef OBJ_ELF
25533 symbolS * sym;
25534 char bind;
404ff6b5 25535
c19d1205 25536 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 25537 {
c19d1205
ZW
25538 if (ARM_IS_THUMB (sym))
25539 {
25540 elf_symbol_type * elf_sym;
404ff6b5 25541
c19d1205
ZW
25542 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
25543 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 25544
b0796911
PB
25545 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
25546 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
25547 {
25548 /* If it's a .thumb_func, declare it as so,
25549 otherwise tag label as .code 16. */
25550 if (THUMB_IS_FUNC (sym))
39d911fc
TP
25551 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
25552 ST_BRANCH_TO_THUMB);
3ba67470 25553 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
25554 elf_sym->internal_elf_sym.st_info =
25555 ELF_ST_INFO (bind, STT_ARM_16BIT);
25556 }
25557 }
25558 }
cd000bff
DJ
25559
25560 /* Remove any overlapping mapping symbols generated by alignment frags. */
25561 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
25562 /* Now do generic ELF adjustments. */
25563 elf_adjust_symtab ();
c19d1205 25564#endif
404ff6b5
AH
25565}
25566
c19d1205 25567/* MD interface: Initialization. */
404ff6b5 25568
a737bd4d 25569static void
c19d1205 25570set_constant_flonums (void)
a737bd4d 25571{
c19d1205 25572 int i;
404ff6b5 25573
c19d1205
ZW
25574 for (i = 0; i < NUM_FLOAT_VALS; i++)
25575 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
25576 abort ();
a737bd4d 25577}
404ff6b5 25578
3e9e4fcf
JB
25579/* Auto-select Thumb mode if it's the only available instruction set for the
25580 given architecture. */
25581
25582static void
25583autoselect_thumb_from_cpu_variant (void)
25584{
25585 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
25586 opcode_select (16);
25587}
25588
c19d1205
ZW
25589void
25590md_begin (void)
a737bd4d 25591{
c19d1205
ZW
25592 unsigned mach;
25593 unsigned int i;
404ff6b5 25594
c19d1205
ZW
25595 if ( (arm_ops_hsh = hash_new ()) == NULL
25596 || (arm_cond_hsh = hash_new ()) == NULL
25597 || (arm_shift_hsh = hash_new ()) == NULL
25598 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 25599 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 25600 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
25601 || (arm_reloc_hsh = hash_new ()) == NULL
25602 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
25603 as_fatal (_("virtual memory exhausted"));
25604
25605 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 25606 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 25607 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 25608 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 25609 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 25610 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 25611 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25612 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 25613 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25614 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 25615 (void *) (v7m_psrs + i));
c19d1205 25616 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 25617 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
25618 for (i = 0;
25619 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
25620 i++)
d3ce72d0 25621 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 25622 (void *) (barrier_opt_names + i));
c19d1205 25623#ifdef OBJ_ELF
3da1d841
NC
25624 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
25625 {
25626 struct reloc_entry * entry = reloc_names + i;
25627
25628 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
25629 /* This makes encode_branch() use the EABI versions of this relocation. */
25630 entry->reloc = BFD_RELOC_UNUSED;
25631
25632 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
25633 }
c19d1205
ZW
25634#endif
25635
25636 set_constant_flonums ();
404ff6b5 25637
c19d1205
ZW
25638 /* Set the cpu variant based on the command-line options. We prefer
25639 -mcpu= over -march= if both are set (as for GCC); and we prefer
25640 -mfpu= over any other way of setting the floating point unit.
25641 Use of legacy options with new options are faulted. */
e74cfd16 25642 if (legacy_cpu)
404ff6b5 25643 {
e74cfd16 25644 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
25645 as_bad (_("use of old and new-style options to set CPU type"));
25646
4d354d8b 25647 selected_arch = *legacy_cpu;
404ff6b5 25648 }
4d354d8b
TP
25649 else if (mcpu_cpu_opt)
25650 {
25651 selected_arch = *mcpu_cpu_opt;
25652 selected_ext = *mcpu_ext_opt;
25653 }
25654 else if (march_cpu_opt)
c168ce07 25655 {
4d354d8b
TP
25656 selected_arch = *march_cpu_opt;
25657 selected_ext = *march_ext_opt;
c168ce07 25658 }
4d354d8b 25659 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
404ff6b5 25660
e74cfd16 25661 if (legacy_fpu)
c19d1205 25662 {
e74cfd16 25663 if (mfpu_opt)
c19d1205 25664 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f 25665
4d354d8b 25666 selected_fpu = *legacy_fpu;
03b1477f 25667 }
4d354d8b
TP
25668 else if (mfpu_opt)
25669 selected_fpu = *mfpu_opt;
25670 else
03b1477f 25671 {
45eb4c1b
NS
25672#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25673 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
25674 /* Some environments specify a default FPU. If they don't, infer it
25675 from the processor. */
e74cfd16 25676 if (mcpu_fpu_opt)
4d354d8b 25677 selected_fpu = *mcpu_fpu_opt;
e7da50fa 25678 else if (march_fpu_opt)
4d354d8b 25679 selected_fpu = *march_fpu_opt;
39c2da32 25680#else
4d354d8b 25681 selected_fpu = fpu_default;
39c2da32 25682#endif
03b1477f
RE
25683 }
25684
4d354d8b 25685 if (ARM_FEATURE_ZERO (selected_fpu))
03b1477f 25686 {
4d354d8b
TP
25687 if (!no_cpu_selected ())
25688 selected_fpu = fpu_default;
03b1477f 25689 else
4d354d8b 25690 selected_fpu = fpu_arch_fpa;
03b1477f
RE
25691 }
25692
ee065d83 25693#ifdef CPU_DEFAULT
4d354d8b 25694 if (ARM_FEATURE_ZERO (selected_arch))
ee065d83 25695 {
4d354d8b
TP
25696 selected_arch = cpu_default;
25697 selected_cpu = selected_arch;
ee065d83 25698 }
4d354d8b 25699 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
e74cfd16 25700#else
4d354d8b
TP
25701 /* Autodection of feature mode: allow all features in cpu_variant but leave
25702 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
25703 after all instruction have been processed and we can decide what CPU
25704 should be selected. */
25705 if (ARM_FEATURE_ZERO (selected_arch))
25706 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
ee065d83 25707 else
4d354d8b 25708 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83 25709#endif
03b1477f 25710
3e9e4fcf
JB
25711 autoselect_thumb_from_cpu_variant ();
25712
e74cfd16 25713 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 25714
f17c130b 25715#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 25716 {
7cc69913
NC
25717 unsigned int flags = 0;
25718
25719#if defined OBJ_ELF
25720 flags = meabi_flags;
d507cf36
PB
25721
25722 switch (meabi_flags)
33a392fb 25723 {
d507cf36 25724 case EF_ARM_EABI_UNKNOWN:
7cc69913 25725#endif
d507cf36
PB
25726 /* Set the flags in the private structure. */
25727 if (uses_apcs_26) flags |= F_APCS26;
25728 if (support_interwork) flags |= F_INTERWORK;
25729 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 25730 if (pic_code) flags |= F_PIC;
e74cfd16 25731 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
25732 flags |= F_SOFT_FLOAT;
25733
d507cf36
PB
25734 switch (mfloat_abi_opt)
25735 {
25736 case ARM_FLOAT_ABI_SOFT:
25737 case ARM_FLOAT_ABI_SOFTFP:
25738 flags |= F_SOFT_FLOAT;
25739 break;
33a392fb 25740
d507cf36
PB
25741 case ARM_FLOAT_ABI_HARD:
25742 if (flags & F_SOFT_FLOAT)
25743 as_bad (_("hard-float conflicts with specified fpu"));
25744 break;
25745 }
03b1477f 25746
e74cfd16
PB
25747 /* Using pure-endian doubles (even if soft-float). */
25748 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 25749 flags |= F_VFP_FLOAT;
f17c130b 25750
fde78edd 25751#if defined OBJ_ELF
e74cfd16 25752 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 25753 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
25754 break;
25755
8cb51566 25756 case EF_ARM_EABI_VER4:
3a4a14e9 25757 case EF_ARM_EABI_VER5:
c19d1205 25758 /* No additional flags to set. */
d507cf36
PB
25759 break;
25760
25761 default:
25762 abort ();
25763 }
7cc69913 25764#endif
b99bd4ef
NC
25765 bfd_set_private_flags (stdoutput, flags);
25766
25767 /* We have run out flags in the COFF header to encode the
25768 status of ATPCS support, so instead we create a dummy,
c19d1205 25769 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
25770 if (atpcs)
25771 {
25772 asection * sec;
25773
25774 sec = bfd_make_section (stdoutput, ".arm.atpcs");
25775
25776 if (sec != NULL)
25777 {
25778 bfd_set_section_flags
25779 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
25780 bfd_set_section_size (stdoutput, sec, 0);
25781 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
25782 }
25783 }
7cc69913 25784 }
f17c130b 25785#endif
b99bd4ef
NC
25786
25787 /* Record the CPU type as well. */
2d447fca
JM
25788 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
25789 mach = bfd_mach_arm_iWMMXt2;
25790 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 25791 mach = bfd_mach_arm_iWMMXt;
e74cfd16 25792 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 25793 mach = bfd_mach_arm_XScale;
e74cfd16 25794 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 25795 mach = bfd_mach_arm_ep9312;
e74cfd16 25796 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 25797 mach = bfd_mach_arm_5TE;
e74cfd16 25798 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 25799 {
e74cfd16 25800 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25801 mach = bfd_mach_arm_5T;
25802 else
25803 mach = bfd_mach_arm_5;
25804 }
e74cfd16 25805 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 25806 {
e74cfd16 25807 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25808 mach = bfd_mach_arm_4T;
25809 else
25810 mach = bfd_mach_arm_4;
25811 }
e74cfd16 25812 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 25813 mach = bfd_mach_arm_3M;
e74cfd16
PB
25814 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25815 mach = bfd_mach_arm_3;
25816 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25817 mach = bfd_mach_arm_2a;
25818 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25819 mach = bfd_mach_arm_2;
25820 else
25821 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
25822
25823 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25824}
25825
c19d1205 25826/* Command line processing. */
b99bd4ef 25827
c19d1205
ZW
25828/* md_parse_option
25829 Invocation line includes a switch not recognized by the base assembler.
25830 See if it's a processor-specific option.
b99bd4ef 25831
c19d1205
ZW
25832 This routine is somewhat complicated by the need for backwards
25833 compatibility (since older releases of gcc can't be changed).
25834 The new options try to make the interface as compatible as
25835 possible with GCC.
b99bd4ef 25836
c19d1205 25837 New options (supported) are:
b99bd4ef 25838
c19d1205
ZW
25839 -mcpu=<cpu name> Assemble for selected processor
25840 -march=<architecture name> Assemble for selected architecture
25841 -mfpu=<fpu architecture> Assemble for selected FPU.
25842 -EB/-mbig-endian Big-endian
25843 -EL/-mlittle-endian Little-endian
25844 -k Generate PIC code
25845 -mthumb Start in Thumb mode
25846 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 25847
278df34e 25848 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 25849 -m[no-]warn-syms Warn when symbols match instructions
267bf995 25850
c19d1205 25851 For now we will also provide support for:
b99bd4ef 25852
c19d1205
ZW
25853 -mapcs-32 32-bit Program counter
25854 -mapcs-26 26-bit Program counter
25855 -macps-float Floats passed in FP registers
25856 -mapcs-reentrant Reentrant code
25857 -matpcs
25858 (sometime these will probably be replaced with -mapcs=<list of options>
25859 and -matpcs=<list of options>)
b99bd4ef 25860
c19d1205
ZW
25861 The remaining options are only supported for back-wards compatibility.
25862 Cpu variants, the arm part is optional:
25863 -m[arm]1 Currently not supported.
25864 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25865 -m[arm]3 Arm 3 processor
25866 -m[arm]6[xx], Arm 6 processors
25867 -m[arm]7[xx][t][[d]m] Arm 7 processors
25868 -m[arm]8[10] Arm 8 processors
25869 -m[arm]9[20][tdmi] Arm 9 processors
25870 -mstrongarm[110[0]] StrongARM processors
25871 -mxscale XScale processors
25872 -m[arm]v[2345[t[e]]] Arm architectures
25873 -mall All (except the ARM1)
25874 FP variants:
25875 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25876 -mfpe-old (No float load/store multiples)
25877 -mvfpxd VFP Single precision
25878 -mvfp All VFP
25879 -mno-fpu Disable all floating point instructions
b99bd4ef 25880
c19d1205
ZW
25881 The following CPU names are recognized:
25882 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25883 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25884 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25885 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25886 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25887 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25888 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25889
c19d1205 25890 */
b99bd4ef 25891
c19d1205 25892const char * md_shortopts = "m:k";
b99bd4ef 25893
c19d1205
ZW
25894#ifdef ARM_BI_ENDIAN
25895#define OPTION_EB (OPTION_MD_BASE + 0)
25896#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25897#else
c19d1205
ZW
25898#if TARGET_BYTES_BIG_ENDIAN
25899#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25900#else
c19d1205
ZW
25901#define OPTION_EL (OPTION_MD_BASE + 1)
25902#endif
b99bd4ef 25903#endif
845b51d6 25904#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
18a20338 25905#define OPTION_FDPIC (OPTION_MD_BASE + 3)
b99bd4ef 25906
c19d1205 25907struct option md_longopts[] =
b99bd4ef 25908{
c19d1205
ZW
25909#ifdef OPTION_EB
25910 {"EB", no_argument, NULL, OPTION_EB},
25911#endif
25912#ifdef OPTION_EL
25913 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25914#endif
845b51d6 25915 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
18a20338
CL
25916#ifdef OBJ_ELF
25917 {"fdpic", no_argument, NULL, OPTION_FDPIC},
25918#endif
c19d1205
ZW
25919 {NULL, no_argument, NULL, 0}
25920};
b99bd4ef 25921
c19d1205 25922size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25923
c19d1205 25924struct arm_option_table
b99bd4ef 25925{
0198d5e6
TC
25926 const char * option; /* Option name to match. */
25927 const char * help; /* Help information. */
25928 int * var; /* Variable to change. */
25929 int value; /* What to change it to. */
25930 const char * deprecated; /* If non-null, print this message. */
c19d1205 25931};
b99bd4ef 25932
c19d1205
ZW
25933struct arm_option_table arm_opts[] =
25934{
25935 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25936 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25937 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25938 &support_interwork, 1, NULL},
25939 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25940 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25941 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25942 1, NULL},
25943 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25944 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25945 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25946 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25947 NULL},
b99bd4ef 25948
c19d1205
ZW
25949 /* These are recognized by the assembler, but have no affect on code. */
25950 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25951 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25952
25953 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25954 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25955 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25956 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25957 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25958 {NULL, NULL, NULL, 0, NULL}
25959};
25960
25961struct arm_legacy_option_table
25962{
0198d5e6
TC
25963 const char * option; /* Option name to match. */
25964 const arm_feature_set ** var; /* Variable to change. */
25965 const arm_feature_set value; /* What to change it to. */
25966 const char * deprecated; /* If non-null, print this message. */
e74cfd16 25967};
b99bd4ef 25968
e74cfd16
PB
25969const struct arm_legacy_option_table arm_legacy_opts[] =
25970{
c19d1205
ZW
25971 /* DON'T add any new processors to this list -- we want the whole list
25972 to go away... Add them to the processors table instead. */
e74cfd16
PB
25973 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25974 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25975 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25976 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25977 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25978 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25979 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25980 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25981 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25982 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25983 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25984 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25985 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25986 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25987 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25988 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25989 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25990 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25991 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25992 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25993 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25994 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25995 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25996 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25997 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25998 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25999 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
26000 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
26001 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
26002 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
26003 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
26004 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
26005 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
26006 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
26007 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
26008 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
26009 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
26010 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
26011 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
26012 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
26013 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
26014 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
26015 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
26016 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
26017 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
26018 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
26019 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
26020 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
26021 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
26022 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
26023 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
26024 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
26025 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
26026 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
26027 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
26028 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
26029 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
26030 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
26031 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
26032 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
26033 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
26034 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
26035 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
26036 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
26037 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
26038 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
26039 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
26040 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
26041 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
26042 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 26043 N_("use -mcpu=strongarm110")},
e74cfd16 26044 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 26045 N_("use -mcpu=strongarm1100")},
e74cfd16 26046 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 26047 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
26048 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
26049 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
26050 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 26051
c19d1205 26052 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
26053 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
26054 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
26055 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
26056 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
26057 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
26058 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
26059 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
26060 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
26061 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
26062 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
26063 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
26064 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
26065 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
26066 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
26067 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
26068 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
26069 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
26070 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 26071
c19d1205 26072 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
26073 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
26074 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
26075 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
26076 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 26077 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 26078
e74cfd16 26079 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 26080};
7ed4c4c5 26081
c19d1205 26082struct arm_cpu_option_table
7ed4c4c5 26083{
0198d5e6
TC
26084 const char * name;
26085 size_t name_len;
26086 const arm_feature_set value;
26087 const arm_feature_set ext;
c19d1205
ZW
26088 /* For some CPUs we assume an FPU unless the user explicitly sets
26089 -mfpu=... */
0198d5e6 26090 const arm_feature_set default_fpu;
ee065d83
PB
26091 /* The canonical name of the CPU, or NULL to use NAME converted to upper
26092 case. */
0198d5e6 26093 const char * canonical_name;
c19d1205 26094};
7ed4c4c5 26095
c19d1205
ZW
26096/* This list should, at a minimum, contain all the cpu names
26097 recognized by GCC. */
996b5569 26098#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 26099
e74cfd16 26100static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 26101{
996b5569
TP
26102 ARM_CPU_OPT ("all", NULL, ARM_ANY,
26103 ARM_ARCH_NONE,
26104 FPU_ARCH_FPA),
26105 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
26106 ARM_ARCH_NONE,
26107 FPU_ARCH_FPA),
26108 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
26109 ARM_ARCH_NONE,
26110 FPU_ARCH_FPA),
26111 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
26112 ARM_ARCH_NONE,
26113 FPU_ARCH_FPA),
26114 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
26115 ARM_ARCH_NONE,
26116 FPU_ARCH_FPA),
26117 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
26118 ARM_ARCH_NONE,
26119 FPU_ARCH_FPA),
26120 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
26121 ARM_ARCH_NONE,
26122 FPU_ARCH_FPA),
26123 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
26124 ARM_ARCH_NONE,
26125 FPU_ARCH_FPA),
26126 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
26127 ARM_ARCH_NONE,
26128 FPU_ARCH_FPA),
26129 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
26130 ARM_ARCH_NONE,
26131 FPU_ARCH_FPA),
26132 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
26133 ARM_ARCH_NONE,
26134 FPU_ARCH_FPA),
26135 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
26136 ARM_ARCH_NONE,
26137 FPU_ARCH_FPA),
26138 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
26139 ARM_ARCH_NONE,
26140 FPU_ARCH_FPA),
26141 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
26142 ARM_ARCH_NONE,
26143 FPU_ARCH_FPA),
26144 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
26145 ARM_ARCH_NONE,
26146 FPU_ARCH_FPA),
26147 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
26148 ARM_ARCH_NONE,
26149 FPU_ARCH_FPA),
26150 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
26151 ARM_ARCH_NONE,
26152 FPU_ARCH_FPA),
26153 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
26154 ARM_ARCH_NONE,
26155 FPU_ARCH_FPA),
26156 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
26157 ARM_ARCH_NONE,
26158 FPU_ARCH_FPA),
26159 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
26160 ARM_ARCH_NONE,
26161 FPU_ARCH_FPA),
26162 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
26163 ARM_ARCH_NONE,
26164 FPU_ARCH_FPA),
26165 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
26166 ARM_ARCH_NONE,
26167 FPU_ARCH_FPA),
26168 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
26169 ARM_ARCH_NONE,
26170 FPU_ARCH_FPA),
26171 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
26172 ARM_ARCH_NONE,
26173 FPU_ARCH_FPA),
26174 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
26175 ARM_ARCH_NONE,
26176 FPU_ARCH_FPA),
26177 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
26178 ARM_ARCH_NONE,
26179 FPU_ARCH_FPA),
26180 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
26181 ARM_ARCH_NONE,
26182 FPU_ARCH_FPA),
26183 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
26184 ARM_ARCH_NONE,
26185 FPU_ARCH_FPA),
26186 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
26187 ARM_ARCH_NONE,
26188 FPU_ARCH_FPA),
26189 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
26190 ARM_ARCH_NONE,
26191 FPU_ARCH_FPA),
26192 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
26193 ARM_ARCH_NONE,
26194 FPU_ARCH_FPA),
26195 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
26196 ARM_ARCH_NONE,
26197 FPU_ARCH_FPA),
26198 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
26199 ARM_ARCH_NONE,
26200 FPU_ARCH_FPA),
26201 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
26202 ARM_ARCH_NONE,
26203 FPU_ARCH_FPA),
26204 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
26205 ARM_ARCH_NONE,
26206 FPU_ARCH_FPA),
26207 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
26208 ARM_ARCH_NONE,
26209 FPU_ARCH_FPA),
26210 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
26211 ARM_ARCH_NONE,
26212 FPU_ARCH_FPA),
26213 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
26214 ARM_ARCH_NONE,
26215 FPU_ARCH_FPA),
26216 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
26217 ARM_ARCH_NONE,
26218 FPU_ARCH_FPA),
26219 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
26220 ARM_ARCH_NONE,
26221 FPU_ARCH_FPA),
26222 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
26223 ARM_ARCH_NONE,
26224 FPU_ARCH_FPA),
26225 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
26226 ARM_ARCH_NONE,
26227 FPU_ARCH_FPA),
26228 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
26229 ARM_ARCH_NONE,
26230 FPU_ARCH_FPA),
26231 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
26232 ARM_ARCH_NONE,
26233 FPU_ARCH_FPA),
26234 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
26235 ARM_ARCH_NONE,
26236 FPU_ARCH_FPA),
26237 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
26238 ARM_ARCH_NONE,
26239 FPU_ARCH_FPA),
26240
c19d1205
ZW
26241 /* For V5 or later processors we default to using VFP; but the user
26242 should really set the FPU type explicitly. */
996b5569
TP
26243 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
26244 ARM_ARCH_NONE,
26245 FPU_ARCH_VFP_V2),
26246 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
26247 ARM_ARCH_NONE,
26248 FPU_ARCH_VFP_V2),
26249 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
26250 ARM_ARCH_NONE,
26251 FPU_ARCH_VFP_V2),
26252 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
26253 ARM_ARCH_NONE,
26254 FPU_ARCH_VFP_V2),
26255 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
26256 ARM_ARCH_NONE,
26257 FPU_ARCH_VFP_V2),
26258 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
26259 ARM_ARCH_NONE,
26260 FPU_ARCH_VFP_V2),
26261 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
26262 ARM_ARCH_NONE,
26263 FPU_ARCH_VFP_V2),
26264 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
26265 ARM_ARCH_NONE,
26266 FPU_ARCH_VFP_V2),
26267 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
26268 ARM_ARCH_NONE,
26269 FPU_ARCH_VFP_V2),
26270 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
26271 ARM_ARCH_NONE,
26272 FPU_ARCH_VFP_V2),
26273 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
26274 ARM_ARCH_NONE,
26275 FPU_ARCH_VFP_V2),
26276 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
26277 ARM_ARCH_NONE,
26278 FPU_ARCH_VFP_V2),
26279 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
26280 ARM_ARCH_NONE,
26281 FPU_ARCH_VFP_V1),
26282 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
26283 ARM_ARCH_NONE,
26284 FPU_ARCH_VFP_V1),
26285 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
26286 ARM_ARCH_NONE,
26287 FPU_ARCH_VFP_V2),
26288 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
26289 ARM_ARCH_NONE,
26290 FPU_ARCH_VFP_V2),
26291 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
26292 ARM_ARCH_NONE,
26293 FPU_ARCH_VFP_V1),
26294 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
26295 ARM_ARCH_NONE,
26296 FPU_ARCH_VFP_V2),
26297 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
26298 ARM_ARCH_NONE,
26299 FPU_ARCH_VFP_V2),
26300 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
26301 ARM_ARCH_NONE,
26302 FPU_ARCH_VFP_V2),
26303 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
26304 ARM_ARCH_NONE,
26305 FPU_ARCH_VFP_V2),
26306 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
26307 ARM_ARCH_NONE,
26308 FPU_ARCH_VFP_V2),
26309 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
26310 ARM_ARCH_NONE,
26311 FPU_ARCH_VFP_V2),
26312 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
26313 ARM_ARCH_NONE,
26314 FPU_ARCH_VFP_V2),
26315 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
26316 ARM_ARCH_NONE,
26317 FPU_ARCH_VFP_V2),
26318 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
26319 ARM_ARCH_NONE,
26320 FPU_ARCH_VFP_V2),
26321 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
26322 ARM_ARCH_NONE,
26323 FPU_NONE),
26324 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
26325 ARM_ARCH_NONE,
26326 FPU_NONE),
26327 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
26328 ARM_ARCH_NONE,
26329 FPU_ARCH_VFP_V2),
26330 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
26331 ARM_ARCH_NONE,
26332 FPU_ARCH_VFP_V2),
26333 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
26334 ARM_ARCH_NONE,
26335 FPU_ARCH_VFP_V2),
26336 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
26337 ARM_ARCH_NONE,
26338 FPU_NONE),
26339 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
26340 ARM_ARCH_NONE,
26341 FPU_NONE),
26342 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
26343 ARM_ARCH_NONE,
26344 FPU_ARCH_VFP_V2),
26345 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
26346 ARM_ARCH_NONE,
26347 FPU_NONE),
26348 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
26349 ARM_ARCH_NONE,
26350 FPU_ARCH_VFP_V2),
26351 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
26352 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26353 FPU_NONE),
26354 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
26355 ARM_ARCH_NONE,
26356 FPU_ARCH_NEON_VFP_V4),
26357 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
26358 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
26359 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26360 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
26361 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26362 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26363 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
26364 ARM_ARCH_NONE,
26365 FPU_ARCH_NEON_VFP_V4),
26366 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
26367 ARM_ARCH_NONE,
26368 FPU_ARCH_NEON_VFP_V4),
26369 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
26370 ARM_ARCH_NONE,
26371 FPU_ARCH_NEON_VFP_V4),
26372 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
26373 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26374 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26375 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
26376 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26377 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26378 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
26379 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26380 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
26381 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
26382 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 26383 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
26384 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
26385 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26386 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26387 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
26388 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26389 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26390 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
26391 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26392 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
26393 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
26394 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 26395 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
7ebd1359 26396 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
26397 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26398 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
ef8df4ca
KT
26399 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
26400 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26401 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
26402 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
26403 ARM_ARCH_NONE,
26404 FPU_NONE),
26405 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
26406 ARM_ARCH_NONE,
26407 FPU_ARCH_VFP_V3D16),
26408 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
26409 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26410 FPU_NONE),
26411 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
26412 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26413 FPU_ARCH_VFP_V3D16),
26414 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
26415 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26416 FPU_ARCH_VFP_V3D16),
0cda1e19
TP
26417 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
26418 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26419 FPU_ARCH_NEON_VFP_ARMV8),
996b5569
TP
26420 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
26421 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26422 FPU_NONE),
26423 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
26424 ARM_ARCH_NONE,
26425 FPU_NONE),
26426 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
26427 ARM_ARCH_NONE,
26428 FPU_NONE),
26429 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
26430 ARM_ARCH_NONE,
26431 FPU_NONE),
26432 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
26433 ARM_ARCH_NONE,
26434 FPU_NONE),
26435 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
26436 ARM_ARCH_NONE,
26437 FPU_NONE),
26438 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
26439 ARM_ARCH_NONE,
26440 FPU_NONE),
26441 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
26442 ARM_ARCH_NONE,
26443 FPU_NONE),
26444 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
26445 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26446 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
83f43c83
KT
26447 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
26448 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26449 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
c19d1205 26450 /* ??? XSCALE is really an architecture. */
996b5569
TP
26451 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
26452 ARM_ARCH_NONE,
26453 FPU_ARCH_VFP_V2),
26454
c19d1205 26455 /* ??? iwmmxt is not a processor. */
996b5569
TP
26456 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
26457 ARM_ARCH_NONE,
26458 FPU_ARCH_VFP_V2),
26459 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
26460 ARM_ARCH_NONE,
26461 FPU_ARCH_VFP_V2),
26462 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
26463 ARM_ARCH_NONE,
26464 FPU_ARCH_VFP_V2),
26465
0198d5e6 26466 /* Maverick. */
996b5569
TP
26467 ARM_CPU_OPT ("ep9312", "ARM920T",
26468 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
26469 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
26470
da4339ed 26471 /* Marvell processors. */
996b5569
TP
26472 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
26473 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26474 FPU_ARCH_VFP_V3D16),
26475 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
26476 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26477 FPU_ARCH_NEON_VFP_V4),
da4339ed 26478
996b5569
TP
26479 /* APM X-Gene family. */
26480 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
26481 ARM_ARCH_NONE,
26482 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26483 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
26484 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26485 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26486
26487 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 26488};
f3bad469 26489#undef ARM_CPU_OPT
7ed4c4c5 26490
34ef62f4
AV
26491struct arm_ext_table
26492{
26493 const char * name;
26494 size_t name_len;
26495 const arm_feature_set merge;
26496 const arm_feature_set clear;
26497};
26498
c19d1205 26499struct arm_arch_option_table
7ed4c4c5 26500{
34ef62f4
AV
26501 const char * name;
26502 size_t name_len;
26503 const arm_feature_set value;
26504 const arm_feature_set default_fpu;
26505 const struct arm_ext_table * ext_table;
26506};
26507
26508/* Used to add support for +E and +noE extension. */
26509#define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
26510/* Used to add support for a +E extension. */
26511#define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
26512/* Used to add support for a +noE extension. */
26513#define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
26514
26515#define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
26516 ~0 & ~FPU_ENDIAN_PURE)
26517
26518static const struct arm_ext_table armv5te_ext_table[] =
26519{
26520 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
26521 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26522};
26523
26524static const struct arm_ext_table armv7_ext_table[] =
26525{
26526 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
26527 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26528};
26529
26530static const struct arm_ext_table armv7ve_ext_table[] =
26531{
26532 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
26533 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
26534 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
26535 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
26536 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
26537 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
26538 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
26539
26540 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
26541 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
26542
26543 /* Aliases for +simd. */
26544 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
26545
26546 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
26547 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
26548 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
26549
26550 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26551};
26552
26553static const struct arm_ext_table armv7a_ext_table[] =
26554{
26555 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
26556 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
26557 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
26558 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
26559 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
26560 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
26561 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
26562
26563 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
26564 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
26565
26566 /* Aliases for +simd. */
26567 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
26568 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
26569
26570 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
26571 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
26572
26573 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
26574 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
26575 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26576};
26577
26578static const struct arm_ext_table armv7r_ext_table[] =
26579{
26580 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
26581 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
26582 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
26583 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
26584 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
26585 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
26586 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
26587 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
26588 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26589};
26590
26591static const struct arm_ext_table armv7em_ext_table[] =
26592{
26593 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
26594 /* Alias for +fp, used to be known as fpv4-sp-d16. */
26595 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
26596 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
26597 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
26598 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
26599 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26600};
26601
26602static const struct arm_ext_table armv8a_ext_table[] =
26603{
26604 ARM_ADD ("crc", ARCH_CRC_ARMV8),
26605 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
26606 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
26607 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26608
26609 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26610 should use the +simd option to turn on FP. */
26611 ARM_REMOVE ("fp", ALL_FP),
26612 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
26613 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
26614 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26615};
26616
26617
26618static const struct arm_ext_table armv81a_ext_table[] =
26619{
26620 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
26621 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
26622 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26623
26624 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26625 should use the +simd option to turn on FP. */
26626 ARM_REMOVE ("fp", ALL_FP),
26627 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
26628 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
26629 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26630};
26631
26632static const struct arm_ext_table armv82a_ext_table[] =
26633{
26634 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
26635 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
26636 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
26637 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
26638 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26639 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
26640
26641 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26642 should use the +simd option to turn on FP. */
26643 ARM_REMOVE ("fp", ALL_FP),
26644 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
26645 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
26646 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26647};
26648
26649static const struct arm_ext_table armv84a_ext_table[] =
26650{
26651 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
26652 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
26653 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
26654 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26655
26656 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26657 should use the +simd option to turn on FP. */
26658 ARM_REMOVE ("fp", ALL_FP),
26659 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
26660 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
26661 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26662};
26663
26664static const struct arm_ext_table armv85a_ext_table[] =
26665{
26666 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
26667 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
26668 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
26669 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26670
26671 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26672 should use the +simd option to turn on FP. */
26673 ARM_REMOVE ("fp", ALL_FP),
26674 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26675};
26676
26677static const struct arm_ext_table armv8m_main_ext_table[] =
26678{
26679 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26680 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
26681 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
26682 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
26683 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26684};
26685
e0991585
AV
26686static const struct arm_ext_table armv8_1m_main_ext_table[] =
26687{
26688 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26689 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
26690 ARM_EXT ("fp",
26691 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
26692 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
26693 ALL_FP),
26694 ARM_ADD ("fp.dp",
26695 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
26696 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
26697 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26698};
26699
34ef62f4
AV
26700static const struct arm_ext_table armv8r_ext_table[] =
26701{
26702 ARM_ADD ("crc", ARCH_CRC_ARMV8),
26703 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
26704 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
26705 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26706 ARM_REMOVE ("fp", ALL_FP),
26707 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
26708 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 26709};
7ed4c4c5 26710
c19d1205
ZW
26711/* This list should, at a minimum, contain all the architecture names
26712 recognized by GCC. */
34ef62f4
AV
26713#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
26714#define ARM_ARCH_OPT2(N, V, DF, ext) \
26715 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
0198d5e6 26716
e74cfd16 26717static const struct arm_arch_option_table arm_archs[] =
c19d1205 26718{
497d849d
TP
26719 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
26720 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
26721 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
26722 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
26723 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
26724 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
26725 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
26726 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
26727 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
26728 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
26729 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
26730 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
26731 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
26732 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
34ef62f4
AV
26733 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
26734 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
26735 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
26736 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
26737 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
26738 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
26739 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
f33026a9
MW
26740 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
26741 kept to preserve existing behaviour. */
34ef62f4
AV
26742 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
26743 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
26744 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
26745 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
26746 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
f33026a9
MW
26747 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
26748 kept to preserve existing behaviour. */
34ef62f4
AV
26749 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
26750 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
497d849d
TP
26751 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
26752 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
34ef62f4 26753 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
c450d570
PB
26754 /* The official spelling of the ARMv7 profile variants is the dashed form.
26755 Accept the non-dashed form for compatibility with old toolchains. */
34ef62f4
AV
26756 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
26757 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
26758 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 26759 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4
AV
26760 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
26761 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 26762 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4 26763 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
497d849d 26764 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
34ef62f4
AV
26765 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
26766 armv8m_main),
e0991585
AV
26767 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
26768 armv8_1m_main),
34ef62f4
AV
26769 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
26770 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
26771 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
26772 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
26773 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
26774 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
26775 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
497d849d
TP
26776 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
26777 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
26778 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
34ef62f4 26779 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 26780};
f3bad469 26781#undef ARM_ARCH_OPT
7ed4c4c5 26782
69133863 26783/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 26784
69133863 26785struct arm_option_extension_value_table
c19d1205 26786{
0198d5e6
TC
26787 const char * name;
26788 size_t name_len;
26789 const arm_feature_set merge_value;
26790 const arm_feature_set clear_value;
d942732e
TP
26791 /* List of architectures for which an extension is available. ARM_ARCH_NONE
26792 indicates that an extension is available for all architectures while
26793 ARM_ANY marks an empty entry. */
0198d5e6 26794 const arm_feature_set allowed_archs[2];
c19d1205 26795};
7ed4c4c5 26796
0198d5e6
TC
26797/* The following table must be in alphabetical order with a NULL last entry. */
26798
d942732e
TP
26799#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
26800#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 26801
34ef62f4
AV
26802/* DEPRECATED: Refrain from using this table to add any new extensions, instead
26803 use the context sensitive approach using arm_ext_table's. */
69133863 26804static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 26805{
823d2571
TG
26806 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26807 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 26808 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
26809 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
26810 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
26811 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
26812 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
26813 ARM_ARCH_V8_2A),
15afaa63
TP
26814 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26815 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26816 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
26817 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
26818 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
26819 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26820 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26821 ARM_ARCH_V8_2A),
01f48020
TC
26822 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
26823 | ARM_EXT2_FP16_FML),
26824 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
26825 | ARM_EXT2_FP16_FML),
26826 ARM_ARCH_V8_2A),
d942732e 26827 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 26828 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
26829 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26830 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
26831 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
26832 Thumb divide instruction. Due to this having the same name as the
26833 previous entry, this will be ignored when doing command-line parsing and
26834 only considered by build attribute selection code. */
26835 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26836 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26837 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 26838 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 26839 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 26840 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 26841 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 26842 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
26843 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
26844 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 26845 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
26846 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26847 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
26848 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26849 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26850 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
26851 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
26852 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 26853 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
dad0c3bf
SD
26854 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
26855 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
26856 ARM_ARCH_V8A),
4d1464f2
MW
26857 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
26858 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 26859 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
26860 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
26861 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 26862 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
7fadb25d
SD
26863 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
26864 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
26865 ARM_ARCH_V8A),
d942732e 26866 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 26867 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
26868 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
26869 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
26870 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
26871 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
26872 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
26873 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
26874 | ARM_EXT_DIV),
26875 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
26876 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
26877 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
26878 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
26879 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 26880};
f3bad469 26881#undef ARM_EXT_OPT
69133863
MGD
26882
26883/* ISA floating-point and Advanced SIMD extensions. */
26884struct arm_option_fpu_value_table
26885{
0198d5e6
TC
26886 const char * name;
26887 const arm_feature_set value;
c19d1205 26888};
7ed4c4c5 26889
c19d1205
ZW
26890/* This list should, at a minimum, contain all the fpu names
26891 recognized by GCC. */
69133863 26892static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
26893{
26894 {"softfpa", FPU_NONE},
26895 {"fpe", FPU_ARCH_FPE},
26896 {"fpe2", FPU_ARCH_FPE},
26897 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
26898 {"fpa", FPU_ARCH_FPA},
26899 {"fpa10", FPU_ARCH_FPA},
26900 {"fpa11", FPU_ARCH_FPA},
26901 {"arm7500fe", FPU_ARCH_FPA},
26902 {"softvfp", FPU_ARCH_VFP},
26903 {"softvfp+vfp", FPU_ARCH_VFP_V2},
26904 {"vfp", FPU_ARCH_VFP_V2},
26905 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 26906 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
26907 {"vfp10", FPU_ARCH_VFP_V2},
26908 {"vfp10-r0", FPU_ARCH_VFP_V1},
26909 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
26910 {"vfpv2", FPU_ARCH_VFP_V2},
26911 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 26912 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 26913 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
26914 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
26915 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
26916 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
26917 {"arm1020t", FPU_ARCH_VFP_V1},
26918 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 26919 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
26920 {"arm1136jf-s", FPU_ARCH_VFP_V2},
26921 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 26922 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 26923 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 26924 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
26925 {"vfpv4", FPU_ARCH_VFP_V4},
26926 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 26927 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
26928 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
26929 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 26930 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
26931 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
26932 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
26933 {"crypto-neon-fp-armv8",
26934 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 26935 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
26936 {"crypto-neon-fp-armv8.1",
26937 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
26938 {NULL, ARM_ARCH_NONE}
26939};
26940
26941struct arm_option_value_table
26942{
e0471c16 26943 const char *name;
e74cfd16 26944 long value;
c19d1205 26945};
7ed4c4c5 26946
e74cfd16 26947static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
26948{
26949 {"hard", ARM_FLOAT_ABI_HARD},
26950 {"softfp", ARM_FLOAT_ABI_SOFTFP},
26951 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 26952 {NULL, 0}
c19d1205 26953};
7ed4c4c5 26954
c19d1205 26955#ifdef OBJ_ELF
3a4a14e9 26956/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 26957static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
26958{
26959 {"gnu", EF_ARM_EABI_UNKNOWN},
26960 {"4", EF_ARM_EABI_VER4},
3a4a14e9 26961 {"5", EF_ARM_EABI_VER5},
e74cfd16 26962 {NULL, 0}
c19d1205
ZW
26963};
26964#endif
7ed4c4c5 26965
c19d1205
ZW
26966struct arm_long_option_table
26967{
0198d5e6 26968 const char * option; /* Substring to match. */
e0471c16 26969 const char * help; /* Help information. */
17b9d67d 26970 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 26971 const char * deprecated; /* If non-null, print this message. */
c19d1205 26972};
7ed4c4c5 26973
c921be7d 26974static bfd_boolean
c168ce07 26975arm_parse_extension (const char *str, const arm_feature_set *opt_set,
34ef62f4
AV
26976 arm_feature_set *ext_set,
26977 const struct arm_ext_table *ext_table)
7ed4c4c5 26978{
69133863 26979 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
26980 extensions being added before being removed. We achieve this by having
26981 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 26982 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 26983 or removing it (0) and only allowing it to change in the order
69133863
MGD
26984 -1 -> 1 -> 0. */
26985 const struct arm_option_extension_value_table * opt = NULL;
d942732e 26986 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26987 int adding_value = -1;
26988
c19d1205 26989 while (str != NULL && *str != 0)
7ed4c4c5 26990 {
82b8a785 26991 const char *ext;
f3bad469 26992 size_t len;
7ed4c4c5 26993
c19d1205
ZW
26994 if (*str != '+')
26995 {
26996 as_bad (_("invalid architectural extension"));
c921be7d 26997 return FALSE;
c19d1205 26998 }
7ed4c4c5 26999
c19d1205
ZW
27000 str++;
27001 ext = strchr (str, '+');
7ed4c4c5 27002
c19d1205 27003 if (ext != NULL)
f3bad469 27004 len = ext - str;
c19d1205 27005 else
f3bad469 27006 len = strlen (str);
7ed4c4c5 27007
f3bad469 27008 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
27009 {
27010 if (adding_value != 0)
27011 {
27012 adding_value = 0;
27013 opt = arm_extensions;
27014 }
27015
f3bad469 27016 len -= 2;
69133863
MGD
27017 str += 2;
27018 }
f3bad469 27019 else if (len > 0)
69133863
MGD
27020 {
27021 if (adding_value == -1)
27022 {
27023 adding_value = 1;
27024 opt = arm_extensions;
27025 }
27026 else if (adding_value != 1)
27027 {
27028 as_bad (_("must specify extensions to add before specifying "
27029 "those to remove"));
27030 return FALSE;
27031 }
27032 }
27033
f3bad469 27034 if (len == 0)
c19d1205
ZW
27035 {
27036 as_bad (_("missing architectural extension"));
c921be7d 27037 return FALSE;
c19d1205 27038 }
7ed4c4c5 27039
69133863
MGD
27040 gas_assert (adding_value != -1);
27041 gas_assert (opt != NULL);
27042
34ef62f4
AV
27043 if (ext_table != NULL)
27044 {
27045 const struct arm_ext_table * ext_opt = ext_table;
27046 bfd_boolean found = FALSE;
27047 for (; ext_opt->name != NULL; ext_opt++)
27048 if (ext_opt->name_len == len
27049 && strncmp (ext_opt->name, str, len) == 0)
27050 {
27051 if (adding_value)
27052 {
27053 if (ARM_FEATURE_ZERO (ext_opt->merge))
27054 /* TODO: Option not supported. When we remove the
27055 legacy table this case should error out. */
27056 continue;
27057
27058 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
27059 }
27060 else
27061 {
27062 if (ARM_FEATURE_ZERO (ext_opt->clear))
27063 /* TODO: Option not supported. When we remove the
27064 legacy table this case should error out. */
27065 continue;
27066 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
27067 }
27068 found = TRUE;
27069 break;
27070 }
27071 if (found)
27072 {
27073 str = ext;
27074 continue;
27075 }
27076 }
27077
69133863
MGD
27078 /* Scan over the options table trying to find an exact match. */
27079 for (; opt->name != NULL; opt++)
f3bad469 27080 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 27081 {
d942732e
TP
27082 int i, nb_allowed_archs =
27083 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 27084 /* Check we can apply the extension to this architecture. */
d942732e
TP
27085 for (i = 0; i < nb_allowed_archs; i++)
27086 {
27087 /* Empty entry. */
27088 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
27089 continue;
c168ce07 27090 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
27091 break;
27092 }
27093 if (i == nb_allowed_archs)
69133863
MGD
27094 {
27095 as_bad (_("extension does not apply to the base architecture"));
27096 return FALSE;
27097 }
27098
27099 /* Add or remove the extension. */
27100 if (adding_value)
4d354d8b 27101 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 27102 else
4d354d8b 27103 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 27104
3d030cdb
TP
27105 /* Allowing Thumb division instructions for ARMv7 in autodetection
27106 rely on this break so that duplicate extensions (extensions
27107 with the same name as a previous extension in the list) are not
27108 considered for command-line parsing. */
c19d1205
ZW
27109 break;
27110 }
7ed4c4c5 27111
c19d1205
ZW
27112 if (opt->name == NULL)
27113 {
69133863
MGD
27114 /* Did we fail to find an extension because it wasn't specified in
27115 alphabetical order, or because it does not exist? */
27116
27117 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 27118 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
27119 break;
27120
27121 if (opt->name == NULL)
27122 as_bad (_("unknown architectural extension `%s'"), str);
27123 else
27124 as_bad (_("architectural extensions must be specified in "
27125 "alphabetical order"));
27126
c921be7d 27127 return FALSE;
c19d1205 27128 }
69133863
MGD
27129 else
27130 {
27131 /* We should skip the extension we've just matched the next time
27132 round. */
27133 opt++;
27134 }
7ed4c4c5 27135
c19d1205
ZW
27136 str = ext;
27137 };
7ed4c4c5 27138
c921be7d 27139 return TRUE;
c19d1205 27140}
7ed4c4c5 27141
c921be7d 27142static bfd_boolean
17b9d67d 27143arm_parse_cpu (const char *str)
7ed4c4c5 27144{
f3bad469 27145 const struct arm_cpu_option_table *opt;
82b8a785 27146 const char *ext = strchr (str, '+');
f3bad469 27147 size_t len;
7ed4c4c5 27148
c19d1205 27149 if (ext != NULL)
f3bad469 27150 len = ext - str;
7ed4c4c5 27151 else
f3bad469 27152 len = strlen (str);
7ed4c4c5 27153
f3bad469 27154 if (len == 0)
7ed4c4c5 27155 {
c19d1205 27156 as_bad (_("missing cpu name `%s'"), str);
c921be7d 27157 return FALSE;
7ed4c4c5
NC
27158 }
27159
c19d1205 27160 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 27161 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 27162 {
c168ce07 27163 mcpu_cpu_opt = &opt->value;
4d354d8b
TP
27164 if (mcpu_ext_opt == NULL)
27165 mcpu_ext_opt = XNEW (arm_feature_set);
27166 *mcpu_ext_opt = opt->ext;
e74cfd16 27167 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 27168 if (opt->canonical_name)
ef8e6722
JW
27169 {
27170 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
27171 strcpy (selected_cpu_name, opt->canonical_name);
27172 }
ee065d83
PB
27173 else
27174 {
f3bad469 27175 size_t i;
c921be7d 27176
ef8e6722
JW
27177 if (len >= sizeof selected_cpu_name)
27178 len = (sizeof selected_cpu_name) - 1;
27179
f3bad469 27180 for (i = 0; i < len; i++)
ee065d83
PB
27181 selected_cpu_name[i] = TOUPPER (opt->name[i]);
27182 selected_cpu_name[i] = 0;
27183 }
7ed4c4c5 27184
c19d1205 27185 if (ext != NULL)
34ef62f4 27186 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
7ed4c4c5 27187
c921be7d 27188 return TRUE;
c19d1205 27189 }
7ed4c4c5 27190
c19d1205 27191 as_bad (_("unknown cpu `%s'"), str);
c921be7d 27192 return FALSE;
7ed4c4c5
NC
27193}
27194
c921be7d 27195static bfd_boolean
17b9d67d 27196arm_parse_arch (const char *str)
7ed4c4c5 27197{
e74cfd16 27198 const struct arm_arch_option_table *opt;
82b8a785 27199 const char *ext = strchr (str, '+');
f3bad469 27200 size_t len;
7ed4c4c5 27201
c19d1205 27202 if (ext != NULL)
f3bad469 27203 len = ext - str;
7ed4c4c5 27204 else
f3bad469 27205 len = strlen (str);
7ed4c4c5 27206
f3bad469 27207 if (len == 0)
7ed4c4c5 27208 {
c19d1205 27209 as_bad (_("missing architecture name `%s'"), str);
c921be7d 27210 return FALSE;
7ed4c4c5
NC
27211 }
27212
c19d1205 27213 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 27214 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 27215 {
e74cfd16 27216 march_cpu_opt = &opt->value;
4d354d8b
TP
27217 if (march_ext_opt == NULL)
27218 march_ext_opt = XNEW (arm_feature_set);
27219 *march_ext_opt = arm_arch_none;
e74cfd16 27220 march_fpu_opt = &opt->default_fpu;
5f4273c7 27221 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 27222
c19d1205 27223 if (ext != NULL)
34ef62f4
AV
27224 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
27225 opt->ext_table);
7ed4c4c5 27226
c921be7d 27227 return TRUE;
c19d1205
ZW
27228 }
27229
27230 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 27231 return FALSE;
7ed4c4c5 27232}
eb043451 27233
c921be7d 27234static bfd_boolean
17b9d67d 27235arm_parse_fpu (const char * str)
c19d1205 27236{
69133863 27237 const struct arm_option_fpu_value_table * opt;
b99bd4ef 27238
c19d1205
ZW
27239 for (opt = arm_fpus; opt->name != NULL; opt++)
27240 if (streq (opt->name, str))
27241 {
e74cfd16 27242 mfpu_opt = &opt->value;
c921be7d 27243 return TRUE;
c19d1205 27244 }
b99bd4ef 27245
c19d1205 27246 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 27247 return FALSE;
c19d1205
ZW
27248}
27249
c921be7d 27250static bfd_boolean
17b9d67d 27251arm_parse_float_abi (const char * str)
b99bd4ef 27252{
e74cfd16 27253 const struct arm_option_value_table * opt;
b99bd4ef 27254
c19d1205
ZW
27255 for (opt = arm_float_abis; opt->name != NULL; opt++)
27256 if (streq (opt->name, str))
27257 {
27258 mfloat_abi_opt = opt->value;
c921be7d 27259 return TRUE;
c19d1205 27260 }
cc8a6dd0 27261
c19d1205 27262 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 27263 return FALSE;
c19d1205 27264}
b99bd4ef 27265
c19d1205 27266#ifdef OBJ_ELF
c921be7d 27267static bfd_boolean
17b9d67d 27268arm_parse_eabi (const char * str)
c19d1205 27269{
e74cfd16 27270 const struct arm_option_value_table *opt;
cc8a6dd0 27271
c19d1205
ZW
27272 for (opt = arm_eabis; opt->name != NULL; opt++)
27273 if (streq (opt->name, str))
27274 {
27275 meabi_flags = opt->value;
c921be7d 27276 return TRUE;
c19d1205
ZW
27277 }
27278 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 27279 return FALSE;
c19d1205
ZW
27280}
27281#endif
cc8a6dd0 27282
c921be7d 27283static bfd_boolean
17b9d67d 27284arm_parse_it_mode (const char * str)
e07e6e58 27285{
c921be7d 27286 bfd_boolean ret = TRUE;
e07e6e58
NC
27287
27288 if (streq ("arm", str))
27289 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
27290 else if (streq ("thumb", str))
27291 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
27292 else if (streq ("always", str))
27293 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
27294 else if (streq ("never", str))
27295 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
27296 else
27297 {
27298 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 27299 "arm, thumb, always, or never."), str);
c921be7d 27300 ret = FALSE;
e07e6e58
NC
27301 }
27302
27303 return ret;
27304}
27305
2e6976a8 27306static bfd_boolean
17b9d67d 27307arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
27308{
27309 codecomposer_syntax = TRUE;
27310 arm_comment_chars[0] = ';';
27311 arm_line_separator_chars[0] = 0;
27312 return TRUE;
27313}
27314
c19d1205
ZW
27315struct arm_long_option_table arm_long_opts[] =
27316{
27317 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
27318 arm_parse_cpu, NULL},
27319 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
27320 arm_parse_arch, NULL},
27321 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
27322 arm_parse_fpu, NULL},
27323 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
27324 arm_parse_float_abi, NULL},
27325#ifdef OBJ_ELF
7fac0536 27326 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
27327 arm_parse_eabi, NULL},
27328#endif
e07e6e58
NC
27329 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
27330 arm_parse_it_mode, NULL},
2e6976a8
DG
27331 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
27332 arm_ccs_mode, NULL},
c19d1205
ZW
27333 {NULL, NULL, 0, NULL}
27334};
cc8a6dd0 27335
c19d1205 27336int
17b9d67d 27337md_parse_option (int c, const char * arg)
c19d1205
ZW
27338{
27339 struct arm_option_table *opt;
e74cfd16 27340 const struct arm_legacy_option_table *fopt;
c19d1205 27341 struct arm_long_option_table *lopt;
b99bd4ef 27342
c19d1205 27343 switch (c)
b99bd4ef 27344 {
c19d1205
ZW
27345#ifdef OPTION_EB
27346 case OPTION_EB:
27347 target_big_endian = 1;
27348 break;
27349#endif
cc8a6dd0 27350
c19d1205
ZW
27351#ifdef OPTION_EL
27352 case OPTION_EL:
27353 target_big_endian = 0;
27354 break;
27355#endif
b99bd4ef 27356
845b51d6
PB
27357 case OPTION_FIX_V4BX:
27358 fix_v4bx = TRUE;
27359 break;
27360
18a20338
CL
27361#ifdef OBJ_ELF
27362 case OPTION_FDPIC:
27363 arm_fdpic = TRUE;
27364 break;
27365#endif /* OBJ_ELF */
27366
c19d1205
ZW
27367 case 'a':
27368 /* Listing option. Just ignore these, we don't support additional
27369 ones. */
27370 return 0;
b99bd4ef 27371
c19d1205
ZW
27372 default:
27373 for (opt = arm_opts; opt->option != NULL; opt++)
27374 {
27375 if (c == opt->option[0]
27376 && ((arg == NULL && opt->option[1] == 0)
27377 || streq (arg, opt->option + 1)))
27378 {
c19d1205 27379 /* If the option is deprecated, tell the user. */
278df34e 27380 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
27381 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
27382 arg ? arg : "", _(opt->deprecated));
b99bd4ef 27383
c19d1205
ZW
27384 if (opt->var != NULL)
27385 *opt->var = opt->value;
cc8a6dd0 27386
c19d1205
ZW
27387 return 1;
27388 }
27389 }
b99bd4ef 27390
e74cfd16
PB
27391 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
27392 {
27393 if (c == fopt->option[0]
27394 && ((arg == NULL && fopt->option[1] == 0)
27395 || streq (arg, fopt->option + 1)))
27396 {
e74cfd16 27397 /* If the option is deprecated, tell the user. */
278df34e 27398 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
27399 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
27400 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
27401
27402 if (fopt->var != NULL)
27403 *fopt->var = &fopt->value;
27404
27405 return 1;
27406 }
27407 }
27408
c19d1205
ZW
27409 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
27410 {
27411 /* These options are expected to have an argument. */
27412 if (c == lopt->option[0]
27413 && arg != NULL
27414 && strncmp (arg, lopt->option + 1,
27415 strlen (lopt->option + 1)) == 0)
27416 {
c19d1205 27417 /* If the option is deprecated, tell the user. */
278df34e 27418 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
27419 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
27420 _(lopt->deprecated));
b99bd4ef 27421
c19d1205
ZW
27422 /* Call the sup-option parser. */
27423 return lopt->func (arg + strlen (lopt->option) - 1);
27424 }
27425 }
a737bd4d 27426
c19d1205
ZW
27427 return 0;
27428 }
a394c00f 27429
c19d1205
ZW
27430 return 1;
27431}
a394c00f 27432
c19d1205
ZW
27433void
27434md_show_usage (FILE * fp)
a394c00f 27435{
c19d1205
ZW
27436 struct arm_option_table *opt;
27437 struct arm_long_option_table *lopt;
a394c00f 27438
c19d1205 27439 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 27440
c19d1205
ZW
27441 for (opt = arm_opts; opt->option != NULL; opt++)
27442 if (opt->help != NULL)
27443 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 27444
c19d1205
ZW
27445 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
27446 if (lopt->help != NULL)
27447 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 27448
c19d1205
ZW
27449#ifdef OPTION_EB
27450 fprintf (fp, _("\
27451 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
27452#endif
27453
c19d1205
ZW
27454#ifdef OPTION_EL
27455 fprintf (fp, _("\
27456 -EL assemble code for a little-endian cpu\n"));
a737bd4d 27457#endif
845b51d6
PB
27458
27459 fprintf (fp, _("\
27460 --fix-v4bx Allow BX in ARMv4 code\n"));
18a20338
CL
27461
27462#ifdef OBJ_ELF
27463 fprintf (fp, _("\
27464 --fdpic generate an FDPIC object file\n"));
27465#endif /* OBJ_ELF */
c19d1205 27466}
ee065d83 27467
ee065d83 27468#ifdef OBJ_ELF
0198d5e6 27469
62b3e311
PB
27470typedef struct
27471{
27472 int val;
27473 arm_feature_set flags;
27474} cpu_arch_ver_table;
27475
2c6b98ea
TP
27476/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
27477 chronologically for architectures, with an exception for ARMv6-M and
27478 ARMv6S-M due to legacy reasons. No new architecture should have a
27479 special case. This allows for build attribute selection results to be
27480 stable when new architectures are added. */
62b3e311
PB
27481static const cpu_arch_ver_table cpu_arch_ver[] =
27482{
031254f2
AV
27483 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
27484 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
27485 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
27486 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
27487 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
27488 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
27489 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
27490 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
27491 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
27492 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
27493 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
27494 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
27495 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
27496 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
27497 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
27498 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
27499 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
27500 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
27501 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
27502 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
27503 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
27504 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
27505 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
27506 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
2c6b98ea
TP
27507
27508 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
27509 always selected build attributes to match those of ARMv6-M
27510 (resp. ARMv6S-M). However, due to these architectures being a strict
27511 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
27512 would be selected when fully respecting chronology of architectures.
27513 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
27514 move them before ARMv7 architectures. */
031254f2
AV
27515 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
27516 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
27517
27518 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
27519 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
27520 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
27521 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
27522 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
27523 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
27524 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
27525 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
27526 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
27527 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
27528 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
27529 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
27530 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
27531 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
27532 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
27533 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
27534 {-1, ARM_ARCH_NONE}
62b3e311
PB
27535};
27536
ee3c0378 27537/* Set an attribute if it has not already been set by the user. */
0198d5e6 27538
ee3c0378
AS
27539static void
27540aeabi_set_attribute_int (int tag, int value)
27541{
27542 if (tag < 1
27543 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
27544 || !attributes_set_explicitly[tag])
27545 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
27546}
27547
27548static void
27549aeabi_set_attribute_string (int tag, const char *value)
27550{
27551 if (tag < 1
27552 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
27553 || !attributes_set_explicitly[tag])
27554 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
27555}
27556
2c6b98ea
TP
27557/* Return whether features in the *NEEDED feature set are available via
27558 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 27559
2c6b98ea
TP
27560static bfd_boolean
27561have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
27562 const arm_feature_set *needed)
27563{
27564 int i, nb_allowed_archs;
27565 arm_feature_set ext_fset;
27566 const struct arm_option_extension_value_table *opt;
27567
27568 ext_fset = arm_arch_none;
27569 for (opt = arm_extensions; opt->name != NULL; opt++)
27570 {
27571 /* Extension does not provide any feature we need. */
27572 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
27573 continue;
27574
27575 nb_allowed_archs =
27576 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
27577 for (i = 0; i < nb_allowed_archs; i++)
27578 {
27579 /* Empty entry. */
27580 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
27581 break;
27582
27583 /* Extension is available, add it. */
27584 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
27585 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
27586 }
27587 }
27588
27589 /* Can we enable all features in *needed? */
27590 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
27591}
27592
27593/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
27594 a given architecture feature set *ARCH_EXT_FSET including extension feature
27595 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
27596 - if true, check for an exact match of the architecture modulo extensions;
27597 - otherwise, select build attribute value of the first superset
27598 architecture released so that results remains stable when new architectures
27599 are added.
27600 For -march/-mcpu=all the build attribute value of the most featureful
27601 architecture is returned. Tag_CPU_arch_profile result is returned in
27602 PROFILE. */
0198d5e6 27603
2c6b98ea
TP
27604static int
27605get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
27606 const arm_feature_set *ext_fset,
27607 char *profile, int exact_match)
27608{
27609 arm_feature_set arch_fset;
27610 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
27611
27612 /* Select most featureful architecture with all its extensions if building
27613 for -march=all as the feature sets used to set build attributes. */
27614 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
27615 {
27616 /* Force revisiting of decision for each new architecture. */
031254f2 27617 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
2c6b98ea
TP
27618 *profile = 'A';
27619 return TAG_CPU_ARCH_V8;
27620 }
27621
27622 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
27623
27624 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
27625 {
27626 arm_feature_set known_arch_fset;
27627
27628 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
27629 if (exact_match)
27630 {
27631 /* Base architecture match user-specified architecture and
27632 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
27633 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
27634 {
27635 p_ver_ret = p_ver;
27636 goto found;
27637 }
27638 /* Base architecture match user-specified architecture only
27639 (eg. ARMv6-M in the same case as above). Record it in case we
27640 find a match with above condition. */
27641 else if (p_ver_ret == NULL
27642 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
27643 p_ver_ret = p_ver;
27644 }
27645 else
27646 {
27647
27648 /* Architecture has all features wanted. */
27649 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
27650 {
27651 arm_feature_set added_fset;
27652
27653 /* Compute features added by this architecture over the one
27654 recorded in p_ver_ret. */
27655 if (p_ver_ret != NULL)
27656 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
27657 p_ver_ret->flags);
27658 /* First architecture that match incl. with extensions, or the
27659 only difference in features over the recorded match is
27660 features that were optional and are now mandatory. */
27661 if (p_ver_ret == NULL
27662 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
27663 {
27664 p_ver_ret = p_ver;
27665 goto found;
27666 }
27667 }
27668 else if (p_ver_ret == NULL)
27669 {
27670 arm_feature_set needed_ext_fset;
27671
27672 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
27673
27674 /* Architecture has all features needed when using some
27675 extensions. Record it and continue searching in case there
27676 exist an architecture providing all needed features without
27677 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
27678 OS extension). */
27679 if (have_ext_for_needed_feat_p (&known_arch_fset,
27680 &needed_ext_fset))
27681 p_ver_ret = p_ver;
27682 }
27683 }
27684 }
27685
27686 if (p_ver_ret == NULL)
27687 return -1;
27688
27689found:
27690 /* Tag_CPU_arch_profile. */
27691 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
27692 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
27693 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
27694 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
27695 *profile = 'A';
27696 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
27697 *profile = 'R';
27698 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
27699 *profile = 'M';
27700 else
27701 *profile = '\0';
27702 return p_ver_ret->val;
27703}
27704
ee065d83 27705/* Set the public EABI object attributes. */
0198d5e6 27706
c168ce07 27707static void
ee065d83
PB
27708aeabi_set_public_attributes (void)
27709{
b90d5ba0 27710 char profile = '\0';
2c6b98ea 27711 int arch = -1;
90ec0d68 27712 int virt_sec = 0;
bca38921 27713 int fp16_optional = 0;
2c6b98ea
TP
27714 int skip_exact_match = 0;
27715 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 27716
54bab281
TP
27717 /* Autodetection mode, choose the architecture based the instructions
27718 actually used. */
27719 if (no_cpu_selected ())
27720 {
27721 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 27722
54bab281
TP
27723 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
27724 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 27725
54bab281
TP
27726 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
27727 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 27728
54bab281 27729 /* Code run during relaxation relies on selected_cpu being set. */
4d354d8b
TP
27730 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
27731 flags_ext = arm_arch_none;
27732 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
27733 selected_ext = flags_ext;
54bab281
TP
27734 selected_cpu = flags;
27735 }
27736 /* Otherwise, choose the architecture based on the capabilities of the
27737 requested cpu. */
27738 else
4d354d8b
TP
27739 {
27740 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
27741 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
27742 flags_ext = selected_ext;
27743 flags = selected_cpu;
27744 }
27745 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
7f78eb34 27746
ddd7f988 27747 /* Allow the user to override the reported architecture. */
4d354d8b 27748 if (!ARM_FEATURE_ZERO (selected_object_arch))
7a1d4c38 27749 {
4d354d8b 27750 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
2c6b98ea 27751 flags_ext = arm_arch_none;
7a1d4c38 27752 }
2c6b98ea 27753 else
4d354d8b 27754 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
2c6b98ea
TP
27755
27756 /* When this function is run again after relaxation has happened there is no
27757 way to determine whether an architecture or CPU was specified by the user:
27758 - selected_cpu is set above for relaxation to work;
27759 - march_cpu_opt is not set if only -mcpu or .cpu is used;
27760 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
27761 Therefore, if not in -march=all case we first try an exact match and fall
27762 back to autodetection. */
27763 if (!skip_exact_match)
27764 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
27765 if (arch == -1)
27766 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
27767 if (arch == -1)
27768 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 27769
ee065d83
PB
27770 /* Tag_CPU_name. */
27771 if (selected_cpu_name[0])
27772 {
91d6fa6a 27773 char *q;
ee065d83 27774
91d6fa6a
NC
27775 q = selected_cpu_name;
27776 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
27777 {
27778 int i;
5f4273c7 27779
91d6fa6a
NC
27780 q += 4;
27781 for (i = 0; q[i]; i++)
27782 q[i] = TOUPPER (q[i]);
ee065d83 27783 }
91d6fa6a 27784 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 27785 }
62f3b8c8 27786
ee065d83 27787 /* Tag_CPU_arch. */
ee3c0378 27788 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 27789
62b3e311 27790 /* Tag_CPU_arch_profile. */
69239280
MGD
27791 if (profile != '\0')
27792 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 27793
15afaa63 27794 /* Tag_DSP_extension. */
4d354d8b 27795 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
6c290d53 27796 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 27797
2c6b98ea 27798 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 27799 /* Tag_ARM_ISA_use. */
ee3c0378 27800 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 27801 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 27802 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 27803
ee065d83 27804 /* Tag_THUMB_ISA_use. */
ee3c0378 27805 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 27806 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
27807 {
27808 int thumb_isa_use;
27809
27810 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 27811 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
27812 thumb_isa_use = 3;
27813 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
27814 thumb_isa_use = 2;
27815 else
27816 thumb_isa_use = 1;
27817 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
27818 }
62f3b8c8 27819
ee065d83 27820 /* Tag_VFP_arch. */
a715796b
TG
27821 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
27822 aeabi_set_attribute_int (Tag_VFP_arch,
27823 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27824 ? 7 : 8);
bca38921 27825 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
27826 aeabi_set_attribute_int (Tag_VFP_arch,
27827 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27828 ? 5 : 6);
27829 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
27830 {
27831 fp16_optional = 1;
27832 aeabi_set_attribute_int (Tag_VFP_arch, 3);
27833 }
ada65aa3 27834 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
27835 {
27836 aeabi_set_attribute_int (Tag_VFP_arch, 4);
27837 fp16_optional = 1;
27838 }
ee3c0378
AS
27839 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
27840 aeabi_set_attribute_int (Tag_VFP_arch, 2);
27841 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 27842 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 27843 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 27844
4547cb56
NC
27845 /* Tag_ABI_HardFP_use. */
27846 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
27847 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
27848 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
27849
ee065d83 27850 /* Tag_WMMX_arch. */
ee3c0378
AS
27851 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
27852 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
27853 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
27854 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 27855
ee3c0378 27856 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
27857 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
27858 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
27859 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
27860 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
27861 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
27862 {
27863 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
27864 {
27865 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
27866 }
27867 else
27868 {
27869 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
27870 fp16_optional = 1;
27871 }
27872 }
fa94de6b 27873
ee3c0378 27874 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 27875 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 27876 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 27877
69239280
MGD
27878 /* Tag_DIV_use.
27879
27880 We set Tag_DIV_use to two when integer divide instructions have been used
27881 in ARM state, or when Thumb integer divide instructions have been used,
27882 but we have no architecture profile set, nor have we any ARM instructions.
27883
4ed7ed8d
TP
27884 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
27885 by the base architecture.
bca38921 27886
69239280 27887 For new architectures we will have to check these tests. */
031254f2 27888 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
4ed7ed8d
TP
27889 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
27890 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
27891 aeabi_set_attribute_int (Tag_DIV_use, 0);
27892 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
27893 || (profile == '\0'
27894 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
27895 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 27896 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
27897
27898 /* Tag_MP_extension_use. */
27899 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
27900 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
27901
27902 /* Tag Virtualization_use. */
27903 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
27904 virt_sec |= 1;
27905 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
27906 virt_sec |= 2;
27907 if (virt_sec != 0)
27908 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
27909}
27910
c168ce07
TP
27911/* Post relaxation hook. Recompute ARM attributes now that relaxation is
27912 finished and free extension feature bits which will not be used anymore. */
0198d5e6 27913
c168ce07
TP
27914void
27915arm_md_post_relax (void)
27916{
27917 aeabi_set_public_attributes ();
4d354d8b
TP
27918 XDELETE (mcpu_ext_opt);
27919 mcpu_ext_opt = NULL;
27920 XDELETE (march_ext_opt);
27921 march_ext_opt = NULL;
c168ce07
TP
27922}
27923
104d59d1 27924/* Add the default contents for the .ARM.attributes section. */
0198d5e6 27925
ee065d83
PB
27926void
27927arm_md_end (void)
27928{
ee065d83
PB
27929 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
27930 return;
27931
27932 aeabi_set_public_attributes ();
ee065d83 27933}
8463be01 27934#endif /* OBJ_ELF */
ee065d83 27935
ee065d83
PB
27936/* Parse a .cpu directive. */
27937
27938static void
27939s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
27940{
e74cfd16 27941 const struct arm_cpu_option_table *opt;
ee065d83
PB
27942 char *name;
27943 char saved_char;
27944
27945 name = input_line_pointer;
5f4273c7 27946 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27947 input_line_pointer++;
27948 saved_char = *input_line_pointer;
27949 *input_line_pointer = 0;
27950
27951 /* Skip the first "all" entry. */
27952 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
27953 if (streq (opt->name, name))
27954 {
4d354d8b
TP
27955 selected_arch = opt->value;
27956 selected_ext = opt->ext;
27957 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
ee065d83 27958 if (opt->canonical_name)
5f4273c7 27959 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
27960 else
27961 {
27962 int i;
27963 for (i = 0; opt->name[i]; i++)
27964 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 27965
ee065d83
PB
27966 selected_cpu_name[i] = 0;
27967 }
4d354d8b
TP
27968 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
27969
ee065d83
PB
27970 *input_line_pointer = saved_char;
27971 demand_empty_rest_of_line ();
27972 return;
27973 }
27974 as_bad (_("unknown cpu `%s'"), name);
27975 *input_line_pointer = saved_char;
27976 ignore_rest_of_line ();
27977}
27978
ee065d83
PB
27979/* Parse a .arch directive. */
27980
27981static void
27982s_arm_arch (int ignored ATTRIBUTE_UNUSED)
27983{
e74cfd16 27984 const struct arm_arch_option_table *opt;
ee065d83
PB
27985 char saved_char;
27986 char *name;
27987
27988 name = input_line_pointer;
5f4273c7 27989 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27990 input_line_pointer++;
27991 saved_char = *input_line_pointer;
27992 *input_line_pointer = 0;
27993
27994 /* Skip the first "all" entry. */
27995 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27996 if (streq (opt->name, name))
27997 {
4d354d8b
TP
27998 selected_arch = opt->value;
27999 selected_ext = arm_arch_none;
28000 selected_cpu = selected_arch;
5f4273c7 28001 strcpy (selected_cpu_name, opt->name);
4d354d8b 28002 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
28003 *input_line_pointer = saved_char;
28004 demand_empty_rest_of_line ();
28005 return;
28006 }
28007
28008 as_bad (_("unknown architecture `%s'\n"), name);
28009 *input_line_pointer = saved_char;
28010 ignore_rest_of_line ();
28011}
28012
7a1d4c38
PB
28013/* Parse a .object_arch directive. */
28014
28015static void
28016s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
28017{
28018 const struct arm_arch_option_table *opt;
28019 char saved_char;
28020 char *name;
28021
28022 name = input_line_pointer;
5f4273c7 28023 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
28024 input_line_pointer++;
28025 saved_char = *input_line_pointer;
28026 *input_line_pointer = 0;
28027
28028 /* Skip the first "all" entry. */
28029 for (opt = arm_archs + 1; opt->name != NULL; opt++)
28030 if (streq (opt->name, name))
28031 {
4d354d8b 28032 selected_object_arch = opt->value;
7a1d4c38
PB
28033 *input_line_pointer = saved_char;
28034 demand_empty_rest_of_line ();
28035 return;
28036 }
28037
28038 as_bad (_("unknown architecture `%s'\n"), name);
28039 *input_line_pointer = saved_char;
28040 ignore_rest_of_line ();
28041}
28042
69133863
MGD
28043/* Parse a .arch_extension directive. */
28044
28045static void
28046s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
28047{
28048 const struct arm_option_extension_value_table *opt;
28049 char saved_char;
28050 char *name;
28051 int adding_value = 1;
28052
28053 name = input_line_pointer;
28054 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
28055 input_line_pointer++;
28056 saved_char = *input_line_pointer;
28057 *input_line_pointer = 0;
28058
28059 if (strlen (name) >= 2
28060 && strncmp (name, "no", 2) == 0)
28061 {
28062 adding_value = 0;
28063 name += 2;
28064 }
28065
28066 for (opt = arm_extensions; opt->name != NULL; opt++)
28067 if (streq (opt->name, name))
28068 {
d942732e
TP
28069 int i, nb_allowed_archs =
28070 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
28071 for (i = 0; i < nb_allowed_archs; i++)
28072 {
28073 /* Empty entry. */
4d354d8b 28074 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
d942732e 28075 continue;
4d354d8b 28076 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
d942732e
TP
28077 break;
28078 }
28079
28080 if (i == nb_allowed_archs)
69133863
MGD
28081 {
28082 as_bad (_("architectural extension `%s' is not allowed for the "
28083 "current base architecture"), name);
28084 break;
28085 }
28086
28087 if (adding_value)
4d354d8b 28088 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
5a70a223 28089 opt->merge_value);
69133863 28090 else
4d354d8b 28091 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
69133863 28092
4d354d8b
TP
28093 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
28094 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
69133863
MGD
28095 *input_line_pointer = saved_char;
28096 demand_empty_rest_of_line ();
3d030cdb
TP
28097 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
28098 on this return so that duplicate extensions (extensions with the
28099 same name as a previous extension in the list) are not considered
28100 for command-line parsing. */
69133863
MGD
28101 return;
28102 }
28103
28104 if (opt->name == NULL)
e673710a 28105 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
28106
28107 *input_line_pointer = saved_char;
28108 ignore_rest_of_line ();
28109}
28110
ee065d83
PB
28111/* Parse a .fpu directive. */
28112
28113static void
28114s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
28115{
69133863 28116 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
28117 char saved_char;
28118 char *name;
28119
28120 name = input_line_pointer;
5f4273c7 28121 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
28122 input_line_pointer++;
28123 saved_char = *input_line_pointer;
28124 *input_line_pointer = 0;
5f4273c7 28125
ee065d83
PB
28126 for (opt = arm_fpus; opt->name != NULL; opt++)
28127 if (streq (opt->name, name))
28128 {
4d354d8b
TP
28129 selected_fpu = opt->value;
28130#ifndef CPU_DEFAULT
28131 if (no_cpu_selected ())
28132 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
28133 else
28134#endif
28135 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
28136 *input_line_pointer = saved_char;
28137 demand_empty_rest_of_line ();
28138 return;
28139 }
28140
28141 as_bad (_("unknown floating point format `%s'\n"), name);
28142 *input_line_pointer = saved_char;
28143 ignore_rest_of_line ();
28144}
ee065d83 28145
794ba86a 28146/* Copy symbol information. */
f31fef98 28147
794ba86a
DJ
28148void
28149arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
28150{
28151 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
28152}
e04befd0 28153
f31fef98 28154#ifdef OBJ_ELF
e04befd0
AS
28155/* Given a symbolic attribute NAME, return the proper integer value.
28156 Returns -1 if the attribute is not known. */
f31fef98 28157
e04befd0
AS
28158int
28159arm_convert_symbolic_attribute (const char *name)
28160{
f31fef98
NC
28161 static const struct
28162 {
28163 const char * name;
28164 const int tag;
28165 }
28166 attribute_table[] =
28167 {
28168 /* When you modify this table you should
28169 also modify the list in doc/c-arm.texi. */
e04befd0 28170#define T(tag) {#tag, tag}
f31fef98
NC
28171 T (Tag_CPU_raw_name),
28172 T (Tag_CPU_name),
28173 T (Tag_CPU_arch),
28174 T (Tag_CPU_arch_profile),
28175 T (Tag_ARM_ISA_use),
28176 T (Tag_THUMB_ISA_use),
75375b3e 28177 T (Tag_FP_arch),
f31fef98
NC
28178 T (Tag_VFP_arch),
28179 T (Tag_WMMX_arch),
28180 T (Tag_Advanced_SIMD_arch),
28181 T (Tag_PCS_config),
28182 T (Tag_ABI_PCS_R9_use),
28183 T (Tag_ABI_PCS_RW_data),
28184 T (Tag_ABI_PCS_RO_data),
28185 T (Tag_ABI_PCS_GOT_use),
28186 T (Tag_ABI_PCS_wchar_t),
28187 T (Tag_ABI_FP_rounding),
28188 T (Tag_ABI_FP_denormal),
28189 T (Tag_ABI_FP_exceptions),
28190 T (Tag_ABI_FP_user_exceptions),
28191 T (Tag_ABI_FP_number_model),
75375b3e 28192 T (Tag_ABI_align_needed),
f31fef98 28193 T (Tag_ABI_align8_needed),
75375b3e 28194 T (Tag_ABI_align_preserved),
f31fef98
NC
28195 T (Tag_ABI_align8_preserved),
28196 T (Tag_ABI_enum_size),
28197 T (Tag_ABI_HardFP_use),
28198 T (Tag_ABI_VFP_args),
28199 T (Tag_ABI_WMMX_args),
28200 T (Tag_ABI_optimization_goals),
28201 T (Tag_ABI_FP_optimization_goals),
28202 T (Tag_compatibility),
28203 T (Tag_CPU_unaligned_access),
75375b3e 28204 T (Tag_FP_HP_extension),
f31fef98
NC
28205 T (Tag_VFP_HP_extension),
28206 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
28207 T (Tag_MPextension_use),
28208 T (Tag_DIV_use),
f31fef98
NC
28209 T (Tag_nodefaults),
28210 T (Tag_also_compatible_with),
28211 T (Tag_conformance),
28212 T (Tag_T2EE_use),
28213 T (Tag_Virtualization_use),
15afaa63 28214 T (Tag_DSP_extension),
cd21e546 28215 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 28216#undef T
f31fef98 28217 };
e04befd0
AS
28218 unsigned int i;
28219
28220 if (name == NULL)
28221 return -1;
28222
f31fef98 28223 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 28224 if (streq (name, attribute_table[i].name))
e04befd0
AS
28225 return attribute_table[i].tag;
28226
28227 return -1;
28228}
267bf995 28229
93ef582d
NC
28230/* Apply sym value for relocations only in the case that they are for
28231 local symbols in the same segment as the fixup and you have the
28232 respective architectural feature for blx and simple switches. */
0198d5e6 28233
267bf995 28234int
93ef582d 28235arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
28236{
28237 if (fixP->fx_addsy
28238 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
28239 /* PR 17444: If the local symbol is in a different section then a reloc
28240 will always be generated for it, so applying the symbol value now
28241 will result in a double offset being stored in the relocation. */
28242 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 28243 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
28244 {
28245 switch (fixP->fx_r_type)
28246 {
28247 case BFD_RELOC_ARM_PCREL_BLX:
28248 case BFD_RELOC_THUMB_PCREL_BRANCH23:
28249 if (ARM_IS_FUNC (fixP->fx_addsy))
28250 return 1;
28251 break;
28252
28253 case BFD_RELOC_ARM_PCREL_CALL:
28254 case BFD_RELOC_THUMB_PCREL_BLX:
28255 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 28256 return 1;
267bf995
RR
28257 break;
28258
28259 default:
28260 break;
28261 }
28262
28263 }
28264 return 0;
28265}
f31fef98 28266#endif /* OBJ_ELF */