]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
[binutils, ARM, 12/16] Scalar Low Overhead loop instructions 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
60f993ce
AV
6546 /* New operands for Armv8.1-M Mainline. */
6547 OP_LR, /* ARM LR register */
6548 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
6549
c19d1205
ZW
6550 OP_REGLST, /* ARM register list */
6551 OP_VRSLST, /* VFP single-precision register list */
6552 OP_VRDLST, /* VFP double-precision register list */
037e8744 6553 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6554 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6555 OP_NSTRLST, /* Neon element/structure list */
6556
5287ad62 6557 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6558 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6559 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6560 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 6561 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 6562 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6563 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6564 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6565 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6566 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6567 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6568 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6569
6570 OP_I0, /* immediate zero */
c19d1205
ZW
6571 OP_I7, /* immediate value 0 .. 7 */
6572 OP_I15, /* 0 .. 15 */
6573 OP_I16, /* 1 .. 16 */
5287ad62 6574 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6575 OP_I31, /* 0 .. 31 */
6576 OP_I31w, /* 0 .. 31, optional trailing ! */
6577 OP_I32, /* 1 .. 32 */
5287ad62
JB
6578 OP_I32z, /* 0 .. 32 */
6579 OP_I63, /* 0 .. 63 */
c19d1205 6580 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6581 OP_I64, /* 1 .. 64 */
6582 OP_I64z, /* 0 .. 64 */
c19d1205 6583 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6584
6585 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6586 OP_I7b, /* 0 .. 7 */
6587 OP_I15b, /* 0 .. 15 */
6588 OP_I31b, /* 0 .. 31 */
6589
6590 OP_SH, /* shifter operand */
4962c51a 6591 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6592 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6593 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6594 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6595 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6596 OP_EXP, /* arbitrary expression */
6597 OP_EXPi, /* same, with optional immediate prefix */
6598 OP_EXPr, /* same, with optional relocation suffix */
e2b0ab59 6599 OP_EXPs, /* same, with optional non-first operand relocation suffix */
b6895b4f 6600 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
6601 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6602 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
6603
6604 OP_CPSF, /* CPS flags */
6605 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6606 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6607 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6608 OP_COND, /* conditional code */
92e90b6e 6609 OP_TB, /* Table branch. */
c19d1205 6610
037e8744
JB
6611 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6612
c19d1205 6613 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 6614 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
6615 OP_RR_EXi, /* ARM register or expression with imm prefix */
6616 OP_RF_IF, /* FPA register or immediate */
6617 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6618 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6619
6620 /* Optional operands. */
6621 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6622 OP_oI31b, /* 0 .. 31 */
5287ad62 6623 OP_oI32b, /* 1 .. 32 */
5f1af56b 6624 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6625 OP_oIffffb, /* 0 .. 65535 */
6626 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6627
6628 OP_oRR, /* ARM register */
60f993ce 6629 OP_oLR, /* ARM LR register */
c19d1205 6630 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6631 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6632 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6633 OP_oRND, /* Optional Neon double precision register */
6634 OP_oRNQ, /* Optional Neon quad precision register */
6635 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6636 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6637 OP_oSHll, /* LSL immediate */
6638 OP_oSHar, /* ASR immediate */
6639 OP_oSHllar, /* LSL or ASR immediate */
6640 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6641 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6642
5be8be5d
DG
6643 /* Some pre-defined mixed (ARM/THUMB) operands. */
6644 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6645 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6646 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6647
c19d1205
ZW
6648 OP_FIRST_OPTIONAL = OP_oI7b
6649};
a737bd4d 6650
c19d1205
ZW
6651/* Generic instruction operand parser. This does no encoding and no
6652 semantic validation; it merely squirrels values away in the inst
6653 structure. Returns SUCCESS or FAIL depending on whether the
6654 specified grammar matched. */
6655static int
5be8be5d 6656parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6657{
5be8be5d 6658 unsigned const int *upat = pattern;
c19d1205
ZW
6659 char *backtrack_pos = 0;
6660 const char *backtrack_error = 0;
99aad254 6661 int i, val = 0, backtrack_index = 0;
5287ad62 6662 enum arm_reg_type rtype;
4962c51a 6663 parse_operand_result result;
5be8be5d 6664 unsigned int op_parse_code;
c19d1205 6665
e07e6e58
NC
6666#define po_char_or_fail(chr) \
6667 do \
6668 { \
6669 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6670 goto bad_args; \
e07e6e58
NC
6671 } \
6672 while (0)
c19d1205 6673
e07e6e58
NC
6674#define po_reg_or_fail(regtype) \
6675 do \
dcbf9037 6676 { \
e07e6e58 6677 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6678 & inst.operands[i].vectype); \
e07e6e58 6679 if (val == FAIL) \
477330fc
RM
6680 { \
6681 first_error (_(reg_expected_msgs[regtype])); \
6682 goto failure; \
6683 } \
e07e6e58
NC
6684 inst.operands[i].reg = val; \
6685 inst.operands[i].isreg = 1; \
6686 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6687 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6688 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6689 || rtype == REG_TYPE_VFD \
6690 || rtype == REG_TYPE_NQ); \
dcbf9037 6691 } \
e07e6e58
NC
6692 while (0)
6693
6694#define po_reg_or_goto(regtype, label) \
6695 do \
6696 { \
6697 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6698 & inst.operands[i].vectype); \
6699 if (val == FAIL) \
6700 goto label; \
dcbf9037 6701 \
e07e6e58
NC
6702 inst.operands[i].reg = val; \
6703 inst.operands[i].isreg = 1; \
6704 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6705 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6706 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6707 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6708 || rtype == REG_TYPE_NQ); \
6709 } \
6710 while (0)
6711
6712#define po_imm_or_fail(min, max, popt) \
6713 do \
6714 { \
6715 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6716 goto failure; \
6717 inst.operands[i].imm = val; \
6718 } \
6719 while (0)
6720
6721#define po_scalar_or_goto(elsz, label) \
6722 do \
6723 { \
6724 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6725 if (val == FAIL) \
6726 goto label; \
6727 inst.operands[i].reg = val; \
6728 inst.operands[i].isscalar = 1; \
6729 } \
6730 while (0)
6731
6732#define po_misc_or_fail(expr) \
6733 do \
6734 { \
6735 if (expr) \
6736 goto failure; \
6737 } \
6738 while (0)
6739
6740#define po_misc_or_fail_no_backtrack(expr) \
6741 do \
6742 { \
6743 result = expr; \
6744 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6745 backtrack_pos = 0; \
6746 if (result != PARSE_OPERAND_SUCCESS) \
6747 goto failure; \
6748 } \
6749 while (0)
4962c51a 6750
52e7f43d
RE
6751#define po_barrier_or_imm(str) \
6752 do \
6753 { \
6754 val = parse_barrier (&str); \
ccb84d65
JB
6755 if (val == FAIL && ! ISALPHA (*str)) \
6756 goto immediate; \
6757 if (val == FAIL \
6758 /* ISB can only take SY as an option. */ \
6759 || ((inst.instruction & 0xf0) == 0x60 \
6760 && val != 0xf)) \
52e7f43d 6761 { \
ccb84d65
JB
6762 inst.error = _("invalid barrier type"); \
6763 backtrack_pos = 0; \
6764 goto failure; \
52e7f43d
RE
6765 } \
6766 } \
6767 while (0)
6768
c19d1205
ZW
6769 skip_whitespace (str);
6770
6771 for (i = 0; upat[i] != OP_stop; i++)
6772 {
5be8be5d
DG
6773 op_parse_code = upat[i];
6774 if (op_parse_code >= 1<<16)
6775 op_parse_code = thumb ? (op_parse_code >> 16)
6776 : (op_parse_code & ((1<<16)-1));
6777
6778 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6779 {
6780 /* Remember where we are in case we need to backtrack. */
9c2799c2 6781 gas_assert (!backtrack_pos);
c19d1205
ZW
6782 backtrack_pos = str;
6783 backtrack_error = inst.error;
6784 backtrack_index = i;
6785 }
6786
b6702015 6787 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6788 po_char_or_fail (',');
6789
5be8be5d 6790 switch (op_parse_code)
c19d1205
ZW
6791 {
6792 /* Registers */
6793 case OP_oRRnpc:
5be8be5d 6794 case OP_oRRnpcsp:
c19d1205 6795 case OP_RRnpc:
5be8be5d 6796 case OP_RRnpcsp:
c19d1205 6797 case OP_oRR:
60f993ce
AV
6798 case OP_LR:
6799 case OP_oLR:
c19d1205
ZW
6800 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6801 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6802 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6803 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6804 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6805 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6806 case OP_oRND:
5287ad62 6807 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6808 case OP_RVC:
6809 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6810 break;
6811 /* Also accept generic coprocessor regs for unknown registers. */
6812 coproc_reg:
6813 po_reg_or_fail (REG_TYPE_CN);
6814 break;
c19d1205
ZW
6815 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6816 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6817 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6818 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6819 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6820 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6821 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6822 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6823 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6824 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6825 case OP_oRNQ:
5287ad62 6826 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 6827 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
477330fc 6828 case OP_oRNDQ:
5287ad62 6829 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6830 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6831 case OP_oRNSDQ:
6832 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6833
6834 /* Neon scalar. Using an element size of 8 means that some invalid
6835 scalars are accepted here, so deal with those in later code. */
6836 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6837
6838 case OP_RNDQ_I0:
6839 {
6840 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6841 break;
6842 try_imm0:
6843 po_imm_or_fail (0, 0, TRUE);
6844 }
6845 break;
6846
6847 case OP_RVSD_I0:
6848 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6849 break;
6850
aacf0b33
KT
6851 case OP_RSVD_FI0:
6852 {
6853 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6854 break;
6855 try_ifimm0:
6856 if (parse_ifimm_zero (&str))
6857 inst.operands[i].imm = 0;
6858 else
6859 {
6860 inst.error
6861 = _("only floating point zero is allowed as immediate value");
6862 goto failure;
6863 }
6864 }
6865 break;
6866
477330fc
RM
6867 case OP_RR_RNSC:
6868 {
6869 po_scalar_or_goto (8, try_rr);
6870 break;
6871 try_rr:
6872 po_reg_or_fail (REG_TYPE_RN);
6873 }
6874 break;
6875
6876 case OP_RNSDQ_RNSC:
6877 {
6878 po_scalar_or_goto (8, try_nsdq);
6879 break;
6880 try_nsdq:
6881 po_reg_or_fail (REG_TYPE_NSDQ);
6882 }
6883 break;
6884
dec41383
JW
6885 case OP_RNSD_RNSC:
6886 {
6887 po_scalar_or_goto (8, try_s_scalar);
6888 break;
6889 try_s_scalar:
6890 po_scalar_or_goto (4, try_nsd);
6891 break;
6892 try_nsd:
6893 po_reg_or_fail (REG_TYPE_NSD);
6894 }
6895 break;
6896
477330fc
RM
6897 case OP_RNDQ_RNSC:
6898 {
6899 po_scalar_or_goto (8, try_ndq);
6900 break;
6901 try_ndq:
6902 po_reg_or_fail (REG_TYPE_NDQ);
6903 }
6904 break;
6905
6906 case OP_RND_RNSC:
6907 {
6908 po_scalar_or_goto (8, try_vfd);
6909 break;
6910 try_vfd:
6911 po_reg_or_fail (REG_TYPE_VFD);
6912 }
6913 break;
6914
6915 case OP_VMOV:
6916 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6917 not careful then bad things might happen. */
6918 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6919 break;
6920
6921 case OP_RNDQ_Ibig:
6922 {
6923 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6924 break;
6925 try_immbig:
6926 /* There's a possibility of getting a 64-bit immediate here, so
6927 we need special handling. */
8335d6aa
JW
6928 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6929 == FAIL)
477330fc
RM
6930 {
6931 inst.error = _("immediate value is out of range");
6932 goto failure;
6933 }
6934 }
6935 break;
6936
6937 case OP_RNDQ_I63b:
6938 {
6939 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6940 break;
6941 try_shimm:
6942 po_imm_or_fail (0, 63, TRUE);
6943 }
6944 break;
c19d1205
ZW
6945
6946 case OP_RRnpcb:
6947 po_char_or_fail ('[');
6948 po_reg_or_fail (REG_TYPE_RN);
6949 po_char_or_fail (']');
6950 break;
a737bd4d 6951
55881a11 6952 case OP_RRnpctw:
c19d1205 6953 case OP_RRw:
b6702015 6954 case OP_oRRw:
c19d1205
ZW
6955 po_reg_or_fail (REG_TYPE_RN);
6956 if (skip_past_char (&str, '!') == SUCCESS)
6957 inst.operands[i].writeback = 1;
6958 break;
6959
6960 /* Immediates */
6961 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6962 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6963 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6964 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6965 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6966 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6967 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6968 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6969 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6970 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6971 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6972 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6973
6974 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6975 case OP_oI7b:
6976 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6977 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6978 case OP_oI31b:
6979 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6980 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6981 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6982 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6983
6984 /* Immediate variants */
6985 case OP_oI255c:
6986 po_char_or_fail ('{');
6987 po_imm_or_fail (0, 255, TRUE);
6988 po_char_or_fail ('}');
6989 break;
6990
6991 case OP_I31w:
6992 /* The expression parser chokes on a trailing !, so we have
6993 to find it first and zap it. */
6994 {
6995 char *s = str;
6996 while (*s && *s != ',')
6997 s++;
6998 if (s[-1] == '!')
6999 {
7000 s[-1] = '\0';
7001 inst.operands[i].writeback = 1;
7002 }
7003 po_imm_or_fail (0, 31, TRUE);
7004 if (str == s - 1)
7005 str = s;
7006 }
7007 break;
7008
7009 /* Expressions */
7010 case OP_EXPi: EXPi:
e2b0ab59 7011 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7012 GE_OPT_PREFIX));
7013 break;
7014
7015 case OP_EXP:
e2b0ab59 7016 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7017 GE_NO_PREFIX));
7018 break;
7019
7020 case OP_EXPr: EXPr:
e2b0ab59 7021 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205 7022 GE_NO_PREFIX));
e2b0ab59 7023 if (inst.relocs[0].exp.X_op == O_symbol)
a737bd4d 7024 {
c19d1205
ZW
7025 val = parse_reloc (&str);
7026 if (val == -1)
7027 {
7028 inst.error = _("unrecognized relocation suffix");
7029 goto failure;
7030 }
7031 else if (val != BFD_RELOC_UNUSED)
7032 {
7033 inst.operands[i].imm = val;
7034 inst.operands[i].hasreloc = 1;
7035 }
a737bd4d 7036 }
c19d1205 7037 break;
a737bd4d 7038
e2b0ab59
AV
7039 case OP_EXPs:
7040 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7041 GE_NO_PREFIX));
7042 if (inst.relocs[i].exp.X_op == O_symbol)
7043 {
7044 inst.operands[i].hasreloc = 1;
7045 }
7046 else if (inst.relocs[i].exp.X_op == O_constant)
7047 {
7048 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7049 inst.operands[i].hasreloc = 0;
7050 }
7051 break;
7052
b6895b4f
PB
7053 /* Operand for MOVW or MOVT. */
7054 case OP_HALF:
7055 po_misc_or_fail (parse_half (&str));
7056 break;
7057
e07e6e58 7058 /* Register or expression. */
c19d1205
ZW
7059 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7060 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7061
e07e6e58 7062 /* Register or immediate. */
c19d1205
ZW
7063 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7064 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7065
c19d1205
ZW
7066 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7067 IF:
7068 if (!is_immediate_prefix (*str))
7069 goto bad_args;
7070 str++;
7071 val = parse_fpa_immediate (&str);
7072 if (val == FAIL)
7073 goto failure;
7074 /* FPA immediates are encoded as registers 8-15.
7075 parse_fpa_immediate has already applied the offset. */
7076 inst.operands[i].reg = val;
7077 inst.operands[i].isreg = 1;
7078 break;
09d92015 7079
2d447fca
JM
7080 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7081 I32z: po_imm_or_fail (0, 32, FALSE); break;
7082
e07e6e58 7083 /* Two kinds of register. */
c19d1205
ZW
7084 case OP_RIWR_RIWC:
7085 {
7086 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7087 if (!rege
7088 || (rege->type != REG_TYPE_MMXWR
7089 && rege->type != REG_TYPE_MMXWC
7090 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7091 {
7092 inst.error = _("iWMMXt data or control register expected");
7093 goto failure;
7094 }
7095 inst.operands[i].reg = rege->number;
7096 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7097 }
7098 break;
09d92015 7099
41adaa5c
JM
7100 case OP_RIWC_RIWG:
7101 {
7102 struct reg_entry *rege = arm_reg_parse_multi (&str);
7103 if (!rege
7104 || (rege->type != REG_TYPE_MMXWC
7105 && rege->type != REG_TYPE_MMXWCG))
7106 {
7107 inst.error = _("iWMMXt control register expected");
7108 goto failure;
7109 }
7110 inst.operands[i].reg = rege->number;
7111 inst.operands[i].isreg = 1;
7112 }
7113 break;
7114
c19d1205
ZW
7115 /* Misc */
7116 case OP_CPSF: val = parse_cps_flags (&str); break;
7117 case OP_ENDI: val = parse_endian_specifier (&str); break;
7118 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7119 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7120 case OP_oBARRIER_I15:
7121 po_barrier_or_imm (str); break;
7122 immediate:
7123 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7124 goto failure;
52e7f43d 7125 break;
c19d1205 7126
fa94de6b 7127 case OP_wPSR:
d2cd1205 7128 case OP_rPSR:
90ec0d68
MGD
7129 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7130 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7131 {
7132 inst.error = _("Banked registers are not available with this "
7133 "architecture.");
7134 goto failure;
7135 }
7136 break;
d2cd1205
JB
7137 try_psr:
7138 val = parse_psr (&str, op_parse_code == OP_wPSR);
7139 break;
037e8744 7140
477330fc
RM
7141 case OP_APSR_RR:
7142 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7143 break;
7144 try_apsr:
7145 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7146 instruction). */
7147 if (strncasecmp (str, "APSR_", 5) == 0)
7148 {
7149 unsigned found = 0;
7150 str += 5;
7151 while (found < 15)
7152 switch (*str++)
7153 {
7154 case 'c': found = (found & 1) ? 16 : found | 1; break;
7155 case 'n': found = (found & 2) ? 16 : found | 2; break;
7156 case 'z': found = (found & 4) ? 16 : found | 4; break;
7157 case 'v': found = (found & 8) ? 16 : found | 8; break;
7158 default: found = 16;
7159 }
7160 if (found != 15)
7161 goto failure;
7162 inst.operands[i].isvec = 1;
f7c21dc7
NC
7163 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7164 inst.operands[i].reg = REG_PC;
477330fc
RM
7165 }
7166 else
7167 goto failure;
7168 break;
037e8744 7169
92e90b6e
PB
7170 case OP_TB:
7171 po_misc_or_fail (parse_tb (&str));
7172 break;
7173
e07e6e58 7174 /* Register lists. */
c19d1205
ZW
7175 case OP_REGLST:
7176 val = parse_reg_list (&str);
7177 if (*str == '^')
7178 {
5e0d7f77 7179 inst.operands[i].writeback = 1;
c19d1205
ZW
7180 str++;
7181 }
7182 break;
09d92015 7183
c19d1205 7184 case OP_VRSLST:
5287ad62 7185 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7186 break;
09d92015 7187
c19d1205 7188 case OP_VRDLST:
5287ad62 7189 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7190 break;
a737bd4d 7191
477330fc
RM
7192 case OP_VRSDLST:
7193 /* Allow Q registers too. */
7194 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7195 REGLIST_NEON_D);
7196 if (val == FAIL)
7197 {
7198 inst.error = NULL;
7199 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7200 REGLIST_VFP_S);
7201 inst.operands[i].issingle = 1;
7202 }
7203 break;
7204
7205 case OP_NRDLST:
7206 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7207 REGLIST_NEON_D);
7208 break;
5287ad62
JB
7209
7210 case OP_NSTRLST:
477330fc
RM
7211 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7212 &inst.operands[i].vectype);
7213 break;
5287ad62 7214
c19d1205
ZW
7215 /* Addressing modes */
7216 case OP_ADDR:
7217 po_misc_or_fail (parse_address (&str, i));
7218 break;
09d92015 7219
4962c51a
MS
7220 case OP_ADDRGLDR:
7221 po_misc_or_fail_no_backtrack (
477330fc 7222 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7223 break;
7224
7225 case OP_ADDRGLDRS:
7226 po_misc_or_fail_no_backtrack (
477330fc 7227 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7228 break;
7229
7230 case OP_ADDRGLDC:
7231 po_misc_or_fail_no_backtrack (
477330fc 7232 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7233 break;
7234
c19d1205
ZW
7235 case OP_SH:
7236 po_misc_or_fail (parse_shifter_operand (&str, i));
7237 break;
09d92015 7238
4962c51a
MS
7239 case OP_SHG:
7240 po_misc_or_fail_no_backtrack (
477330fc 7241 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7242 break;
7243
c19d1205
ZW
7244 case OP_oSHll:
7245 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7246 break;
09d92015 7247
c19d1205
ZW
7248 case OP_oSHar:
7249 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7250 break;
09d92015 7251
c19d1205
ZW
7252 case OP_oSHllar:
7253 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7254 break;
09d92015 7255
c19d1205 7256 default:
5be8be5d 7257 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7258 }
09d92015 7259
c19d1205
ZW
7260 /* Various value-based sanity checks and shared operations. We
7261 do not signal immediate failures for the register constraints;
7262 this allows a syntax error to take precedence. */
5be8be5d 7263 switch (op_parse_code)
c19d1205
ZW
7264 {
7265 case OP_oRRnpc:
7266 case OP_RRnpc:
7267 case OP_RRnpcb:
7268 case OP_RRw:
b6702015 7269 case OP_oRRw:
c19d1205
ZW
7270 case OP_RRnpc_I0:
7271 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7272 inst.error = BAD_PC;
7273 break;
09d92015 7274
5be8be5d
DG
7275 case OP_oRRnpcsp:
7276 case OP_RRnpcsp:
7277 if (inst.operands[i].isreg)
7278 {
7279 if (inst.operands[i].reg == REG_PC)
7280 inst.error = BAD_PC;
5c8ed6a4
JW
7281 else if (inst.operands[i].reg == REG_SP
7282 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7283 relaxed since ARMv8-A. */
7284 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7285 {
7286 gas_assert (thumb);
7287 inst.error = BAD_SP;
7288 }
5be8be5d
DG
7289 }
7290 break;
7291
55881a11 7292 case OP_RRnpctw:
fa94de6b
RM
7293 if (inst.operands[i].isreg
7294 && inst.operands[i].reg == REG_PC
55881a11
MGD
7295 && (inst.operands[i].writeback || thumb))
7296 inst.error = BAD_PC;
7297 break;
7298
c19d1205
ZW
7299 case OP_CPSF:
7300 case OP_ENDI:
7301 case OP_oROR:
d2cd1205
JB
7302 case OP_wPSR:
7303 case OP_rPSR:
c19d1205 7304 case OP_COND:
52e7f43d 7305 case OP_oBARRIER_I15:
c19d1205
ZW
7306 case OP_REGLST:
7307 case OP_VRSLST:
7308 case OP_VRDLST:
477330fc
RM
7309 case OP_VRSDLST:
7310 case OP_NRDLST:
7311 case OP_NSTRLST:
c19d1205
ZW
7312 if (val == FAIL)
7313 goto failure;
7314 inst.operands[i].imm = val;
7315 break;
a737bd4d 7316
60f993ce
AV
7317 case OP_LR:
7318 case OP_oLR:
7319 if (inst.operands[i].reg != REG_LR)
7320 inst.error = _("operand must be LR register");
7321 break;
7322
c19d1205
ZW
7323 default:
7324 break;
7325 }
09d92015 7326
c19d1205
ZW
7327 /* If we get here, this operand was successfully parsed. */
7328 inst.operands[i].present = 1;
7329 continue;
09d92015 7330
c19d1205 7331 bad_args:
09d92015 7332 inst.error = BAD_ARGS;
c19d1205
ZW
7333
7334 failure:
7335 if (!backtrack_pos)
d252fdde
PB
7336 {
7337 /* The parse routine should already have set inst.error, but set a
5f4273c7 7338 default here just in case. */
d252fdde
PB
7339 if (!inst.error)
7340 inst.error = _("syntax error");
7341 return FAIL;
7342 }
c19d1205
ZW
7343
7344 /* Do not backtrack over a trailing optional argument that
7345 absorbed some text. We will only fail again, with the
7346 'garbage following instruction' error message, which is
7347 probably less helpful than the current one. */
7348 if (backtrack_index == i && backtrack_pos != str
7349 && upat[i+1] == OP_stop)
d252fdde
PB
7350 {
7351 if (!inst.error)
7352 inst.error = _("syntax error");
7353 return FAIL;
7354 }
c19d1205
ZW
7355
7356 /* Try again, skipping the optional argument at backtrack_pos. */
7357 str = backtrack_pos;
7358 inst.error = backtrack_error;
7359 inst.operands[backtrack_index].present = 0;
7360 i = backtrack_index;
7361 backtrack_pos = 0;
09d92015 7362 }
09d92015 7363
c19d1205
ZW
7364 /* Check that we have parsed all the arguments. */
7365 if (*str != '\0' && !inst.error)
7366 inst.error = _("garbage following instruction");
09d92015 7367
c19d1205 7368 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7369}
7370
c19d1205
ZW
7371#undef po_char_or_fail
7372#undef po_reg_or_fail
7373#undef po_reg_or_goto
7374#undef po_imm_or_fail
5287ad62 7375#undef po_scalar_or_fail
52e7f43d 7376#undef po_barrier_or_imm
e07e6e58 7377
c19d1205 7378/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7379#define constraint(expr, err) \
7380 do \
c19d1205 7381 { \
e07e6e58
NC
7382 if (expr) \
7383 { \
7384 inst.error = err; \
7385 return; \
7386 } \
c19d1205 7387 } \
e07e6e58 7388 while (0)
c19d1205 7389
fdfde340
JM
7390/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7391 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
7392 is the BadReg predicate in ARM's Thumb-2 documentation.
7393
7394 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7395 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7396#define reject_bad_reg(reg) \
7397 do \
7398 if (reg == REG_PC) \
7399 { \
7400 inst.error = BAD_PC; \
7401 return; \
7402 } \
7403 else if (reg == REG_SP \
7404 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7405 { \
7406 inst.error = BAD_SP; \
7407 return; \
7408 } \
fdfde340
JM
7409 while (0)
7410
94206790
MM
7411/* If REG is R13 (the stack pointer), warn that its use is
7412 deprecated. */
7413#define warn_deprecated_sp(reg) \
7414 do \
7415 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7416 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7417 while (0)
7418
c19d1205
ZW
7419/* Functions for operand encoding. ARM, then Thumb. */
7420
d840c081 7421#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7422
9db2f6b4
RL
7423/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7424
7425 The only binary encoding difference is the Coprocessor number. Coprocessor
7426 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 7427 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
7428 exists for Single-Precision operation. */
7429
7430static void
7431do_scalar_fp16_v82_encode (void)
7432{
7433 if (inst.cond != COND_ALWAYS)
7434 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7435 " the behaviour is UNPREDICTABLE"));
7436 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7437 _(BAD_FP16));
7438
7439 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7440 mark_feature_used (&arm_ext_fp16);
7441}
7442
c19d1205
ZW
7443/* If VAL can be encoded in the immediate field of an ARM instruction,
7444 return the encoded form. Otherwise, return FAIL. */
7445
7446static unsigned int
7447encode_arm_immediate (unsigned int val)
09d92015 7448{
c19d1205
ZW
7449 unsigned int a, i;
7450
4f1d6205
L
7451 if (val <= 0xff)
7452 return val;
7453
7454 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7455 if ((a = rotate_left (val, i)) <= 0xff)
7456 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7457
7458 return FAIL;
09d92015
MM
7459}
7460
c19d1205
ZW
7461/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7462 return the encoded form. Otherwise, return FAIL. */
7463static unsigned int
7464encode_thumb32_immediate (unsigned int val)
09d92015 7465{
c19d1205 7466 unsigned int a, i;
09d92015 7467
9c3c69f2 7468 if (val <= 0xff)
c19d1205 7469 return val;
a737bd4d 7470
9c3c69f2 7471 for (i = 1; i <= 24; i++)
09d92015 7472 {
9c3c69f2
PB
7473 a = val >> i;
7474 if ((val & ~(0xff << i)) == 0)
7475 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7476 }
a737bd4d 7477
c19d1205
ZW
7478 a = val & 0xff;
7479 if (val == ((a << 16) | a))
7480 return 0x100 | a;
7481 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7482 return 0x300 | a;
09d92015 7483
c19d1205
ZW
7484 a = val & 0xff00;
7485 if (val == ((a << 16) | a))
7486 return 0x200 | (a >> 8);
a737bd4d 7487
c19d1205 7488 return FAIL;
09d92015 7489}
5287ad62 7490/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7491
7492static void
5287ad62
JB
7493encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7494{
7495 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7496 && reg > 15)
7497 {
b1cc4aeb 7498 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7499 {
7500 if (thumb_mode)
7501 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7502 fpu_vfp_ext_d32);
7503 else
7504 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7505 fpu_vfp_ext_d32);
7506 }
5287ad62 7507 else
477330fc
RM
7508 {
7509 first_error (_("D register out of range for selected VFP version"));
7510 return;
7511 }
5287ad62
JB
7512 }
7513
c19d1205 7514 switch (pos)
09d92015 7515 {
c19d1205
ZW
7516 case VFP_REG_Sd:
7517 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7518 break;
7519
7520 case VFP_REG_Sn:
7521 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7522 break;
7523
7524 case VFP_REG_Sm:
7525 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7526 break;
7527
5287ad62
JB
7528 case VFP_REG_Dd:
7529 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7530 break;
5f4273c7 7531
5287ad62
JB
7532 case VFP_REG_Dn:
7533 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7534 break;
5f4273c7 7535
5287ad62
JB
7536 case VFP_REG_Dm:
7537 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7538 break;
7539
c19d1205
ZW
7540 default:
7541 abort ();
09d92015 7542 }
09d92015
MM
7543}
7544
c19d1205 7545/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7546 if any, is handled by md_apply_fix. */
09d92015 7547static void
c19d1205 7548encode_arm_shift (int i)
09d92015 7549{
008a97ef
RL
7550 /* register-shifted register. */
7551 if (inst.operands[i].immisreg)
7552 {
bf355b69
MR
7553 int op_index;
7554 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 7555 {
5689c942
RL
7556 /* Check the operand only when it's presented. In pre-UAL syntax,
7557 if the destination register is the same as the first operand, two
7558 register form of the instruction can be used. */
bf355b69
MR
7559 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7560 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
7561 as_warn (UNPRED_REG ("r15"));
7562 }
7563
7564 if (inst.operands[i].imm == REG_PC)
7565 as_warn (UNPRED_REG ("r15"));
7566 }
7567
c19d1205
ZW
7568 if (inst.operands[i].shift_kind == SHIFT_RRX)
7569 inst.instruction |= SHIFT_ROR << 5;
7570 else
09d92015 7571 {
c19d1205
ZW
7572 inst.instruction |= inst.operands[i].shift_kind << 5;
7573 if (inst.operands[i].immisreg)
7574 {
7575 inst.instruction |= SHIFT_BY_REG;
7576 inst.instruction |= inst.operands[i].imm << 8;
7577 }
7578 else
e2b0ab59 7579 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7580 }
c19d1205 7581}
09d92015 7582
c19d1205
ZW
7583static void
7584encode_arm_shifter_operand (int i)
7585{
7586 if (inst.operands[i].isreg)
09d92015 7587 {
c19d1205
ZW
7588 inst.instruction |= inst.operands[i].reg;
7589 encode_arm_shift (i);
09d92015 7590 }
c19d1205 7591 else
a415b1cd
JB
7592 {
7593 inst.instruction |= INST_IMMEDIATE;
e2b0ab59 7594 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
a415b1cd
JB
7595 inst.instruction |= inst.operands[i].imm;
7596 }
09d92015
MM
7597}
7598
c19d1205 7599/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7600static void
c19d1205 7601encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7602{
2b2f5df9
NC
7603 /* PR 14260:
7604 Generate an error if the operand is not a register. */
7605 constraint (!inst.operands[i].isreg,
7606 _("Instruction does not support =N addresses"));
7607
c19d1205 7608 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7609
c19d1205 7610 if (inst.operands[i].preind)
09d92015 7611 {
c19d1205
ZW
7612 if (is_t)
7613 {
7614 inst.error = _("instruction does not accept preindexed addressing");
7615 return;
7616 }
7617 inst.instruction |= PRE_INDEX;
7618 if (inst.operands[i].writeback)
7619 inst.instruction |= WRITE_BACK;
09d92015 7620
c19d1205
ZW
7621 }
7622 else if (inst.operands[i].postind)
7623 {
9c2799c2 7624 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7625 if (is_t)
7626 inst.instruction |= WRITE_BACK;
7627 }
7628 else /* unindexed - only for coprocessor */
09d92015 7629 {
c19d1205 7630 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7631 return;
7632 }
7633
c19d1205
ZW
7634 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7635 && (((inst.instruction & 0x000f0000) >> 16)
7636 == ((inst.instruction & 0x0000f000) >> 12)))
7637 as_warn ((inst.instruction & LOAD_BIT)
7638 ? _("destination register same as write-back base")
7639 : _("source register same as write-back base"));
09d92015
MM
7640}
7641
c19d1205
ZW
7642/* inst.operands[i] was set up by parse_address. Encode it into an
7643 ARM-format mode 2 load or store instruction. If is_t is true,
7644 reject forms that cannot be used with a T instruction (i.e. not
7645 post-indexed). */
a737bd4d 7646static void
c19d1205 7647encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7648{
5be8be5d
DG
7649 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7650
c19d1205 7651 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7652
c19d1205 7653 if (inst.operands[i].immisreg)
09d92015 7654 {
5be8be5d
DG
7655 constraint ((inst.operands[i].imm == REG_PC
7656 || (is_pc && inst.operands[i].writeback)),
7657 BAD_PC_ADDRESSING);
c19d1205
ZW
7658 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7659 inst.instruction |= inst.operands[i].imm;
7660 if (!inst.operands[i].negative)
7661 inst.instruction |= INDEX_UP;
7662 if (inst.operands[i].shifted)
7663 {
7664 if (inst.operands[i].shift_kind == SHIFT_RRX)
7665 inst.instruction |= SHIFT_ROR << 5;
7666 else
7667 {
7668 inst.instruction |= inst.operands[i].shift_kind << 5;
e2b0ab59 7669 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
c19d1205
ZW
7670 }
7671 }
09d92015 7672 }
e2b0ab59 7673 else /* immediate offset in inst.relocs[0] */
09d92015 7674 {
e2b0ab59 7675 if (is_pc && !inst.relocs[0].pc_rel)
5be8be5d
DG
7676 {
7677 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7678
7679 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7680 cannot use PC in addressing.
7681 PC cannot be used in writeback addressing, either. */
7682 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7683 BAD_PC_ADDRESSING);
23a10334 7684
dc5ec521 7685 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7686 if (warn_on_deprecated
7687 && !is_load
7688 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7689 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7690 }
7691
e2b0ab59 7692 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
7693 {
7694 /* Prefer + for zero encoded value. */
7695 if (!inst.operands[i].negative)
7696 inst.instruction |= INDEX_UP;
e2b0ab59 7697 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
26d97720 7698 }
09d92015 7699 }
09d92015
MM
7700}
7701
c19d1205
ZW
7702/* inst.operands[i] was set up by parse_address. Encode it into an
7703 ARM-format mode 3 load or store instruction. Reject forms that
7704 cannot be used with such instructions. If is_t is true, reject
7705 forms that cannot be used with a T instruction (i.e. not
7706 post-indexed). */
7707static void
7708encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7709{
c19d1205 7710 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7711 {
c19d1205
ZW
7712 inst.error = _("instruction does not accept scaled register index");
7713 return;
09d92015 7714 }
a737bd4d 7715
c19d1205 7716 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7717
c19d1205
ZW
7718 if (inst.operands[i].immisreg)
7719 {
5be8be5d 7720 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7721 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7722 BAD_PC_ADDRESSING);
eb9f3f00
JB
7723 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7724 BAD_PC_WRITEBACK);
c19d1205
ZW
7725 inst.instruction |= inst.operands[i].imm;
7726 if (!inst.operands[i].negative)
7727 inst.instruction |= INDEX_UP;
7728 }
e2b0ab59 7729 else /* immediate offset in inst.relocs[0] */
c19d1205 7730 {
e2b0ab59 7731 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
5be8be5d
DG
7732 && inst.operands[i].writeback),
7733 BAD_PC_WRITEBACK);
c19d1205 7734 inst.instruction |= HWOFFSET_IMM;
e2b0ab59 7735 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
7736 {
7737 /* Prefer + for zero encoded value. */
7738 if (!inst.operands[i].negative)
7739 inst.instruction |= INDEX_UP;
7740
e2b0ab59 7741 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
26d97720 7742 }
c19d1205 7743 }
a737bd4d
NC
7744}
7745
8335d6aa
JW
7746/* Write immediate bits [7:0] to the following locations:
7747
7748 |28/24|23 19|18 16|15 4|3 0|
7749 | 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|
7750
7751 This function is used by VMOV/VMVN/VORR/VBIC. */
7752
7753static void
7754neon_write_immbits (unsigned immbits)
7755{
7756 inst.instruction |= immbits & 0xf;
7757 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7758 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7759}
7760
7761/* Invert low-order SIZE bits of XHI:XLO. */
7762
7763static void
7764neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7765{
7766 unsigned immlo = xlo ? *xlo : 0;
7767 unsigned immhi = xhi ? *xhi : 0;
7768
7769 switch (size)
7770 {
7771 case 8:
7772 immlo = (~immlo) & 0xff;
7773 break;
7774
7775 case 16:
7776 immlo = (~immlo) & 0xffff;
7777 break;
7778
7779 case 64:
7780 immhi = (~immhi) & 0xffffffff;
7781 /* fall through. */
7782
7783 case 32:
7784 immlo = (~immlo) & 0xffffffff;
7785 break;
7786
7787 default:
7788 abort ();
7789 }
7790
7791 if (xlo)
7792 *xlo = immlo;
7793
7794 if (xhi)
7795 *xhi = immhi;
7796}
7797
7798/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7799 A, B, C, D. */
09d92015 7800
c19d1205 7801static int
8335d6aa 7802neon_bits_same_in_bytes (unsigned imm)
09d92015 7803{
8335d6aa
JW
7804 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7805 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7806 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7807 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7808}
a737bd4d 7809
8335d6aa 7810/* For immediate of above form, return 0bABCD. */
09d92015 7811
8335d6aa
JW
7812static unsigned
7813neon_squash_bits (unsigned imm)
7814{
7815 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7816 | ((imm & 0x01000000) >> 21);
7817}
7818
7819/* Compress quarter-float representation to 0b...000 abcdefgh. */
7820
7821static unsigned
7822neon_qfloat_bits (unsigned imm)
7823{
7824 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7825}
7826
7827/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7828 the instruction. *OP is passed as the initial value of the op field, and
7829 may be set to a different value depending on the constant (i.e.
7830 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7831 MVN). If the immediate looks like a repeated pattern then also
7832 try smaller element sizes. */
7833
7834static int
7835neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7836 unsigned *immbits, int *op, int size,
7837 enum neon_el_type type)
7838{
7839 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7840 float. */
7841 if (type == NT_float && !float_p)
7842 return FAIL;
7843
7844 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7845 {
8335d6aa
JW
7846 if (size != 32 || *op == 1)
7847 return FAIL;
7848 *immbits = neon_qfloat_bits (immlo);
7849 return 0xf;
7850 }
7851
7852 if (size == 64)
7853 {
7854 if (neon_bits_same_in_bytes (immhi)
7855 && neon_bits_same_in_bytes (immlo))
c19d1205 7856 {
8335d6aa
JW
7857 if (*op == 1)
7858 return FAIL;
7859 *immbits = (neon_squash_bits (immhi) << 4)
7860 | neon_squash_bits (immlo);
7861 *op = 1;
7862 return 0xe;
c19d1205 7863 }
a737bd4d 7864
8335d6aa
JW
7865 if (immhi != immlo)
7866 return FAIL;
7867 }
a737bd4d 7868
8335d6aa 7869 if (size >= 32)
09d92015 7870 {
8335d6aa 7871 if (immlo == (immlo & 0x000000ff))
c19d1205 7872 {
8335d6aa
JW
7873 *immbits = immlo;
7874 return 0x0;
c19d1205 7875 }
8335d6aa 7876 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7877 {
8335d6aa
JW
7878 *immbits = immlo >> 8;
7879 return 0x2;
c19d1205 7880 }
8335d6aa
JW
7881 else if (immlo == (immlo & 0x00ff0000))
7882 {
7883 *immbits = immlo >> 16;
7884 return 0x4;
7885 }
7886 else if (immlo == (immlo & 0xff000000))
7887 {
7888 *immbits = immlo >> 24;
7889 return 0x6;
7890 }
7891 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7892 {
7893 *immbits = (immlo >> 8) & 0xff;
7894 return 0xc;
7895 }
7896 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7897 {
7898 *immbits = (immlo >> 16) & 0xff;
7899 return 0xd;
7900 }
7901
7902 if ((immlo & 0xffff) != (immlo >> 16))
7903 return FAIL;
7904 immlo &= 0xffff;
09d92015 7905 }
a737bd4d 7906
8335d6aa 7907 if (size >= 16)
4962c51a 7908 {
8335d6aa
JW
7909 if (immlo == (immlo & 0x000000ff))
7910 {
7911 *immbits = immlo;
7912 return 0x8;
7913 }
7914 else if (immlo == (immlo & 0x0000ff00))
7915 {
7916 *immbits = immlo >> 8;
7917 return 0xa;
7918 }
7919
7920 if ((immlo & 0xff) != (immlo >> 8))
7921 return FAIL;
7922 immlo &= 0xff;
4962c51a
MS
7923 }
7924
8335d6aa
JW
7925 if (immlo == (immlo & 0x000000ff))
7926 {
7927 /* Don't allow MVN with 8-bit immediate. */
7928 if (*op == 1)
7929 return FAIL;
7930 *immbits = immlo;
7931 return 0xe;
7932 }
26d97720 7933
8335d6aa 7934 return FAIL;
c19d1205 7935}
a737bd4d 7936
5fc177c8 7937#if defined BFD_HOST_64_BIT
ba592044
AM
7938/* Returns TRUE if double precision value V may be cast
7939 to single precision without loss of accuracy. */
7940
7941static bfd_boolean
5fc177c8 7942is_double_a_single (bfd_int64_t v)
ba592044 7943{
5fc177c8 7944 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7945 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7946
7947 return (exp == 0 || exp == 0x7FF
7948 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7949 && (mantissa & 0x1FFFFFFFl) == 0;
7950}
7951
3739860c 7952/* Returns a double precision value casted to single precision
ba592044
AM
7953 (ignoring the least significant bits in exponent and mantissa). */
7954
7955static int
5fc177c8 7956double_to_single (bfd_int64_t v)
ba592044
AM
7957{
7958 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7959 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7960 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7961
7962 if (exp == 0x7FF)
7963 exp = 0xFF;
7964 else
7965 {
7966 exp = exp - 1023 + 127;
7967 if (exp >= 0xFF)
7968 {
7969 /* Infinity. */
7970 exp = 0x7F;
7971 mantissa = 0;
7972 }
7973 else if (exp < 0)
7974 {
7975 /* No denormalized numbers. */
7976 exp = 0;
7977 mantissa = 0;
7978 }
7979 }
7980 mantissa >>= 29;
7981 return (sign << 31) | (exp << 23) | mantissa;
7982}
5fc177c8 7983#endif /* BFD_HOST_64_BIT */
ba592044 7984
8335d6aa
JW
7985enum lit_type
7986{
7987 CONST_THUMB,
7988 CONST_ARM,
7989 CONST_VEC
7990};
7991
ba592044
AM
7992static void do_vfp_nsyn_opcode (const char *);
7993
e2b0ab59 7994/* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
c19d1205
ZW
7995 Determine whether it can be performed with a move instruction; if
7996 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7997 return TRUE; if it can't, convert inst.instruction to a literal-pool
7998 load and return FALSE. If this is not a valid thing to do in the
7999 current context, set inst.error and return TRUE.
a737bd4d 8000
c19d1205
ZW
8001 inst.operands[i] describes the destination register. */
8002
c921be7d 8003static bfd_boolean
8335d6aa 8004move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 8005{
53365c0d 8006 unsigned long tbit;
8335d6aa
JW
8007 bfd_boolean thumb_p = (t == CONST_THUMB);
8008 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
8009
8010 if (thumb_p)
8011 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8012 else
8013 tbit = LOAD_BIT;
8014
8015 if ((inst.instruction & tbit) == 0)
09d92015 8016 {
c19d1205 8017 inst.error = _("invalid pseudo operation");
c921be7d 8018 return TRUE;
09d92015 8019 }
ba592044 8020
e2b0ab59
AV
8021 if (inst.relocs[0].exp.X_op != O_constant
8022 && inst.relocs[0].exp.X_op != O_symbol
8023 && inst.relocs[0].exp.X_op != O_big)
09d92015
MM
8024 {
8025 inst.error = _("constant expression expected");
c921be7d 8026 return TRUE;
09d92015 8027 }
ba592044 8028
e2b0ab59
AV
8029 if (inst.relocs[0].exp.X_op == O_constant
8030 || inst.relocs[0].exp.X_op == O_big)
8335d6aa 8031 {
5fc177c8
NC
8032#if defined BFD_HOST_64_BIT
8033 bfd_int64_t v;
8034#else
ba592044 8035 offsetT v;
5fc177c8 8036#endif
e2b0ab59 8037 if (inst.relocs[0].exp.X_op == O_big)
8335d6aa 8038 {
ba592044
AM
8039 LITTLENUM_TYPE w[X_PRECISION];
8040 LITTLENUM_TYPE * l;
8041
e2b0ab59 8042 if (inst.relocs[0].exp.X_add_number == -1)
8335d6aa 8043 {
ba592044
AM
8044 gen_to_words (w, X_PRECISION, E_PRECISION);
8045 l = w;
8046 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 8047 }
ba592044
AM
8048 else
8049 l = generic_bignum;
3739860c 8050
5fc177c8
NC
8051#if defined BFD_HOST_64_BIT
8052 v =
8053 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8054 << LITTLENUM_NUMBER_OF_BITS)
8055 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8056 << LITTLENUM_NUMBER_OF_BITS)
8057 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8058 << LITTLENUM_NUMBER_OF_BITS)
8059 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8060#else
ba592044
AM
8061 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8062 | (l[0] & LITTLENUM_MASK);
5fc177c8 8063#endif
8335d6aa 8064 }
ba592044 8065 else
e2b0ab59 8066 v = inst.relocs[0].exp.X_add_number;
ba592044
AM
8067
8068 if (!inst.operands[i].issingle)
8335d6aa 8069 {
12569877 8070 if (thumb_p)
8335d6aa 8071 {
53445554
TP
8072 /* LDR should not use lead in a flag-setting instruction being
8073 chosen so we do not check whether movs can be used. */
12569877 8074
53445554 8075 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8076 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8077 && inst.operands[i].reg != 13
8078 && inst.operands[i].reg != 15)
12569877 8079 {
fc289b0a
TP
8080 /* Check if on thumb2 it can be done with a mov.w, mvn or
8081 movw instruction. */
12569877
AM
8082 unsigned int newimm;
8083 bfd_boolean isNegated;
8084
8085 newimm = encode_thumb32_immediate (v);
8086 if (newimm != (unsigned int) FAIL)
8087 isNegated = FALSE;
8088 else
8089 {
582cfe03 8090 newimm = encode_thumb32_immediate (~v);
12569877
AM
8091 if (newimm != (unsigned int) FAIL)
8092 isNegated = TRUE;
8093 }
8094
fc289b0a
TP
8095 /* The number can be loaded with a mov.w or mvn
8096 instruction. */
ff8646ee
TP
8097 if (newimm != (unsigned int) FAIL
8098 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8099 {
fc289b0a 8100 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8101 | (inst.operands[i].reg << 8));
fc289b0a 8102 /* Change to MOVN. */
582cfe03 8103 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8104 inst.instruction |= (newimm & 0x800) << 15;
8105 inst.instruction |= (newimm & 0x700) << 4;
8106 inst.instruction |= (newimm & 0x0ff);
8107 return TRUE;
8108 }
fc289b0a 8109 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8110 else if ((v & ~0xFFFF) == 0
8111 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8112 {
582cfe03 8113 int imm = v & 0xFFFF;
12569877 8114
582cfe03 8115 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8116 inst.instruction |= (inst.operands[i].reg << 8);
8117 inst.instruction |= (imm & 0xf000) << 4;
8118 inst.instruction |= (imm & 0x0800) << 15;
8119 inst.instruction |= (imm & 0x0700) << 4;
8120 inst.instruction |= (imm & 0x00ff);
8121 return TRUE;
8122 }
8123 }
8335d6aa 8124 }
12569877 8125 else if (arm_p)
ba592044
AM
8126 {
8127 int value = encode_arm_immediate (v);
12569877 8128
ba592044
AM
8129 if (value != FAIL)
8130 {
8131 /* This can be done with a mov instruction. */
8132 inst.instruction &= LITERAL_MASK;
8133 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8134 inst.instruction |= value & 0xfff;
8135 return TRUE;
8136 }
8335d6aa 8137
ba592044
AM
8138 value = encode_arm_immediate (~ v);
8139 if (value != FAIL)
8140 {
8141 /* This can be done with a mvn instruction. */
8142 inst.instruction &= LITERAL_MASK;
8143 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8144 inst.instruction |= value & 0xfff;
8145 return TRUE;
8146 }
8147 }
934c2632 8148 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8149 {
ba592044
AM
8150 int op = 0;
8151 unsigned immbits = 0;
8152 unsigned immlo = inst.operands[1].imm;
8153 unsigned immhi = inst.operands[1].regisimm
8154 ? inst.operands[1].reg
e2b0ab59 8155 : inst.relocs[0].exp.X_unsigned
ba592044
AM
8156 ? 0
8157 : ((bfd_int64_t)((int) immlo)) >> 32;
8158 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8159 &op, 64, NT_invtype);
8160
8161 if (cmode == FAIL)
8162 {
8163 neon_invert_size (&immlo, &immhi, 64);
8164 op = !op;
8165 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8166 &op, 64, NT_invtype);
8167 }
8168
8169 if (cmode != FAIL)
8170 {
8171 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8172 | (1 << 23)
8173 | (cmode << 8)
8174 | (op << 5)
8175 | (1 << 4);
8176
8177 /* Fill other bits in vmov encoding for both thumb and arm. */
8178 if (thumb_mode)
eff0bc54 8179 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8180 else
eff0bc54 8181 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8182 neon_write_immbits (immbits);
8183 return TRUE;
8184 }
8335d6aa
JW
8185 }
8186 }
8335d6aa 8187
ba592044
AM
8188 if (t == CONST_VEC)
8189 {
8190 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8191 if (inst.operands[i].issingle
8192 && is_quarter_float (inst.operands[1].imm)
8193 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8194 {
ba592044
AM
8195 inst.operands[1].imm =
8196 neon_qfloat_bits (v);
8197 do_vfp_nsyn_opcode ("fconsts");
8198 return TRUE;
8335d6aa 8199 }
5fc177c8
NC
8200
8201 /* If our host does not support a 64-bit type then we cannot perform
8202 the following optimization. This mean that there will be a
8203 discrepancy between the output produced by an assembler built for
8204 a 32-bit-only host and the output produced from a 64-bit host, but
8205 this cannot be helped. */
8206#if defined BFD_HOST_64_BIT
ba592044
AM
8207 else if (!inst.operands[1].issingle
8208 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8209 {
ba592044
AM
8210 if (is_double_a_single (v)
8211 && is_quarter_float (double_to_single (v)))
8212 {
8213 inst.operands[1].imm =
8214 neon_qfloat_bits (double_to_single (v));
8215 do_vfp_nsyn_opcode ("fconstd");
8216 return TRUE;
8217 }
8335d6aa 8218 }
5fc177c8 8219#endif
8335d6aa
JW
8220 }
8221 }
8222
8223 if (add_to_lit_pool ((!inst.operands[i].isvec
8224 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8225 return TRUE;
8226
8227 inst.operands[1].reg = REG_PC;
8228 inst.operands[1].isreg = 1;
8229 inst.operands[1].preind = 1;
e2b0ab59
AV
8230 inst.relocs[0].pc_rel = 1;
8231 inst.relocs[0].type = (thumb_p
8335d6aa
JW
8232 ? BFD_RELOC_ARM_THUMB_OFFSET
8233 : (mode_3
8234 ? BFD_RELOC_ARM_HWLITERAL
8235 : BFD_RELOC_ARM_LITERAL));
8236 return FALSE;
8237}
8238
8239/* inst.operands[i] was set up by parse_address. Encode it into an
8240 ARM-format instruction. Reject all forms which cannot be encoded
8241 into a coprocessor load/store instruction. If wb_ok is false,
8242 reject use of writeback; if unind_ok is false, reject use of
8243 unindexed addressing. If reloc_override is not 0, use it instead
8244 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8245 (in which case it is preserved). */
8246
8247static int
8248encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8249{
8250 if (!inst.operands[i].isreg)
8251 {
99b2a2dd
NC
8252 /* PR 18256 */
8253 if (! inst.operands[0].isvec)
8254 {
8255 inst.error = _("invalid co-processor operand");
8256 return FAIL;
8257 }
8335d6aa
JW
8258 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8259 return SUCCESS;
8260 }
8261
8262 inst.instruction |= inst.operands[i].reg << 16;
8263
8264 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8265
8266 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8267 {
8268 gas_assert (!inst.operands[i].writeback);
8269 if (!unind_ok)
8270 {
8271 inst.error = _("instruction does not support unindexed addressing");
8272 return FAIL;
8273 }
8274 inst.instruction |= inst.operands[i].imm;
8275 inst.instruction |= INDEX_UP;
8276 return SUCCESS;
8277 }
8278
8279 if (inst.operands[i].preind)
8280 inst.instruction |= PRE_INDEX;
8281
8282 if (inst.operands[i].writeback)
09d92015 8283 {
8335d6aa 8284 if (inst.operands[i].reg == REG_PC)
c19d1205 8285 {
8335d6aa
JW
8286 inst.error = _("pc may not be used with write-back");
8287 return FAIL;
c19d1205 8288 }
8335d6aa 8289 if (!wb_ok)
c19d1205 8290 {
8335d6aa
JW
8291 inst.error = _("instruction does not support writeback");
8292 return FAIL;
c19d1205 8293 }
8335d6aa 8294 inst.instruction |= WRITE_BACK;
09d92015
MM
8295 }
8296
8335d6aa 8297 if (reloc_override)
e2b0ab59
AV
8298 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
8299 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
8300 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
8301 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8302 {
8335d6aa 8303 if (thumb_mode)
e2b0ab59 8304 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8335d6aa 8305 else
e2b0ab59 8306 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8307 }
8335d6aa
JW
8308
8309 /* Prefer + for zero encoded value. */
8310 if (!inst.operands[i].negative)
8311 inst.instruction |= INDEX_UP;
8312
8313 return SUCCESS;
09d92015
MM
8314}
8315
5f4273c7 8316/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8317 First some generics; their names are taken from the conventional
8318 bit positions for register arguments in ARM format instructions. */
09d92015 8319
a737bd4d 8320static void
c19d1205 8321do_noargs (void)
09d92015 8322{
c19d1205 8323}
a737bd4d 8324
c19d1205
ZW
8325static void
8326do_rd (void)
8327{
8328 inst.instruction |= inst.operands[0].reg << 12;
8329}
a737bd4d 8330
16a1fa25
TP
8331static void
8332do_rn (void)
8333{
8334 inst.instruction |= inst.operands[0].reg << 16;
8335}
8336
c19d1205
ZW
8337static void
8338do_rd_rm (void)
8339{
8340 inst.instruction |= inst.operands[0].reg << 12;
8341 inst.instruction |= inst.operands[1].reg;
8342}
09d92015 8343
9eb6c0f1
MGD
8344static void
8345do_rm_rn (void)
8346{
8347 inst.instruction |= inst.operands[0].reg;
8348 inst.instruction |= inst.operands[1].reg << 16;
8349}
8350
c19d1205
ZW
8351static void
8352do_rd_rn (void)
8353{
8354 inst.instruction |= inst.operands[0].reg << 12;
8355 inst.instruction |= inst.operands[1].reg << 16;
8356}
a737bd4d 8357
c19d1205
ZW
8358static void
8359do_rn_rd (void)
8360{
8361 inst.instruction |= inst.operands[0].reg << 16;
8362 inst.instruction |= inst.operands[1].reg << 12;
8363}
09d92015 8364
4ed7ed8d
TP
8365static void
8366do_tt (void)
8367{
8368 inst.instruction |= inst.operands[0].reg << 8;
8369 inst.instruction |= inst.operands[1].reg << 16;
8370}
8371
59d09be6
MGD
8372static bfd_boolean
8373check_obsolete (const arm_feature_set *feature, const char *msg)
8374{
8375 if (ARM_CPU_IS_ANY (cpu_variant))
8376 {
5c3696f8 8377 as_tsktsk ("%s", msg);
59d09be6
MGD
8378 return TRUE;
8379 }
8380 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8381 {
8382 as_bad ("%s", msg);
8383 return TRUE;
8384 }
8385
8386 return FALSE;
8387}
8388
c19d1205
ZW
8389static void
8390do_rd_rm_rn (void)
8391{
9a64e435 8392 unsigned Rn = inst.operands[2].reg;
708587a4 8393 /* Enforce restrictions on SWP instruction. */
9a64e435 8394 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8395 {
8396 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8397 _("Rn must not overlap other operands"));
8398
59d09be6
MGD
8399 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8400 */
8401 if (!check_obsolete (&arm_ext_v8,
8402 _("swp{b} use is obsoleted for ARMv8 and later"))
8403 && warn_on_deprecated
8404 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8405 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8406 }
59d09be6 8407
c19d1205
ZW
8408 inst.instruction |= inst.operands[0].reg << 12;
8409 inst.instruction |= inst.operands[1].reg;
9a64e435 8410 inst.instruction |= Rn << 16;
c19d1205 8411}
09d92015 8412
c19d1205
ZW
8413static void
8414do_rd_rn_rm (void)
8415{
8416 inst.instruction |= inst.operands[0].reg << 12;
8417 inst.instruction |= inst.operands[1].reg << 16;
8418 inst.instruction |= inst.operands[2].reg;
8419}
a737bd4d 8420
c19d1205
ZW
8421static void
8422do_rm_rd_rn (void)
8423{
5be8be5d 8424 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
e2b0ab59
AV
8425 constraint (((inst.relocs[0].exp.X_op != O_constant
8426 && inst.relocs[0].exp.X_op != O_illegal)
8427 || inst.relocs[0].exp.X_add_number != 0),
5be8be5d 8428 BAD_ADDR_MODE);
c19d1205
ZW
8429 inst.instruction |= inst.operands[0].reg;
8430 inst.instruction |= inst.operands[1].reg << 12;
8431 inst.instruction |= inst.operands[2].reg << 16;
8432}
09d92015 8433
c19d1205
ZW
8434static void
8435do_imm0 (void)
8436{
8437 inst.instruction |= inst.operands[0].imm;
8438}
09d92015 8439
c19d1205
ZW
8440static void
8441do_rd_cpaddr (void)
8442{
8443 inst.instruction |= inst.operands[0].reg << 12;
8444 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8445}
a737bd4d 8446
c19d1205
ZW
8447/* ARM instructions, in alphabetical order by function name (except
8448 that wrapper functions appear immediately after the function they
8449 wrap). */
09d92015 8450
c19d1205
ZW
8451/* This is a pseudo-op of the form "adr rd, label" to be converted
8452 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8453
8454static void
c19d1205 8455do_adr (void)
09d92015 8456{
c19d1205 8457 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8458
c19d1205
ZW
8459 /* Frag hacking will turn this into a sub instruction if the offset turns
8460 out to be negative. */
e2b0ab59
AV
8461 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
8462 inst.relocs[0].pc_rel = 1;
8463 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 8464
fc6141f0 8465 if (support_interwork
e2b0ab59
AV
8466 && inst.relocs[0].exp.X_op == O_symbol
8467 && inst.relocs[0].exp.X_add_symbol != NULL
8468 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
8469 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
8470 inst.relocs[0].exp.X_add_number |= 1;
c19d1205 8471}
b99bd4ef 8472
c19d1205
ZW
8473/* This is a pseudo-op of the form "adrl rd, label" to be converted
8474 into a relative address of the form:
8475 add rd, pc, #low(label-.-8)"
8476 add rd, rd, #high(label-.-8)" */
b99bd4ef 8477
c19d1205
ZW
8478static void
8479do_adrl (void)
8480{
8481 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8482
c19d1205
ZW
8483 /* Frag hacking will turn this into a sub instruction if the offset turns
8484 out to be negative. */
e2b0ab59
AV
8485 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
8486 inst.relocs[0].pc_rel = 1;
c19d1205 8487 inst.size = INSN_SIZE * 2;
e2b0ab59 8488 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 8489
fc6141f0 8490 if (support_interwork
e2b0ab59
AV
8491 && inst.relocs[0].exp.X_op == O_symbol
8492 && inst.relocs[0].exp.X_add_symbol != NULL
8493 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
8494 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
8495 inst.relocs[0].exp.X_add_number |= 1;
b99bd4ef
NC
8496}
8497
b99bd4ef 8498static void
c19d1205 8499do_arit (void)
b99bd4ef 8500{
e2b0ab59
AV
8501 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8502 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 8503 THUMB1_RELOC_ONLY);
c19d1205
ZW
8504 if (!inst.operands[1].present)
8505 inst.operands[1].reg = inst.operands[0].reg;
8506 inst.instruction |= inst.operands[0].reg << 12;
8507 inst.instruction |= inst.operands[1].reg << 16;
8508 encode_arm_shifter_operand (2);
8509}
b99bd4ef 8510
62b3e311
PB
8511static void
8512do_barrier (void)
8513{
8514 if (inst.operands[0].present)
ccb84d65 8515 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8516 else
8517 inst.instruction |= 0xf;
8518}
8519
c19d1205
ZW
8520static void
8521do_bfc (void)
8522{
8523 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8524 constraint (msb > 32, _("bit-field extends past end of register"));
8525 /* The instruction encoding stores the LSB and MSB,
8526 not the LSB and width. */
8527 inst.instruction |= inst.operands[0].reg << 12;
8528 inst.instruction |= inst.operands[1].imm << 7;
8529 inst.instruction |= (msb - 1) << 16;
8530}
b99bd4ef 8531
c19d1205
ZW
8532static void
8533do_bfi (void)
8534{
8535 unsigned int msb;
b99bd4ef 8536
c19d1205
ZW
8537 /* #0 in second position is alternative syntax for bfc, which is
8538 the same instruction but with REG_PC in the Rm field. */
8539 if (!inst.operands[1].isreg)
8540 inst.operands[1].reg = REG_PC;
b99bd4ef 8541
c19d1205
ZW
8542 msb = inst.operands[2].imm + inst.operands[3].imm;
8543 constraint (msb > 32, _("bit-field extends past end of register"));
8544 /* The instruction encoding stores the LSB and MSB,
8545 not the LSB and width. */
8546 inst.instruction |= inst.operands[0].reg << 12;
8547 inst.instruction |= inst.operands[1].reg;
8548 inst.instruction |= inst.operands[2].imm << 7;
8549 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8550}
8551
b99bd4ef 8552static void
c19d1205 8553do_bfx (void)
b99bd4ef 8554{
c19d1205
ZW
8555 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8556 _("bit-field extends past end of register"));
8557 inst.instruction |= inst.operands[0].reg << 12;
8558 inst.instruction |= inst.operands[1].reg;
8559 inst.instruction |= inst.operands[2].imm << 7;
8560 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8561}
09d92015 8562
c19d1205
ZW
8563/* ARM V5 breakpoint instruction (argument parse)
8564 BKPT <16 bit unsigned immediate>
8565 Instruction is not conditional.
8566 The bit pattern given in insns[] has the COND_ALWAYS condition,
8567 and it is an error if the caller tried to override that. */
b99bd4ef 8568
c19d1205
ZW
8569static void
8570do_bkpt (void)
8571{
8572 /* Top 12 of 16 bits to bits 19:8. */
8573 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8574
c19d1205
ZW
8575 /* Bottom 4 of 16 bits to bits 3:0. */
8576 inst.instruction |= inst.operands[0].imm & 0xf;
8577}
09d92015 8578
c19d1205
ZW
8579static void
8580encode_branch (int default_reloc)
8581{
8582 if (inst.operands[0].hasreloc)
8583 {
0855e32b
NS
8584 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8585 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8586 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
e2b0ab59 8587 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
0855e32b
NS
8588 ? BFD_RELOC_ARM_PLT32
8589 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8590 }
b99bd4ef 8591 else
e2b0ab59
AV
8592 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
8593 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
8594}
8595
b99bd4ef 8596static void
c19d1205 8597do_branch (void)
b99bd4ef 8598{
39b41c9c
PB
8599#ifdef OBJ_ELF
8600 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8601 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8602 else
8603#endif
8604 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8605}
8606
8607static void
8608do_bl (void)
8609{
8610#ifdef OBJ_ELF
8611 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8612 {
8613 if (inst.cond == COND_ALWAYS)
8614 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8615 else
8616 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8617 }
8618 else
8619#endif
8620 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8621}
b99bd4ef 8622
c19d1205
ZW
8623/* ARM V5 branch-link-exchange instruction (argument parse)
8624 BLX <target_addr> ie BLX(1)
8625 BLX{<condition>} <Rm> ie BLX(2)
8626 Unfortunately, there are two different opcodes for this mnemonic.
8627 So, the insns[].value is not used, and the code here zaps values
8628 into inst.instruction.
8629 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8630
c19d1205
ZW
8631static void
8632do_blx (void)
8633{
8634 if (inst.operands[0].isreg)
b99bd4ef 8635 {
c19d1205
ZW
8636 /* Arg is a register; the opcode provided by insns[] is correct.
8637 It is not illegal to do "blx pc", just useless. */
8638 if (inst.operands[0].reg == REG_PC)
8639 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8640
c19d1205
ZW
8641 inst.instruction |= inst.operands[0].reg;
8642 }
8643 else
b99bd4ef 8644 {
c19d1205 8645 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8646 conditionally, and the opcode must be adjusted.
8647 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8648 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8649 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8650 inst.instruction = 0xfa000000;
267bf995 8651 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8652 }
c19d1205
ZW
8653}
8654
8655static void
8656do_bx (void)
8657{
845b51d6
PB
8658 bfd_boolean want_reloc;
8659
c19d1205
ZW
8660 if (inst.operands[0].reg == REG_PC)
8661 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8662
c19d1205 8663 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8664 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8665 it is for ARMv4t or earlier. */
8666 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
4d354d8b
TP
8667 if (!ARM_FEATURE_ZERO (selected_object_arch)
8668 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
845b51d6
PB
8669 want_reloc = TRUE;
8670
5ad34203 8671#ifdef OBJ_ELF
845b51d6 8672 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8673#endif
584206db 8674 want_reloc = FALSE;
845b51d6
PB
8675
8676 if (want_reloc)
e2b0ab59 8677 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8678}
8679
c19d1205
ZW
8680
8681/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8682
8683static void
c19d1205 8684do_bxj (void)
a737bd4d 8685{
c19d1205
ZW
8686 if (inst.operands[0].reg == REG_PC)
8687 as_tsktsk (_("use of r15 in bxj is not really useful"));
8688
8689 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8690}
8691
c19d1205
ZW
8692/* Co-processor data operation:
8693 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8694 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8695static void
8696do_cdp (void)
8697{
8698 inst.instruction |= inst.operands[0].reg << 8;
8699 inst.instruction |= inst.operands[1].imm << 20;
8700 inst.instruction |= inst.operands[2].reg << 12;
8701 inst.instruction |= inst.operands[3].reg << 16;
8702 inst.instruction |= inst.operands[4].reg;
8703 inst.instruction |= inst.operands[5].imm << 5;
8704}
a737bd4d
NC
8705
8706static void
c19d1205 8707do_cmp (void)
a737bd4d 8708{
c19d1205
ZW
8709 inst.instruction |= inst.operands[0].reg << 16;
8710 encode_arm_shifter_operand (1);
a737bd4d
NC
8711}
8712
c19d1205
ZW
8713/* Transfer between coprocessor and ARM registers.
8714 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8715 MRC2
8716 MCR{cond}
8717 MCR2
8718
8719 No special properties. */
09d92015 8720
dcbd0d71
MGD
8721struct deprecated_coproc_regs_s
8722{
8723 unsigned cp;
8724 int opc1;
8725 unsigned crn;
8726 unsigned crm;
8727 int opc2;
8728 arm_feature_set deprecated;
8729 arm_feature_set obsoleted;
8730 const char *dep_msg;
8731 const char *obs_msg;
8732};
8733
8734#define DEPR_ACCESS_V8 \
8735 N_("This coprocessor register access is deprecated in ARMv8")
8736
8737/* Table of all deprecated coprocessor registers. */
8738static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8739{
8740 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8741 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8742 DEPR_ACCESS_V8, NULL},
8743 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8744 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8745 DEPR_ACCESS_V8, NULL},
8746 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8747 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8748 DEPR_ACCESS_V8, NULL},
8749 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8750 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8751 DEPR_ACCESS_V8, NULL},
8752 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8753 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8754 DEPR_ACCESS_V8, NULL},
8755};
8756
8757#undef DEPR_ACCESS_V8
8758
8759static const size_t deprecated_coproc_reg_count =
8760 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8761
09d92015 8762static void
c19d1205 8763do_co_reg (void)
09d92015 8764{
fdfde340 8765 unsigned Rd;
dcbd0d71 8766 size_t i;
fdfde340
JM
8767
8768 Rd = inst.operands[2].reg;
8769 if (thumb_mode)
8770 {
8771 if (inst.instruction == 0xee000010
8772 || inst.instruction == 0xfe000010)
8773 /* MCR, MCR2 */
8774 reject_bad_reg (Rd);
5c8ed6a4 8775 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
8776 /* MRC, MRC2 */
8777 constraint (Rd == REG_SP, BAD_SP);
8778 }
8779 else
8780 {
8781 /* MCR */
8782 if (inst.instruction == 0xe000010)
8783 constraint (Rd == REG_PC, BAD_PC);
8784 }
8785
dcbd0d71
MGD
8786 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8787 {
8788 const struct deprecated_coproc_regs_s *r =
8789 deprecated_coproc_regs + i;
8790
8791 if (inst.operands[0].reg == r->cp
8792 && inst.operands[1].imm == r->opc1
8793 && inst.operands[3].reg == r->crn
8794 && inst.operands[4].reg == r->crm
8795 && inst.operands[5].imm == r->opc2)
8796 {
b10bf8c5 8797 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8798 && warn_on_deprecated
dcbd0d71 8799 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8800 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8801 }
8802 }
fdfde340 8803
c19d1205
ZW
8804 inst.instruction |= inst.operands[0].reg << 8;
8805 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8806 inst.instruction |= Rd << 12;
c19d1205
ZW
8807 inst.instruction |= inst.operands[3].reg << 16;
8808 inst.instruction |= inst.operands[4].reg;
8809 inst.instruction |= inst.operands[5].imm << 5;
8810}
09d92015 8811
c19d1205
ZW
8812/* Transfer between coprocessor register and pair of ARM registers.
8813 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8814 MCRR2
8815 MRRC{cond}
8816 MRRC2
b99bd4ef 8817
c19d1205 8818 Two XScale instructions are special cases of these:
09d92015 8819
c19d1205
ZW
8820 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8821 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8822
5f4273c7 8823 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8824
c19d1205
ZW
8825static void
8826do_co_reg2c (void)
8827{
fdfde340
JM
8828 unsigned Rd, Rn;
8829
8830 Rd = inst.operands[2].reg;
8831 Rn = inst.operands[3].reg;
8832
8833 if (thumb_mode)
8834 {
8835 reject_bad_reg (Rd);
8836 reject_bad_reg (Rn);
8837 }
8838 else
8839 {
8840 constraint (Rd == REG_PC, BAD_PC);
8841 constraint (Rn == REG_PC, BAD_PC);
8842 }
8843
873f10f0
TC
8844 /* Only check the MRRC{2} variants. */
8845 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8846 {
8847 /* If Rd == Rn, error that the operation is
8848 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8849 constraint (Rd == Rn, BAD_OVERLAP);
8850 }
8851
c19d1205
ZW
8852 inst.instruction |= inst.operands[0].reg << 8;
8853 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8854 inst.instruction |= Rd << 12;
8855 inst.instruction |= Rn << 16;
c19d1205 8856 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8857}
8858
c19d1205
ZW
8859static void
8860do_cpsi (void)
8861{
8862 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8863 if (inst.operands[1].present)
8864 {
8865 inst.instruction |= CPSI_MMOD;
8866 inst.instruction |= inst.operands[1].imm;
8867 }
c19d1205 8868}
b99bd4ef 8869
62b3e311
PB
8870static void
8871do_dbg (void)
8872{
8873 inst.instruction |= inst.operands[0].imm;
8874}
8875
eea54501
MGD
8876static void
8877do_div (void)
8878{
8879 unsigned Rd, Rn, Rm;
8880
8881 Rd = inst.operands[0].reg;
8882 Rn = (inst.operands[1].present
8883 ? inst.operands[1].reg : Rd);
8884 Rm = inst.operands[2].reg;
8885
8886 constraint ((Rd == REG_PC), BAD_PC);
8887 constraint ((Rn == REG_PC), BAD_PC);
8888 constraint ((Rm == REG_PC), BAD_PC);
8889
8890 inst.instruction |= Rd << 16;
8891 inst.instruction |= Rn << 0;
8892 inst.instruction |= Rm << 8;
8893}
8894
b99bd4ef 8895static void
c19d1205 8896do_it (void)
b99bd4ef 8897{
c19d1205 8898 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8899 process it to do the validation as if in
8900 thumb mode, just in case the code gets
8901 assembled for thumb using the unified syntax. */
8902
c19d1205 8903 inst.size = 0;
e07e6e58
NC
8904 if (unified_syntax)
8905 {
8906 set_it_insn_type (IT_INSN);
8907 now_it.mask = (inst.instruction & 0xf) | 0x10;
8908 now_it.cc = inst.operands[0].imm;
8909 }
09d92015 8910}
b99bd4ef 8911
6530b175
NC
8912/* If there is only one register in the register list,
8913 then return its register number. Otherwise return -1. */
8914static int
8915only_one_reg_in_list (int range)
8916{
8917 int i = ffs (range) - 1;
8918 return (i > 15 || range != (1 << i)) ? -1 : i;
8919}
8920
09d92015 8921static void
6530b175 8922encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8923{
c19d1205
ZW
8924 int base_reg = inst.operands[0].reg;
8925 int range = inst.operands[1].imm;
6530b175 8926 int one_reg;
ea6ef066 8927
c19d1205
ZW
8928 inst.instruction |= base_reg << 16;
8929 inst.instruction |= range;
ea6ef066 8930
c19d1205
ZW
8931 if (inst.operands[1].writeback)
8932 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8933
c19d1205 8934 if (inst.operands[0].writeback)
ea6ef066 8935 {
c19d1205
ZW
8936 inst.instruction |= WRITE_BACK;
8937 /* Check for unpredictable uses of writeback. */
8938 if (inst.instruction & LOAD_BIT)
09d92015 8939 {
c19d1205
ZW
8940 /* Not allowed in LDM type 2. */
8941 if ((inst.instruction & LDM_TYPE_2_OR_3)
8942 && ((range & (1 << REG_PC)) == 0))
8943 as_warn (_("writeback of base register is UNPREDICTABLE"));
8944 /* Only allowed if base reg not in list for other types. */
8945 else if (range & (1 << base_reg))
8946 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8947 }
8948 else /* STM. */
8949 {
8950 /* Not allowed for type 2. */
8951 if (inst.instruction & LDM_TYPE_2_OR_3)
8952 as_warn (_("writeback of base register is UNPREDICTABLE"));
8953 /* Only allowed if base reg not in list, or first in list. */
8954 else if ((range & (1 << base_reg))
8955 && (range & ((1 << base_reg) - 1)))
8956 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8957 }
ea6ef066 8958 }
6530b175
NC
8959
8960 /* If PUSH/POP has only one register, then use the A2 encoding. */
8961 one_reg = only_one_reg_in_list (range);
8962 if (from_push_pop_mnem && one_reg >= 0)
8963 {
8964 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8965
4f588891
NC
8966 if (is_push && one_reg == 13 /* SP */)
8967 /* PR 22483: The A2 encoding cannot be used when
8968 pushing the stack pointer as this is UNPREDICTABLE. */
8969 return;
8970
6530b175
NC
8971 inst.instruction &= A_COND_MASK;
8972 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8973 inst.instruction |= one_reg << 12;
8974 }
8975}
8976
8977static void
8978do_ldmstm (void)
8979{
8980 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8981}
8982
c19d1205
ZW
8983/* ARMv5TE load-consecutive (argument parse)
8984 Mode is like LDRH.
8985
8986 LDRccD R, mode
8987 STRccD R, mode. */
8988
a737bd4d 8989static void
c19d1205 8990do_ldrd (void)
a737bd4d 8991{
c19d1205 8992 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8993 _("first transfer register must be even"));
c19d1205
ZW
8994 constraint (inst.operands[1].present
8995 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8996 _("can only transfer two consecutive registers"));
c19d1205
ZW
8997 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8998 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8999
c19d1205
ZW
9000 if (!inst.operands[1].present)
9001 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 9002
c56791bb
RE
9003 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9004 register and the first register written; we have to diagnose
9005 overlap between the base and the second register written here. */
ea6ef066 9006
c56791bb
RE
9007 if (inst.operands[2].reg == inst.operands[1].reg
9008 && (inst.operands[2].writeback || inst.operands[2].postind))
9009 as_warn (_("base register written back, and overlaps "
9010 "second transfer register"));
b05fe5cf 9011
c56791bb
RE
9012 if (!(inst.instruction & V4_STR_BIT))
9013 {
c19d1205 9014 /* For an index-register load, the index register must not overlap the
c56791bb
RE
9015 destination (even if not write-back). */
9016 if (inst.operands[2].immisreg
9017 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9018 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9019 as_warn (_("index register overlaps transfer register"));
b05fe5cf 9020 }
c19d1205
ZW
9021 inst.instruction |= inst.operands[0].reg << 12;
9022 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
9023}
9024
9025static void
c19d1205 9026do_ldrex (void)
b05fe5cf 9027{
c19d1205
ZW
9028 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9029 || inst.operands[1].postind || inst.operands[1].writeback
9030 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
9031 || inst.operands[1].negative
9032 /* This can arise if the programmer has written
9033 strex rN, rM, foo
9034 or if they have mistakenly used a register name as the last
9035 operand, eg:
9036 strex rN, rM, rX
9037 It is very difficult to distinguish between these two cases
9038 because "rX" might actually be a label. ie the register
9039 name has been occluded by a symbol of the same name. So we
9040 just generate a general 'bad addressing mode' type error
9041 message and leave it up to the programmer to discover the
9042 true cause and fix their mistake. */
9043 || (inst.operands[1].reg == REG_PC),
9044 BAD_ADDR_MODE);
b05fe5cf 9045
e2b0ab59
AV
9046 constraint (inst.relocs[0].exp.X_op != O_constant
9047 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9048 _("offset must be zero in ARM encoding"));
b05fe5cf 9049
5be8be5d
DG
9050 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9051
c19d1205
ZW
9052 inst.instruction |= inst.operands[0].reg << 12;
9053 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 9054 inst.relocs[0].type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
9055}
9056
9057static void
c19d1205 9058do_ldrexd (void)
b05fe5cf 9059{
c19d1205
ZW
9060 constraint (inst.operands[0].reg % 2 != 0,
9061 _("even register required"));
9062 constraint (inst.operands[1].present
9063 && inst.operands[1].reg != inst.operands[0].reg + 1,
9064 _("can only load two consecutive registers"));
9065 /* If op 1 were present and equal to PC, this function wouldn't
9066 have been called in the first place. */
9067 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9068
c19d1205
ZW
9069 inst.instruction |= inst.operands[0].reg << 12;
9070 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9071}
9072
1be5fd2e
NC
9073/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9074 which is not a multiple of four is UNPREDICTABLE. */
9075static void
9076check_ldr_r15_aligned (void)
9077{
9078 constraint (!(inst.operands[1].immisreg)
9079 && (inst.operands[0].reg == REG_PC
9080 && inst.operands[1].reg == REG_PC
e2b0ab59 9081 && (inst.relocs[0].exp.X_add_number & 0x3)),
de194d85 9082 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9083}
9084
b05fe5cf 9085static void
c19d1205 9086do_ldst (void)
b05fe5cf 9087{
c19d1205
ZW
9088 inst.instruction |= inst.operands[0].reg << 12;
9089 if (!inst.operands[1].isreg)
8335d6aa 9090 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9091 return;
c19d1205 9092 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9093 check_ldr_r15_aligned ();
b05fe5cf
ZW
9094}
9095
9096static void
c19d1205 9097do_ldstt (void)
b05fe5cf 9098{
c19d1205
ZW
9099 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9100 reject [Rn,...]. */
9101 if (inst.operands[1].preind)
b05fe5cf 9102 {
e2b0ab59
AV
9103 constraint (inst.relocs[0].exp.X_op != O_constant
9104 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9105 _("this instruction requires a post-indexed address"));
b05fe5cf 9106
c19d1205
ZW
9107 inst.operands[1].preind = 0;
9108 inst.operands[1].postind = 1;
9109 inst.operands[1].writeback = 1;
b05fe5cf 9110 }
c19d1205
ZW
9111 inst.instruction |= inst.operands[0].reg << 12;
9112 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9113}
b05fe5cf 9114
c19d1205 9115/* Halfword and signed-byte load/store operations. */
b05fe5cf 9116
c19d1205
ZW
9117static void
9118do_ldstv4 (void)
9119{
ff4a8d2b 9120 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9121 inst.instruction |= inst.operands[0].reg << 12;
9122 if (!inst.operands[1].isreg)
8335d6aa 9123 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9124 return;
c19d1205 9125 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9126}
9127
9128static void
c19d1205 9129do_ldsttv4 (void)
b05fe5cf 9130{
c19d1205
ZW
9131 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9132 reject [Rn,...]. */
9133 if (inst.operands[1].preind)
b05fe5cf 9134 {
e2b0ab59
AV
9135 constraint (inst.relocs[0].exp.X_op != O_constant
9136 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9137 _("this instruction requires a post-indexed address"));
b05fe5cf 9138
c19d1205
ZW
9139 inst.operands[1].preind = 0;
9140 inst.operands[1].postind = 1;
9141 inst.operands[1].writeback = 1;
b05fe5cf 9142 }
c19d1205
ZW
9143 inst.instruction |= inst.operands[0].reg << 12;
9144 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9145}
b05fe5cf 9146
c19d1205
ZW
9147/* Co-processor register load/store.
9148 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9149static void
9150do_lstc (void)
9151{
9152 inst.instruction |= inst.operands[0].reg << 8;
9153 inst.instruction |= inst.operands[1].reg << 12;
9154 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9155}
9156
b05fe5cf 9157static void
c19d1205 9158do_mlas (void)
b05fe5cf 9159{
8fb9d7b9 9160 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9161 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9162 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9163 && !(inst.instruction & 0x00400000))
8fb9d7b9 9164 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9165
c19d1205
ZW
9166 inst.instruction |= inst.operands[0].reg << 16;
9167 inst.instruction |= inst.operands[1].reg;
9168 inst.instruction |= inst.operands[2].reg << 8;
9169 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9170}
b05fe5cf 9171
c19d1205
ZW
9172static void
9173do_mov (void)
9174{
e2b0ab59
AV
9175 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9176 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9177 THUMB1_RELOC_ONLY);
c19d1205
ZW
9178 inst.instruction |= inst.operands[0].reg << 12;
9179 encode_arm_shifter_operand (1);
9180}
b05fe5cf 9181
c19d1205
ZW
9182/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9183static void
9184do_mov16 (void)
9185{
b6895b4f
PB
9186 bfd_vma imm;
9187 bfd_boolean top;
9188
9189 top = (inst.instruction & 0x00400000) != 0;
e2b0ab59 9190 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
33eaf5de 9191 _(":lower16: not allowed in this instruction"));
e2b0ab59 9192 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
33eaf5de 9193 _(":upper16: not allowed in this instruction"));
c19d1205 9194 inst.instruction |= inst.operands[0].reg << 12;
e2b0ab59 9195 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 9196 {
e2b0ab59 9197 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
9198 /* The value is in two pieces: 0:11, 16:19. */
9199 inst.instruction |= (imm & 0x00000fff);
9200 inst.instruction |= (imm & 0x0000f000) << 4;
9201 }
b05fe5cf 9202}
b99bd4ef 9203
037e8744
JB
9204static int
9205do_vfp_nsyn_mrs (void)
9206{
9207 if (inst.operands[0].isvec)
9208 {
9209 if (inst.operands[1].reg != 1)
477330fc 9210 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9211 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9212 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9213 do_vfp_nsyn_opcode ("fmstat");
9214 }
9215 else if (inst.operands[1].isvec)
9216 do_vfp_nsyn_opcode ("fmrx");
9217 else
9218 return FAIL;
5f4273c7 9219
037e8744
JB
9220 return SUCCESS;
9221}
9222
9223static int
9224do_vfp_nsyn_msr (void)
9225{
9226 if (inst.operands[0].isvec)
9227 do_vfp_nsyn_opcode ("fmxr");
9228 else
9229 return FAIL;
9230
9231 return SUCCESS;
9232}
9233
f7c21dc7
NC
9234static void
9235do_vmrs (void)
9236{
9237 unsigned Rt = inst.operands[0].reg;
fa94de6b 9238
16d02dc9 9239 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9240 {
9241 inst.error = BAD_SP;
9242 return;
9243 }
9244
40c7d507
RR
9245 /* MVFR2 is only valid at ARMv8-A. */
9246 if (inst.operands[1].reg == 5)
9247 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9248 _(BAD_FPU));
9249
f7c21dc7 9250 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9251 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9252 {
9253 inst.error = BAD_PC;
9254 return;
9255 }
9256
16d02dc9
JB
9257 /* If we get through parsing the register name, we just insert the number
9258 generated into the instruction without further validation. */
9259 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9260 inst.instruction |= (Rt << 12);
9261}
9262
9263static void
9264do_vmsr (void)
9265{
9266 unsigned Rt = inst.operands[1].reg;
fa94de6b 9267
f7c21dc7
NC
9268 if (thumb_mode)
9269 reject_bad_reg (Rt);
9270 else if (Rt == REG_PC)
9271 {
9272 inst.error = BAD_PC;
9273 return;
9274 }
9275
40c7d507
RR
9276 /* MVFR2 is only valid for ARMv8-A. */
9277 if (inst.operands[0].reg == 5)
9278 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9279 _(BAD_FPU));
9280
16d02dc9
JB
9281 /* If we get through parsing the register name, we just insert the number
9282 generated into the instruction without further validation. */
9283 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9284 inst.instruction |= (Rt << 12);
9285}
9286
b99bd4ef 9287static void
c19d1205 9288do_mrs (void)
b99bd4ef 9289{
90ec0d68
MGD
9290 unsigned br;
9291
037e8744
JB
9292 if (do_vfp_nsyn_mrs () == SUCCESS)
9293 return;
9294
ff4a8d2b 9295 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9296 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9297
9298 if (inst.operands[1].isreg)
9299 {
9300 br = inst.operands[1].reg;
806ab1c0 9301 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
90ec0d68
MGD
9302 as_bad (_("bad register for mrs"));
9303 }
9304 else
9305 {
9306 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9307 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9308 != (PSR_c|PSR_f),
d2cd1205 9309 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9310 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9311 }
9312
9313 inst.instruction |= br;
c19d1205 9314}
b99bd4ef 9315
c19d1205
ZW
9316/* Two possible forms:
9317 "{C|S}PSR_<field>, Rm",
9318 "{C|S}PSR_f, #expression". */
b99bd4ef 9319
c19d1205
ZW
9320static void
9321do_msr (void)
9322{
037e8744
JB
9323 if (do_vfp_nsyn_msr () == SUCCESS)
9324 return;
9325
c19d1205
ZW
9326 inst.instruction |= inst.operands[0].imm;
9327 if (inst.operands[1].isreg)
9328 inst.instruction |= inst.operands[1].reg;
9329 else
b99bd4ef 9330 {
c19d1205 9331 inst.instruction |= INST_IMMEDIATE;
e2b0ab59
AV
9332 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9333 inst.relocs[0].pc_rel = 0;
b99bd4ef 9334 }
b99bd4ef
NC
9335}
9336
c19d1205
ZW
9337static void
9338do_mul (void)
a737bd4d 9339{
ff4a8d2b
NC
9340 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9341
c19d1205
ZW
9342 if (!inst.operands[2].present)
9343 inst.operands[2].reg = inst.operands[0].reg;
9344 inst.instruction |= inst.operands[0].reg << 16;
9345 inst.instruction |= inst.operands[1].reg;
9346 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9347
8fb9d7b9
MS
9348 if (inst.operands[0].reg == inst.operands[1].reg
9349 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9350 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9351}
9352
c19d1205
ZW
9353/* Long Multiply Parser
9354 UMULL RdLo, RdHi, Rm, Rs
9355 SMULL RdLo, RdHi, Rm, Rs
9356 UMLAL RdLo, RdHi, Rm, Rs
9357 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9358
9359static void
c19d1205 9360do_mull (void)
b99bd4ef 9361{
c19d1205
ZW
9362 inst.instruction |= inst.operands[0].reg << 12;
9363 inst.instruction |= inst.operands[1].reg << 16;
9364 inst.instruction |= inst.operands[2].reg;
9365 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9366
682b27ad
PB
9367 /* rdhi and rdlo must be different. */
9368 if (inst.operands[0].reg == inst.operands[1].reg)
9369 as_tsktsk (_("rdhi and rdlo must be different"));
9370
9371 /* rdhi, rdlo and rm must all be different before armv6. */
9372 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9373 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9374 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9375 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9376}
b99bd4ef 9377
c19d1205
ZW
9378static void
9379do_nop (void)
9380{
e7495e45
NS
9381 if (inst.operands[0].present
9382 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9383 {
9384 /* Architectural NOP hints are CPSR sets with no bits selected. */
9385 inst.instruction &= 0xf0000000;
e7495e45
NS
9386 inst.instruction |= 0x0320f000;
9387 if (inst.operands[0].present)
9388 inst.instruction |= inst.operands[0].imm;
c19d1205 9389 }
b99bd4ef
NC
9390}
9391
c19d1205
ZW
9392/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9393 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9394 Condition defaults to COND_ALWAYS.
9395 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9396
9397static void
c19d1205 9398do_pkhbt (void)
b99bd4ef 9399{
c19d1205
ZW
9400 inst.instruction |= inst.operands[0].reg << 12;
9401 inst.instruction |= inst.operands[1].reg << 16;
9402 inst.instruction |= inst.operands[2].reg;
9403 if (inst.operands[3].present)
9404 encode_arm_shift (3);
9405}
b99bd4ef 9406
c19d1205 9407/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9408
c19d1205
ZW
9409static void
9410do_pkhtb (void)
9411{
9412 if (!inst.operands[3].present)
b99bd4ef 9413 {
c19d1205
ZW
9414 /* If the shift specifier is omitted, turn the instruction
9415 into pkhbt rd, rm, rn. */
9416 inst.instruction &= 0xfff00010;
9417 inst.instruction |= inst.operands[0].reg << 12;
9418 inst.instruction |= inst.operands[1].reg;
9419 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9420 }
9421 else
9422 {
c19d1205
ZW
9423 inst.instruction |= inst.operands[0].reg << 12;
9424 inst.instruction |= inst.operands[1].reg << 16;
9425 inst.instruction |= inst.operands[2].reg;
9426 encode_arm_shift (3);
b99bd4ef
NC
9427 }
9428}
9429
c19d1205 9430/* ARMv5TE: Preload-Cache
60e5ef9f 9431 MP Extensions: Preload for write
c19d1205 9432
60e5ef9f 9433 PLD(W) <addr_mode>
c19d1205
ZW
9434
9435 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9436
9437static void
c19d1205 9438do_pld (void)
b99bd4ef 9439{
c19d1205
ZW
9440 constraint (!inst.operands[0].isreg,
9441 _("'[' expected after PLD mnemonic"));
9442 constraint (inst.operands[0].postind,
9443 _("post-indexed expression used in preload instruction"));
9444 constraint (inst.operands[0].writeback,
9445 _("writeback used in preload instruction"));
9446 constraint (!inst.operands[0].preind,
9447 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9448 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9449}
b99bd4ef 9450
62b3e311
PB
9451/* ARMv7: PLI <addr_mode> */
9452static void
9453do_pli (void)
9454{
9455 constraint (!inst.operands[0].isreg,
9456 _("'[' expected after PLI mnemonic"));
9457 constraint (inst.operands[0].postind,
9458 _("post-indexed expression used in preload instruction"));
9459 constraint (inst.operands[0].writeback,
9460 _("writeback used in preload instruction"));
9461 constraint (!inst.operands[0].preind,
9462 _("unindexed addressing used in preload instruction"));
9463 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9464 inst.instruction &= ~PRE_INDEX;
9465}
9466
c19d1205
ZW
9467static void
9468do_push_pop (void)
9469{
5e0d7f77
MP
9470 constraint (inst.operands[0].writeback,
9471 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9472 inst.operands[1] = inst.operands[0];
9473 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9474 inst.operands[0].isreg = 1;
9475 inst.operands[0].writeback = 1;
9476 inst.operands[0].reg = REG_SP;
6530b175 9477 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9478}
b99bd4ef 9479
c19d1205
ZW
9480/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9481 word at the specified address and the following word
9482 respectively.
9483 Unconditionally executed.
9484 Error if Rn is R15. */
b99bd4ef 9485
c19d1205
ZW
9486static void
9487do_rfe (void)
9488{
9489 inst.instruction |= inst.operands[0].reg << 16;
9490 if (inst.operands[0].writeback)
9491 inst.instruction |= WRITE_BACK;
9492}
b99bd4ef 9493
c19d1205 9494/* ARM V6 ssat (argument parse). */
b99bd4ef 9495
c19d1205
ZW
9496static void
9497do_ssat (void)
9498{
9499 inst.instruction |= inst.operands[0].reg << 12;
9500 inst.instruction |= (inst.operands[1].imm - 1) << 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 usat (argument parse). */
b99bd4ef
NC
9508
9509static void
c19d1205 9510do_usat (void)
b99bd4ef 9511{
c19d1205
ZW
9512 inst.instruction |= inst.operands[0].reg << 12;
9513 inst.instruction |= inst.operands[1].imm << 16;
9514 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9515
c19d1205
ZW
9516 if (inst.operands[3].present)
9517 encode_arm_shift (3);
b99bd4ef
NC
9518}
9519
c19d1205 9520/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9521
9522static void
c19d1205 9523do_ssat16 (void)
09d92015 9524{
c19d1205
ZW
9525 inst.instruction |= inst.operands[0].reg << 12;
9526 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9527 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9528}
9529
c19d1205
ZW
9530static void
9531do_usat16 (void)
a737bd4d 9532{
c19d1205
ZW
9533 inst.instruction |= inst.operands[0].reg << 12;
9534 inst.instruction |= inst.operands[1].imm << 16;
9535 inst.instruction |= inst.operands[2].reg;
9536}
a737bd4d 9537
c19d1205
ZW
9538/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9539 preserving the other bits.
a737bd4d 9540
c19d1205
ZW
9541 setend <endian_specifier>, where <endian_specifier> is either
9542 BE or LE. */
a737bd4d 9543
c19d1205
ZW
9544static void
9545do_setend (void)
9546{
12e37cbc
MGD
9547 if (warn_on_deprecated
9548 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9549 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9550
c19d1205
ZW
9551 if (inst.operands[0].imm)
9552 inst.instruction |= 0x200;
a737bd4d
NC
9553}
9554
9555static void
c19d1205 9556do_shift (void)
a737bd4d 9557{
c19d1205
ZW
9558 unsigned int Rm = (inst.operands[1].present
9559 ? inst.operands[1].reg
9560 : inst.operands[0].reg);
a737bd4d 9561
c19d1205
ZW
9562 inst.instruction |= inst.operands[0].reg << 12;
9563 inst.instruction |= Rm;
9564 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9565 {
c19d1205
ZW
9566 inst.instruction |= inst.operands[2].reg << 8;
9567 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9568 /* PR 12854: Error on extraneous shifts. */
9569 constraint (inst.operands[2].shifted,
9570 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9571 }
9572 else
e2b0ab59 9573 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9574}
9575
09d92015 9576static void
3eb17e6b 9577do_smc (void)
09d92015 9578{
e2b0ab59
AV
9579 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
9580 inst.relocs[0].pc_rel = 0;
09d92015
MM
9581}
9582
90ec0d68
MGD
9583static void
9584do_hvc (void)
9585{
e2b0ab59
AV
9586 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
9587 inst.relocs[0].pc_rel = 0;
90ec0d68
MGD
9588}
9589
09d92015 9590static void
c19d1205 9591do_swi (void)
09d92015 9592{
e2b0ab59
AV
9593 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
9594 inst.relocs[0].pc_rel = 0;
09d92015
MM
9595}
9596
ddfded2f
MW
9597static void
9598do_setpan (void)
9599{
9600 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9601 _("selected processor does not support SETPAN instruction"));
9602
9603 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9604}
9605
9606static void
9607do_t_setpan (void)
9608{
9609 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9610 _("selected processor does not support SETPAN instruction"));
9611
9612 inst.instruction |= (inst.operands[0].imm << 3);
9613}
9614
c19d1205
ZW
9615/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9616 SMLAxy{cond} Rd,Rm,Rs,Rn
9617 SMLAWy{cond} Rd,Rm,Rs,Rn
9618 Error if any register is R15. */
e16bb312 9619
c19d1205
ZW
9620static void
9621do_smla (void)
e16bb312 9622{
c19d1205
ZW
9623 inst.instruction |= inst.operands[0].reg << 16;
9624 inst.instruction |= inst.operands[1].reg;
9625 inst.instruction |= inst.operands[2].reg << 8;
9626 inst.instruction |= inst.operands[3].reg << 12;
9627}
a737bd4d 9628
c19d1205
ZW
9629/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9630 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9631 Error if any register is R15.
9632 Warning if Rdlo == Rdhi. */
a737bd4d 9633
c19d1205
ZW
9634static void
9635do_smlal (void)
9636{
9637 inst.instruction |= inst.operands[0].reg << 12;
9638 inst.instruction |= inst.operands[1].reg << 16;
9639 inst.instruction |= inst.operands[2].reg;
9640 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9641
c19d1205
ZW
9642 if (inst.operands[0].reg == inst.operands[1].reg)
9643 as_tsktsk (_("rdhi and rdlo must be different"));
9644}
a737bd4d 9645
c19d1205
ZW
9646/* ARM V5E (El Segundo) signed-multiply (argument parse)
9647 SMULxy{cond} Rd,Rm,Rs
9648 Error if any register is R15. */
a737bd4d 9649
c19d1205
ZW
9650static void
9651do_smul (void)
9652{
9653 inst.instruction |= inst.operands[0].reg << 16;
9654 inst.instruction |= inst.operands[1].reg;
9655 inst.instruction |= inst.operands[2].reg << 8;
9656}
a737bd4d 9657
b6702015
PB
9658/* ARM V6 srs (argument parse). The variable fields in the encoding are
9659 the same for both ARM and Thumb-2. */
a737bd4d 9660
c19d1205
ZW
9661static void
9662do_srs (void)
9663{
b6702015
PB
9664 int reg;
9665
9666 if (inst.operands[0].present)
9667 {
9668 reg = inst.operands[0].reg;
fdfde340 9669 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9670 }
9671 else
fdfde340 9672 reg = REG_SP;
b6702015
PB
9673
9674 inst.instruction |= reg << 16;
9675 inst.instruction |= inst.operands[1].imm;
9676 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9677 inst.instruction |= WRITE_BACK;
9678}
a737bd4d 9679
c19d1205 9680/* ARM V6 strex (argument parse). */
a737bd4d 9681
c19d1205
ZW
9682static void
9683do_strex (void)
9684{
9685 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9686 || inst.operands[2].postind || inst.operands[2].writeback
9687 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9688 || inst.operands[2].negative
9689 /* See comment in do_ldrex(). */
9690 || (inst.operands[2].reg == REG_PC),
9691 BAD_ADDR_MODE);
a737bd4d 9692
c19d1205
ZW
9693 constraint (inst.operands[0].reg == inst.operands[1].reg
9694 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9695
e2b0ab59
AV
9696 constraint (inst.relocs[0].exp.X_op != O_constant
9697 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9698 _("offset must be zero in ARM encoding"));
a737bd4d 9699
c19d1205
ZW
9700 inst.instruction |= inst.operands[0].reg << 12;
9701 inst.instruction |= inst.operands[1].reg;
9702 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 9703 inst.relocs[0].type = BFD_RELOC_UNUSED;
e16bb312
NC
9704}
9705
877807f8
NC
9706static void
9707do_t_strexbh (void)
9708{
9709 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9710 || inst.operands[2].postind || inst.operands[2].writeback
9711 || inst.operands[2].immisreg || inst.operands[2].shifted
9712 || inst.operands[2].negative,
9713 BAD_ADDR_MODE);
9714
9715 constraint (inst.operands[0].reg == inst.operands[1].reg
9716 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9717
9718 do_rm_rd_rn ();
9719}
9720
e16bb312 9721static void
c19d1205 9722do_strexd (void)
e16bb312 9723{
c19d1205
ZW
9724 constraint (inst.operands[1].reg % 2 != 0,
9725 _("even register required"));
9726 constraint (inst.operands[2].present
9727 && inst.operands[2].reg != inst.operands[1].reg + 1,
9728 _("can only store two consecutive registers"));
9729 /* If op 2 were present and equal to PC, this function wouldn't
9730 have been called in the first place. */
9731 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9732
c19d1205
ZW
9733 constraint (inst.operands[0].reg == inst.operands[1].reg
9734 || inst.operands[0].reg == inst.operands[1].reg + 1
9735 || inst.operands[0].reg == inst.operands[3].reg,
9736 BAD_OVERLAP);
e16bb312 9737
c19d1205
ZW
9738 inst.instruction |= inst.operands[0].reg << 12;
9739 inst.instruction |= inst.operands[1].reg;
9740 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9741}
9742
9eb6c0f1
MGD
9743/* ARM V8 STRL. */
9744static void
4b8c8c02 9745do_stlex (void)
9eb6c0f1
MGD
9746{
9747 constraint (inst.operands[0].reg == inst.operands[1].reg
9748 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9749
9750 do_rd_rm_rn ();
9751}
9752
9753static void
4b8c8c02 9754do_t_stlex (void)
9eb6c0f1
MGD
9755{
9756 constraint (inst.operands[0].reg == inst.operands[1].reg
9757 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9758
9759 do_rm_rd_rn ();
9760}
9761
c19d1205
ZW
9762/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9763 extends it to 32-bits, and adds the result to a value in another
9764 register. You can specify a rotation by 0, 8, 16, or 24 bits
9765 before extracting the 16-bit value.
9766 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9767 Condition defaults to COND_ALWAYS.
9768 Error if any register uses R15. */
9769
e16bb312 9770static void
c19d1205 9771do_sxtah (void)
e16bb312 9772{
c19d1205
ZW
9773 inst.instruction |= inst.operands[0].reg << 12;
9774 inst.instruction |= inst.operands[1].reg << 16;
9775 inst.instruction |= inst.operands[2].reg;
9776 inst.instruction |= inst.operands[3].imm << 10;
9777}
e16bb312 9778
c19d1205 9779/* ARM V6 SXTH.
e16bb312 9780
c19d1205
ZW
9781 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9782 Condition defaults to COND_ALWAYS.
9783 Error if any register uses R15. */
e16bb312
NC
9784
9785static void
c19d1205 9786do_sxth (void)
e16bb312 9787{
c19d1205
ZW
9788 inst.instruction |= inst.operands[0].reg << 12;
9789 inst.instruction |= inst.operands[1].reg;
9790 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9791}
c19d1205
ZW
9792\f
9793/* VFP instructions. In a logical order: SP variant first, monad
9794 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9795
9796static void
c19d1205 9797do_vfp_sp_monadic (void)
e16bb312 9798{
5287ad62
JB
9799 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9800 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9801}
9802
9803static void
c19d1205 9804do_vfp_sp_dyadic (void)
e16bb312 9805{
5287ad62
JB
9806 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9807 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9808 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9809}
9810
9811static void
c19d1205 9812do_vfp_sp_compare_z (void)
e16bb312 9813{
5287ad62 9814 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9815}
9816
9817static void
c19d1205 9818do_vfp_dp_sp_cvt (void)
e16bb312 9819{
5287ad62
JB
9820 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9821 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9822}
9823
9824static void
c19d1205 9825do_vfp_sp_dp_cvt (void)
e16bb312 9826{
5287ad62
JB
9827 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9828 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9829}
9830
9831static void
c19d1205 9832do_vfp_reg_from_sp (void)
e16bb312 9833{
c19d1205 9834 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9835 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9836}
9837
9838static void
c19d1205 9839do_vfp_reg2_from_sp2 (void)
e16bb312 9840{
c19d1205
ZW
9841 constraint (inst.operands[2].imm != 2,
9842 _("only two consecutive VFP SP registers allowed here"));
9843 inst.instruction |= inst.operands[0].reg << 12;
9844 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9845 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9846}
9847
9848static void
c19d1205 9849do_vfp_sp_from_reg (void)
e16bb312 9850{
5287ad62 9851 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9852 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9853}
9854
9855static void
c19d1205 9856do_vfp_sp2_from_reg2 (void)
e16bb312 9857{
c19d1205
ZW
9858 constraint (inst.operands[0].imm != 2,
9859 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9860 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9861 inst.instruction |= inst.operands[1].reg << 12;
9862 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9863}
9864
9865static void
c19d1205 9866do_vfp_sp_ldst (void)
e16bb312 9867{
5287ad62 9868 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9869 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9870}
9871
9872static void
c19d1205 9873do_vfp_dp_ldst (void)
e16bb312 9874{
5287ad62 9875 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9876 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9877}
9878
c19d1205 9879
e16bb312 9880static void
c19d1205 9881vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9882{
c19d1205
ZW
9883 if (inst.operands[0].writeback)
9884 inst.instruction |= WRITE_BACK;
9885 else
9886 constraint (ldstm_type != VFP_LDSTMIA,
9887 _("this addressing mode requires base-register writeback"));
9888 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9889 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9890 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9891}
9892
9893static void
c19d1205 9894vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9895{
c19d1205 9896 int count;
e16bb312 9897
c19d1205
ZW
9898 if (inst.operands[0].writeback)
9899 inst.instruction |= WRITE_BACK;
9900 else
9901 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9902 _("this addressing mode requires base-register writeback"));
e16bb312 9903
c19d1205 9904 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9905 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9906
c19d1205
ZW
9907 count = inst.operands[1].imm << 1;
9908 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9909 count += 1;
e16bb312 9910
c19d1205 9911 inst.instruction |= count;
e16bb312
NC
9912}
9913
9914static void
c19d1205 9915do_vfp_sp_ldstmia (void)
e16bb312 9916{
c19d1205 9917 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9918}
9919
9920static void
c19d1205 9921do_vfp_sp_ldstmdb (void)
e16bb312 9922{
c19d1205 9923 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9924}
9925
9926static void
c19d1205 9927do_vfp_dp_ldstmia (void)
e16bb312 9928{
c19d1205 9929 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9930}
9931
9932static void
c19d1205 9933do_vfp_dp_ldstmdb (void)
e16bb312 9934{
c19d1205 9935 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9936}
9937
9938static void
c19d1205 9939do_vfp_xp_ldstmia (void)
e16bb312 9940{
c19d1205
ZW
9941 vfp_dp_ldstm (VFP_LDSTMIAX);
9942}
e16bb312 9943
c19d1205
ZW
9944static void
9945do_vfp_xp_ldstmdb (void)
9946{
9947 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9948}
5287ad62
JB
9949
9950static void
9951do_vfp_dp_rd_rm (void)
9952{
9953 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9954 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9955}
9956
9957static void
9958do_vfp_dp_rn_rd (void)
9959{
9960 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9961 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9962}
9963
9964static void
9965do_vfp_dp_rd_rn (void)
9966{
9967 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9968 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9969}
9970
9971static void
9972do_vfp_dp_rd_rn_rm (void)
9973{
9974 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9975 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9976 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9977}
9978
9979static void
9980do_vfp_dp_rd (void)
9981{
9982 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9983}
9984
9985static void
9986do_vfp_dp_rm_rd_rn (void)
9987{
9988 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9989 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9990 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9991}
9992
9993/* VFPv3 instructions. */
9994static void
9995do_vfp_sp_const (void)
9996{
9997 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9998 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9999 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10000}
10001
10002static void
10003do_vfp_dp_const (void)
10004{
10005 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
10006 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10007 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10008}
10009
10010static void
10011vfp_conv (int srcsize)
10012{
5f1af56b
MGD
10013 int immbits = srcsize - inst.operands[1].imm;
10014
fa94de6b
RM
10015 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10016 {
5f1af56b 10017 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 10018 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
10019 inst.error = _("immediate value out of range, expected range [0, 16]");
10020 return;
10021 }
fa94de6b 10022 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
10023 {
10024 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 10025 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
10026 inst.error = _("immediate value out of range, expected range [1, 32]");
10027 return;
10028 }
10029
5287ad62
JB
10030 inst.instruction |= (immbits & 1) << 5;
10031 inst.instruction |= (immbits >> 1);
10032}
10033
10034static void
10035do_vfp_sp_conv_16 (void)
10036{
10037 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10038 vfp_conv (16);
10039}
10040
10041static void
10042do_vfp_dp_conv_16 (void)
10043{
10044 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10045 vfp_conv (16);
10046}
10047
10048static void
10049do_vfp_sp_conv_32 (void)
10050{
10051 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10052 vfp_conv (32);
10053}
10054
10055static void
10056do_vfp_dp_conv_32 (void)
10057{
10058 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10059 vfp_conv (32);
10060}
c19d1205
ZW
10061\f
10062/* FPA instructions. Also in a logical order. */
e16bb312 10063
c19d1205
ZW
10064static void
10065do_fpa_cmp (void)
10066{
10067 inst.instruction |= inst.operands[0].reg << 16;
10068 inst.instruction |= inst.operands[1].reg;
10069}
b99bd4ef
NC
10070
10071static void
c19d1205 10072do_fpa_ldmstm (void)
b99bd4ef 10073{
c19d1205
ZW
10074 inst.instruction |= inst.operands[0].reg << 12;
10075 switch (inst.operands[1].imm)
10076 {
10077 case 1: inst.instruction |= CP_T_X; break;
10078 case 2: inst.instruction |= CP_T_Y; break;
10079 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10080 case 4: break;
10081 default: abort ();
10082 }
b99bd4ef 10083
c19d1205
ZW
10084 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10085 {
10086 /* The instruction specified "ea" or "fd", so we can only accept
10087 [Rn]{!}. The instruction does not really support stacking or
10088 unstacking, so we have to emulate these by setting appropriate
10089 bits and offsets. */
e2b0ab59
AV
10090 constraint (inst.relocs[0].exp.X_op != O_constant
10091 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 10092 _("this instruction does not support indexing"));
b99bd4ef 10093
c19d1205 10094 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
e2b0ab59 10095 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 10096
c19d1205 10097 if (!(inst.instruction & INDEX_UP))
e2b0ab59 10098 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
b99bd4ef 10099
c19d1205
ZW
10100 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10101 {
10102 inst.operands[2].preind = 0;
10103 inst.operands[2].postind = 1;
10104 }
10105 }
b99bd4ef 10106
c19d1205 10107 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 10108}
c19d1205
ZW
10109\f
10110/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 10111
c19d1205
ZW
10112static void
10113do_iwmmxt_tandorc (void)
10114{
10115 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10116}
b99bd4ef 10117
c19d1205
ZW
10118static void
10119do_iwmmxt_textrc (void)
10120{
10121 inst.instruction |= inst.operands[0].reg << 12;
10122 inst.instruction |= inst.operands[1].imm;
10123}
b99bd4ef
NC
10124
10125static void
c19d1205 10126do_iwmmxt_textrm (void)
b99bd4ef 10127{
c19d1205
ZW
10128 inst.instruction |= inst.operands[0].reg << 12;
10129 inst.instruction |= inst.operands[1].reg << 16;
10130 inst.instruction |= inst.operands[2].imm;
10131}
b99bd4ef 10132
c19d1205
ZW
10133static void
10134do_iwmmxt_tinsr (void)
10135{
10136 inst.instruction |= inst.operands[0].reg << 16;
10137 inst.instruction |= inst.operands[1].reg << 12;
10138 inst.instruction |= inst.operands[2].imm;
10139}
b99bd4ef 10140
c19d1205
ZW
10141static void
10142do_iwmmxt_tmia (void)
10143{
10144 inst.instruction |= inst.operands[0].reg << 5;
10145 inst.instruction |= inst.operands[1].reg;
10146 inst.instruction |= inst.operands[2].reg << 12;
10147}
b99bd4ef 10148
c19d1205
ZW
10149static void
10150do_iwmmxt_waligni (void)
10151{
10152 inst.instruction |= inst.operands[0].reg << 12;
10153 inst.instruction |= inst.operands[1].reg << 16;
10154 inst.instruction |= inst.operands[2].reg;
10155 inst.instruction |= inst.operands[3].imm << 20;
10156}
b99bd4ef 10157
2d447fca
JM
10158static void
10159do_iwmmxt_wmerge (void)
10160{
10161 inst.instruction |= inst.operands[0].reg << 12;
10162 inst.instruction |= inst.operands[1].reg << 16;
10163 inst.instruction |= inst.operands[2].reg;
10164 inst.instruction |= inst.operands[3].imm << 21;
10165}
10166
c19d1205
ZW
10167static void
10168do_iwmmxt_wmov (void)
10169{
10170 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10171 inst.instruction |= inst.operands[0].reg << 12;
10172 inst.instruction |= inst.operands[1].reg << 16;
10173 inst.instruction |= inst.operands[1].reg;
10174}
b99bd4ef 10175
c19d1205
ZW
10176static void
10177do_iwmmxt_wldstbh (void)
10178{
8f06b2d8 10179 int reloc;
c19d1205 10180 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10181 if (thumb_mode)
10182 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10183 else
10184 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10185 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10186}
10187
c19d1205
ZW
10188static void
10189do_iwmmxt_wldstw (void)
10190{
10191 /* RIWR_RIWC clears .isreg for a control register. */
10192 if (!inst.operands[0].isreg)
10193 {
10194 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10195 inst.instruction |= 0xf0000000;
10196 }
b99bd4ef 10197
c19d1205
ZW
10198 inst.instruction |= inst.operands[0].reg << 12;
10199 encode_arm_cp_address (1, TRUE, TRUE, 0);
10200}
b99bd4ef
NC
10201
10202static void
c19d1205 10203do_iwmmxt_wldstd (void)
b99bd4ef 10204{
c19d1205 10205 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10206 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10207 && inst.operands[1].immisreg)
10208 {
10209 inst.instruction &= ~0x1a000ff;
eff0bc54 10210 inst.instruction |= (0xfU << 28);
2d447fca
JM
10211 if (inst.operands[1].preind)
10212 inst.instruction |= PRE_INDEX;
10213 if (!inst.operands[1].negative)
10214 inst.instruction |= INDEX_UP;
10215 if (inst.operands[1].writeback)
10216 inst.instruction |= WRITE_BACK;
10217 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 10218 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
2d447fca
JM
10219 inst.instruction |= inst.operands[1].imm;
10220 }
10221 else
10222 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10223}
b99bd4ef 10224
c19d1205
ZW
10225static void
10226do_iwmmxt_wshufh (void)
10227{
10228 inst.instruction |= inst.operands[0].reg << 12;
10229 inst.instruction |= inst.operands[1].reg << 16;
10230 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10231 inst.instruction |= (inst.operands[2].imm & 0x0f);
10232}
b99bd4ef 10233
c19d1205
ZW
10234static void
10235do_iwmmxt_wzero (void)
10236{
10237 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10238 inst.instruction |= inst.operands[0].reg;
10239 inst.instruction |= inst.operands[0].reg << 12;
10240 inst.instruction |= inst.operands[0].reg << 16;
10241}
2d447fca
JM
10242
10243static void
10244do_iwmmxt_wrwrwr_or_imm5 (void)
10245{
10246 if (inst.operands[2].isreg)
10247 do_rd_rn_rm ();
10248 else {
10249 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10250 _("immediate operand requires iWMMXt2"));
10251 do_rd_rn ();
10252 if (inst.operands[2].imm == 0)
10253 {
10254 switch ((inst.instruction >> 20) & 0xf)
10255 {
10256 case 4:
10257 case 5:
10258 case 6:
5f4273c7 10259 case 7:
2d447fca
JM
10260 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10261 inst.operands[2].imm = 16;
10262 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10263 break;
10264 case 8:
10265 case 9:
10266 case 10:
10267 case 11:
10268 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10269 inst.operands[2].imm = 32;
10270 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10271 break;
10272 case 12:
10273 case 13:
10274 case 14:
10275 case 15:
10276 {
10277 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10278 unsigned long wrn;
10279 wrn = (inst.instruction >> 16) & 0xf;
10280 inst.instruction &= 0xff0fff0f;
10281 inst.instruction |= wrn;
10282 /* Bail out here; the instruction is now assembled. */
10283 return;
10284 }
10285 }
10286 }
10287 /* Map 32 -> 0, etc. */
10288 inst.operands[2].imm &= 0x1f;
eff0bc54 10289 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10290 }
10291}
c19d1205
ZW
10292\f
10293/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10294 operations first, then control, shift, and load/store. */
b99bd4ef 10295
c19d1205 10296/* Insns like "foo X,Y,Z". */
b99bd4ef 10297
c19d1205
ZW
10298static void
10299do_mav_triple (void)
10300{
10301 inst.instruction |= inst.operands[0].reg << 16;
10302 inst.instruction |= inst.operands[1].reg;
10303 inst.instruction |= inst.operands[2].reg << 12;
10304}
b99bd4ef 10305
c19d1205
ZW
10306/* Insns like "foo W,X,Y,Z".
10307 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10308
c19d1205
ZW
10309static void
10310do_mav_quad (void)
10311{
10312 inst.instruction |= inst.operands[0].reg << 5;
10313 inst.instruction |= inst.operands[1].reg << 12;
10314 inst.instruction |= inst.operands[2].reg << 16;
10315 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10316}
10317
c19d1205
ZW
10318/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10319static void
10320do_mav_dspsc (void)
a737bd4d 10321{
c19d1205
ZW
10322 inst.instruction |= inst.operands[1].reg << 12;
10323}
a737bd4d 10324
c19d1205
ZW
10325/* Maverick shift immediate instructions.
10326 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10327 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10328
c19d1205
ZW
10329static void
10330do_mav_shift (void)
10331{
10332 int imm = inst.operands[2].imm;
a737bd4d 10333
c19d1205
ZW
10334 inst.instruction |= inst.operands[0].reg << 12;
10335 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10336
c19d1205
ZW
10337 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10338 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10339 Bit 4 should be 0. */
10340 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10341
c19d1205
ZW
10342 inst.instruction |= imm;
10343}
10344\f
10345/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10346
c19d1205
ZW
10347/* Xscale multiply-accumulate (argument parse)
10348 MIAcc acc0,Rm,Rs
10349 MIAPHcc acc0,Rm,Rs
10350 MIAxycc acc0,Rm,Rs. */
a737bd4d 10351
c19d1205
ZW
10352static void
10353do_xsc_mia (void)
10354{
10355 inst.instruction |= inst.operands[1].reg;
10356 inst.instruction |= inst.operands[2].reg << 12;
10357}
a737bd4d 10358
c19d1205 10359/* Xscale move-accumulator-register (argument parse)
a737bd4d 10360
c19d1205 10361 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10362
c19d1205
ZW
10363static void
10364do_xsc_mar (void)
10365{
10366 inst.instruction |= inst.operands[1].reg << 12;
10367 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10368}
10369
c19d1205 10370/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10371
c19d1205 10372 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10373
10374static void
c19d1205 10375do_xsc_mra (void)
b99bd4ef 10376{
c19d1205
ZW
10377 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10378 inst.instruction |= inst.operands[0].reg << 12;
10379 inst.instruction |= inst.operands[1].reg << 16;
10380}
10381\f
10382/* Encoding functions relevant only to Thumb. */
b99bd4ef 10383
c19d1205
ZW
10384/* inst.operands[i] is a shifted-register operand; encode
10385 it into inst.instruction in the format used by Thumb32. */
10386
10387static void
10388encode_thumb32_shifted_operand (int i)
10389{
e2b0ab59 10390 unsigned int value = inst.relocs[0].exp.X_add_number;
c19d1205 10391 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10392
9c3c69f2
PB
10393 constraint (inst.operands[i].immisreg,
10394 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10395 inst.instruction |= inst.operands[i].reg;
10396 if (shift == SHIFT_RRX)
10397 inst.instruction |= SHIFT_ROR << 4;
10398 else
b99bd4ef 10399 {
e2b0ab59 10400 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
10401 _("expression too complex"));
10402
10403 constraint (value > 32
10404 || (value == 32 && (shift == SHIFT_LSL
10405 || shift == SHIFT_ROR)),
10406 _("shift expression is too large"));
10407
10408 if (value == 0)
10409 shift = SHIFT_LSL;
10410 else if (value == 32)
10411 value = 0;
10412
10413 inst.instruction |= shift << 4;
10414 inst.instruction |= (value & 0x1c) << 10;
10415 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10416 }
c19d1205 10417}
b99bd4ef 10418
b99bd4ef 10419
c19d1205
ZW
10420/* inst.operands[i] was set up by parse_address. Encode it into a
10421 Thumb32 format load or store instruction. Reject forms that cannot
10422 be used with such instructions. If is_t is true, reject forms that
10423 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10424 that cannot be used with a D instruction. If it is a store insn,
10425 reject PC in Rn. */
b99bd4ef 10426
c19d1205
ZW
10427static void
10428encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10429{
5be8be5d 10430 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10431
10432 constraint (!inst.operands[i].isreg,
53365c0d 10433 _("Instruction does not support =N addresses"));
b99bd4ef 10434
c19d1205
ZW
10435 inst.instruction |= inst.operands[i].reg << 16;
10436 if (inst.operands[i].immisreg)
b99bd4ef 10437 {
5be8be5d 10438 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10439 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10440 constraint (inst.operands[i].negative,
10441 _("Thumb does not support negative register indexing"));
10442 constraint (inst.operands[i].postind,
10443 _("Thumb does not support register post-indexing"));
10444 constraint (inst.operands[i].writeback,
10445 _("Thumb does not support register indexing with writeback"));
10446 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10447 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10448
f40d1643 10449 inst.instruction |= inst.operands[i].imm;
c19d1205 10450 if (inst.operands[i].shifted)
b99bd4ef 10451 {
e2b0ab59 10452 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 10453 _("expression too complex"));
e2b0ab59
AV
10454 constraint (inst.relocs[0].exp.X_add_number < 0
10455 || inst.relocs[0].exp.X_add_number > 3,
c19d1205 10456 _("shift out of range"));
e2b0ab59 10457 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
c19d1205 10458 }
e2b0ab59 10459 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205
ZW
10460 }
10461 else if (inst.operands[i].preind)
10462 {
5be8be5d 10463 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10464 constraint (is_t && inst.operands[i].writeback,
c19d1205 10465 _("cannot use writeback with this instruction"));
4755303e
WN
10466 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10467 BAD_PC_ADDRESSING);
c19d1205
ZW
10468
10469 if (is_d)
10470 {
10471 inst.instruction |= 0x01000000;
10472 if (inst.operands[i].writeback)
10473 inst.instruction |= 0x00200000;
b99bd4ef 10474 }
c19d1205 10475 else
b99bd4ef 10476 {
c19d1205
ZW
10477 inst.instruction |= 0x00000c00;
10478 if (inst.operands[i].writeback)
10479 inst.instruction |= 0x00000100;
b99bd4ef 10480 }
e2b0ab59 10481 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10482 }
c19d1205 10483 else if (inst.operands[i].postind)
b99bd4ef 10484 {
9c2799c2 10485 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10486 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10487 constraint (is_t, _("cannot use post-indexing with this instruction"));
10488
10489 if (is_d)
10490 inst.instruction |= 0x00200000;
10491 else
10492 inst.instruction |= 0x00000900;
e2b0ab59 10493 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
c19d1205
ZW
10494 }
10495 else /* unindexed - only for coprocessor */
10496 inst.error = _("instruction does not accept unindexed addressing");
10497}
10498
10499/* Table of Thumb instructions which exist in both 16- and 32-bit
10500 encodings (the latter only in post-V6T2 cores). The index is the
10501 value used in the insns table below. When there is more than one
10502 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10503 holds variant (1).
10504 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10505#define T16_32_TAB \
21d799b5
NC
10506 X(_adc, 4140, eb400000), \
10507 X(_adcs, 4140, eb500000), \
10508 X(_add, 1c00, eb000000), \
10509 X(_adds, 1c00, eb100000), \
10510 X(_addi, 0000, f1000000), \
10511 X(_addis, 0000, f1100000), \
10512 X(_add_pc,000f, f20f0000), \
10513 X(_add_sp,000d, f10d0000), \
10514 X(_adr, 000f, f20f0000), \
10515 X(_and, 4000, ea000000), \
10516 X(_ands, 4000, ea100000), \
10517 X(_asr, 1000, fa40f000), \
10518 X(_asrs, 1000, fa50f000), \
10519 X(_b, e000, f000b000), \
10520 X(_bcond, d000, f0008000), \
4389b29a 10521 X(_bf, 0000, f040e001), \
f6b2b12d 10522 X(_bfcsel,0000, f000e001), \
f1c7f421 10523 X(_bfx, 0000, f060e001), \
65d1bc05 10524 X(_bfl, 0000, f000c001), \
f1c7f421 10525 X(_bflx, 0000, f070e001), \
21d799b5
NC
10526 X(_bic, 4380, ea200000), \
10527 X(_bics, 4380, ea300000), \
10528 X(_cmn, 42c0, eb100f00), \
10529 X(_cmp, 2800, ebb00f00), \
10530 X(_cpsie, b660, f3af8400), \
10531 X(_cpsid, b670, f3af8600), \
10532 X(_cpy, 4600, ea4f0000), \
10533 X(_dec_sp,80dd, f1ad0d00), \
60f993ce 10534 X(_dls, 0000, f040e001), \
21d799b5
NC
10535 X(_eor, 4040, ea800000), \
10536 X(_eors, 4040, ea900000), \
10537 X(_inc_sp,00dd, f10d0d00), \
10538 X(_ldmia, c800, e8900000), \
10539 X(_ldr, 6800, f8500000), \
10540 X(_ldrb, 7800, f8100000), \
10541 X(_ldrh, 8800, f8300000), \
10542 X(_ldrsb, 5600, f9100000), \
10543 X(_ldrsh, 5e00, f9300000), \
10544 X(_ldr_pc,4800, f85f0000), \
10545 X(_ldr_pc2,4800, f85f0000), \
10546 X(_ldr_sp,9800, f85d0000), \
60f993ce 10547 X(_le, 0000, f00fc001), \
21d799b5
NC
10548 X(_lsl, 0000, fa00f000), \
10549 X(_lsls, 0000, fa10f000), \
10550 X(_lsr, 0800, fa20f000), \
10551 X(_lsrs, 0800, fa30f000), \
10552 X(_mov, 2000, ea4f0000), \
10553 X(_movs, 2000, ea5f0000), \
10554 X(_mul, 4340, fb00f000), \
10555 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10556 X(_mvn, 43c0, ea6f0000), \
10557 X(_mvns, 43c0, ea7f0000), \
10558 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10559 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10560 X(_orr, 4300, ea400000), \
10561 X(_orrs, 4300, ea500000), \
10562 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10563 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10564 X(_rev, ba00, fa90f080), \
10565 X(_rev16, ba40, fa90f090), \
10566 X(_revsh, bac0, fa90f0b0), \
10567 X(_ror, 41c0, fa60f000), \
10568 X(_rors, 41c0, fa70f000), \
10569 X(_sbc, 4180, eb600000), \
10570 X(_sbcs, 4180, eb700000), \
10571 X(_stmia, c000, e8800000), \
10572 X(_str, 6000, f8400000), \
10573 X(_strb, 7000, f8000000), \
10574 X(_strh, 8000, f8200000), \
10575 X(_str_sp,9000, f84d0000), \
10576 X(_sub, 1e00, eba00000), \
10577 X(_subs, 1e00, ebb00000), \
10578 X(_subi, 8000, f1a00000), \
10579 X(_subis, 8000, f1b00000), \
10580 X(_sxtb, b240, fa4ff080), \
10581 X(_sxth, b200, fa0ff080), \
10582 X(_tst, 4200, ea100f00), \
10583 X(_uxtb, b2c0, fa5ff080), \
10584 X(_uxth, b280, fa1ff080), \
10585 X(_nop, bf00, f3af8000), \
10586 X(_yield, bf10, f3af8001), \
10587 X(_wfe, bf20, f3af8002), \
10588 X(_wfi, bf30, f3af8003), \
60f993ce 10589 X(_wls, 0000, f040c001), \
53c4b28b 10590 X(_sev, bf40, f3af8004), \
74db7efb
NC
10591 X(_sevl, bf50, f3af8005), \
10592 X(_udf, de00, f7f0a000)
c19d1205
ZW
10593
10594/* To catch errors in encoding functions, the codes are all offset by
10595 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10596 as 16-bit instructions. */
21d799b5 10597#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10598enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10599#undef X
10600
10601#define X(a,b,c) 0x##b
10602static const unsigned short thumb_op16[] = { T16_32_TAB };
10603#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10604#undef X
10605
10606#define X(a,b,c) 0x##c
10607static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10608#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10609#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10610#undef X
10611#undef T16_32_TAB
10612
10613/* Thumb instruction encoders, in alphabetical order. */
10614
92e90b6e 10615/* ADDW or SUBW. */
c921be7d 10616
92e90b6e
PB
10617static void
10618do_t_add_sub_w (void)
10619{
10620 int Rd, Rn;
10621
10622 Rd = inst.operands[0].reg;
10623 Rn = inst.operands[1].reg;
10624
539d4391
NC
10625 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10626 is the SP-{plus,minus}-immediate form of the instruction. */
10627 if (Rn == REG_SP)
10628 constraint (Rd == REG_PC, BAD_PC);
10629 else
10630 reject_bad_reg (Rd);
fdfde340 10631
92e90b6e 10632 inst.instruction |= (Rn << 16) | (Rd << 8);
e2b0ab59 10633 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
92e90b6e
PB
10634}
10635
c19d1205 10636/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 10637 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
10638
10639static void
10640do_t_add_sub (void)
10641{
10642 int Rd, Rs, Rn;
10643
10644 Rd = inst.operands[0].reg;
10645 Rs = (inst.operands[1].present
10646 ? inst.operands[1].reg /* Rd, Rs, foo */
10647 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10648
e07e6e58
NC
10649 if (Rd == REG_PC)
10650 set_it_insn_type_last ();
10651
c19d1205
ZW
10652 if (unified_syntax)
10653 {
0110f2b8
PB
10654 bfd_boolean flags;
10655 bfd_boolean narrow;
10656 int opcode;
10657
10658 flags = (inst.instruction == T_MNEM_adds
10659 || inst.instruction == T_MNEM_subs);
10660 if (flags)
e07e6e58 10661 narrow = !in_it_block ();
0110f2b8 10662 else
e07e6e58 10663 narrow = in_it_block ();
c19d1205 10664 if (!inst.operands[2].isreg)
b99bd4ef 10665 {
16805f35
PB
10666 int add;
10667
5c8ed6a4
JW
10668 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10669 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 10670
16805f35
PB
10671 add = (inst.instruction == T_MNEM_add
10672 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10673 opcode = 0;
10674 if (inst.size_req != 4)
10675 {
0110f2b8 10676 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10677 appropriate. */
0110f2b8
PB
10678 if (Rd == REG_SP && Rs == REG_SP && !flags)
10679 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10680 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10681 opcode = T_MNEM_add_sp;
10682 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10683 opcode = T_MNEM_add_pc;
10684 else if (Rd <= 7 && Rs <= 7 && narrow)
10685 {
10686 if (flags)
10687 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10688 else
10689 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10690 }
10691 if (opcode)
10692 {
10693 inst.instruction = THUMB_OP16(opcode);
10694 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59
AV
10695 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10696 || (inst.relocs[0].type
10697 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
a9f02af8
MG
10698 {
10699 if (inst.size_req == 2)
e2b0ab59 10700 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
a9f02af8
MG
10701 else
10702 inst.relax = opcode;
10703 }
0110f2b8
PB
10704 }
10705 else
10706 constraint (inst.size_req == 2, BAD_HIREG);
10707 }
10708 if (inst.size_req == 4
10709 || (inst.size_req != 2 && !opcode))
10710 {
e2b0ab59
AV
10711 constraint ((inst.relocs[0].type
10712 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
10713 && (inst.relocs[0].type
10714 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8 10715 THUMB1_RELOC_ONLY);
efd81785
PB
10716 if (Rd == REG_PC)
10717 {
fdfde340 10718 constraint (add, BAD_PC);
efd81785
PB
10719 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10720 _("only SUBS PC, LR, #const allowed"));
e2b0ab59 10721 constraint (inst.relocs[0].exp.X_op != O_constant,
efd81785 10722 _("expression too complex"));
e2b0ab59
AV
10723 constraint (inst.relocs[0].exp.X_add_number < 0
10724 || inst.relocs[0].exp.X_add_number > 0xff,
efd81785
PB
10725 _("immediate value out of range"));
10726 inst.instruction = T2_SUBS_PC_LR
e2b0ab59
AV
10727 | inst.relocs[0].exp.X_add_number;
10728 inst.relocs[0].type = BFD_RELOC_UNUSED;
efd81785
PB
10729 return;
10730 }
10731 else if (Rs == REG_PC)
16805f35
PB
10732 {
10733 /* Always use addw/subw. */
10734 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
e2b0ab59 10735 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
16805f35
PB
10736 }
10737 else
10738 {
10739 inst.instruction = THUMB_OP32 (inst.instruction);
10740 inst.instruction = (inst.instruction & 0xe1ffffff)
10741 | 0x10000000;
10742 if (flags)
e2b0ab59 10743 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
16805f35 10744 else
e2b0ab59 10745 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
16805f35 10746 }
dc4503c6
PB
10747 inst.instruction |= Rd << 8;
10748 inst.instruction |= Rs << 16;
0110f2b8 10749 }
b99bd4ef 10750 }
c19d1205
ZW
10751 else
10752 {
e2b0ab59 10753 unsigned int value = inst.relocs[0].exp.X_add_number;
5f4cb198
NC
10754 unsigned int shift = inst.operands[2].shift_kind;
10755
c19d1205
ZW
10756 Rn = inst.operands[2].reg;
10757 /* See if we can do this with a 16-bit instruction. */
10758 if (!inst.operands[2].shifted && inst.size_req != 4)
10759 {
e27ec89e
PB
10760 if (Rd > 7 || Rs > 7 || Rn > 7)
10761 narrow = FALSE;
10762
10763 if (narrow)
c19d1205 10764 {
e27ec89e
PB
10765 inst.instruction = ((inst.instruction == T_MNEM_adds
10766 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10767 ? T_OPCODE_ADD_R3
10768 : T_OPCODE_SUB_R3);
10769 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10770 return;
10771 }
b99bd4ef 10772
7e806470 10773 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10774 {
7e806470
PB
10775 /* Thumb-1 cores (except v6-M) require at least one high
10776 register in a narrow non flag setting add. */
10777 if (Rd > 7 || Rn > 7
10778 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10779 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10780 {
7e806470
PB
10781 if (Rd == Rn)
10782 {
10783 Rn = Rs;
10784 Rs = Rd;
10785 }
c19d1205
ZW
10786 inst.instruction = T_OPCODE_ADD_HI;
10787 inst.instruction |= (Rd & 8) << 4;
10788 inst.instruction |= (Rd & 7);
10789 inst.instruction |= Rn << 3;
10790 return;
10791 }
c19d1205
ZW
10792 }
10793 }
c921be7d 10794
fdfde340 10795 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
10796 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10797 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
10798 constraint (Rs == REG_PC, BAD_PC);
10799 reject_bad_reg (Rn);
10800
c19d1205
ZW
10801 /* If we get here, it can't be done in 16 bits. */
10802 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10803 _("shift must be constant"));
10804 inst.instruction = THUMB_OP32 (inst.instruction);
10805 inst.instruction |= Rd << 8;
10806 inst.instruction |= Rs << 16;
5f4cb198
NC
10807 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10808 _("shift value over 3 not allowed in thumb mode"));
10809 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10810 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10811 encode_thumb32_shifted_operand (2);
10812 }
10813 }
10814 else
10815 {
10816 constraint (inst.instruction == T_MNEM_adds
10817 || inst.instruction == T_MNEM_subs,
10818 BAD_THUMB32);
b99bd4ef 10819
c19d1205 10820 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10821 {
c19d1205
ZW
10822 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10823 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10824 BAD_HIREG);
10825
10826 inst.instruction = (inst.instruction == T_MNEM_add
10827 ? 0x0000 : 0x8000);
10828 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59 10829 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10830 return;
10831 }
10832
c19d1205
ZW
10833 Rn = inst.operands[2].reg;
10834 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10835
c19d1205
ZW
10836 /* We now have Rd, Rs, and Rn set to registers. */
10837 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10838 {
c19d1205
ZW
10839 /* Can't do this for SUB. */
10840 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10841 inst.instruction = T_OPCODE_ADD_HI;
10842 inst.instruction |= (Rd & 8) << 4;
10843 inst.instruction |= (Rd & 7);
10844 if (Rs == Rd)
10845 inst.instruction |= Rn << 3;
10846 else if (Rn == Rd)
10847 inst.instruction |= Rs << 3;
10848 else
10849 constraint (1, _("dest must overlap one source register"));
10850 }
10851 else
10852 {
10853 inst.instruction = (inst.instruction == T_MNEM_add
10854 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10855 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10856 }
b99bd4ef 10857 }
b99bd4ef
NC
10858}
10859
c19d1205
ZW
10860static void
10861do_t_adr (void)
10862{
fdfde340
JM
10863 unsigned Rd;
10864
10865 Rd = inst.operands[0].reg;
10866 reject_bad_reg (Rd);
10867
10868 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10869 {
10870 /* Defer to section relaxation. */
10871 inst.relax = inst.instruction;
10872 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10873 inst.instruction |= Rd << 4;
0110f2b8
PB
10874 }
10875 else if (unified_syntax && inst.size_req != 2)
e9f89963 10876 {
0110f2b8 10877 /* Generate a 32-bit opcode. */
e9f89963 10878 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10879 inst.instruction |= Rd << 8;
e2b0ab59
AV
10880 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
10881 inst.relocs[0].pc_rel = 1;
e9f89963
PB
10882 }
10883 else
10884 {
0110f2b8 10885 /* Generate a 16-bit opcode. */
e9f89963 10886 inst.instruction = THUMB_OP16 (inst.instruction);
e2b0ab59
AV
10887 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
10888 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
10889 inst.relocs[0].pc_rel = 1;
fdfde340 10890 inst.instruction |= Rd << 4;
e9f89963 10891 }
52a86f84 10892
e2b0ab59
AV
10893 if (inst.relocs[0].exp.X_op == O_symbol
10894 && inst.relocs[0].exp.X_add_symbol != NULL
10895 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
10896 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
10897 inst.relocs[0].exp.X_add_number += 1;
c19d1205 10898}
b99bd4ef 10899
c19d1205
ZW
10900/* Arithmetic instructions for which there is just one 16-bit
10901 instruction encoding, and it allows only two low registers.
10902 For maximal compatibility with ARM syntax, we allow three register
10903 operands even when Thumb-32 instructions are not available, as long
10904 as the first two are identical. For instance, both "sbc r0,r1" and
10905 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10906static void
c19d1205 10907do_t_arit3 (void)
b99bd4ef 10908{
c19d1205 10909 int Rd, Rs, Rn;
b99bd4ef 10910
c19d1205
ZW
10911 Rd = inst.operands[0].reg;
10912 Rs = (inst.operands[1].present
10913 ? inst.operands[1].reg /* Rd, Rs, foo */
10914 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10915 Rn = inst.operands[2].reg;
b99bd4ef 10916
fdfde340
JM
10917 reject_bad_reg (Rd);
10918 reject_bad_reg (Rs);
10919 if (inst.operands[2].isreg)
10920 reject_bad_reg (Rn);
10921
c19d1205 10922 if (unified_syntax)
b99bd4ef 10923 {
c19d1205
ZW
10924 if (!inst.operands[2].isreg)
10925 {
10926 /* For an immediate, we always generate a 32-bit opcode;
10927 section relaxation will shrink it later if possible. */
10928 inst.instruction = THUMB_OP32 (inst.instruction);
10929 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10930 inst.instruction |= Rd << 8;
10931 inst.instruction |= Rs << 16;
e2b0ab59 10932 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
c19d1205
ZW
10933 }
10934 else
10935 {
e27ec89e
PB
10936 bfd_boolean narrow;
10937
c19d1205 10938 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10939 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10940 narrow = !in_it_block ();
e27ec89e 10941 else
e07e6e58 10942 narrow = in_it_block ();
e27ec89e
PB
10943
10944 if (Rd > 7 || Rn > 7 || Rs > 7)
10945 narrow = FALSE;
10946 if (inst.operands[2].shifted)
10947 narrow = FALSE;
10948 if (inst.size_req == 4)
10949 narrow = FALSE;
10950
10951 if (narrow
c19d1205
ZW
10952 && Rd == Rs)
10953 {
10954 inst.instruction = THUMB_OP16 (inst.instruction);
10955 inst.instruction |= Rd;
10956 inst.instruction |= Rn << 3;
10957 return;
10958 }
b99bd4ef 10959
c19d1205
ZW
10960 /* If we get here, it can't be done in 16 bits. */
10961 constraint (inst.operands[2].shifted
10962 && inst.operands[2].immisreg,
10963 _("shift must be constant"));
10964 inst.instruction = THUMB_OP32 (inst.instruction);
10965 inst.instruction |= Rd << 8;
10966 inst.instruction |= Rs << 16;
10967 encode_thumb32_shifted_operand (2);
10968 }
a737bd4d 10969 }
c19d1205 10970 else
b99bd4ef 10971 {
c19d1205
ZW
10972 /* On its face this is a lie - the instruction does set the
10973 flags. However, the only supported mnemonic in this mode
10974 says it doesn't. */
10975 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10976
c19d1205
ZW
10977 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10978 _("unshifted register required"));
10979 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10980 constraint (Rd != Rs,
10981 _("dest and source1 must be the same register"));
a737bd4d 10982
c19d1205
ZW
10983 inst.instruction = THUMB_OP16 (inst.instruction);
10984 inst.instruction |= Rd;
10985 inst.instruction |= Rn << 3;
b99bd4ef 10986 }
a737bd4d 10987}
b99bd4ef 10988
c19d1205
ZW
10989/* Similarly, but for instructions where the arithmetic operation is
10990 commutative, so we can allow either of them to be different from
10991 the destination operand in a 16-bit instruction. For instance, all
10992 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10993 accepted. */
10994static void
10995do_t_arit3c (void)
a737bd4d 10996{
c19d1205 10997 int Rd, Rs, Rn;
b99bd4ef 10998
c19d1205
ZW
10999 Rd = inst.operands[0].reg;
11000 Rs = (inst.operands[1].present
11001 ? inst.operands[1].reg /* Rd, Rs, foo */
11002 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11003 Rn = inst.operands[2].reg;
c921be7d 11004
fdfde340
JM
11005 reject_bad_reg (Rd);
11006 reject_bad_reg (Rs);
11007 if (inst.operands[2].isreg)
11008 reject_bad_reg (Rn);
a737bd4d 11009
c19d1205 11010 if (unified_syntax)
a737bd4d 11011 {
c19d1205 11012 if (!inst.operands[2].isreg)
b99bd4ef 11013 {
c19d1205
ZW
11014 /* For an immediate, we always generate a 32-bit opcode;
11015 section relaxation will shrink it later if possible. */
11016 inst.instruction = THUMB_OP32 (inst.instruction);
11017 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11018 inst.instruction |= Rd << 8;
11019 inst.instruction |= Rs << 16;
e2b0ab59 11020 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11021 }
c19d1205 11022 else
a737bd4d 11023 {
e27ec89e
PB
11024 bfd_boolean narrow;
11025
c19d1205 11026 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11027 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11028 narrow = !in_it_block ();
e27ec89e 11029 else
e07e6e58 11030 narrow = in_it_block ();
e27ec89e
PB
11031
11032 if (Rd > 7 || Rn > 7 || Rs > 7)
11033 narrow = FALSE;
11034 if (inst.operands[2].shifted)
11035 narrow = FALSE;
11036 if (inst.size_req == 4)
11037 narrow = FALSE;
11038
11039 if (narrow)
a737bd4d 11040 {
c19d1205 11041 if (Rd == Rs)
a737bd4d 11042 {
c19d1205
ZW
11043 inst.instruction = THUMB_OP16 (inst.instruction);
11044 inst.instruction |= Rd;
11045 inst.instruction |= Rn << 3;
11046 return;
a737bd4d 11047 }
c19d1205 11048 if (Rd == Rn)
a737bd4d 11049 {
c19d1205
ZW
11050 inst.instruction = THUMB_OP16 (inst.instruction);
11051 inst.instruction |= Rd;
11052 inst.instruction |= Rs << 3;
11053 return;
a737bd4d
NC
11054 }
11055 }
c19d1205
ZW
11056
11057 /* If we get here, it can't be done in 16 bits. */
11058 constraint (inst.operands[2].shifted
11059 && inst.operands[2].immisreg,
11060 _("shift must be constant"));
11061 inst.instruction = THUMB_OP32 (inst.instruction);
11062 inst.instruction |= Rd << 8;
11063 inst.instruction |= Rs << 16;
11064 encode_thumb32_shifted_operand (2);
a737bd4d 11065 }
b99bd4ef 11066 }
c19d1205
ZW
11067 else
11068 {
11069 /* On its face this is a lie - the instruction does set the
11070 flags. However, the only supported mnemonic in this mode
11071 says it doesn't. */
11072 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11073
c19d1205
ZW
11074 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11075 _("unshifted register required"));
11076 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11077
11078 inst.instruction = THUMB_OP16 (inst.instruction);
11079 inst.instruction |= Rd;
11080
11081 if (Rd == Rs)
11082 inst.instruction |= Rn << 3;
11083 else if (Rd == Rn)
11084 inst.instruction |= Rs << 3;
11085 else
11086 constraint (1, _("dest must overlap one source register"));
11087 }
a737bd4d
NC
11088}
11089
c19d1205
ZW
11090static void
11091do_t_bfc (void)
a737bd4d 11092{
fdfde340 11093 unsigned Rd;
c19d1205
ZW
11094 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11095 constraint (msb > 32, _("bit-field extends past end of register"));
11096 /* The instruction encoding stores the LSB and MSB,
11097 not the LSB and width. */
fdfde340
JM
11098 Rd = inst.operands[0].reg;
11099 reject_bad_reg (Rd);
11100 inst.instruction |= Rd << 8;
c19d1205
ZW
11101 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11102 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11103 inst.instruction |= msb - 1;
b99bd4ef
NC
11104}
11105
c19d1205
ZW
11106static void
11107do_t_bfi (void)
b99bd4ef 11108{
fdfde340 11109 int Rd, Rn;
c19d1205 11110 unsigned int msb;
b99bd4ef 11111
fdfde340
JM
11112 Rd = inst.operands[0].reg;
11113 reject_bad_reg (Rd);
11114
c19d1205
ZW
11115 /* #0 in second position is alternative syntax for bfc, which is
11116 the same instruction but with REG_PC in the Rm field. */
11117 if (!inst.operands[1].isreg)
fdfde340
JM
11118 Rn = REG_PC;
11119 else
11120 {
11121 Rn = inst.operands[1].reg;
11122 reject_bad_reg (Rn);
11123 }
b99bd4ef 11124
c19d1205
ZW
11125 msb = inst.operands[2].imm + inst.operands[3].imm;
11126 constraint (msb > 32, _("bit-field extends past end of register"));
11127 /* The instruction encoding stores the LSB and MSB,
11128 not the LSB and width. */
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 |= msb - 1;
b99bd4ef
NC
11134}
11135
c19d1205
ZW
11136static void
11137do_t_bfx (void)
b99bd4ef 11138{
fdfde340
JM
11139 unsigned Rd, Rn;
11140
11141 Rd = inst.operands[0].reg;
11142 Rn = inst.operands[1].reg;
11143
11144 reject_bad_reg (Rd);
11145 reject_bad_reg (Rn);
11146
c19d1205
ZW
11147 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11148 _("bit-field extends past end of register"));
fdfde340
JM
11149 inst.instruction |= Rd << 8;
11150 inst.instruction |= Rn << 16;
c19d1205
ZW
11151 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11152 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11153 inst.instruction |= inst.operands[3].imm - 1;
11154}
b99bd4ef 11155
c19d1205
ZW
11156/* ARM V5 Thumb BLX (argument parse)
11157 BLX <target_addr> which is BLX(1)
11158 BLX <Rm> which is BLX(2)
11159 Unfortunately, there are two different opcodes for this mnemonic.
11160 So, the insns[].value is not used, and the code here zaps values
11161 into inst.instruction.
b99bd4ef 11162
c19d1205
ZW
11163 ??? How to take advantage of the additional two bits of displacement
11164 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11165
c19d1205
ZW
11166static void
11167do_t_blx (void)
11168{
e07e6e58
NC
11169 set_it_insn_type_last ();
11170
c19d1205 11171 if (inst.operands[0].isreg)
fdfde340
JM
11172 {
11173 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11174 /* We have a register, so this is BLX(2). */
11175 inst.instruction |= inst.operands[0].reg << 3;
11176 }
b99bd4ef
NC
11177 else
11178 {
c19d1205 11179 /* No register. This must be BLX(1). */
2fc8bdac 11180 inst.instruction = 0xf000e800;
0855e32b 11181 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11182 }
11183}
11184
c19d1205
ZW
11185static void
11186do_t_branch (void)
b99bd4ef 11187{
0110f2b8 11188 int opcode;
dfa9f0d5 11189 int cond;
2fe88214 11190 bfd_reloc_code_real_type reloc;
dfa9f0d5 11191
e07e6e58
NC
11192 cond = inst.cond;
11193 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11194
11195 if (in_it_block ())
dfa9f0d5
PB
11196 {
11197 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11198 branches. */
dfa9f0d5 11199 cond = COND_ALWAYS;
dfa9f0d5
PB
11200 }
11201 else
11202 cond = inst.cond;
11203
11204 if (cond != COND_ALWAYS)
0110f2b8
PB
11205 opcode = T_MNEM_bcond;
11206 else
11207 opcode = inst.instruction;
11208
12d6b0b7
RS
11209 if (unified_syntax
11210 && (inst.size_req == 4
10960bfb
PB
11211 || (inst.size_req != 2
11212 && (inst.operands[0].hasreloc
e2b0ab59 11213 || inst.relocs[0].exp.X_op == O_constant))))
c19d1205 11214 {
0110f2b8 11215 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11216 if (cond == COND_ALWAYS)
9ae92b05 11217 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11218 else
11219 {
ff8646ee
TP
11220 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11221 _("selected architecture does not support "
11222 "wide conditional branch instruction"));
11223
9c2799c2 11224 gas_assert (cond != 0xF);
dfa9f0d5 11225 inst.instruction |= cond << 22;
9ae92b05 11226 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11227 }
11228 }
b99bd4ef
NC
11229 else
11230 {
0110f2b8 11231 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11232 if (cond == COND_ALWAYS)
9ae92b05 11233 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11234 else
b99bd4ef 11235 {
dfa9f0d5 11236 inst.instruction |= cond << 8;
9ae92b05 11237 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11238 }
0110f2b8
PB
11239 /* Allow section relaxation. */
11240 if (unified_syntax && inst.size_req != 2)
11241 inst.relax = opcode;
b99bd4ef 11242 }
e2b0ab59
AV
11243 inst.relocs[0].type = reloc;
11244 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
11245}
11246
8884b720 11247/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11248 between the two is the maximum immediate allowed - which is passed in
8884b720 11249 RANGE. */
b99bd4ef 11250static void
8884b720 11251do_t_bkpt_hlt1 (int range)
b99bd4ef 11252{
dfa9f0d5
PB
11253 constraint (inst.cond != COND_ALWAYS,
11254 _("instruction is always unconditional"));
c19d1205 11255 if (inst.operands[0].present)
b99bd4ef 11256 {
8884b720 11257 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11258 _("immediate value out of range"));
11259 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11260 }
8884b720
MGD
11261
11262 set_it_insn_type (NEUTRAL_IT_INSN);
11263}
11264
11265static void
11266do_t_hlt (void)
11267{
11268 do_t_bkpt_hlt1 (63);
11269}
11270
11271static void
11272do_t_bkpt (void)
11273{
11274 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11275}
11276
11277static void
c19d1205 11278do_t_branch23 (void)
b99bd4ef 11279{
e07e6e58 11280 set_it_insn_type_last ();
0855e32b 11281 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11282
0855e32b
NS
11283 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11284 this file. We used to simply ignore the PLT reloc type here --
11285 the branch encoding is now needed to deal with TLSCALL relocs.
11286 So if we see a PLT reloc now, put it back to how it used to be to
11287 keep the preexisting behaviour. */
e2b0ab59
AV
11288 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
11289 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11290
4343666d 11291#if defined(OBJ_COFF)
c19d1205
ZW
11292 /* If the destination of the branch is a defined symbol which does not have
11293 the THUMB_FUNC attribute, then we must be calling a function which has
11294 the (interfacearm) attribute. We look for the Thumb entry point to that
11295 function and change the branch to refer to that function instead. */
e2b0ab59
AV
11296 if ( inst.relocs[0].exp.X_op == O_symbol
11297 && inst.relocs[0].exp.X_add_symbol != NULL
11298 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11299 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11300 inst.relocs[0].exp.X_add_symbol
11301 = find_real_start (inst.relocs[0].exp.X_add_symbol);
4343666d 11302#endif
90e4755a
RE
11303}
11304
11305static void
c19d1205 11306do_t_bx (void)
90e4755a 11307{
e07e6e58 11308 set_it_insn_type_last ();
c19d1205
ZW
11309 inst.instruction |= inst.operands[0].reg << 3;
11310 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11311 should cause the alignment to be checked once it is known. This is
11312 because BX PC only works if the instruction is word aligned. */
11313}
90e4755a 11314
c19d1205
ZW
11315static void
11316do_t_bxj (void)
11317{
fdfde340 11318 int Rm;
90e4755a 11319
e07e6e58 11320 set_it_insn_type_last ();
fdfde340
JM
11321 Rm = inst.operands[0].reg;
11322 reject_bad_reg (Rm);
11323 inst.instruction |= Rm << 16;
90e4755a
RE
11324}
11325
11326static void
c19d1205 11327do_t_clz (void)
90e4755a 11328{
fdfde340
JM
11329 unsigned Rd;
11330 unsigned Rm;
11331
11332 Rd = inst.operands[0].reg;
11333 Rm = inst.operands[1].reg;
11334
11335 reject_bad_reg (Rd);
11336 reject_bad_reg (Rm);
11337
11338 inst.instruction |= Rd << 8;
11339 inst.instruction |= Rm << 16;
11340 inst.instruction |= Rm;
c19d1205 11341}
90e4755a 11342
91d8b670
JG
11343static void
11344do_t_csdb (void)
11345{
11346 set_it_insn_type (OUTSIDE_IT_INSN);
11347}
11348
dfa9f0d5
PB
11349static void
11350do_t_cps (void)
11351{
e07e6e58 11352 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11353 inst.instruction |= inst.operands[0].imm;
11354}
11355
c19d1205
ZW
11356static void
11357do_t_cpsi (void)
11358{
e07e6e58 11359 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11360 if (unified_syntax
62b3e311
PB
11361 && (inst.operands[1].present || inst.size_req == 4)
11362 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11363 {
c19d1205
ZW
11364 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11365 inst.instruction = 0xf3af8000;
11366 inst.instruction |= imod << 9;
11367 inst.instruction |= inst.operands[0].imm << 5;
11368 if (inst.operands[1].present)
11369 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11370 }
c19d1205 11371 else
90e4755a 11372 {
62b3e311
PB
11373 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11374 && (inst.operands[0].imm & 4),
11375 _("selected processor does not support 'A' form "
11376 "of this instruction"));
11377 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11378 _("Thumb does not support the 2-argument "
11379 "form of this instruction"));
11380 inst.instruction |= inst.operands[0].imm;
90e4755a 11381 }
90e4755a
RE
11382}
11383
c19d1205
ZW
11384/* THUMB CPY instruction (argument parse). */
11385
90e4755a 11386static void
c19d1205 11387do_t_cpy (void)
90e4755a 11388{
c19d1205 11389 if (inst.size_req == 4)
90e4755a 11390 {
c19d1205
ZW
11391 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11392 inst.instruction |= inst.operands[0].reg << 8;
11393 inst.instruction |= inst.operands[1].reg;
90e4755a 11394 }
c19d1205 11395 else
90e4755a 11396 {
c19d1205
ZW
11397 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11398 inst.instruction |= (inst.operands[0].reg & 0x7);
11399 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11400 }
90e4755a
RE
11401}
11402
90e4755a 11403static void
25fe350b 11404do_t_cbz (void)
90e4755a 11405{
e07e6e58 11406 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11407 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11408 inst.instruction |= inst.operands[0].reg;
e2b0ab59
AV
11409 inst.relocs[0].pc_rel = 1;
11410 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
c19d1205 11411}
90e4755a 11412
62b3e311
PB
11413static void
11414do_t_dbg (void)
11415{
11416 inst.instruction |= inst.operands[0].imm;
11417}
11418
11419static void
11420do_t_div (void)
11421{
fdfde340
JM
11422 unsigned Rd, Rn, Rm;
11423
11424 Rd = inst.operands[0].reg;
11425 Rn = (inst.operands[1].present
11426 ? inst.operands[1].reg : Rd);
11427 Rm = inst.operands[2].reg;
11428
11429 reject_bad_reg (Rd);
11430 reject_bad_reg (Rn);
11431 reject_bad_reg (Rm);
11432
11433 inst.instruction |= Rd << 8;
11434 inst.instruction |= Rn << 16;
11435 inst.instruction |= Rm;
62b3e311
PB
11436}
11437
c19d1205
ZW
11438static void
11439do_t_hint (void)
11440{
11441 if (unified_syntax && inst.size_req == 4)
11442 inst.instruction = THUMB_OP32 (inst.instruction);
11443 else
11444 inst.instruction = THUMB_OP16 (inst.instruction);
11445}
90e4755a 11446
c19d1205
ZW
11447static void
11448do_t_it (void)
11449{
11450 unsigned int cond = inst.operands[0].imm;
e27ec89e 11451
e07e6e58
NC
11452 set_it_insn_type (IT_INSN);
11453 now_it.mask = (inst.instruction & 0xf) | 0x10;
11454 now_it.cc = cond;
5a01bb1d 11455 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11456
11457 /* If the condition is a negative condition, invert the mask. */
c19d1205 11458 if ((cond & 0x1) == 0x0)
90e4755a 11459 {
c19d1205 11460 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11461
c19d1205 11462 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11463 {
11464 /* No conversion needed. */
11465 now_it.block_length = 1;
11466 }
c19d1205 11467 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11468 {
11469 mask ^= 0x8;
11470 now_it.block_length = 2;
11471 }
e27ec89e 11472 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11473 {
11474 mask ^= 0xC;
11475 now_it.block_length = 3;
11476 }
c19d1205 11477 else
5a01bb1d
MGD
11478 {
11479 mask ^= 0xE;
11480 now_it.block_length = 4;
11481 }
90e4755a 11482
e27ec89e
PB
11483 inst.instruction &= 0xfff0;
11484 inst.instruction |= mask;
c19d1205 11485 }
90e4755a 11486
c19d1205
ZW
11487 inst.instruction |= cond << 4;
11488}
90e4755a 11489
3c707909
PB
11490/* Helper function used for both push/pop and ldm/stm. */
11491static void
11492encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11493{
11494 bfd_boolean load;
11495
11496 load = (inst.instruction & (1 << 20)) != 0;
11497
11498 if (mask & (1 << 13))
11499 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11500
11501 if ((mask & (1 << base)) != 0
11502 && writeback)
11503 inst.error = _("having the base register in the register list when "
11504 "using write back is UNPREDICTABLE");
11505
3c707909
PB
11506 if (load)
11507 {
e07e6e58 11508 if (mask & (1 << 15))
477330fc
RM
11509 {
11510 if (mask & (1 << 14))
11511 inst.error = _("LR and PC should not both be in register list");
11512 else
11513 set_it_insn_type_last ();
11514 }
3c707909
PB
11515 }
11516 else
11517 {
11518 if (mask & (1 << 15))
11519 inst.error = _("PC not allowed in register list");
3c707909
PB
11520 }
11521
11522 if ((mask & (mask - 1)) == 0)
11523 {
11524 /* Single register transfers implemented as str/ldr. */
11525 if (writeback)
11526 {
11527 if (inst.instruction & (1 << 23))
11528 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11529 else
11530 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11531 }
11532 else
11533 {
11534 if (inst.instruction & (1 << 23))
11535 inst.instruction = 0x00800000; /* ia -> [base] */
11536 else
11537 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11538 }
11539
11540 inst.instruction |= 0xf8400000;
11541 if (load)
11542 inst.instruction |= 0x00100000;
11543
5f4273c7 11544 mask = ffs (mask) - 1;
3c707909
PB
11545 mask <<= 12;
11546 }
11547 else if (writeback)
11548 inst.instruction |= WRITE_BACK;
11549
11550 inst.instruction |= mask;
11551 inst.instruction |= base << 16;
11552}
11553
c19d1205
ZW
11554static void
11555do_t_ldmstm (void)
11556{
11557 /* This really doesn't seem worth it. */
e2b0ab59 11558 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205
ZW
11559 _("expression too complex"));
11560 constraint (inst.operands[1].writeback,
11561 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11562
c19d1205
ZW
11563 if (unified_syntax)
11564 {
3c707909
PB
11565 bfd_boolean narrow;
11566 unsigned mask;
11567
11568 narrow = FALSE;
c19d1205
ZW
11569 /* See if we can use a 16-bit instruction. */
11570 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11571 && inst.size_req != 4
3c707909 11572 && !(inst.operands[1].imm & ~0xff))
90e4755a 11573 {
3c707909 11574 mask = 1 << inst.operands[0].reg;
90e4755a 11575
eab4f823 11576 if (inst.operands[0].reg <= 7)
90e4755a 11577 {
3c707909 11578 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11579 ? inst.operands[0].writeback
11580 : (inst.operands[0].writeback
11581 == !(inst.operands[1].imm & mask)))
477330fc 11582 {
eab4f823
MGD
11583 if (inst.instruction == T_MNEM_stmia
11584 && (inst.operands[1].imm & mask)
11585 && (inst.operands[1].imm & (mask - 1)))
11586 as_warn (_("value stored for r%d is UNKNOWN"),
11587 inst.operands[0].reg);
3c707909 11588
eab4f823
MGD
11589 inst.instruction = THUMB_OP16 (inst.instruction);
11590 inst.instruction |= inst.operands[0].reg << 8;
11591 inst.instruction |= inst.operands[1].imm;
11592 narrow = TRUE;
11593 }
11594 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11595 {
11596 /* This means 1 register in reg list one of 3 situations:
11597 1. Instruction is stmia, but without writeback.
11598 2. lmdia without writeback, but with Rn not in
477330fc 11599 reglist.
eab4f823
MGD
11600 3. ldmia with writeback, but with Rn in reglist.
11601 Case 3 is UNPREDICTABLE behaviour, so we handle
11602 case 1 and 2 which can be converted into a 16-bit
11603 str or ldr. The SP cases are handled below. */
11604 unsigned long opcode;
11605 /* First, record an error for Case 3. */
11606 if (inst.operands[1].imm & mask
11607 && inst.operands[0].writeback)
fa94de6b 11608 inst.error =
eab4f823
MGD
11609 _("having the base register in the register list when "
11610 "using write back is UNPREDICTABLE");
fa94de6b
RM
11611
11612 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11613 : T_MNEM_ldr);
11614 inst.instruction = THUMB_OP16 (opcode);
11615 inst.instruction |= inst.operands[0].reg << 3;
11616 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11617 narrow = TRUE;
11618 }
90e4755a 11619 }
eab4f823 11620 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11621 {
eab4f823
MGD
11622 if (inst.operands[0].writeback)
11623 {
fa94de6b 11624 inst.instruction =
eab4f823 11625 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11626 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11627 inst.instruction |= inst.operands[1].imm;
477330fc 11628 narrow = TRUE;
eab4f823
MGD
11629 }
11630 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11631 {
fa94de6b 11632 inst.instruction =
eab4f823 11633 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11634 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11635 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11636 narrow = TRUE;
eab4f823 11637 }
90e4755a 11638 }
3c707909
PB
11639 }
11640
11641 if (!narrow)
11642 {
c19d1205
ZW
11643 if (inst.instruction < 0xffff)
11644 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11645
5f4273c7
NC
11646 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11647 inst.operands[0].writeback);
90e4755a
RE
11648 }
11649 }
c19d1205 11650 else
90e4755a 11651 {
c19d1205
ZW
11652 constraint (inst.operands[0].reg > 7
11653 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11654 constraint (inst.instruction != T_MNEM_ldmia
11655 && inst.instruction != T_MNEM_stmia,
11656 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11657 if (inst.instruction == T_MNEM_stmia)
f03698e6 11658 {
c19d1205
ZW
11659 if (!inst.operands[0].writeback)
11660 as_warn (_("this instruction will write back the base register"));
11661 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11662 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11663 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11664 inst.operands[0].reg);
f03698e6 11665 }
c19d1205 11666 else
90e4755a 11667 {
c19d1205
ZW
11668 if (!inst.operands[0].writeback
11669 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11670 as_warn (_("this instruction will write back the base register"));
11671 else if (inst.operands[0].writeback
11672 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11673 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11674 }
11675
c19d1205
ZW
11676 inst.instruction = THUMB_OP16 (inst.instruction);
11677 inst.instruction |= inst.operands[0].reg << 8;
11678 inst.instruction |= inst.operands[1].imm;
11679 }
11680}
e28cd48c 11681
c19d1205
ZW
11682static void
11683do_t_ldrex (void)
11684{
11685 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11686 || inst.operands[1].postind || inst.operands[1].writeback
11687 || inst.operands[1].immisreg || inst.operands[1].shifted
11688 || inst.operands[1].negative,
01cfc07f 11689 BAD_ADDR_MODE);
e28cd48c 11690
5be8be5d
DG
11691 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11692
c19d1205
ZW
11693 inst.instruction |= inst.operands[0].reg << 12;
11694 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 11695 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
c19d1205 11696}
e28cd48c 11697
c19d1205
ZW
11698static void
11699do_t_ldrexd (void)
11700{
11701 if (!inst.operands[1].present)
1cac9012 11702 {
c19d1205
ZW
11703 constraint (inst.operands[0].reg == REG_LR,
11704 _("r14 not allowed as first register "
11705 "when second register is omitted"));
11706 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11707 }
c19d1205
ZW
11708 constraint (inst.operands[0].reg == inst.operands[1].reg,
11709 BAD_OVERLAP);
b99bd4ef 11710
c19d1205
ZW
11711 inst.instruction |= inst.operands[0].reg << 12;
11712 inst.instruction |= inst.operands[1].reg << 8;
11713 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11714}
11715
11716static void
c19d1205 11717do_t_ldst (void)
b99bd4ef 11718{
0110f2b8
PB
11719 unsigned long opcode;
11720 int Rn;
11721
e07e6e58
NC
11722 if (inst.operands[0].isreg
11723 && !inst.operands[0].preind
11724 && inst.operands[0].reg == REG_PC)
11725 set_it_insn_type_last ();
11726
0110f2b8 11727 opcode = inst.instruction;
c19d1205 11728 if (unified_syntax)
b99bd4ef 11729 {
53365c0d
PB
11730 if (!inst.operands[1].isreg)
11731 {
11732 if (opcode <= 0xffff)
11733 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11734 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11735 return;
11736 }
0110f2b8
PB
11737 if (inst.operands[1].isreg
11738 && !inst.operands[1].writeback
c19d1205
ZW
11739 && !inst.operands[1].shifted && !inst.operands[1].postind
11740 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11741 && opcode <= 0xffff
11742 && inst.size_req != 4)
c19d1205 11743 {
0110f2b8
PB
11744 /* Insn may have a 16-bit form. */
11745 Rn = inst.operands[1].reg;
11746 if (inst.operands[1].immisreg)
11747 {
11748 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11749 /* [Rn, Rik] */
0110f2b8
PB
11750 if (Rn <= 7 && inst.operands[1].imm <= 7)
11751 goto op16;
5be8be5d
DG
11752 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11753 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11754 }
11755 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11756 && opcode != T_MNEM_ldrsb)
11757 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11758 || (Rn == REG_SP && opcode == T_MNEM_str))
11759 {
11760 /* [Rn, #const] */
11761 if (Rn > 7)
11762 {
11763 if (Rn == REG_PC)
11764 {
e2b0ab59 11765 if (inst.relocs[0].pc_rel)
0110f2b8
PB
11766 opcode = T_MNEM_ldr_pc2;
11767 else
11768 opcode = T_MNEM_ldr_pc;
11769 }
11770 else
11771 {
11772 if (opcode == T_MNEM_ldr)
11773 opcode = T_MNEM_ldr_sp;
11774 else
11775 opcode = T_MNEM_str_sp;
11776 }
11777 inst.instruction = inst.operands[0].reg << 8;
11778 }
11779 else
11780 {
11781 inst.instruction = inst.operands[0].reg;
11782 inst.instruction |= inst.operands[1].reg << 3;
11783 }
11784 inst.instruction |= THUMB_OP16 (opcode);
11785 if (inst.size_req == 2)
e2b0ab59 11786 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
0110f2b8
PB
11787 else
11788 inst.relax = opcode;
11789 return;
11790 }
c19d1205 11791 }
0110f2b8 11792 /* Definitely a 32-bit variant. */
5be8be5d 11793
8d67f500
NC
11794 /* Warning for Erratum 752419. */
11795 if (opcode == T_MNEM_ldr
11796 && inst.operands[0].reg == REG_SP
11797 && inst.operands[1].writeback == 1
11798 && !inst.operands[1].immisreg)
11799 {
11800 if (no_cpu_selected ()
11801 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11802 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11803 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11804 as_warn (_("This instruction may be unpredictable "
11805 "if executed on M-profile cores "
11806 "with interrupts enabled."));
11807 }
11808
5be8be5d 11809 /* Do some validations regarding addressing modes. */
1be5fd2e 11810 if (inst.operands[1].immisreg)
5be8be5d
DG
11811 reject_bad_reg (inst.operands[1].imm);
11812
1be5fd2e
NC
11813 constraint (inst.operands[1].writeback == 1
11814 && inst.operands[0].reg == inst.operands[1].reg,
11815 BAD_OVERLAP);
11816
0110f2b8 11817 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11818 inst.instruction |= inst.operands[0].reg << 12;
11819 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11820 check_ldr_r15_aligned ();
b99bd4ef
NC
11821 return;
11822 }
11823
c19d1205
ZW
11824 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11825
11826 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11827 {
c19d1205
ZW
11828 /* Only [Rn,Rm] is acceptable. */
11829 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11830 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11831 || inst.operands[1].postind || inst.operands[1].shifted
11832 || inst.operands[1].negative,
11833 _("Thumb does not support this addressing mode"));
11834 inst.instruction = THUMB_OP16 (inst.instruction);
11835 goto op16;
b99bd4ef 11836 }
5f4273c7 11837
c19d1205
ZW
11838 inst.instruction = THUMB_OP16 (inst.instruction);
11839 if (!inst.operands[1].isreg)
8335d6aa 11840 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11841 return;
b99bd4ef 11842
c19d1205
ZW
11843 constraint (!inst.operands[1].preind
11844 || inst.operands[1].shifted
11845 || inst.operands[1].writeback,
11846 _("Thumb does not support this addressing mode"));
11847 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11848 {
c19d1205
ZW
11849 constraint (inst.instruction & 0x0600,
11850 _("byte or halfword not valid for base register"));
11851 constraint (inst.operands[1].reg == REG_PC
11852 && !(inst.instruction & THUMB_LOAD_BIT),
11853 _("r15 based store not allowed"));
11854 constraint (inst.operands[1].immisreg,
11855 _("invalid base register for register offset"));
b99bd4ef 11856
c19d1205
ZW
11857 if (inst.operands[1].reg == REG_PC)
11858 inst.instruction = T_OPCODE_LDR_PC;
11859 else if (inst.instruction & THUMB_LOAD_BIT)
11860 inst.instruction = T_OPCODE_LDR_SP;
11861 else
11862 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11863
c19d1205 11864 inst.instruction |= inst.operands[0].reg << 8;
e2b0ab59 11865 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
11866 return;
11867 }
90e4755a 11868
c19d1205
ZW
11869 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11870 if (!inst.operands[1].immisreg)
11871 {
11872 /* Immediate offset. */
11873 inst.instruction |= inst.operands[0].reg;
11874 inst.instruction |= inst.operands[1].reg << 3;
e2b0ab59 11875 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
11876 return;
11877 }
90e4755a 11878
c19d1205
ZW
11879 /* Register offset. */
11880 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11881 constraint (inst.operands[1].negative,
11882 _("Thumb does not support this addressing mode"));
90e4755a 11883
c19d1205
ZW
11884 op16:
11885 switch (inst.instruction)
11886 {
11887 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11888 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11889 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11890 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11891 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11892 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11893 case 0x5600 /* ldrsb */:
11894 case 0x5e00 /* ldrsh */: break;
11895 default: abort ();
11896 }
90e4755a 11897
c19d1205
ZW
11898 inst.instruction |= inst.operands[0].reg;
11899 inst.instruction |= inst.operands[1].reg << 3;
11900 inst.instruction |= inst.operands[1].imm << 6;
11901}
90e4755a 11902
c19d1205
ZW
11903static void
11904do_t_ldstd (void)
11905{
11906 if (!inst.operands[1].present)
b99bd4ef 11907 {
c19d1205
ZW
11908 inst.operands[1].reg = inst.operands[0].reg + 1;
11909 constraint (inst.operands[0].reg == REG_LR,
11910 _("r14 not allowed here"));
bd340a04 11911 constraint (inst.operands[0].reg == REG_R12,
477330fc 11912 _("r12 not allowed here"));
b99bd4ef 11913 }
bd340a04
MGD
11914
11915 if (inst.operands[2].writeback
11916 && (inst.operands[0].reg == inst.operands[2].reg
11917 || inst.operands[1].reg == inst.operands[2].reg))
11918 as_warn (_("base register written back, and overlaps "
477330fc 11919 "one of transfer registers"));
bd340a04 11920
c19d1205
ZW
11921 inst.instruction |= inst.operands[0].reg << 12;
11922 inst.instruction |= inst.operands[1].reg << 8;
11923 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11924}
11925
c19d1205
ZW
11926static void
11927do_t_ldstt (void)
11928{
11929 inst.instruction |= inst.operands[0].reg << 12;
11930 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11931}
a737bd4d 11932
b99bd4ef 11933static void
c19d1205 11934do_t_mla (void)
b99bd4ef 11935{
fdfde340 11936 unsigned Rd, Rn, Rm, Ra;
c921be7d 11937
fdfde340
JM
11938 Rd = inst.operands[0].reg;
11939 Rn = inst.operands[1].reg;
11940 Rm = inst.operands[2].reg;
11941 Ra = inst.operands[3].reg;
11942
11943 reject_bad_reg (Rd);
11944 reject_bad_reg (Rn);
11945 reject_bad_reg (Rm);
11946 reject_bad_reg (Ra);
11947
11948 inst.instruction |= Rd << 8;
11949 inst.instruction |= Rn << 16;
11950 inst.instruction |= Rm;
11951 inst.instruction |= Ra << 12;
c19d1205 11952}
b99bd4ef 11953
c19d1205
ZW
11954static void
11955do_t_mlal (void)
11956{
fdfde340
JM
11957 unsigned RdLo, RdHi, Rn, Rm;
11958
11959 RdLo = inst.operands[0].reg;
11960 RdHi = inst.operands[1].reg;
11961 Rn = inst.operands[2].reg;
11962 Rm = inst.operands[3].reg;
11963
11964 reject_bad_reg (RdLo);
11965 reject_bad_reg (RdHi);
11966 reject_bad_reg (Rn);
11967 reject_bad_reg (Rm);
11968
11969 inst.instruction |= RdLo << 12;
11970 inst.instruction |= RdHi << 8;
11971 inst.instruction |= Rn << 16;
11972 inst.instruction |= Rm;
c19d1205 11973}
b99bd4ef 11974
c19d1205
ZW
11975static void
11976do_t_mov_cmp (void)
11977{
fdfde340
JM
11978 unsigned Rn, Rm;
11979
11980 Rn = inst.operands[0].reg;
11981 Rm = inst.operands[1].reg;
11982
e07e6e58
NC
11983 if (Rn == REG_PC)
11984 set_it_insn_type_last ();
11985
c19d1205 11986 if (unified_syntax)
b99bd4ef 11987 {
c19d1205
ZW
11988 int r0off = (inst.instruction == T_MNEM_mov
11989 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11990 unsigned long opcode;
3d388997
PB
11991 bfd_boolean narrow;
11992 bfd_boolean low_regs;
11993
fdfde340 11994 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11995 opcode = inst.instruction;
e07e6e58 11996 if (in_it_block ())
0110f2b8 11997 narrow = opcode != T_MNEM_movs;
3d388997 11998 else
0110f2b8 11999 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
12000 if (inst.size_req == 4
12001 || inst.operands[1].shifted)
12002 narrow = FALSE;
12003
efd81785
PB
12004 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12005 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12006 && !inst.operands[1].shifted
fdfde340
JM
12007 && Rn == REG_PC
12008 && Rm == REG_LR)
efd81785
PB
12009 {
12010 inst.instruction = T2_SUBS_PC_LR;
12011 return;
12012 }
12013
fdfde340
JM
12014 if (opcode == T_MNEM_cmp)
12015 {
12016 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
12017 if (narrow)
12018 {
12019 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
12020 but valid. */
12021 warn_deprecated_sp (Rm);
12022 /* R15 was documented as a valid choice for Rm in ARMv6,
12023 but as UNPREDICTABLE in ARMv7. ARM's proprietary
12024 tools reject R15, so we do too. */
12025 constraint (Rm == REG_PC, BAD_PC);
12026 }
12027 else
12028 reject_bad_reg (Rm);
fdfde340
JM
12029 }
12030 else if (opcode == T_MNEM_mov
12031 || opcode == T_MNEM_movs)
12032 {
12033 if (inst.operands[1].isreg)
12034 {
12035 if (opcode == T_MNEM_movs)
12036 {
12037 reject_bad_reg (Rn);
12038 reject_bad_reg (Rm);
12039 }
76fa04a4
MGD
12040 else if (narrow)
12041 {
12042 /* This is mov.n. */
12043 if ((Rn == REG_SP || Rn == REG_PC)
12044 && (Rm == REG_SP || Rm == REG_PC))
12045 {
5c3696f8 12046 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
12047 "deprecated when r%u is the destination "
12048 "register."), Rm, Rn);
12049 }
12050 }
12051 else
12052 {
12053 /* This is mov.w. */
12054 constraint (Rn == REG_PC, BAD_PC);
12055 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
12056 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12057 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 12058 }
fdfde340
JM
12059 }
12060 else
12061 reject_bad_reg (Rn);
12062 }
12063
c19d1205
ZW
12064 if (!inst.operands[1].isreg)
12065 {
0110f2b8 12066 /* Immediate operand. */
e07e6e58 12067 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
12068 narrow = 0;
12069 if (low_regs && narrow)
12070 {
12071 inst.instruction = THUMB_OP16 (opcode);
fdfde340 12072 inst.instruction |= Rn << 8;
e2b0ab59
AV
12073 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12074 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 12075 {
a9f02af8 12076 if (inst.size_req == 2)
e2b0ab59 12077 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
12078 else
12079 inst.relax = opcode;
72d98d16 12080 }
0110f2b8
PB
12081 }
12082 else
12083 {
e2b0ab59
AV
12084 constraint ((inst.relocs[0].type
12085 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
12086 && (inst.relocs[0].type
12087 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8
MG
12088 THUMB1_RELOC_ONLY);
12089
0110f2b8
PB
12090 inst.instruction = THUMB_OP32 (inst.instruction);
12091 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12092 inst.instruction |= Rn << r0off;
e2b0ab59 12093 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8 12094 }
c19d1205 12095 }
728ca7c9
PB
12096 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12097 && (inst.instruction == T_MNEM_mov
12098 || inst.instruction == T_MNEM_movs))
12099 {
12100 /* Register shifts are encoded as separate shift instructions. */
12101 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
12102
e07e6e58 12103 if (in_it_block ())
728ca7c9
PB
12104 narrow = !flags;
12105 else
12106 narrow = flags;
12107
12108 if (inst.size_req == 4)
12109 narrow = FALSE;
12110
12111 if (!low_regs || inst.operands[1].imm > 7)
12112 narrow = FALSE;
12113
fdfde340 12114 if (Rn != Rm)
728ca7c9
PB
12115 narrow = FALSE;
12116
12117 switch (inst.operands[1].shift_kind)
12118 {
12119 case SHIFT_LSL:
12120 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12121 break;
12122 case SHIFT_ASR:
12123 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12124 break;
12125 case SHIFT_LSR:
12126 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12127 break;
12128 case SHIFT_ROR:
12129 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12130 break;
12131 default:
5f4273c7 12132 abort ();
728ca7c9
PB
12133 }
12134
12135 inst.instruction = opcode;
12136 if (narrow)
12137 {
fdfde340 12138 inst.instruction |= Rn;
728ca7c9
PB
12139 inst.instruction |= inst.operands[1].imm << 3;
12140 }
12141 else
12142 {
12143 if (flags)
12144 inst.instruction |= CONDS_BIT;
12145
fdfde340
JM
12146 inst.instruction |= Rn << 8;
12147 inst.instruction |= Rm << 16;
728ca7c9
PB
12148 inst.instruction |= inst.operands[1].imm;
12149 }
12150 }
3d388997 12151 else if (!narrow)
c19d1205 12152 {
728ca7c9
PB
12153 /* Some mov with immediate shift have narrow variants.
12154 Register shifts are handled above. */
12155 if (low_regs && inst.operands[1].shifted
12156 && (inst.instruction == T_MNEM_mov
12157 || inst.instruction == T_MNEM_movs))
12158 {
e07e6e58 12159 if (in_it_block ())
728ca7c9
PB
12160 narrow = (inst.instruction == T_MNEM_mov);
12161 else
12162 narrow = (inst.instruction == T_MNEM_movs);
12163 }
12164
12165 if (narrow)
12166 {
12167 switch (inst.operands[1].shift_kind)
12168 {
12169 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12170 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12171 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12172 default: narrow = FALSE; break;
12173 }
12174 }
12175
12176 if (narrow)
12177 {
fdfde340
JM
12178 inst.instruction |= Rn;
12179 inst.instruction |= Rm << 3;
e2b0ab59 12180 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
728ca7c9
PB
12181 }
12182 else
12183 {
12184 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12185 inst.instruction |= Rn << r0off;
728ca7c9
PB
12186 encode_thumb32_shifted_operand (1);
12187 }
c19d1205
ZW
12188 }
12189 else
12190 switch (inst.instruction)
12191 {
12192 case T_MNEM_mov:
837b3435 12193 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12194 results. Don't allow this. */
12195 if (low_regs)
12196 {
12197 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12198 "MOV Rd, Rs with two low registers is not "
12199 "permitted on this architecture");
fa94de6b 12200 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12201 arm_ext_v6);
12202 }
12203
c19d1205 12204 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12205 inst.instruction |= (Rn & 0x8) << 4;
12206 inst.instruction |= (Rn & 0x7);
12207 inst.instruction |= Rm << 3;
c19d1205 12208 break;
b99bd4ef 12209
c19d1205
ZW
12210 case T_MNEM_movs:
12211 /* We know we have low registers at this point.
941a8a52
MGD
12212 Generate LSLS Rd, Rs, #0. */
12213 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12214 inst.instruction |= Rn;
12215 inst.instruction |= Rm << 3;
c19d1205
ZW
12216 break;
12217
12218 case T_MNEM_cmp:
3d388997 12219 if (low_regs)
c19d1205
ZW
12220 {
12221 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12222 inst.instruction |= Rn;
12223 inst.instruction |= Rm << 3;
c19d1205
ZW
12224 }
12225 else
12226 {
12227 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12228 inst.instruction |= (Rn & 0x8) << 4;
12229 inst.instruction |= (Rn & 0x7);
12230 inst.instruction |= Rm << 3;
c19d1205
ZW
12231 }
12232 break;
12233 }
b99bd4ef
NC
12234 return;
12235 }
12236
c19d1205 12237 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12238
12239 /* PR 10443: Do not silently ignore shifted operands. */
12240 constraint (inst.operands[1].shifted,
12241 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12242
c19d1205 12243 if (inst.operands[1].isreg)
b99bd4ef 12244 {
fdfde340 12245 if (Rn < 8 && Rm < 8)
b99bd4ef 12246 {
c19d1205
ZW
12247 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12248 since a MOV instruction produces unpredictable results. */
12249 if (inst.instruction == T_OPCODE_MOV_I8)
12250 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12251 else
c19d1205 12252 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12253
fdfde340
JM
12254 inst.instruction |= Rn;
12255 inst.instruction |= Rm << 3;
b99bd4ef
NC
12256 }
12257 else
12258 {
c19d1205
ZW
12259 if (inst.instruction == T_OPCODE_MOV_I8)
12260 inst.instruction = T_OPCODE_MOV_HR;
12261 else
12262 inst.instruction = T_OPCODE_CMP_HR;
12263 do_t_cpy ();
b99bd4ef
NC
12264 }
12265 }
c19d1205 12266 else
b99bd4ef 12267 {
fdfde340 12268 constraint (Rn > 7,
c19d1205 12269 _("only lo regs allowed with immediate"));
fdfde340 12270 inst.instruction |= Rn << 8;
e2b0ab59 12271 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
c19d1205
ZW
12272 }
12273}
b99bd4ef 12274
c19d1205
ZW
12275static void
12276do_t_mov16 (void)
12277{
fdfde340 12278 unsigned Rd;
b6895b4f
PB
12279 bfd_vma imm;
12280 bfd_boolean top;
12281
12282 top = (inst.instruction & 0x00800000) != 0;
e2b0ab59 12283 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
b6895b4f 12284 {
33eaf5de 12285 constraint (top, _(":lower16: not allowed in this instruction"));
e2b0ab59 12286 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
b6895b4f 12287 }
e2b0ab59 12288 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
b6895b4f 12289 {
33eaf5de 12290 constraint (!top, _(":upper16: not allowed in this instruction"));
e2b0ab59 12291 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
b6895b4f
PB
12292 }
12293
fdfde340
JM
12294 Rd = inst.operands[0].reg;
12295 reject_bad_reg (Rd);
12296
12297 inst.instruction |= Rd << 8;
e2b0ab59 12298 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 12299 {
e2b0ab59 12300 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
12301 inst.instruction |= (imm & 0xf000) << 4;
12302 inst.instruction |= (imm & 0x0800) << 15;
12303 inst.instruction |= (imm & 0x0700) << 4;
12304 inst.instruction |= (imm & 0x00ff);
12305 }
c19d1205 12306}
b99bd4ef 12307
c19d1205
ZW
12308static void
12309do_t_mvn_tst (void)
12310{
fdfde340 12311 unsigned Rn, Rm;
c921be7d 12312
fdfde340
JM
12313 Rn = inst.operands[0].reg;
12314 Rm = inst.operands[1].reg;
12315
12316 if (inst.instruction == T_MNEM_cmp
12317 || inst.instruction == T_MNEM_cmn)
12318 constraint (Rn == REG_PC, BAD_PC);
12319 else
12320 reject_bad_reg (Rn);
12321 reject_bad_reg (Rm);
12322
c19d1205
ZW
12323 if (unified_syntax)
12324 {
12325 int r0off = (inst.instruction == T_MNEM_mvn
12326 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12327 bfd_boolean narrow;
12328
12329 if (inst.size_req == 4
12330 || inst.instruction > 0xffff
12331 || inst.operands[1].shifted
fdfde340 12332 || Rn > 7 || Rm > 7)
3d388997 12333 narrow = FALSE;
fe8b4cc3
KT
12334 else if (inst.instruction == T_MNEM_cmn
12335 || inst.instruction == T_MNEM_tst)
3d388997
PB
12336 narrow = TRUE;
12337 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12338 narrow = !in_it_block ();
3d388997 12339 else
e07e6e58 12340 narrow = in_it_block ();
3d388997 12341
c19d1205 12342 if (!inst.operands[1].isreg)
b99bd4ef 12343 {
c19d1205
ZW
12344 /* For an immediate, we always generate a 32-bit opcode;
12345 section relaxation will shrink it later if possible. */
12346 if (inst.instruction < 0xffff)
12347 inst.instruction = THUMB_OP32 (inst.instruction);
12348 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12349 inst.instruction |= Rn << r0off;
e2b0ab59 12350 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12351 }
c19d1205 12352 else
b99bd4ef 12353 {
c19d1205 12354 /* See if we can do this with a 16-bit instruction. */
3d388997 12355 if (narrow)
b99bd4ef 12356 {
c19d1205 12357 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12358 inst.instruction |= Rn;
12359 inst.instruction |= Rm << 3;
b99bd4ef 12360 }
c19d1205 12361 else
b99bd4ef 12362 {
c19d1205
ZW
12363 constraint (inst.operands[1].shifted
12364 && inst.operands[1].immisreg,
12365 _("shift must be constant"));
12366 if (inst.instruction < 0xffff)
12367 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12368 inst.instruction |= Rn << r0off;
c19d1205 12369 encode_thumb32_shifted_operand (1);
b99bd4ef 12370 }
b99bd4ef
NC
12371 }
12372 }
12373 else
12374 {
c19d1205
ZW
12375 constraint (inst.instruction > 0xffff
12376 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12377 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12378 _("unshifted register required"));
fdfde340 12379 constraint (Rn > 7 || Rm > 7,
c19d1205 12380 BAD_HIREG);
b99bd4ef 12381
c19d1205 12382 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12383 inst.instruction |= Rn;
12384 inst.instruction |= Rm << 3;
b99bd4ef 12385 }
b99bd4ef
NC
12386}
12387
b05fe5cf 12388static void
c19d1205 12389do_t_mrs (void)
b05fe5cf 12390{
fdfde340 12391 unsigned Rd;
037e8744
JB
12392
12393 if (do_vfp_nsyn_mrs () == SUCCESS)
12394 return;
12395
90ec0d68
MGD
12396 Rd = inst.operands[0].reg;
12397 reject_bad_reg (Rd);
12398 inst.instruction |= Rd << 8;
12399
12400 if (inst.operands[1].isreg)
62b3e311 12401 {
90ec0d68
MGD
12402 unsigned br = inst.operands[1].reg;
12403 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12404 as_bad (_("bad register for mrs"));
12405
12406 inst.instruction |= br & (0xf << 16);
12407 inst.instruction |= (br & 0x300) >> 4;
12408 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12409 }
12410 else
12411 {
90ec0d68 12412 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12413
d2cd1205 12414 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12415 {
12416 /* PR gas/12698: The constraint is only applied for m_profile.
12417 If the user has specified -march=all, we want to ignore it as
12418 we are building for any CPU type, including non-m variants. */
823d2571
TG
12419 bfd_boolean m_profile =
12420 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12421 constraint ((flags != 0) && m_profile, _("selected processor does "
12422 "not support requested special purpose register"));
12423 }
90ec0d68 12424 else
d2cd1205
JB
12425 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12426 devices). */
12427 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12428 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12429
90ec0d68
MGD
12430 inst.instruction |= (flags & SPSR_BIT) >> 2;
12431 inst.instruction |= inst.operands[1].imm & 0xff;
12432 inst.instruction |= 0xf0000;
12433 }
c19d1205 12434}
b05fe5cf 12435
c19d1205
ZW
12436static void
12437do_t_msr (void)
12438{
62b3e311 12439 int flags;
fdfde340 12440 unsigned Rn;
62b3e311 12441
037e8744
JB
12442 if (do_vfp_nsyn_msr () == SUCCESS)
12443 return;
12444
c19d1205
ZW
12445 constraint (!inst.operands[1].isreg,
12446 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12447
12448 if (inst.operands[0].isreg)
12449 flags = (int)(inst.operands[0].reg);
12450 else
12451 flags = inst.operands[0].imm;
12452
d2cd1205 12453 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12454 {
d2cd1205
JB
12455 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12456
1a43faaf 12457 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12458 If the user has specified -march=all, we want to ignore it as
12459 we are building for any CPU type, including non-m variants. */
823d2571
TG
12460 bfd_boolean m_profile =
12461 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12462 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12463 && (bits & ~(PSR_s | PSR_f)) != 0)
12464 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12465 && bits != PSR_f)) && m_profile,
12466 _("selected processor does not support requested special "
12467 "purpose register"));
62b3e311
PB
12468 }
12469 else
d2cd1205
JB
12470 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12471 "requested special purpose register"));
c921be7d 12472
fdfde340
JM
12473 Rn = inst.operands[1].reg;
12474 reject_bad_reg (Rn);
12475
62b3e311 12476 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12477 inst.instruction |= (flags & 0xf0000) >> 8;
12478 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12479 inst.instruction |= (flags & 0xff);
fdfde340 12480 inst.instruction |= Rn << 16;
c19d1205 12481}
b05fe5cf 12482
c19d1205
ZW
12483static void
12484do_t_mul (void)
12485{
17828f45 12486 bfd_boolean narrow;
fdfde340 12487 unsigned Rd, Rn, Rm;
17828f45 12488
c19d1205
ZW
12489 if (!inst.operands[2].present)
12490 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12491
fdfde340
JM
12492 Rd = inst.operands[0].reg;
12493 Rn = inst.operands[1].reg;
12494 Rm = inst.operands[2].reg;
12495
17828f45 12496 if (unified_syntax)
b05fe5cf 12497 {
17828f45 12498 if (inst.size_req == 4
fdfde340
JM
12499 || (Rd != Rn
12500 && Rd != Rm)
12501 || Rn > 7
12502 || Rm > 7)
17828f45
JM
12503 narrow = FALSE;
12504 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12505 narrow = !in_it_block ();
17828f45 12506 else
e07e6e58 12507 narrow = in_it_block ();
b05fe5cf 12508 }
c19d1205 12509 else
b05fe5cf 12510 {
17828f45 12511 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12512 constraint (Rn > 7 || Rm > 7,
c19d1205 12513 BAD_HIREG);
17828f45
JM
12514 narrow = TRUE;
12515 }
b05fe5cf 12516
17828f45
JM
12517 if (narrow)
12518 {
12519 /* 16-bit MULS/Conditional MUL. */
c19d1205 12520 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12521 inst.instruction |= Rd;
b05fe5cf 12522
fdfde340
JM
12523 if (Rd == Rn)
12524 inst.instruction |= Rm << 3;
12525 else if (Rd == Rm)
12526 inst.instruction |= Rn << 3;
c19d1205
ZW
12527 else
12528 constraint (1, _("dest must overlap one source register"));
12529 }
17828f45
JM
12530 else
12531 {
e07e6e58
NC
12532 constraint (inst.instruction != T_MNEM_mul,
12533 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12534 /* 32-bit MUL. */
12535 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12536 inst.instruction |= Rd << 8;
12537 inst.instruction |= Rn << 16;
12538 inst.instruction |= Rm << 0;
12539
12540 reject_bad_reg (Rd);
12541 reject_bad_reg (Rn);
12542 reject_bad_reg (Rm);
17828f45 12543 }
c19d1205 12544}
b05fe5cf 12545
c19d1205
ZW
12546static void
12547do_t_mull (void)
12548{
fdfde340 12549 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12550
fdfde340
JM
12551 RdLo = inst.operands[0].reg;
12552 RdHi = inst.operands[1].reg;
12553 Rn = inst.operands[2].reg;
12554 Rm = inst.operands[3].reg;
12555
12556 reject_bad_reg (RdLo);
12557 reject_bad_reg (RdHi);
12558 reject_bad_reg (Rn);
12559 reject_bad_reg (Rm);
12560
12561 inst.instruction |= RdLo << 12;
12562 inst.instruction |= RdHi << 8;
12563 inst.instruction |= Rn << 16;
12564 inst.instruction |= Rm;
12565
12566 if (RdLo == RdHi)
c19d1205
ZW
12567 as_tsktsk (_("rdhi and rdlo must be different"));
12568}
b05fe5cf 12569
c19d1205
ZW
12570static void
12571do_t_nop (void)
12572{
e07e6e58
NC
12573 set_it_insn_type (NEUTRAL_IT_INSN);
12574
c19d1205
ZW
12575 if (unified_syntax)
12576 {
12577 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12578 {
c19d1205
ZW
12579 inst.instruction = THUMB_OP32 (inst.instruction);
12580 inst.instruction |= inst.operands[0].imm;
12581 }
12582 else
12583 {
bc2d1808
NC
12584 /* PR9722: Check for Thumb2 availability before
12585 generating a thumb2 nop instruction. */
afa62d5e 12586 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12587 {
12588 inst.instruction = THUMB_OP16 (inst.instruction);
12589 inst.instruction |= inst.operands[0].imm << 4;
12590 }
12591 else
12592 inst.instruction = 0x46c0;
c19d1205
ZW
12593 }
12594 }
12595 else
12596 {
12597 constraint (inst.operands[0].present,
12598 _("Thumb does not support NOP with hints"));
12599 inst.instruction = 0x46c0;
12600 }
12601}
b05fe5cf 12602
c19d1205
ZW
12603static void
12604do_t_neg (void)
12605{
12606 if (unified_syntax)
12607 {
3d388997
PB
12608 bfd_boolean narrow;
12609
12610 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12611 narrow = !in_it_block ();
3d388997 12612 else
e07e6e58 12613 narrow = in_it_block ();
3d388997
PB
12614 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12615 narrow = FALSE;
12616 if (inst.size_req == 4)
12617 narrow = FALSE;
12618
12619 if (!narrow)
c19d1205
ZW
12620 {
12621 inst.instruction = THUMB_OP32 (inst.instruction);
12622 inst.instruction |= inst.operands[0].reg << 8;
12623 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12624 }
12625 else
12626 {
c19d1205
ZW
12627 inst.instruction = THUMB_OP16 (inst.instruction);
12628 inst.instruction |= inst.operands[0].reg;
12629 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12630 }
12631 }
12632 else
12633 {
c19d1205
ZW
12634 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12635 BAD_HIREG);
12636 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12637
12638 inst.instruction = THUMB_OP16 (inst.instruction);
12639 inst.instruction |= inst.operands[0].reg;
12640 inst.instruction |= inst.operands[1].reg << 3;
12641 }
12642}
12643
1c444d06
JM
12644static void
12645do_t_orn (void)
12646{
12647 unsigned Rd, Rn;
12648
12649 Rd = inst.operands[0].reg;
12650 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12651
fdfde340
JM
12652 reject_bad_reg (Rd);
12653 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12654 reject_bad_reg (Rn);
12655
1c444d06
JM
12656 inst.instruction |= Rd << 8;
12657 inst.instruction |= Rn << 16;
12658
12659 if (!inst.operands[2].isreg)
12660 {
12661 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 12662 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
1c444d06
JM
12663 }
12664 else
12665 {
12666 unsigned Rm;
12667
12668 Rm = inst.operands[2].reg;
fdfde340 12669 reject_bad_reg (Rm);
1c444d06
JM
12670
12671 constraint (inst.operands[2].shifted
12672 && inst.operands[2].immisreg,
12673 _("shift must be constant"));
12674 encode_thumb32_shifted_operand (2);
12675 }
12676}
12677
c19d1205
ZW
12678static void
12679do_t_pkhbt (void)
12680{
fdfde340
JM
12681 unsigned Rd, Rn, Rm;
12682
12683 Rd = inst.operands[0].reg;
12684 Rn = inst.operands[1].reg;
12685 Rm = inst.operands[2].reg;
12686
12687 reject_bad_reg (Rd);
12688 reject_bad_reg (Rn);
12689 reject_bad_reg (Rm);
12690
12691 inst.instruction |= Rd << 8;
12692 inst.instruction |= Rn << 16;
12693 inst.instruction |= Rm;
c19d1205
ZW
12694 if (inst.operands[3].present)
12695 {
e2b0ab59
AV
12696 unsigned int val = inst.relocs[0].exp.X_add_number;
12697 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
12698 _("expression too complex"));
12699 inst.instruction |= (val & 0x1c) << 10;
12700 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12701 }
c19d1205 12702}
b05fe5cf 12703
c19d1205
ZW
12704static void
12705do_t_pkhtb (void)
12706{
12707 if (!inst.operands[3].present)
1ef52f49
NC
12708 {
12709 unsigned Rtmp;
12710
12711 inst.instruction &= ~0x00000020;
12712
12713 /* PR 10168. Swap the Rm and Rn registers. */
12714 Rtmp = inst.operands[1].reg;
12715 inst.operands[1].reg = inst.operands[2].reg;
12716 inst.operands[2].reg = Rtmp;
12717 }
c19d1205 12718 do_t_pkhbt ();
b05fe5cf
ZW
12719}
12720
c19d1205
ZW
12721static void
12722do_t_pld (void)
12723{
fdfde340
JM
12724 if (inst.operands[0].immisreg)
12725 reject_bad_reg (inst.operands[0].imm);
12726
c19d1205
ZW
12727 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12728}
b05fe5cf 12729
c19d1205
ZW
12730static void
12731do_t_push_pop (void)
b99bd4ef 12732{
e9f89963 12733 unsigned mask;
5f4273c7 12734
c19d1205
ZW
12735 constraint (inst.operands[0].writeback,
12736 _("push/pop do not support {reglist}^"));
e2b0ab59 12737 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205 12738 _("expression too complex"));
b99bd4ef 12739
e9f89963 12740 mask = inst.operands[0].imm;
d3bfe16e 12741 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12742 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12743 else if (inst.size_req != 4
c6025a80 12744 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12745 ? REG_LR : REG_PC)))
b99bd4ef 12746 {
c19d1205
ZW
12747 inst.instruction = THUMB_OP16 (inst.instruction);
12748 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12749 inst.instruction |= mask & 0xff;
c19d1205
ZW
12750 }
12751 else if (unified_syntax)
12752 {
3c707909 12753 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12754 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12755 }
12756 else
12757 {
12758 inst.error = _("invalid register list to push/pop instruction");
12759 return;
12760 }
c19d1205 12761}
b99bd4ef 12762
c19d1205
ZW
12763static void
12764do_t_rbit (void)
12765{
fdfde340
JM
12766 unsigned Rd, Rm;
12767
12768 Rd = inst.operands[0].reg;
12769 Rm = inst.operands[1].reg;
12770
12771 reject_bad_reg (Rd);
12772 reject_bad_reg (Rm);
12773
12774 inst.instruction |= Rd << 8;
12775 inst.instruction |= Rm << 16;
12776 inst.instruction |= Rm;
c19d1205 12777}
b99bd4ef 12778
c19d1205
ZW
12779static void
12780do_t_rev (void)
12781{
fdfde340
JM
12782 unsigned Rd, Rm;
12783
12784 Rd = inst.operands[0].reg;
12785 Rm = inst.operands[1].reg;
12786
12787 reject_bad_reg (Rd);
12788 reject_bad_reg (Rm);
12789
12790 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12791 && inst.size_req != 4)
12792 {
12793 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12794 inst.instruction |= Rd;
12795 inst.instruction |= Rm << 3;
c19d1205
ZW
12796 }
12797 else if (unified_syntax)
12798 {
12799 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12800 inst.instruction |= Rd << 8;
12801 inst.instruction |= Rm << 16;
12802 inst.instruction |= Rm;
c19d1205
ZW
12803 }
12804 else
12805 inst.error = BAD_HIREG;
12806}
b99bd4ef 12807
1c444d06
JM
12808static void
12809do_t_rrx (void)
12810{
12811 unsigned Rd, Rm;
12812
12813 Rd = inst.operands[0].reg;
12814 Rm = inst.operands[1].reg;
12815
fdfde340
JM
12816 reject_bad_reg (Rd);
12817 reject_bad_reg (Rm);
c921be7d 12818
1c444d06
JM
12819 inst.instruction |= Rd << 8;
12820 inst.instruction |= Rm;
12821}
12822
c19d1205
ZW
12823static void
12824do_t_rsb (void)
12825{
fdfde340 12826 unsigned Rd, Rs;
b99bd4ef 12827
c19d1205
ZW
12828 Rd = inst.operands[0].reg;
12829 Rs = (inst.operands[1].present
12830 ? inst.operands[1].reg /* Rd, Rs, foo */
12831 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12832
fdfde340
JM
12833 reject_bad_reg (Rd);
12834 reject_bad_reg (Rs);
12835 if (inst.operands[2].isreg)
12836 reject_bad_reg (inst.operands[2].reg);
12837
c19d1205
ZW
12838 inst.instruction |= Rd << 8;
12839 inst.instruction |= Rs << 16;
12840 if (!inst.operands[2].isreg)
12841 {
026d3abb
PB
12842 bfd_boolean narrow;
12843
12844 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12845 narrow = !in_it_block ();
026d3abb 12846 else
e07e6e58 12847 narrow = in_it_block ();
026d3abb
PB
12848
12849 if (Rd > 7 || Rs > 7)
12850 narrow = FALSE;
12851
12852 if (inst.size_req == 4 || !unified_syntax)
12853 narrow = FALSE;
12854
e2b0ab59
AV
12855 if (inst.relocs[0].exp.X_op != O_constant
12856 || inst.relocs[0].exp.X_add_number != 0)
026d3abb
PB
12857 narrow = FALSE;
12858
12859 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12860 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12861 if (narrow)
12862 {
e2b0ab59 12863 inst.relocs[0].type = BFD_RELOC_UNUSED;
026d3abb
PB
12864 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12865 inst.instruction |= Rs << 3;
12866 inst.instruction |= Rd;
12867 }
12868 else
12869 {
12870 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 12871 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
026d3abb 12872 }
c19d1205
ZW
12873 }
12874 else
12875 encode_thumb32_shifted_operand (2);
12876}
b99bd4ef 12877
c19d1205
ZW
12878static void
12879do_t_setend (void)
12880{
12e37cbc
MGD
12881 if (warn_on_deprecated
12882 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12883 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12884
e07e6e58 12885 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12886 if (inst.operands[0].imm)
12887 inst.instruction |= 0x8;
12888}
b99bd4ef 12889
c19d1205
ZW
12890static void
12891do_t_shift (void)
12892{
12893 if (!inst.operands[1].present)
12894 inst.operands[1].reg = inst.operands[0].reg;
12895
12896 if (unified_syntax)
12897 {
3d388997
PB
12898 bfd_boolean narrow;
12899 int shift_kind;
12900
12901 switch (inst.instruction)
12902 {
12903 case T_MNEM_asr:
12904 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12905 case T_MNEM_lsl:
12906 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12907 case T_MNEM_lsr:
12908 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12909 case T_MNEM_ror:
12910 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12911 default: abort ();
12912 }
12913
12914 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12915 narrow = !in_it_block ();
3d388997 12916 else
e07e6e58 12917 narrow = in_it_block ();
3d388997
PB
12918 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12919 narrow = FALSE;
12920 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12921 narrow = FALSE;
12922 if (inst.operands[2].isreg
12923 && (inst.operands[1].reg != inst.operands[0].reg
12924 || inst.operands[2].reg > 7))
12925 narrow = FALSE;
12926 if (inst.size_req == 4)
12927 narrow = FALSE;
12928
fdfde340
JM
12929 reject_bad_reg (inst.operands[0].reg);
12930 reject_bad_reg (inst.operands[1].reg);
c921be7d 12931
3d388997 12932 if (!narrow)
c19d1205
ZW
12933 {
12934 if (inst.operands[2].isreg)
b99bd4ef 12935 {
fdfde340 12936 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12937 inst.instruction = THUMB_OP32 (inst.instruction);
12938 inst.instruction |= inst.operands[0].reg << 8;
12939 inst.instruction |= inst.operands[1].reg << 16;
12940 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12941
12942 /* PR 12854: Error on extraneous shifts. */
12943 constraint (inst.operands[2].shifted,
12944 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12945 }
12946 else
12947 {
12948 inst.operands[1].shifted = 1;
3d388997 12949 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12950 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12951 ? T_MNEM_movs : T_MNEM_mov);
12952 inst.instruction |= inst.operands[0].reg << 8;
12953 encode_thumb32_shifted_operand (1);
12954 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
e2b0ab59 12955 inst.relocs[0].type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12956 }
12957 }
12958 else
12959 {
c19d1205 12960 if (inst.operands[2].isreg)
b99bd4ef 12961 {
3d388997 12962 switch (shift_kind)
b99bd4ef 12963 {
3d388997
PB
12964 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12965 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12966 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12967 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12968 default: abort ();
b99bd4ef 12969 }
5f4273c7 12970
c19d1205
ZW
12971 inst.instruction |= inst.operands[0].reg;
12972 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12973
12974 /* PR 12854: Error on extraneous shifts. */
12975 constraint (inst.operands[2].shifted,
12976 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12977 }
12978 else
12979 {
3d388997 12980 switch (shift_kind)
b99bd4ef 12981 {
3d388997
PB
12982 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12983 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12984 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12985 default: abort ();
b99bd4ef 12986 }
e2b0ab59 12987 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
12988 inst.instruction |= inst.operands[0].reg;
12989 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12990 }
12991 }
c19d1205
ZW
12992 }
12993 else
12994 {
12995 constraint (inst.operands[0].reg > 7
12996 || inst.operands[1].reg > 7, BAD_HIREG);
12997 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12998
c19d1205
ZW
12999 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
13000 {
13001 constraint (inst.operands[2].reg > 7, BAD_HIREG);
13002 constraint (inst.operands[0].reg != inst.operands[1].reg,
13003 _("source1 and dest must be same register"));
b99bd4ef 13004
c19d1205
ZW
13005 switch (inst.instruction)
13006 {
13007 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
13008 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
13009 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
13010 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
13011 default: abort ();
13012 }
5f4273c7 13013
c19d1205
ZW
13014 inst.instruction |= inst.operands[0].reg;
13015 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
13016
13017 /* PR 12854: Error on extraneous shifts. */
13018 constraint (inst.operands[2].shifted,
13019 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
13020 }
13021 else
b99bd4ef 13022 {
c19d1205
ZW
13023 switch (inst.instruction)
13024 {
13025 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
13026 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
13027 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
13028 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
13029 default: abort ();
13030 }
e2b0ab59 13031 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
13032 inst.instruction |= inst.operands[0].reg;
13033 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
13034 }
13035 }
b99bd4ef
NC
13036}
13037
13038static void
c19d1205 13039do_t_simd (void)
b99bd4ef 13040{
fdfde340
JM
13041 unsigned Rd, Rn, Rm;
13042
13043 Rd = inst.operands[0].reg;
13044 Rn = inst.operands[1].reg;
13045 Rm = inst.operands[2].reg;
13046
13047 reject_bad_reg (Rd);
13048 reject_bad_reg (Rn);
13049 reject_bad_reg (Rm);
13050
13051 inst.instruction |= Rd << 8;
13052 inst.instruction |= Rn << 16;
13053 inst.instruction |= Rm;
c19d1205 13054}
b99bd4ef 13055
03ee1b7f
NC
13056static void
13057do_t_simd2 (void)
13058{
13059 unsigned Rd, Rn, Rm;
13060
13061 Rd = inst.operands[0].reg;
13062 Rm = inst.operands[1].reg;
13063 Rn = inst.operands[2].reg;
13064
13065 reject_bad_reg (Rd);
13066 reject_bad_reg (Rn);
13067 reject_bad_reg (Rm);
13068
13069 inst.instruction |= Rd << 8;
13070 inst.instruction |= Rn << 16;
13071 inst.instruction |= Rm;
13072}
13073
c19d1205 13074static void
3eb17e6b 13075do_t_smc (void)
c19d1205 13076{
e2b0ab59 13077 unsigned int value = inst.relocs[0].exp.X_add_number;
f4c65163
MGD
13078 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
13079 _("SMC is not permitted on this architecture"));
e2b0ab59 13080 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 13081 _("expression too complex"));
e2b0ab59 13082 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205
ZW
13083 inst.instruction |= (value & 0xf000) >> 12;
13084 inst.instruction |= (value & 0x0ff0);
13085 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
13086 /* PR gas/15623: SMC instructions must be last in an IT block. */
13087 set_it_insn_type_last ();
c19d1205 13088}
b99bd4ef 13089
90ec0d68
MGD
13090static void
13091do_t_hvc (void)
13092{
e2b0ab59 13093 unsigned int value = inst.relocs[0].exp.X_add_number;
90ec0d68 13094
e2b0ab59 13095 inst.relocs[0].type = BFD_RELOC_UNUSED;
90ec0d68
MGD
13096 inst.instruction |= (value & 0x0fff);
13097 inst.instruction |= (value & 0xf000) << 4;
13098}
13099
c19d1205 13100static void
3a21c15a 13101do_t_ssat_usat (int bias)
c19d1205 13102{
fdfde340
JM
13103 unsigned Rd, Rn;
13104
13105 Rd = inst.operands[0].reg;
13106 Rn = inst.operands[2].reg;
13107
13108 reject_bad_reg (Rd);
13109 reject_bad_reg (Rn);
13110
13111 inst.instruction |= Rd << 8;
3a21c15a 13112 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 13113 inst.instruction |= Rn << 16;
b99bd4ef 13114
c19d1205 13115 if (inst.operands[3].present)
b99bd4ef 13116 {
e2b0ab59 13117 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
3a21c15a 13118
e2b0ab59 13119 inst.relocs[0].type = BFD_RELOC_UNUSED;
3a21c15a 13120
e2b0ab59 13121 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 13122 _("expression too complex"));
b99bd4ef 13123
3a21c15a 13124 if (shift_amount != 0)
6189168b 13125 {
3a21c15a
NC
13126 constraint (shift_amount > 31,
13127 _("shift expression is too large"));
13128
c19d1205 13129 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
13130 inst.instruction |= 0x00200000; /* sh bit. */
13131
13132 inst.instruction |= (shift_amount & 0x1c) << 10;
13133 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
13134 }
13135 }
b99bd4ef 13136}
c921be7d 13137
3a21c15a
NC
13138static void
13139do_t_ssat (void)
13140{
13141 do_t_ssat_usat (1);
13142}
b99bd4ef 13143
0dd132b6 13144static void
c19d1205 13145do_t_ssat16 (void)
0dd132b6 13146{
fdfde340
JM
13147 unsigned Rd, Rn;
13148
13149 Rd = inst.operands[0].reg;
13150 Rn = inst.operands[2].reg;
13151
13152 reject_bad_reg (Rd);
13153 reject_bad_reg (Rn);
13154
13155 inst.instruction |= Rd << 8;
c19d1205 13156 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 13157 inst.instruction |= Rn << 16;
c19d1205 13158}
0dd132b6 13159
c19d1205
ZW
13160static void
13161do_t_strex (void)
13162{
13163 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13164 || inst.operands[2].postind || inst.operands[2].writeback
13165 || inst.operands[2].immisreg || inst.operands[2].shifted
13166 || inst.operands[2].negative,
01cfc07f 13167 BAD_ADDR_MODE);
0dd132b6 13168
5be8be5d
DG
13169 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13170
c19d1205
ZW
13171 inst.instruction |= inst.operands[0].reg << 8;
13172 inst.instruction |= inst.operands[1].reg << 12;
13173 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 13174 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13175}
13176
b99bd4ef 13177static void
c19d1205 13178do_t_strexd (void)
b99bd4ef 13179{
c19d1205
ZW
13180 if (!inst.operands[2].present)
13181 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13182
c19d1205
ZW
13183 constraint (inst.operands[0].reg == inst.operands[1].reg
13184 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13185 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13186 BAD_OVERLAP);
b99bd4ef 13187
c19d1205
ZW
13188 inst.instruction |= inst.operands[0].reg;
13189 inst.instruction |= inst.operands[1].reg << 12;
13190 inst.instruction |= inst.operands[2].reg << 8;
13191 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13192}
13193
13194static void
c19d1205 13195do_t_sxtah (void)
b99bd4ef 13196{
fdfde340
JM
13197 unsigned Rd, Rn, Rm;
13198
13199 Rd = inst.operands[0].reg;
13200 Rn = inst.operands[1].reg;
13201 Rm = inst.operands[2].reg;
13202
13203 reject_bad_reg (Rd);
13204 reject_bad_reg (Rn);
13205 reject_bad_reg (Rm);
13206
13207 inst.instruction |= Rd << 8;
13208 inst.instruction |= Rn << 16;
13209 inst.instruction |= Rm;
c19d1205
ZW
13210 inst.instruction |= inst.operands[3].imm << 4;
13211}
b99bd4ef 13212
c19d1205
ZW
13213static void
13214do_t_sxth (void)
13215{
fdfde340
JM
13216 unsigned Rd, Rm;
13217
13218 Rd = inst.operands[0].reg;
13219 Rm = inst.operands[1].reg;
13220
13221 reject_bad_reg (Rd);
13222 reject_bad_reg (Rm);
c921be7d
NC
13223
13224 if (inst.instruction <= 0xffff
13225 && inst.size_req != 4
fdfde340 13226 && Rd <= 7 && Rm <= 7
c19d1205 13227 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13228 {
c19d1205 13229 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13230 inst.instruction |= Rd;
13231 inst.instruction |= Rm << 3;
b99bd4ef 13232 }
c19d1205 13233 else if (unified_syntax)
b99bd4ef 13234 {
c19d1205
ZW
13235 if (inst.instruction <= 0xffff)
13236 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13237 inst.instruction |= Rd << 8;
13238 inst.instruction |= Rm;
c19d1205 13239 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13240 }
c19d1205 13241 else
b99bd4ef 13242 {
c19d1205
ZW
13243 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13244 _("Thumb encoding does not support rotation"));
13245 constraint (1, BAD_HIREG);
b99bd4ef 13246 }
c19d1205 13247}
b99bd4ef 13248
c19d1205
ZW
13249static void
13250do_t_swi (void)
13251{
e2b0ab59 13252 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
c19d1205 13253}
b99bd4ef 13254
92e90b6e
PB
13255static void
13256do_t_tb (void)
13257{
fdfde340 13258 unsigned Rn, Rm;
92e90b6e
PB
13259 int half;
13260
13261 half = (inst.instruction & 0x10) != 0;
e07e6e58 13262 set_it_insn_type_last ();
dfa9f0d5
PB
13263 constraint (inst.operands[0].immisreg,
13264 _("instruction requires register index"));
fdfde340
JM
13265
13266 Rn = inst.operands[0].reg;
13267 Rm = inst.operands[0].imm;
c921be7d 13268
5c8ed6a4
JW
13269 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13270 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
13271 reject_bad_reg (Rm);
13272
92e90b6e
PB
13273 constraint (!half && inst.operands[0].shifted,
13274 _("instruction does not allow shifted index"));
fdfde340 13275 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13276}
13277
74db7efb
NC
13278static void
13279do_t_udf (void)
13280{
13281 if (!inst.operands[0].present)
13282 inst.operands[0].imm = 0;
13283
13284 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13285 {
13286 constraint (inst.size_req == 2,
13287 _("immediate value out of range"));
13288 inst.instruction = THUMB_OP32 (inst.instruction);
13289 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13290 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13291 }
13292 else
13293 {
13294 inst.instruction = THUMB_OP16 (inst.instruction);
13295 inst.instruction |= inst.operands[0].imm;
13296 }
13297
13298 set_it_insn_type (NEUTRAL_IT_INSN);
13299}
13300
13301
c19d1205
ZW
13302static void
13303do_t_usat (void)
13304{
3a21c15a 13305 do_t_ssat_usat (0);
b99bd4ef
NC
13306}
13307
13308static void
c19d1205 13309do_t_usat16 (void)
b99bd4ef 13310{
fdfde340
JM
13311 unsigned Rd, Rn;
13312
13313 Rd = inst.operands[0].reg;
13314 Rn = inst.operands[2].reg;
13315
13316 reject_bad_reg (Rd);
13317 reject_bad_reg (Rn);
13318
13319 inst.instruction |= Rd << 8;
c19d1205 13320 inst.instruction |= inst.operands[1].imm;
fdfde340 13321 inst.instruction |= Rn << 16;
b99bd4ef 13322}
c19d1205 13323
e12437dc
AV
13324/* Checking the range of the branch offset (VAL) with NBITS bits
13325 and IS_SIGNED signedness. Also checks the LSB to be 0. */
13326static int
13327v8_1_branch_value_check (int val, int nbits, int is_signed)
13328{
13329 gas_assert (nbits > 0 && nbits <= 32);
13330 if (is_signed)
13331 {
13332 int cmp = (1 << (nbits - 1));
13333 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
13334 return FAIL;
13335 }
13336 else
13337 {
13338 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
13339 return FAIL;
13340 }
13341 return SUCCESS;
13342}
13343
4389b29a
AV
13344/* For branches in Armv8.1-M Mainline. */
13345static void
13346do_t_branch_future (void)
13347{
13348 unsigned long insn = inst.instruction;
13349
13350 inst.instruction = THUMB_OP32 (inst.instruction);
13351 if (inst.operands[0].hasreloc == 0)
13352 {
13353 if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL)
13354 as_bad (BAD_BRANCH_OFF);
13355
13356 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
13357 }
13358 else
13359 {
13360 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
13361 inst.relocs[0].pc_rel = 1;
13362 }
13363
13364 switch (insn)
13365 {
13366 case T_MNEM_bf:
13367 if (inst.operands[1].hasreloc == 0)
13368 {
13369 int val = inst.operands[1].imm;
13370 if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL)
13371 as_bad (BAD_BRANCH_OFF);
13372
13373 int immA = (val & 0x0001f000) >> 12;
13374 int immB = (val & 0x00000ffc) >> 2;
13375 int immC = (val & 0x00000002) >> 1;
13376 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
13377 }
13378 else
13379 {
13380 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
13381 inst.relocs[1].pc_rel = 1;
13382 }
13383 break;
13384
65d1bc05
AV
13385 case T_MNEM_bfl:
13386 if (inst.operands[1].hasreloc == 0)
13387 {
13388 int val = inst.operands[1].imm;
13389 if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL)
13390 as_bad (BAD_BRANCH_OFF);
13391
13392 int immA = (val & 0x0007f000) >> 12;
13393 int immB = (val & 0x00000ffc) >> 2;
13394 int immC = (val & 0x00000002) >> 1;
13395 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
13396 }
13397 else
13398 {
13399 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
13400 inst.relocs[1].pc_rel = 1;
13401 }
13402 break;
13403
f6b2b12d
AV
13404 case T_MNEM_bfcsel:
13405 /* Operand 1. */
13406 if (inst.operands[1].hasreloc == 0)
13407 {
13408 int val = inst.operands[1].imm;
13409 int immA = (val & 0x00001000) >> 12;
13410 int immB = (val & 0x00000ffc) >> 2;
13411 int immC = (val & 0x00000002) >> 1;
13412 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
13413 }
13414 else
13415 {
13416 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
13417 inst.relocs[1].pc_rel = 1;
13418 }
13419
13420 /* Operand 2. */
13421 if (inst.operands[2].hasreloc == 0)
13422 {
13423 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
13424 int val2 = inst.operands[2].imm;
13425 int val0 = inst.operands[0].imm & 0x1f;
13426 int diff = val2 - val0;
13427 if (diff == 4)
13428 inst.instruction |= 1 << 17; /* T bit. */
13429 else if (diff != 2)
13430 as_bad (_("out of range label-relative fixup value"));
13431 }
13432 else
13433 {
13434 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
13435 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
13436 inst.relocs[2].pc_rel = 1;
13437 }
13438
13439 /* Operand 3. */
13440 constraint (inst.cond != COND_ALWAYS, BAD_COND);
13441 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
13442 break;
13443
f1c7f421
AV
13444 case T_MNEM_bfx:
13445 case T_MNEM_bflx:
13446 inst.instruction |= inst.operands[1].reg << 16;
13447 break;
13448
4389b29a
AV
13449 default: abort ();
13450 }
13451}
13452
60f993ce
AV
13453/* Helper function for do_t_loloop to handle relocations. */
13454static void
13455v8_1_loop_reloc (int is_le)
13456{
13457 if (inst.relocs[0].exp.X_op == O_constant)
13458 {
13459 int value = inst.relocs[0].exp.X_add_number;
13460 value = (is_le) ? -value : value;
13461
13462 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
13463 as_bad (BAD_BRANCH_OFF);
13464
13465 int imml, immh;
13466
13467 immh = (value & 0x00000ffc) >> 2;
13468 imml = (value & 0x00000002) >> 1;
13469
13470 inst.instruction |= (imml << 11) | (immh << 1);
13471 }
13472 else
13473 {
13474 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
13475 inst.relocs[0].pc_rel = 1;
13476 }
13477}
13478
13479/* To handle the Scalar Low Overhead Loop instructions
13480 in Armv8.1-M Mainline. */
13481static void
13482do_t_loloop (void)
13483{
13484 unsigned long insn = inst.instruction;
13485
13486 set_it_insn_type (OUTSIDE_IT_INSN);
13487 inst.instruction = THUMB_OP32 (inst.instruction);
13488
13489 switch (insn)
13490 {
13491 case T_MNEM_le:
13492 /* le <label>. */
13493 if (!inst.operands[0].present)
13494 inst.instruction |= 1 << 21;
13495
13496 v8_1_loop_reloc (TRUE);
13497 break;
13498
13499 case T_MNEM_wls:
13500 v8_1_loop_reloc (FALSE);
13501 /* Fall through. */
13502 case T_MNEM_dls:
13503 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
13504 inst.instruction |= (inst.operands[1].reg << 16);
13505 break;
13506
13507 default: abort();
13508 }
13509}
13510
5287ad62 13511/* Neon instruction encoder helpers. */
5f4273c7 13512
5287ad62 13513/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13514
5287ad62
JB
13515/* An "invalid" code for the following tables. */
13516#define N_INV -1u
13517
13518struct neon_tab_entry
b99bd4ef 13519{
5287ad62
JB
13520 unsigned integer;
13521 unsigned float_or_poly;
13522 unsigned scalar_or_imm;
13523};
5f4273c7 13524
5287ad62
JB
13525/* Map overloaded Neon opcodes to their respective encodings. */
13526#define NEON_ENC_TAB \
13527 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13528 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13529 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13530 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13531 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13532 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13533 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13534 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13535 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13536 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13537 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13538 /* Register variants of the following two instructions are encoded as
e07e6e58 13539 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13540 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13541 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13542 X(vfma, N_INV, 0x0000c10, N_INV), \
13543 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13544 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13545 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13546 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13547 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13548 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13549 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13550 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13551 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13552 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13553 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13554 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13555 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13556 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13557 X(vshl, 0x0000400, N_INV, 0x0800510), \
13558 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13559 X(vand, 0x0000110, N_INV, 0x0800030), \
13560 X(vbic, 0x0100110, N_INV, 0x0800030), \
13561 X(veor, 0x1000110, N_INV, N_INV), \
13562 X(vorn, 0x0300110, N_INV, 0x0800010), \
13563 X(vorr, 0x0200110, N_INV, 0x0800010), \
13564 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13565 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13566 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13567 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13568 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13569 X(vst1, 0x0000000, 0x0800000, N_INV), \
13570 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13571 X(vst2, 0x0000100, 0x0800100, N_INV), \
13572 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13573 X(vst3, 0x0000200, 0x0800200, N_INV), \
13574 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13575 X(vst4, 0x0000300, 0x0800300, N_INV), \
13576 X(vmovn, 0x1b20200, N_INV, N_INV), \
13577 X(vtrn, 0x1b20080, N_INV, N_INV), \
13578 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13579 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13580 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13581 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13582 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13583 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13584 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13585 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13586 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13587 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13588 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13589 X(vseleq, 0xe000a00, N_INV, N_INV), \
13590 X(vselvs, 0xe100a00, N_INV, N_INV), \
13591 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13592 X(vselgt, 0xe300a00, N_INV, N_INV), \
13593 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13594 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13595 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13596 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13597 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13598 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13599 X(sha3op, 0x2000c00, N_INV, N_INV), \
13600 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13601 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13602
13603enum neon_opc
13604{
13605#define X(OPC,I,F,S) N_MNEM_##OPC
13606NEON_ENC_TAB
13607#undef X
13608};
b99bd4ef 13609
5287ad62
JB
13610static const struct neon_tab_entry neon_enc_tab[] =
13611{
13612#define X(OPC,I,F,S) { (I), (F), (S) }
13613NEON_ENC_TAB
13614#undef X
13615};
b99bd4ef 13616
88714cb8
DG
13617/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13618#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13619#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13620#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13621#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13622#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13623#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13624#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13625#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13626#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13627#define NEON_ENC_SINGLE_(X) \
037e8744 13628 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13629#define NEON_ENC_DOUBLE_(X) \
037e8744 13630 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13631#define NEON_ENC_FPV8_(X) \
13632 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13633
88714cb8
DG
13634#define NEON_ENCODE(type, inst) \
13635 do \
13636 { \
13637 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13638 inst.is_neon = 1; \
13639 } \
13640 while (0)
13641
13642#define check_neon_suffixes \
13643 do \
13644 { \
13645 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13646 { \
13647 as_bad (_("invalid neon suffix for non neon instruction")); \
13648 return; \
13649 } \
13650 } \
13651 while (0)
13652
037e8744
JB
13653/* Define shapes for instruction operands. The following mnemonic characters
13654 are used in this table:
5287ad62 13655
037e8744 13656 F - VFP S<n> register
5287ad62
JB
13657 D - Neon D<n> register
13658 Q - Neon Q<n> register
13659 I - Immediate
13660 S - Scalar
13661 R - ARM register
13662 L - D<n> register list
5f4273c7 13663
037e8744
JB
13664 This table is used to generate various data:
13665 - enumerations of the form NS_DDR to be used as arguments to
13666 neon_select_shape.
13667 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13668 - a table used to drive neon_select_shape. */
b99bd4ef 13669
037e8744
JB
13670#define NEON_SHAPE_DEF \
13671 X(3, (D, D, D), DOUBLE), \
13672 X(3, (Q, Q, Q), QUAD), \
13673 X(3, (D, D, I), DOUBLE), \
13674 X(3, (Q, Q, I), QUAD), \
13675 X(3, (D, D, S), DOUBLE), \
13676 X(3, (Q, Q, S), QUAD), \
13677 X(2, (D, D), DOUBLE), \
13678 X(2, (Q, Q), QUAD), \
13679 X(2, (D, S), DOUBLE), \
13680 X(2, (Q, S), QUAD), \
13681 X(2, (D, R), DOUBLE), \
13682 X(2, (Q, R), QUAD), \
13683 X(2, (D, I), DOUBLE), \
13684 X(2, (Q, I), QUAD), \
13685 X(3, (D, L, D), DOUBLE), \
13686 X(2, (D, Q), MIXED), \
13687 X(2, (Q, D), MIXED), \
13688 X(3, (D, Q, I), MIXED), \
13689 X(3, (Q, D, I), MIXED), \
13690 X(3, (Q, D, D), MIXED), \
13691 X(3, (D, Q, Q), MIXED), \
13692 X(3, (Q, Q, D), MIXED), \
13693 X(3, (Q, D, S), MIXED), \
13694 X(3, (D, Q, S), MIXED), \
13695 X(4, (D, D, D, I), DOUBLE), \
13696 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
13697 X(4, (D, D, S, I), DOUBLE), \
13698 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
13699 X(2, (F, F), SINGLE), \
13700 X(3, (F, F, F), SINGLE), \
13701 X(2, (F, I), SINGLE), \
13702 X(2, (F, D), MIXED), \
13703 X(2, (D, F), MIXED), \
13704 X(3, (F, F, I), MIXED), \
13705 X(4, (R, R, F, F), SINGLE), \
13706 X(4, (F, F, R, R), SINGLE), \
13707 X(3, (D, R, R), DOUBLE), \
13708 X(3, (R, R, D), DOUBLE), \
13709 X(2, (S, R), SINGLE), \
13710 X(2, (R, S), SINGLE), \
13711 X(2, (F, R), SINGLE), \
d54af2d0
RL
13712 X(2, (R, F), SINGLE), \
13713/* Half float shape supported so far. */\
13714 X (2, (H, D), MIXED), \
13715 X (2, (D, H), MIXED), \
13716 X (2, (H, F), MIXED), \
13717 X (2, (F, H), MIXED), \
13718 X (2, (H, H), HALF), \
13719 X (2, (H, R), HALF), \
13720 X (2, (R, H), HALF), \
13721 X (2, (H, I), HALF), \
13722 X (3, (H, H, H), HALF), \
13723 X (3, (H, F, I), MIXED), \
dec41383
JW
13724 X (3, (F, H, I), MIXED), \
13725 X (3, (D, H, H), MIXED), \
13726 X (3, (D, H, S), MIXED)
037e8744
JB
13727
13728#define S2(A,B) NS_##A##B
13729#define S3(A,B,C) NS_##A##B##C
13730#define S4(A,B,C,D) NS_##A##B##C##D
13731
13732#define X(N, L, C) S##N L
13733
5287ad62
JB
13734enum neon_shape
13735{
037e8744
JB
13736 NEON_SHAPE_DEF,
13737 NS_NULL
5287ad62 13738};
b99bd4ef 13739
037e8744
JB
13740#undef X
13741#undef S2
13742#undef S3
13743#undef S4
13744
13745enum neon_shape_class
13746{
d54af2d0 13747 SC_HALF,
037e8744
JB
13748 SC_SINGLE,
13749 SC_DOUBLE,
13750 SC_QUAD,
13751 SC_MIXED
13752};
13753
13754#define X(N, L, C) SC_##C
13755
13756static enum neon_shape_class neon_shape_class[] =
13757{
13758 NEON_SHAPE_DEF
13759};
13760
13761#undef X
13762
13763enum neon_shape_el
13764{
d54af2d0 13765 SE_H,
037e8744
JB
13766 SE_F,
13767 SE_D,
13768 SE_Q,
13769 SE_I,
13770 SE_S,
13771 SE_R,
13772 SE_L
13773};
13774
13775/* Register widths of above. */
13776static unsigned neon_shape_el_size[] =
13777{
d54af2d0 13778 16,
037e8744
JB
13779 32,
13780 64,
13781 128,
13782 0,
13783 32,
13784 32,
13785 0
13786};
13787
13788struct neon_shape_info
13789{
13790 unsigned els;
13791 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13792};
13793
13794#define S2(A,B) { SE_##A, SE_##B }
13795#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13796#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13797
13798#define X(N, L, C) { N, S##N L }
13799
13800static struct neon_shape_info neon_shape_tab[] =
13801{
13802 NEON_SHAPE_DEF
13803};
13804
13805#undef X
13806#undef S2
13807#undef S3
13808#undef S4
13809
5287ad62
JB
13810/* Bit masks used in type checking given instructions.
13811 'N_EQK' means the type must be the same as (or based on in some way) the key
13812 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13813 set, various other bits can be set as well in order to modify the meaning of
13814 the type constraint. */
13815
13816enum neon_type_mask
13817{
8e79c3df
CM
13818 N_S8 = 0x0000001,
13819 N_S16 = 0x0000002,
13820 N_S32 = 0x0000004,
13821 N_S64 = 0x0000008,
13822 N_U8 = 0x0000010,
13823 N_U16 = 0x0000020,
13824 N_U32 = 0x0000040,
13825 N_U64 = 0x0000080,
13826 N_I8 = 0x0000100,
13827 N_I16 = 0x0000200,
13828 N_I32 = 0x0000400,
13829 N_I64 = 0x0000800,
13830 N_8 = 0x0001000,
13831 N_16 = 0x0002000,
13832 N_32 = 0x0004000,
13833 N_64 = 0x0008000,
13834 N_P8 = 0x0010000,
13835 N_P16 = 0x0020000,
13836 N_F16 = 0x0040000,
13837 N_F32 = 0x0080000,
13838 N_F64 = 0x0100000,
4f51b4bd 13839 N_P64 = 0x0200000,
c921be7d
NC
13840 N_KEY = 0x1000000, /* Key element (main type specifier). */
13841 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13842 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13843 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13844 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13845 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13846 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13847 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13848 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13849 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13850 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13851 N_UTYP = 0,
4f51b4bd 13852 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13853};
13854
dcbf9037
JB
13855#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13856
5287ad62
JB
13857#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13858#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13859#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13860#define N_S_32 (N_S8 | N_S16 | N_S32)
13861#define N_F_16_32 (N_F16 | N_F32)
13862#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13863#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13864#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13865#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13866
13867/* Pass this as the first type argument to neon_check_type to ignore types
13868 altogether. */
13869#define N_IGNORE_TYPE (N_KEY | N_EQK)
13870
037e8744
JB
13871/* Select a "shape" for the current instruction (describing register types or
13872 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13873 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13874 function of operand parsing, so this function doesn't need to be called.
13875 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13876
13877static enum neon_shape
037e8744 13878neon_select_shape (enum neon_shape shape, ...)
5287ad62 13879{
037e8744
JB
13880 va_list ap;
13881 enum neon_shape first_shape = shape;
5287ad62
JB
13882
13883 /* Fix missing optional operands. FIXME: we don't know at this point how
13884 many arguments we should have, so this makes the assumption that we have
13885 > 1. This is true of all current Neon opcodes, I think, but may not be
13886 true in the future. */
13887 if (!inst.operands[1].present)
13888 inst.operands[1] = inst.operands[0];
13889
037e8744 13890 va_start (ap, shape);
5f4273c7 13891
21d799b5 13892 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13893 {
13894 unsigned j;
13895 int matches = 1;
13896
13897 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13898 {
13899 if (!inst.operands[j].present)
13900 {
13901 matches = 0;
13902 break;
13903 }
13904
13905 switch (neon_shape_tab[shape].el[j])
13906 {
d54af2d0
RL
13907 /* If a .f16, .16, .u16, .s16 type specifier is given over
13908 a VFP single precision register operand, it's essentially
13909 means only half of the register is used.
13910
13911 If the type specifier is given after the mnemonics, the
13912 information is stored in inst.vectype. If the type specifier
13913 is given after register operand, the information is stored
13914 in inst.operands[].vectype.
13915
13916 When there is only one type specifier, and all the register
13917 operands are the same type of hardware register, the type
13918 specifier applies to all register operands.
13919
13920 If no type specifier is given, the shape is inferred from
13921 operand information.
13922
13923 for example:
13924 vadd.f16 s0, s1, s2: NS_HHH
13925 vabs.f16 s0, s1: NS_HH
13926 vmov.f16 s0, r1: NS_HR
13927 vmov.f16 r0, s1: NS_RH
13928 vcvt.f16 r0, s1: NS_RH
13929 vcvt.f16.s32 s2, s2, #29: NS_HFI
13930 vcvt.f16.s32 s2, s2: NS_HF
13931 */
13932 case SE_H:
13933 if (!(inst.operands[j].isreg
13934 && inst.operands[j].isvec
13935 && inst.operands[j].issingle
13936 && !inst.operands[j].isquad
13937 && ((inst.vectype.elems == 1
13938 && inst.vectype.el[0].size == 16)
13939 || (inst.vectype.elems > 1
13940 && inst.vectype.el[j].size == 16)
13941 || (inst.vectype.elems == 0
13942 && inst.operands[j].vectype.type != NT_invtype
13943 && inst.operands[j].vectype.size == 16))))
13944 matches = 0;
13945 break;
13946
477330fc
RM
13947 case SE_F:
13948 if (!(inst.operands[j].isreg
13949 && inst.operands[j].isvec
13950 && inst.operands[j].issingle
d54af2d0
RL
13951 && !inst.operands[j].isquad
13952 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13953 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13954 || (inst.vectype.elems == 0
13955 && (inst.operands[j].vectype.size == 32
13956 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13957 matches = 0;
13958 break;
13959
13960 case SE_D:
13961 if (!(inst.operands[j].isreg
13962 && inst.operands[j].isvec
13963 && !inst.operands[j].isquad
13964 && !inst.operands[j].issingle))
13965 matches = 0;
13966 break;
13967
13968 case SE_R:
13969 if (!(inst.operands[j].isreg
13970 && !inst.operands[j].isvec))
13971 matches = 0;
13972 break;
13973
13974 case SE_Q:
13975 if (!(inst.operands[j].isreg
13976 && inst.operands[j].isvec
13977 && inst.operands[j].isquad
13978 && !inst.operands[j].issingle))
13979 matches = 0;
13980 break;
13981
13982 case SE_I:
13983 if (!(!inst.operands[j].isreg
13984 && !inst.operands[j].isscalar))
13985 matches = 0;
13986 break;
13987
13988 case SE_S:
13989 if (!(!inst.operands[j].isreg
13990 && inst.operands[j].isscalar))
13991 matches = 0;
13992 break;
13993
13994 case SE_L:
13995 break;
13996 }
3fde54a2
JZ
13997 if (!matches)
13998 break;
477330fc 13999 }
ad6cec43
MGD
14000 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
14001 /* We've matched all the entries in the shape table, and we don't
14002 have any left over operands which have not been matched. */
477330fc 14003 break;
037e8744 14004 }
5f4273c7 14005
037e8744 14006 va_end (ap);
5287ad62 14007
037e8744
JB
14008 if (shape == NS_NULL && first_shape != NS_NULL)
14009 first_error (_("invalid instruction shape"));
5287ad62 14010
037e8744
JB
14011 return shape;
14012}
5287ad62 14013
037e8744
JB
14014/* True if SHAPE is predominantly a quadword operation (most of the time, this
14015 means the Q bit should be set). */
14016
14017static int
14018neon_quad (enum neon_shape shape)
14019{
14020 return neon_shape_class[shape] == SC_QUAD;
5287ad62 14021}
037e8744 14022
5287ad62
JB
14023static void
14024neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 14025 unsigned *g_size)
5287ad62
JB
14026{
14027 /* Allow modification to be made to types which are constrained to be
14028 based on the key element, based on bits set alongside N_EQK. */
14029 if ((typebits & N_EQK) != 0)
14030 {
14031 if ((typebits & N_HLF) != 0)
14032 *g_size /= 2;
14033 else if ((typebits & N_DBL) != 0)
14034 *g_size *= 2;
14035 if ((typebits & N_SGN) != 0)
14036 *g_type = NT_signed;
14037 else if ((typebits & N_UNS) != 0)
477330fc 14038 *g_type = NT_unsigned;
5287ad62 14039 else if ((typebits & N_INT) != 0)
477330fc 14040 *g_type = NT_integer;
5287ad62 14041 else if ((typebits & N_FLT) != 0)
477330fc 14042 *g_type = NT_float;
dcbf9037 14043 else if ((typebits & N_SIZ) != 0)
477330fc 14044 *g_type = NT_untyped;
5287ad62
JB
14045 }
14046}
5f4273c7 14047
5287ad62
JB
14048/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
14049 operand type, i.e. the single type specified in a Neon instruction when it
14050 is the only one given. */
14051
14052static struct neon_type_el
14053neon_type_promote (struct neon_type_el *key, unsigned thisarg)
14054{
14055 struct neon_type_el dest = *key;
5f4273c7 14056
9c2799c2 14057 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 14058
5287ad62
JB
14059 neon_modify_type_size (thisarg, &dest.type, &dest.size);
14060
14061 return dest;
14062}
14063
14064/* Convert Neon type and size into compact bitmask representation. */
14065
14066static enum neon_type_mask
14067type_chk_of_el_type (enum neon_el_type type, unsigned size)
14068{
14069 switch (type)
14070 {
14071 case NT_untyped:
14072 switch (size)
477330fc
RM
14073 {
14074 case 8: return N_8;
14075 case 16: return N_16;
14076 case 32: return N_32;
14077 case 64: return N_64;
14078 default: ;
14079 }
5287ad62
JB
14080 break;
14081
14082 case NT_integer:
14083 switch (size)
477330fc
RM
14084 {
14085 case 8: return N_I8;
14086 case 16: return N_I16;
14087 case 32: return N_I32;
14088 case 64: return N_I64;
14089 default: ;
14090 }
5287ad62
JB
14091 break;
14092
14093 case NT_float:
037e8744 14094 switch (size)
477330fc 14095 {
8e79c3df 14096 case 16: return N_F16;
477330fc
RM
14097 case 32: return N_F32;
14098 case 64: return N_F64;
14099 default: ;
14100 }
5287ad62
JB
14101 break;
14102
14103 case NT_poly:
14104 switch (size)
477330fc
RM
14105 {
14106 case 8: return N_P8;
14107 case 16: return N_P16;
4f51b4bd 14108 case 64: return N_P64;
477330fc
RM
14109 default: ;
14110 }
5287ad62
JB
14111 break;
14112
14113 case NT_signed:
14114 switch (size)
477330fc
RM
14115 {
14116 case 8: return N_S8;
14117 case 16: return N_S16;
14118 case 32: return N_S32;
14119 case 64: return N_S64;
14120 default: ;
14121 }
5287ad62
JB
14122 break;
14123
14124 case NT_unsigned:
14125 switch (size)
477330fc
RM
14126 {
14127 case 8: return N_U8;
14128 case 16: return N_U16;
14129 case 32: return N_U32;
14130 case 64: return N_U64;
14131 default: ;
14132 }
5287ad62
JB
14133 break;
14134
14135 default: ;
14136 }
5f4273c7 14137
5287ad62
JB
14138 return N_UTYP;
14139}
14140
14141/* Convert compact Neon bitmask type representation to a type and size. Only
14142 handles the case where a single bit is set in the mask. */
14143
dcbf9037 14144static int
5287ad62 14145el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 14146 enum neon_type_mask mask)
5287ad62 14147{
dcbf9037
JB
14148 if ((mask & N_EQK) != 0)
14149 return FAIL;
14150
5287ad62
JB
14151 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
14152 *size = 8;
c70a8987 14153 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 14154 *size = 16;
dcbf9037 14155 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 14156 *size = 32;
4f51b4bd 14157 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 14158 *size = 64;
dcbf9037
JB
14159 else
14160 return FAIL;
14161
5287ad62
JB
14162 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
14163 *type = NT_signed;
dcbf9037 14164 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 14165 *type = NT_unsigned;
dcbf9037 14166 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 14167 *type = NT_integer;
dcbf9037 14168 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 14169 *type = NT_untyped;
4f51b4bd 14170 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 14171 *type = NT_poly;
d54af2d0 14172 else if ((mask & (N_F_ALL)) != 0)
5287ad62 14173 *type = NT_float;
dcbf9037
JB
14174 else
14175 return FAIL;
5f4273c7 14176
dcbf9037 14177 return SUCCESS;
5287ad62
JB
14178}
14179
14180/* Modify a bitmask of allowed types. This is only needed for type
14181 relaxation. */
14182
14183static unsigned
14184modify_types_allowed (unsigned allowed, unsigned mods)
14185{
14186 unsigned size;
14187 enum neon_el_type type;
14188 unsigned destmask;
14189 int i;
5f4273c7 14190
5287ad62 14191 destmask = 0;
5f4273c7 14192
5287ad62
JB
14193 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
14194 {
21d799b5 14195 if (el_type_of_type_chk (&type, &size,
477330fc
RM
14196 (enum neon_type_mask) (allowed & i)) == SUCCESS)
14197 {
14198 neon_modify_type_size (mods, &type, &size);
14199 destmask |= type_chk_of_el_type (type, size);
14200 }
5287ad62 14201 }
5f4273c7 14202
5287ad62
JB
14203 return destmask;
14204}
14205
14206/* Check type and return type classification.
14207 The manual states (paraphrase): If one datatype is given, it indicates the
14208 type given in:
14209 - the second operand, if there is one
14210 - the operand, if there is no second operand
14211 - the result, if there are no operands.
14212 This isn't quite good enough though, so we use a concept of a "key" datatype
14213 which is set on a per-instruction basis, which is the one which matters when
14214 only one data type is written.
14215 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 14216 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
14217
14218static struct neon_type_el
14219neon_check_type (unsigned els, enum neon_shape ns, ...)
14220{
14221 va_list ap;
14222 unsigned i, pass, key_el = 0;
14223 unsigned types[NEON_MAX_TYPE_ELS];
14224 enum neon_el_type k_type = NT_invtype;
14225 unsigned k_size = -1u;
14226 struct neon_type_el badtype = {NT_invtype, -1};
14227 unsigned key_allowed = 0;
14228
14229 /* Optional registers in Neon instructions are always (not) in operand 1.
14230 Fill in the missing operand here, if it was omitted. */
14231 if (els > 1 && !inst.operands[1].present)
14232 inst.operands[1] = inst.operands[0];
14233
14234 /* Suck up all the varargs. */
14235 va_start (ap, ns);
14236 for (i = 0; i < els; i++)
14237 {
14238 unsigned thisarg = va_arg (ap, unsigned);
14239 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
14240 {
14241 va_end (ap);
14242 return badtype;
14243 }
5287ad62
JB
14244 types[i] = thisarg;
14245 if ((thisarg & N_KEY) != 0)
477330fc 14246 key_el = i;
5287ad62
JB
14247 }
14248 va_end (ap);
14249
dcbf9037
JB
14250 if (inst.vectype.elems > 0)
14251 for (i = 0; i < els; i++)
14252 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
14253 {
14254 first_error (_("types specified in both the mnemonic and operands"));
14255 return badtype;
14256 }
dcbf9037 14257
5287ad62
JB
14258 /* Duplicate inst.vectype elements here as necessary.
14259 FIXME: No idea if this is exactly the same as the ARM assembler,
14260 particularly when an insn takes one register and one non-register
14261 operand. */
14262 if (inst.vectype.elems == 1 && els > 1)
14263 {
14264 unsigned j;
14265 inst.vectype.elems = els;
14266 inst.vectype.el[key_el] = inst.vectype.el[0];
14267 for (j = 0; j < els; j++)
477330fc
RM
14268 if (j != key_el)
14269 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14270 types[j]);
dcbf9037
JB
14271 }
14272 else if (inst.vectype.elems == 0 && els > 0)
14273 {
14274 unsigned j;
14275 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
14276 after each operand. We allow some flexibility here; as long as the
14277 "key" operand has a type, we can infer the others. */
dcbf9037 14278 for (j = 0; j < els; j++)
477330fc
RM
14279 if (inst.operands[j].vectype.type != NT_invtype)
14280 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
14281
14282 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
14283 {
14284 for (j = 0; j < els; j++)
14285 if (inst.operands[j].vectype.type == NT_invtype)
14286 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14287 types[j]);
14288 }
dcbf9037 14289 else
477330fc
RM
14290 {
14291 first_error (_("operand types can't be inferred"));
14292 return badtype;
14293 }
5287ad62
JB
14294 }
14295 else if (inst.vectype.elems != els)
14296 {
dcbf9037 14297 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
14298 return badtype;
14299 }
14300
14301 for (pass = 0; pass < 2; pass++)
14302 {
14303 for (i = 0; i < els; i++)
477330fc
RM
14304 {
14305 unsigned thisarg = types[i];
14306 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
14307 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
14308 enum neon_el_type g_type = inst.vectype.el[i].type;
14309 unsigned g_size = inst.vectype.el[i].size;
14310
14311 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 14312 integer types if sign-specific variants are unavailable. */
477330fc 14313 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
14314 && (types_allowed & N_SU_ALL) == 0)
14315 g_type = NT_integer;
14316
477330fc 14317 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
14318 them. Some instructions only care about signs for some element
14319 sizes, so handle that properly. */
477330fc 14320 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
14321 && ((g_size == 8 && (types_allowed & N_8) != 0)
14322 || (g_size == 16 && (types_allowed & N_16) != 0)
14323 || (g_size == 32 && (types_allowed & N_32) != 0)
14324 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
14325 g_type = NT_untyped;
14326
477330fc
RM
14327 if (pass == 0)
14328 {
14329 if ((thisarg & N_KEY) != 0)
14330 {
14331 k_type = g_type;
14332 k_size = g_size;
14333 key_allowed = thisarg & ~N_KEY;
cc933301
JW
14334
14335 /* Check architecture constraint on FP16 extension. */
14336 if (k_size == 16
14337 && k_type == NT_float
14338 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14339 {
14340 inst.error = _(BAD_FP16);
14341 return badtype;
14342 }
477330fc
RM
14343 }
14344 }
14345 else
14346 {
14347 if ((thisarg & N_VFP) != 0)
14348 {
14349 enum neon_shape_el regshape;
14350 unsigned regwidth, match;
99b253c5
NC
14351
14352 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14353 if (ns == NS_NULL)
14354 {
14355 first_error (_("invalid instruction shape"));
14356 return badtype;
14357 }
477330fc
RM
14358 regshape = neon_shape_tab[ns].el[i];
14359 regwidth = neon_shape_el_size[regshape];
14360
14361 /* In VFP mode, operands must match register widths. If we
14362 have a key operand, use its width, else use the width of
14363 the current operand. */
14364 if (k_size != -1u)
14365 match = k_size;
14366 else
14367 match = g_size;
14368
9db2f6b4
RL
14369 /* FP16 will use a single precision register. */
14370 if (regwidth == 32 && match == 16)
14371 {
14372 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14373 match = regwidth;
14374 else
14375 {
14376 inst.error = _(BAD_FP16);
14377 return badtype;
14378 }
14379 }
14380
477330fc
RM
14381 if (regwidth != match)
14382 {
14383 first_error (_("operand size must match register width"));
14384 return badtype;
14385 }
14386 }
14387
14388 if ((thisarg & N_EQK) == 0)
14389 {
14390 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14391
14392 if ((given_type & types_allowed) == 0)
14393 {
14394 first_error (_("bad type in Neon instruction"));
14395 return badtype;
14396 }
14397 }
14398 else
14399 {
14400 enum neon_el_type mod_k_type = k_type;
14401 unsigned mod_k_size = k_size;
14402 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14403 if (g_type != mod_k_type || g_size != mod_k_size)
14404 {
14405 first_error (_("inconsistent types in Neon instruction"));
14406 return badtype;
14407 }
14408 }
14409 }
14410 }
5287ad62
JB
14411 }
14412
14413 return inst.vectype.el[key_el];
14414}
14415
037e8744 14416/* Neon-style VFP instruction forwarding. */
5287ad62 14417
037e8744
JB
14418/* Thumb VFP instructions have 0xE in the condition field. */
14419
14420static void
14421do_vfp_cond_or_thumb (void)
5287ad62 14422{
88714cb8
DG
14423 inst.is_neon = 1;
14424
5287ad62 14425 if (thumb_mode)
037e8744 14426 inst.instruction |= 0xe0000000;
5287ad62 14427 else
037e8744 14428 inst.instruction |= inst.cond << 28;
5287ad62
JB
14429}
14430
037e8744
JB
14431/* Look up and encode a simple mnemonic, for use as a helper function for the
14432 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14433 etc. It is assumed that operand parsing has already been done, and that the
14434 operands are in the form expected by the given opcode (this isn't necessarily
14435 the same as the form in which they were parsed, hence some massaging must
14436 take place before this function is called).
14437 Checks current arch version against that in the looked-up opcode. */
5287ad62 14438
037e8744
JB
14439static void
14440do_vfp_nsyn_opcode (const char *opname)
5287ad62 14441{
037e8744 14442 const struct asm_opcode *opcode;
5f4273c7 14443
21d799b5 14444 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14445
037e8744
JB
14446 if (!opcode)
14447 abort ();
5287ad62 14448
037e8744 14449 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14450 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14451 _(BAD_FPU));
5287ad62 14452
88714cb8
DG
14453 inst.is_neon = 1;
14454
037e8744
JB
14455 if (thumb_mode)
14456 {
14457 inst.instruction = opcode->tvalue;
14458 opcode->tencode ();
14459 }
14460 else
14461 {
14462 inst.instruction = (inst.cond << 28) | opcode->avalue;
14463 opcode->aencode ();
14464 }
14465}
5287ad62
JB
14466
14467static void
037e8744 14468do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14469{
037e8744
JB
14470 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14471
9db2f6b4 14472 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14473 {
14474 if (is_add)
477330fc 14475 do_vfp_nsyn_opcode ("fadds");
037e8744 14476 else
477330fc 14477 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14478
14479 /* ARMv8.2 fp16 instruction. */
14480 if (rs == NS_HHH)
14481 do_scalar_fp16_v82_encode ();
037e8744
JB
14482 }
14483 else
14484 {
14485 if (is_add)
477330fc 14486 do_vfp_nsyn_opcode ("faddd");
037e8744 14487 else
477330fc 14488 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14489 }
14490}
14491
14492/* Check operand types to see if this is a VFP instruction, and if so call
14493 PFN (). */
14494
14495static int
14496try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14497{
14498 enum neon_shape rs;
14499 struct neon_type_el et;
14500
14501 switch (args)
14502 {
14503 case 2:
9db2f6b4
RL
14504 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14505 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14506 break;
5f4273c7 14507
037e8744 14508 case 3:
9db2f6b4
RL
14509 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14510 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14511 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14512 break;
14513
14514 default:
14515 abort ();
14516 }
14517
14518 if (et.type != NT_invtype)
14519 {
14520 pfn (rs);
14521 return SUCCESS;
14522 }
037e8744 14523
99b253c5 14524 inst.error = NULL;
037e8744
JB
14525 return FAIL;
14526}
14527
14528static void
14529do_vfp_nsyn_mla_mls (enum neon_shape rs)
14530{
14531 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14532
9db2f6b4 14533 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14534 {
14535 if (is_mla)
477330fc 14536 do_vfp_nsyn_opcode ("fmacs");
037e8744 14537 else
477330fc 14538 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14539
14540 /* ARMv8.2 fp16 instruction. */
14541 if (rs == NS_HHH)
14542 do_scalar_fp16_v82_encode ();
037e8744
JB
14543 }
14544 else
14545 {
14546 if (is_mla)
477330fc 14547 do_vfp_nsyn_opcode ("fmacd");
037e8744 14548 else
477330fc 14549 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14550 }
14551}
14552
62f3b8c8
PB
14553static void
14554do_vfp_nsyn_fma_fms (enum neon_shape rs)
14555{
14556 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14557
9db2f6b4 14558 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14559 {
14560 if (is_fma)
477330fc 14561 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14562 else
477330fc 14563 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14564
14565 /* ARMv8.2 fp16 instruction. */
14566 if (rs == NS_HHH)
14567 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14568 }
14569 else
14570 {
14571 if (is_fma)
477330fc 14572 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14573 else
477330fc 14574 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14575 }
14576}
14577
037e8744
JB
14578static void
14579do_vfp_nsyn_mul (enum neon_shape rs)
14580{
9db2f6b4
RL
14581 if (rs == NS_FFF || rs == NS_HHH)
14582 {
14583 do_vfp_nsyn_opcode ("fmuls");
14584
14585 /* ARMv8.2 fp16 instruction. */
14586 if (rs == NS_HHH)
14587 do_scalar_fp16_v82_encode ();
14588 }
037e8744
JB
14589 else
14590 do_vfp_nsyn_opcode ("fmuld");
14591}
14592
14593static void
14594do_vfp_nsyn_abs_neg (enum neon_shape rs)
14595{
14596 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14597 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14598
9db2f6b4 14599 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14600 {
14601 if (is_neg)
477330fc 14602 do_vfp_nsyn_opcode ("fnegs");
037e8744 14603 else
477330fc 14604 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14605
14606 /* ARMv8.2 fp16 instruction. */
14607 if (rs == NS_HH)
14608 do_scalar_fp16_v82_encode ();
037e8744
JB
14609 }
14610 else
14611 {
14612 if (is_neg)
477330fc 14613 do_vfp_nsyn_opcode ("fnegd");
037e8744 14614 else
477330fc 14615 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14616 }
14617}
14618
14619/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14620 insns belong to Neon, and are handled elsewhere. */
14621
14622static void
14623do_vfp_nsyn_ldm_stm (int is_dbmode)
14624{
14625 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14626 if (is_ldm)
14627 {
14628 if (is_dbmode)
477330fc 14629 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14630 else
477330fc 14631 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14632 }
14633 else
14634 {
14635 if (is_dbmode)
477330fc 14636 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14637 else
477330fc 14638 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14639 }
14640}
14641
037e8744
JB
14642static void
14643do_vfp_nsyn_sqrt (void)
14644{
9db2f6b4
RL
14645 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14646 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14647
9db2f6b4
RL
14648 if (rs == NS_FF || rs == NS_HH)
14649 {
14650 do_vfp_nsyn_opcode ("fsqrts");
14651
14652 /* ARMv8.2 fp16 instruction. */
14653 if (rs == NS_HH)
14654 do_scalar_fp16_v82_encode ();
14655 }
037e8744
JB
14656 else
14657 do_vfp_nsyn_opcode ("fsqrtd");
14658}
14659
14660static void
14661do_vfp_nsyn_div (void)
14662{
9db2f6b4 14663 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14664 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14665 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14666
9db2f6b4
RL
14667 if (rs == NS_FFF || rs == NS_HHH)
14668 {
14669 do_vfp_nsyn_opcode ("fdivs");
14670
14671 /* ARMv8.2 fp16 instruction. */
14672 if (rs == NS_HHH)
14673 do_scalar_fp16_v82_encode ();
14674 }
037e8744
JB
14675 else
14676 do_vfp_nsyn_opcode ("fdivd");
14677}
14678
14679static void
14680do_vfp_nsyn_nmul (void)
14681{
9db2f6b4 14682 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14683 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14684 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14685
9db2f6b4 14686 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14687 {
88714cb8 14688 NEON_ENCODE (SINGLE, inst);
037e8744 14689 do_vfp_sp_dyadic ();
9db2f6b4
RL
14690
14691 /* ARMv8.2 fp16 instruction. */
14692 if (rs == NS_HHH)
14693 do_scalar_fp16_v82_encode ();
037e8744
JB
14694 }
14695 else
14696 {
88714cb8 14697 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14698 do_vfp_dp_rd_rn_rm ();
14699 }
14700 do_vfp_cond_or_thumb ();
9db2f6b4 14701
037e8744
JB
14702}
14703
14704static void
14705do_vfp_nsyn_cmp (void)
14706{
9db2f6b4 14707 enum neon_shape rs;
037e8744
JB
14708 if (inst.operands[1].isreg)
14709 {
9db2f6b4
RL
14710 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14711 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14712
9db2f6b4 14713 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14714 {
14715 NEON_ENCODE (SINGLE, inst);
14716 do_vfp_sp_monadic ();
14717 }
037e8744 14718 else
477330fc
RM
14719 {
14720 NEON_ENCODE (DOUBLE, inst);
14721 do_vfp_dp_rd_rm ();
14722 }
037e8744
JB
14723 }
14724 else
14725 {
9db2f6b4
RL
14726 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14727 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14728
14729 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14730 {
14731 case N_MNEM_vcmp:
14732 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14733 break;
14734 case N_MNEM_vcmpe:
14735 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14736 break;
14737 default:
14738 abort ();
14739 }
5f4273c7 14740
9db2f6b4 14741 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14742 {
14743 NEON_ENCODE (SINGLE, inst);
14744 do_vfp_sp_compare_z ();
14745 }
037e8744 14746 else
477330fc
RM
14747 {
14748 NEON_ENCODE (DOUBLE, inst);
14749 do_vfp_dp_rd ();
14750 }
037e8744
JB
14751 }
14752 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14753
14754 /* ARMv8.2 fp16 instruction. */
14755 if (rs == NS_HI || rs == NS_HH)
14756 do_scalar_fp16_v82_encode ();
037e8744
JB
14757}
14758
14759static void
14760nsyn_insert_sp (void)
14761{
14762 inst.operands[1] = inst.operands[0];
14763 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14764 inst.operands[0].reg = REG_SP;
037e8744
JB
14765 inst.operands[0].isreg = 1;
14766 inst.operands[0].writeback = 1;
14767 inst.operands[0].present = 1;
14768}
14769
14770static void
14771do_vfp_nsyn_push (void)
14772{
14773 nsyn_insert_sp ();
b126985e
NC
14774
14775 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14776 _("register list must contain at least 1 and at most 16 "
14777 "registers"));
14778
037e8744
JB
14779 if (inst.operands[1].issingle)
14780 do_vfp_nsyn_opcode ("fstmdbs");
14781 else
14782 do_vfp_nsyn_opcode ("fstmdbd");
14783}
14784
14785static void
14786do_vfp_nsyn_pop (void)
14787{
14788 nsyn_insert_sp ();
b126985e
NC
14789
14790 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14791 _("register list must contain at least 1 and at most 16 "
14792 "registers"));
14793
037e8744 14794 if (inst.operands[1].issingle)
22b5b651 14795 do_vfp_nsyn_opcode ("fldmias");
037e8744 14796 else
22b5b651 14797 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14798}
14799
14800/* Fix up Neon data-processing instructions, ORing in the correct bits for
14801 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14802
88714cb8
DG
14803static void
14804neon_dp_fixup (struct arm_it* insn)
037e8744 14805{
88714cb8
DG
14806 unsigned int i = insn->instruction;
14807 insn->is_neon = 1;
14808
037e8744
JB
14809 if (thumb_mode)
14810 {
14811 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14812 if (i & (1 << 24))
477330fc 14813 i |= 1 << 28;
5f4273c7 14814
037e8744 14815 i &= ~(1 << 24);
5f4273c7 14816
037e8744
JB
14817 i |= 0xef000000;
14818 }
14819 else
14820 i |= 0xf2000000;
5f4273c7 14821
88714cb8 14822 insn->instruction = i;
037e8744
JB
14823}
14824
14825/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14826 (0, 1, 2, 3). */
14827
14828static unsigned
14829neon_logbits (unsigned x)
14830{
14831 return ffs (x) - 4;
14832}
14833
14834#define LOW4(R) ((R) & 0xf)
14835#define HI1(R) (((R) >> 4) & 1)
14836
14837/* Encode insns with bit pattern:
14838
14839 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14840 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14841
037e8744
JB
14842 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14843 different meaning for some instruction. */
14844
14845static void
14846neon_three_same (int isquad, int ubit, int size)
14847{
14848 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14849 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14850 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14851 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14852 inst.instruction |= LOW4 (inst.operands[2].reg);
14853 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14854 inst.instruction |= (isquad != 0) << 6;
14855 inst.instruction |= (ubit != 0) << 24;
14856 if (size != -1)
14857 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14858
88714cb8 14859 neon_dp_fixup (&inst);
037e8744
JB
14860}
14861
14862/* Encode instructions of the form:
14863
14864 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14865 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14866
14867 Don't write size if SIZE == -1. */
14868
14869static void
14870neon_two_same (int qbit, int ubit, int size)
14871{
14872 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14873 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14874 inst.instruction |= LOW4 (inst.operands[1].reg);
14875 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14876 inst.instruction |= (qbit != 0) << 6;
14877 inst.instruction |= (ubit != 0) << 24;
14878
14879 if (size != -1)
14880 inst.instruction |= neon_logbits (size) << 18;
14881
88714cb8 14882 neon_dp_fixup (&inst);
5287ad62
JB
14883}
14884
14885/* Neon instruction encoders, in approximate order of appearance. */
14886
14887static void
14888do_neon_dyadic_i_su (void)
14889{
037e8744 14890 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14891 struct neon_type_el et = neon_check_type (3, rs,
14892 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14893 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14894}
14895
14896static void
14897do_neon_dyadic_i64_su (void)
14898{
037e8744 14899 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14900 struct neon_type_el et = neon_check_type (3, rs,
14901 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14902 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14903}
14904
14905static void
14906neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14907 unsigned immbits)
5287ad62
JB
14908{
14909 unsigned size = et.size >> 3;
14910 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14911 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14912 inst.instruction |= LOW4 (inst.operands[1].reg);
14913 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14914 inst.instruction |= (isquad != 0) << 6;
14915 inst.instruction |= immbits << 16;
14916 inst.instruction |= (size >> 3) << 7;
14917 inst.instruction |= (size & 0x7) << 19;
14918 if (write_ubit)
14919 inst.instruction |= (uval != 0) << 24;
14920
88714cb8 14921 neon_dp_fixup (&inst);
5287ad62
JB
14922}
14923
14924static void
14925do_neon_shl_imm (void)
14926{
14927 if (!inst.operands[2].isreg)
14928 {
037e8744 14929 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14930 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14931 int imm = inst.operands[2].imm;
14932
14933 constraint (imm < 0 || (unsigned)imm >= et.size,
14934 _("immediate out of range for shift"));
88714cb8 14935 NEON_ENCODE (IMMED, inst);
cb3b1e65 14936 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14937 }
14938 else
14939 {
037e8744 14940 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14941 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14942 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14943 unsigned int tmp;
14944
14945 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14946 vshl.xx Dd, Dm, Dn
14947 whereas other 3-register operations encoded by neon_three_same have
14948 syntax like:
14949 vadd.xx Dd, Dn, Dm
14950 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14951 here. */
627907b7
JB
14952 tmp = inst.operands[2].reg;
14953 inst.operands[2].reg = inst.operands[1].reg;
14954 inst.operands[1].reg = tmp;
88714cb8 14955 NEON_ENCODE (INTEGER, inst);
037e8744 14956 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14957 }
14958}
14959
14960static void
14961do_neon_qshl_imm (void)
14962{
14963 if (!inst.operands[2].isreg)
14964 {
037e8744 14965 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14966 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14967 int imm = inst.operands[2].imm;
627907b7 14968
cb3b1e65
JB
14969 constraint (imm < 0 || (unsigned)imm >= et.size,
14970 _("immediate out of range for shift"));
88714cb8 14971 NEON_ENCODE (IMMED, inst);
cb3b1e65 14972 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14973 }
14974 else
14975 {
037e8744 14976 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14977 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14978 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14979 unsigned int tmp;
14980
14981 /* See note in do_neon_shl_imm. */
14982 tmp = inst.operands[2].reg;
14983 inst.operands[2].reg = inst.operands[1].reg;
14984 inst.operands[1].reg = tmp;
88714cb8 14985 NEON_ENCODE (INTEGER, inst);
037e8744 14986 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14987 }
14988}
14989
627907b7
JB
14990static void
14991do_neon_rshl (void)
14992{
14993 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14994 struct neon_type_el et = neon_check_type (3, rs,
14995 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14996 unsigned int tmp;
14997
14998 tmp = inst.operands[2].reg;
14999 inst.operands[2].reg = inst.operands[1].reg;
15000 inst.operands[1].reg = tmp;
15001 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
15002}
15003
5287ad62
JB
15004static int
15005neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
15006{
036dc3f7
PB
15007 /* Handle .I8 pseudo-instructions. */
15008 if (size == 8)
5287ad62 15009 {
5287ad62 15010 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
15011 FIXME is this the intended semantics? There doesn't seem much point in
15012 accepting .I8 if so. */
5287ad62
JB
15013 immediate |= immediate << 8;
15014 size = 16;
036dc3f7
PB
15015 }
15016
15017 if (size >= 32)
15018 {
15019 if (immediate == (immediate & 0x000000ff))
15020 {
15021 *immbits = immediate;
15022 return 0x1;
15023 }
15024 else if (immediate == (immediate & 0x0000ff00))
15025 {
15026 *immbits = immediate >> 8;
15027 return 0x3;
15028 }
15029 else if (immediate == (immediate & 0x00ff0000))
15030 {
15031 *immbits = immediate >> 16;
15032 return 0x5;
15033 }
15034 else if (immediate == (immediate & 0xff000000))
15035 {
15036 *immbits = immediate >> 24;
15037 return 0x7;
15038 }
15039 if ((immediate & 0xffff) != (immediate >> 16))
15040 goto bad_immediate;
15041 immediate &= 0xffff;
5287ad62
JB
15042 }
15043
15044 if (immediate == (immediate & 0x000000ff))
15045 {
15046 *immbits = immediate;
036dc3f7 15047 return 0x9;
5287ad62
JB
15048 }
15049 else if (immediate == (immediate & 0x0000ff00))
15050 {
15051 *immbits = immediate >> 8;
036dc3f7 15052 return 0xb;
5287ad62
JB
15053 }
15054
15055 bad_immediate:
dcbf9037 15056 first_error (_("immediate value out of range"));
5287ad62
JB
15057 return FAIL;
15058}
15059
5287ad62
JB
15060static void
15061do_neon_logic (void)
15062{
15063 if (inst.operands[2].present && inst.operands[2].isreg)
15064 {
037e8744 15065 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15066 neon_check_type (3, rs, N_IGNORE_TYPE);
15067 /* U bit and size field were set as part of the bitmask. */
88714cb8 15068 NEON_ENCODE (INTEGER, inst);
037e8744 15069 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
15070 }
15071 else
15072 {
4316f0d2
DG
15073 const int three_ops_form = (inst.operands[2].present
15074 && !inst.operands[2].isreg);
15075 const int immoperand = (three_ops_form ? 2 : 1);
15076 enum neon_shape rs = (three_ops_form
15077 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
15078 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 15079 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15080 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 15081 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
15082 unsigned immbits;
15083 int cmode;
5f4273c7 15084
5287ad62 15085 if (et.type == NT_invtype)
477330fc 15086 return;
5f4273c7 15087
4316f0d2
DG
15088 if (three_ops_form)
15089 constraint (inst.operands[0].reg != inst.operands[1].reg,
15090 _("first and second operands shall be the same register"));
15091
88714cb8 15092 NEON_ENCODE (IMMED, inst);
5287ad62 15093
4316f0d2 15094 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
15095 if (et.size == 64)
15096 {
15097 /* .i64 is a pseudo-op, so the immediate must be a repeating
15098 pattern. */
4316f0d2
DG
15099 if (immbits != (inst.operands[immoperand].regisimm ?
15100 inst.operands[immoperand].reg : 0))
036dc3f7
PB
15101 {
15102 /* Set immbits to an invalid constant. */
15103 immbits = 0xdeadbeef;
15104 }
15105 }
15106
5287ad62 15107 switch (opcode)
477330fc
RM
15108 {
15109 case N_MNEM_vbic:
15110 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
15111 break;
15112
15113 case N_MNEM_vorr:
15114 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
15115 break;
15116
15117 case N_MNEM_vand:
15118 /* Pseudo-instruction for VBIC. */
15119 neon_invert_size (&immbits, 0, et.size);
15120 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
15121 break;
15122
15123 case N_MNEM_vorn:
15124 /* Pseudo-instruction for VORR. */
15125 neon_invert_size (&immbits, 0, et.size);
15126 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
15127 break;
15128
15129 default:
15130 abort ();
15131 }
5287ad62
JB
15132
15133 if (cmode == FAIL)
477330fc 15134 return;
5287ad62 15135
037e8744 15136 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15137 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15138 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15139 inst.instruction |= cmode << 8;
15140 neon_write_immbits (immbits);
5f4273c7 15141
88714cb8 15142 neon_dp_fixup (&inst);
5287ad62
JB
15143 }
15144}
15145
15146static void
15147do_neon_bitfield (void)
15148{
037e8744 15149 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 15150 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 15151 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
15152}
15153
15154static void
dcbf9037 15155neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 15156 unsigned destbits)
5287ad62 15157{
037e8744 15158 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 15159 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 15160 types | N_KEY);
5287ad62
JB
15161 if (et.type == NT_float)
15162 {
88714cb8 15163 NEON_ENCODE (FLOAT, inst);
cc933301 15164 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15165 }
15166 else
15167 {
88714cb8 15168 NEON_ENCODE (INTEGER, inst);
037e8744 15169 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
15170 }
15171}
15172
15173static void
15174do_neon_dyadic_if_su (void)
15175{
dcbf9037 15176 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
15177}
15178
15179static void
15180do_neon_dyadic_if_su_d (void)
15181{
15182 /* This version only allow D registers, but that constraint is enforced during
15183 operand parsing so we don't need to do anything extra here. */
dcbf9037 15184 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
15185}
15186
5287ad62
JB
15187static void
15188do_neon_dyadic_if_i_d (void)
15189{
428e3f1f
PB
15190 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15191 affected if we specify unsigned args. */
15192 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
15193}
15194
037e8744
JB
15195enum vfp_or_neon_is_neon_bits
15196{
15197 NEON_CHECK_CC = 1,
73924fbc
MGD
15198 NEON_CHECK_ARCH = 2,
15199 NEON_CHECK_ARCH8 = 4
037e8744
JB
15200};
15201
15202/* Call this function if an instruction which may have belonged to the VFP or
15203 Neon instruction sets, but turned out to be a Neon instruction (due to the
15204 operand types involved, etc.). We have to check and/or fix-up a couple of
15205 things:
15206
15207 - Make sure the user hasn't attempted to make a Neon instruction
15208 conditional.
15209 - Alter the value in the condition code field if necessary.
15210 - Make sure that the arch supports Neon instructions.
15211
15212 Which of these operations take place depends on bits from enum
15213 vfp_or_neon_is_neon_bits.
15214
15215 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
15216 current instruction's condition is COND_ALWAYS, the condition field is
15217 changed to inst.uncond_value. This is necessary because instructions shared
15218 between VFP and Neon may be conditional for the VFP variants only, and the
15219 unconditional Neon version must have, e.g., 0xF in the condition field. */
15220
15221static int
15222vfp_or_neon_is_neon (unsigned check)
15223{
15224 /* Conditions are always legal in Thumb mode (IT blocks). */
15225 if (!thumb_mode && (check & NEON_CHECK_CC))
15226 {
15227 if (inst.cond != COND_ALWAYS)
477330fc
RM
15228 {
15229 first_error (_(BAD_COND));
15230 return FAIL;
15231 }
037e8744 15232 if (inst.uncond_value != -1)
477330fc 15233 inst.instruction |= inst.uncond_value << 28;
037e8744 15234 }
5f4273c7 15235
037e8744 15236 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
15237 && !mark_feature_used (&fpu_neon_ext_v1))
15238 {
15239 first_error (_(BAD_FPU));
15240 return FAIL;
15241 }
15242
15243 if ((check & NEON_CHECK_ARCH8)
15244 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
15245 {
15246 first_error (_(BAD_FPU));
15247 return FAIL;
15248 }
5f4273c7 15249
037e8744
JB
15250 return SUCCESS;
15251}
15252
5287ad62
JB
15253static void
15254do_neon_addsub_if_i (void)
15255{
037e8744
JB
15256 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
15257 return;
15258
15259 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15260 return;
15261
5287ad62
JB
15262 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15263 affected if we specify unsigned args. */
dcbf9037 15264 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
15265}
15266
15267/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
15268 result to be:
15269 V<op> A,B (A is operand 0, B is operand 2)
15270 to mean:
15271 V<op> A,B,A
15272 not:
15273 V<op> A,B,B
15274 so handle that case specially. */
15275
15276static void
15277neon_exchange_operands (void)
15278{
5287ad62
JB
15279 if (inst.operands[1].present)
15280 {
e1fa0163
NC
15281 void *scratch = xmalloc (sizeof (inst.operands[0]));
15282
5287ad62
JB
15283 /* Swap operands[1] and operands[2]. */
15284 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
15285 inst.operands[1] = inst.operands[2];
15286 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 15287 free (scratch);
5287ad62
JB
15288 }
15289 else
15290 {
15291 inst.operands[1] = inst.operands[2];
15292 inst.operands[2] = inst.operands[0];
15293 }
15294}
15295
15296static void
15297neon_compare (unsigned regtypes, unsigned immtypes, int invert)
15298{
15299 if (inst.operands[2].isreg)
15300 {
15301 if (invert)
477330fc 15302 neon_exchange_operands ();
dcbf9037 15303 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
15304 }
15305 else
15306 {
037e8744 15307 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 15308 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15309 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 15310
88714cb8 15311 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15312 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15313 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15314 inst.instruction |= LOW4 (inst.operands[1].reg);
15315 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15316 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15317 inst.instruction |= (et.type == NT_float) << 10;
15318 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15319
88714cb8 15320 neon_dp_fixup (&inst);
5287ad62
JB
15321 }
15322}
15323
15324static void
15325do_neon_cmp (void)
15326{
cc933301 15327 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
15328}
15329
15330static void
15331do_neon_cmp_inv (void)
15332{
cc933301 15333 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
15334}
15335
15336static void
15337do_neon_ceq (void)
15338{
15339 neon_compare (N_IF_32, N_IF_32, FALSE);
15340}
15341
15342/* For multiply instructions, we have the possibility of 16-bit or 32-bit
15343 scalars, which are encoded in 5 bits, M : Rm.
15344 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15345 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
15346 index in M.
15347
15348 Dot Product instructions are similar to multiply instructions except elsize
15349 should always be 32.
15350
15351 This function translates SCALAR, which is GAS's internal encoding of indexed
15352 scalar register, to raw encoding. There is also register and index range
15353 check based on ELSIZE. */
5287ad62
JB
15354
15355static unsigned
15356neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15357{
dcbf9037
JB
15358 unsigned regno = NEON_SCALAR_REG (scalar);
15359 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
15360
15361 switch (elsize)
15362 {
15363 case 16:
15364 if (regno > 7 || elno > 3)
477330fc 15365 goto bad_scalar;
5287ad62 15366 return regno | (elno << 3);
5f4273c7 15367
5287ad62
JB
15368 case 32:
15369 if (regno > 15 || elno > 1)
477330fc 15370 goto bad_scalar;
5287ad62
JB
15371 return regno | (elno << 4);
15372
15373 default:
15374 bad_scalar:
dcbf9037 15375 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15376 }
15377
15378 return 0;
15379}
15380
15381/* Encode multiply / multiply-accumulate scalar instructions. */
15382
15383static void
15384neon_mul_mac (struct neon_type_el et, int ubit)
15385{
dcbf9037
JB
15386 unsigned scalar;
15387
15388 /* Give a more helpful error message if we have an invalid type. */
15389 if (et.type == NT_invtype)
15390 return;
5f4273c7 15391
dcbf9037 15392 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15393 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15394 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15395 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15396 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15397 inst.instruction |= LOW4 (scalar);
15398 inst.instruction |= HI1 (scalar) << 5;
15399 inst.instruction |= (et.type == NT_float) << 8;
15400 inst.instruction |= neon_logbits (et.size) << 20;
15401 inst.instruction |= (ubit != 0) << 24;
15402
88714cb8 15403 neon_dp_fixup (&inst);
5287ad62
JB
15404}
15405
15406static void
15407do_neon_mac_maybe_scalar (void)
15408{
037e8744
JB
15409 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15410 return;
15411
15412 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15413 return;
15414
5287ad62
JB
15415 if (inst.operands[2].isscalar)
15416 {
037e8744 15417 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15418 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15419 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15420 NEON_ENCODE (SCALAR, inst);
037e8744 15421 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15422 }
15423 else
428e3f1f
PB
15424 {
15425 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15426 affected if we specify unsigned args. */
15427 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15428 }
5287ad62
JB
15429}
15430
62f3b8c8
PB
15431static void
15432do_neon_fmac (void)
15433{
15434 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15435 return;
15436
15437 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15438 return;
15439
15440 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15441}
15442
5287ad62
JB
15443static void
15444do_neon_tst (void)
15445{
037e8744 15446 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15447 struct neon_type_el et = neon_check_type (3, rs,
15448 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15449 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15450}
15451
15452/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15453 same types as the MAC equivalents. The polynomial type for this instruction
15454 is encoded the same as the integer type. */
15455
15456static void
15457do_neon_mul (void)
15458{
037e8744
JB
15459 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15460 return;
15461
15462 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15463 return;
15464
5287ad62
JB
15465 if (inst.operands[2].isscalar)
15466 do_neon_mac_maybe_scalar ();
15467 else
cc933301 15468 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15469}
15470
15471static void
15472do_neon_qdmulh (void)
15473{
15474 if (inst.operands[2].isscalar)
15475 {
037e8744 15476 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15477 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15478 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15479 NEON_ENCODE (SCALAR, inst);
037e8744 15480 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15481 }
15482 else
15483 {
037e8744 15484 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15485 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15486 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15487 NEON_ENCODE (INTEGER, inst);
5287ad62 15488 /* The U bit (rounding) comes from bit mask. */
037e8744 15489 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15490 }
15491}
15492
643afb90
MW
15493static void
15494do_neon_qrdmlah (void)
15495{
15496 /* Check we're on the correct architecture. */
15497 if (!mark_feature_used (&fpu_neon_ext_armv8))
15498 inst.error =
15499 _("instruction form not available on this architecture.");
15500 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15501 {
15502 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15503 record_feature_use (&fpu_neon_ext_v8_1);
15504 }
15505
15506 if (inst.operands[2].isscalar)
15507 {
15508 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15509 struct neon_type_el et = neon_check_type (3, rs,
15510 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15511 NEON_ENCODE (SCALAR, inst);
15512 neon_mul_mac (et, neon_quad (rs));
15513 }
15514 else
15515 {
15516 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15517 struct neon_type_el et = neon_check_type (3, rs,
15518 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15519 NEON_ENCODE (INTEGER, inst);
15520 /* The U bit (rounding) comes from bit mask. */
15521 neon_three_same (neon_quad (rs), 0, et.size);
15522 }
15523}
15524
5287ad62
JB
15525static void
15526do_neon_fcmp_absolute (void)
15527{
037e8744 15528 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15529 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15530 N_F_16_32 | N_KEY);
5287ad62 15531 /* Size field comes from bit mask. */
cc933301 15532 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15533}
15534
15535static void
15536do_neon_fcmp_absolute_inv (void)
15537{
15538 neon_exchange_operands ();
15539 do_neon_fcmp_absolute ();
15540}
15541
15542static void
15543do_neon_step (void)
15544{
037e8744 15545 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15546 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15547 N_F_16_32 | N_KEY);
15548 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15549}
15550
15551static void
15552do_neon_abs_neg (void)
15553{
037e8744
JB
15554 enum neon_shape rs;
15555 struct neon_type_el et;
5f4273c7 15556
037e8744
JB
15557 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15558 return;
15559
15560 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15561 return;
15562
15563 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15564 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15565
5287ad62
JB
15566 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15567 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15568 inst.instruction |= LOW4 (inst.operands[1].reg);
15569 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15570 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15571 inst.instruction |= (et.type == NT_float) << 10;
15572 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15573
88714cb8 15574 neon_dp_fixup (&inst);
5287ad62
JB
15575}
15576
15577static void
15578do_neon_sli (void)
15579{
037e8744 15580 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15581 struct neon_type_el et = neon_check_type (2, rs,
15582 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15583 int imm = inst.operands[2].imm;
15584 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15585 _("immediate out of range for insert"));
037e8744 15586 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15587}
15588
15589static void
15590do_neon_sri (void)
15591{
037e8744 15592 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15593 struct neon_type_el et = neon_check_type (2, rs,
15594 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15595 int imm = inst.operands[2].imm;
15596 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15597 _("immediate out of range for insert"));
037e8744 15598 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15599}
15600
15601static void
15602do_neon_qshlu_imm (void)
15603{
037e8744 15604 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15605 struct neon_type_el et = neon_check_type (2, rs,
15606 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15607 int imm = inst.operands[2].imm;
15608 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15609 _("immediate out of range for shift"));
5287ad62
JB
15610 /* Only encodes the 'U present' variant of the instruction.
15611 In this case, signed types have OP (bit 8) set to 0.
15612 Unsigned types have OP set to 1. */
15613 inst.instruction |= (et.type == NT_unsigned) << 8;
15614 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15615 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15616}
15617
15618static void
15619do_neon_qmovn (void)
15620{
15621 struct neon_type_el et = neon_check_type (2, NS_DQ,
15622 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15623 /* Saturating move where operands can be signed or unsigned, and the
15624 destination has the same signedness. */
88714cb8 15625 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15626 if (et.type == NT_unsigned)
15627 inst.instruction |= 0xc0;
15628 else
15629 inst.instruction |= 0x80;
15630 neon_two_same (0, 1, et.size / 2);
15631}
15632
15633static void
15634do_neon_qmovun (void)
15635{
15636 struct neon_type_el et = neon_check_type (2, NS_DQ,
15637 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15638 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15639 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15640 neon_two_same (0, 1, et.size / 2);
15641}
15642
15643static void
15644do_neon_rshift_sat_narrow (void)
15645{
15646 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15647 or unsigned. If operands are unsigned, results must also be unsigned. */
15648 struct neon_type_el et = neon_check_type (2, NS_DQI,
15649 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15650 int imm = inst.operands[2].imm;
15651 /* This gets the bounds check, size encoding and immediate bits calculation
15652 right. */
15653 et.size /= 2;
5f4273c7 15654
5287ad62
JB
15655 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15656 VQMOVN.I<size> <Dd>, <Qm>. */
15657 if (imm == 0)
15658 {
15659 inst.operands[2].present = 0;
15660 inst.instruction = N_MNEM_vqmovn;
15661 do_neon_qmovn ();
15662 return;
15663 }
5f4273c7 15664
5287ad62 15665 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15666 _("immediate out of range"));
5287ad62
JB
15667 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15668}
15669
15670static void
15671do_neon_rshift_sat_narrow_u (void)
15672{
15673 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15674 or unsigned. If operands are unsigned, results must also be unsigned. */
15675 struct neon_type_el et = neon_check_type (2, NS_DQI,
15676 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15677 int imm = inst.operands[2].imm;
15678 /* This gets the bounds check, size encoding and immediate bits calculation
15679 right. */
15680 et.size /= 2;
15681
15682 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15683 VQMOVUN.I<size> <Dd>, <Qm>. */
15684 if (imm == 0)
15685 {
15686 inst.operands[2].present = 0;
15687 inst.instruction = N_MNEM_vqmovun;
15688 do_neon_qmovun ();
15689 return;
15690 }
15691
15692 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15693 _("immediate out of range"));
5287ad62
JB
15694 /* FIXME: The manual is kind of unclear about what value U should have in
15695 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15696 must be 1. */
15697 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15698}
15699
15700static void
15701do_neon_movn (void)
15702{
15703 struct neon_type_el et = neon_check_type (2, NS_DQ,
15704 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15705 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15706 neon_two_same (0, 1, et.size / 2);
15707}
15708
15709static void
15710do_neon_rshift_narrow (void)
15711{
15712 struct neon_type_el et = neon_check_type (2, NS_DQI,
15713 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15714 int imm = inst.operands[2].imm;
15715 /* This gets the bounds check, size encoding and immediate bits calculation
15716 right. */
15717 et.size /= 2;
5f4273c7 15718
5287ad62
JB
15719 /* If immediate is zero then we are a pseudo-instruction for
15720 VMOVN.I<size> <Dd>, <Qm> */
15721 if (imm == 0)
15722 {
15723 inst.operands[2].present = 0;
15724 inst.instruction = N_MNEM_vmovn;
15725 do_neon_movn ();
15726 return;
15727 }
5f4273c7 15728
5287ad62 15729 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15730 _("immediate out of range for narrowing operation"));
5287ad62
JB
15731 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15732}
15733
15734static void
15735do_neon_shll (void)
15736{
15737 /* FIXME: Type checking when lengthening. */
15738 struct neon_type_el et = neon_check_type (2, NS_QDI,
15739 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15740 unsigned imm = inst.operands[2].imm;
15741
15742 if (imm == et.size)
15743 {
15744 /* Maximum shift variant. */
88714cb8 15745 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15746 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15747 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15748 inst.instruction |= LOW4 (inst.operands[1].reg);
15749 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15750 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15751
88714cb8 15752 neon_dp_fixup (&inst);
5287ad62
JB
15753 }
15754 else
15755 {
15756 /* A more-specific type check for non-max versions. */
15757 et = neon_check_type (2, NS_QDI,
477330fc 15758 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15759 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15760 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15761 }
15762}
15763
037e8744 15764/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15765 the current instruction is. */
15766
6b9a8b67
MGD
15767#define CVT_FLAVOUR_VAR \
15768 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15769 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15770 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15771 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15772 /* Half-precision conversions. */ \
cc933301
JW
15773 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15774 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15775 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15776 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15777 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15778 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15779 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15780 Compared with single/double precision variants, only the co-processor \
15781 field is different, so the encoding flow is reused here. */ \
15782 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15783 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15784 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15785 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15786 /* VFP instructions. */ \
15787 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15788 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15789 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15790 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15791 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15792 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15793 /* VFP instructions with bitshift. */ \
15794 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15795 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15796 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15797 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15798 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15799 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15800 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15801 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15802
15803#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15804 neon_cvt_flavour_##C,
15805
15806/* The different types of conversions we can do. */
15807enum neon_cvt_flavour
15808{
15809 CVT_FLAVOUR_VAR
15810 neon_cvt_flavour_invalid,
15811 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15812};
15813
15814#undef CVT_VAR
15815
15816static enum neon_cvt_flavour
15817get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15818{
6b9a8b67
MGD
15819#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15820 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15821 if (et.type != NT_invtype) \
15822 { \
15823 inst.error = NULL; \
15824 return (neon_cvt_flavour_##C); \
5287ad62 15825 }
6b9a8b67 15826
5287ad62 15827 struct neon_type_el et;
037e8744 15828 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15829 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15830 /* The instruction versions which take an immediate take one register
15831 argument, which is extended to the width of the full register. Thus the
15832 "source" and "destination" registers must have the same width. Hack that
15833 here by making the size equal to the key (wider, in this case) operand. */
15834 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15835
6b9a8b67
MGD
15836 CVT_FLAVOUR_VAR;
15837
15838 return neon_cvt_flavour_invalid;
5287ad62
JB
15839#undef CVT_VAR
15840}
15841
7e8e6784
MGD
15842enum neon_cvt_mode
15843{
15844 neon_cvt_mode_a,
15845 neon_cvt_mode_n,
15846 neon_cvt_mode_p,
15847 neon_cvt_mode_m,
15848 neon_cvt_mode_z,
30bdf752
MGD
15849 neon_cvt_mode_x,
15850 neon_cvt_mode_r
7e8e6784
MGD
15851};
15852
037e8744
JB
15853/* Neon-syntax VFP conversions. */
15854
5287ad62 15855static void
6b9a8b67 15856do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15857{
037e8744 15858 const char *opname = 0;
5f4273c7 15859
d54af2d0
RL
15860 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15861 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15862 {
037e8744
JB
15863 /* Conversions with immediate bitshift. */
15864 const char *enc[] =
477330fc 15865 {
6b9a8b67
MGD
15866#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15867 CVT_FLAVOUR_VAR
15868 NULL
15869#undef CVT_VAR
477330fc 15870 };
037e8744 15871
6b9a8b67 15872 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15873 {
15874 opname = enc[flavour];
15875 constraint (inst.operands[0].reg != inst.operands[1].reg,
15876 _("operands 0 and 1 must be the same register"));
15877 inst.operands[1] = inst.operands[2];
15878 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15879 }
5287ad62
JB
15880 }
15881 else
15882 {
037e8744
JB
15883 /* Conversions without bitshift. */
15884 const char *enc[] =
477330fc 15885 {
6b9a8b67
MGD
15886#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15887 CVT_FLAVOUR_VAR
15888 NULL
15889#undef CVT_VAR
477330fc 15890 };
037e8744 15891
6b9a8b67 15892 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15893 opname = enc[flavour];
037e8744
JB
15894 }
15895
15896 if (opname)
15897 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15898
15899 /* ARMv8.2 fp16 VCVT instruction. */
15900 if (flavour == neon_cvt_flavour_s32_f16
15901 || flavour == neon_cvt_flavour_u32_f16
15902 || flavour == neon_cvt_flavour_f16_u32
15903 || flavour == neon_cvt_flavour_f16_s32)
15904 do_scalar_fp16_v82_encode ();
037e8744
JB
15905}
15906
15907static void
15908do_vfp_nsyn_cvtz (void)
15909{
d54af2d0 15910 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15911 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15912 const char *enc[] =
15913 {
6b9a8b67
MGD
15914#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15915 CVT_FLAVOUR_VAR
15916 NULL
15917#undef CVT_VAR
037e8744
JB
15918 };
15919
6b9a8b67 15920 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15921 do_vfp_nsyn_opcode (enc[flavour]);
15922}
f31fef98 15923
037e8744 15924static void
bacebabc 15925do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15926 enum neon_cvt_mode mode)
15927{
15928 int sz, op;
15929 int rm;
15930
a715796b
TG
15931 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15932 D register operands. */
15933 if (flavour == neon_cvt_flavour_s32_f64
15934 || flavour == neon_cvt_flavour_u32_f64)
15935 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15936 _(BAD_FPU));
15937
9db2f6b4
RL
15938 if (flavour == neon_cvt_flavour_s32_f16
15939 || flavour == neon_cvt_flavour_u32_f16)
15940 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15941 _(BAD_FP16));
15942
7e8e6784
MGD
15943 set_it_insn_type (OUTSIDE_IT_INSN);
15944
15945 switch (flavour)
15946 {
15947 case neon_cvt_flavour_s32_f64:
15948 sz = 1;
827f64ff 15949 op = 1;
7e8e6784
MGD
15950 break;
15951 case neon_cvt_flavour_s32_f32:
15952 sz = 0;
15953 op = 1;
15954 break;
9db2f6b4
RL
15955 case neon_cvt_flavour_s32_f16:
15956 sz = 0;
15957 op = 1;
15958 break;
7e8e6784
MGD
15959 case neon_cvt_flavour_u32_f64:
15960 sz = 1;
15961 op = 0;
15962 break;
15963 case neon_cvt_flavour_u32_f32:
15964 sz = 0;
15965 op = 0;
15966 break;
9db2f6b4
RL
15967 case neon_cvt_flavour_u32_f16:
15968 sz = 0;
15969 op = 0;
15970 break;
7e8e6784
MGD
15971 default:
15972 first_error (_("invalid instruction shape"));
15973 return;
15974 }
15975
15976 switch (mode)
15977 {
15978 case neon_cvt_mode_a: rm = 0; break;
15979 case neon_cvt_mode_n: rm = 1; break;
15980 case neon_cvt_mode_p: rm = 2; break;
15981 case neon_cvt_mode_m: rm = 3; break;
15982 default: first_error (_("invalid rounding mode")); return;
15983 }
15984
15985 NEON_ENCODE (FPV8, inst);
15986 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15987 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15988 inst.instruction |= sz << 8;
9db2f6b4
RL
15989
15990 /* ARMv8.2 fp16 VCVT instruction. */
15991 if (flavour == neon_cvt_flavour_s32_f16
15992 ||flavour == neon_cvt_flavour_u32_f16)
15993 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15994 inst.instruction |= op << 7;
15995 inst.instruction |= rm << 16;
15996 inst.instruction |= 0xf0000000;
15997 inst.is_neon = TRUE;
15998}
15999
16000static void
16001do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
16002{
16003 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
16004 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
16005 NS_FH, NS_HF, NS_FHI, NS_HFI,
16006 NS_NULL);
6b9a8b67 16007 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 16008
cc933301
JW
16009 if (flavour == neon_cvt_flavour_invalid)
16010 return;
16011
e3e535bc 16012 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 16013 if (mode == neon_cvt_mode_z
e3e535bc 16014 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
16015 && (flavour == neon_cvt_flavour_s16_f16
16016 || flavour == neon_cvt_flavour_u16_f16
16017 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
16018 || flavour == neon_cvt_flavour_u32_f32
16019 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 16020 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
16021 && (rs == NS_FD || rs == NS_FF))
16022 {
16023 do_vfp_nsyn_cvtz ();
16024 return;
16025 }
16026
9db2f6b4
RL
16027 /* ARMv8.2 fp16 VCVT conversions. */
16028 if (mode == neon_cvt_mode_z
16029 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
16030 && (flavour == neon_cvt_flavour_s32_f16
16031 || flavour == neon_cvt_flavour_u32_f16)
16032 && (rs == NS_FH))
16033 {
16034 do_vfp_nsyn_cvtz ();
16035 do_scalar_fp16_v82_encode ();
16036 return;
16037 }
16038
037e8744 16039 /* VFP rather than Neon conversions. */
6b9a8b67 16040 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 16041 {
7e8e6784
MGD
16042 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
16043 do_vfp_nsyn_cvt (rs, flavour);
16044 else
16045 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
16046
037e8744
JB
16047 return;
16048 }
16049
16050 switch (rs)
16051 {
16052 case NS_DDI:
16053 case NS_QQI:
16054 {
477330fc 16055 unsigned immbits;
cc933301
JW
16056 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
16057 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 16058
477330fc
RM
16059 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16060 return;
037e8744 16061
477330fc
RM
16062 /* Fixed-point conversion with #0 immediate is encoded as an
16063 integer conversion. */
16064 if (inst.operands[2].present && inst.operands[2].imm == 0)
16065 goto int_encode;
477330fc
RM
16066 NEON_ENCODE (IMMED, inst);
16067 if (flavour != neon_cvt_flavour_invalid)
16068 inst.instruction |= enctab[flavour];
16069 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16070 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16071 inst.instruction |= LOW4 (inst.operands[1].reg);
16072 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16073 inst.instruction |= neon_quad (rs) << 6;
16074 inst.instruction |= 1 << 21;
cc933301
JW
16075 if (flavour < neon_cvt_flavour_s16_f16)
16076 {
16077 inst.instruction |= 1 << 21;
16078 immbits = 32 - inst.operands[2].imm;
16079 inst.instruction |= immbits << 16;
16080 }
16081 else
16082 {
16083 inst.instruction |= 3 << 20;
16084 immbits = 16 - inst.operands[2].imm;
16085 inst.instruction |= immbits << 16;
16086 inst.instruction &= ~(1 << 9);
16087 }
477330fc
RM
16088
16089 neon_dp_fixup (&inst);
037e8744
JB
16090 }
16091 break;
16092
16093 case NS_DD:
16094 case NS_QQ:
7e8e6784
MGD
16095 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
16096 {
16097 NEON_ENCODE (FLOAT, inst);
16098 set_it_insn_type (OUTSIDE_IT_INSN);
16099
16100 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16101 return;
16102
16103 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16104 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16105 inst.instruction |= LOW4 (inst.operands[1].reg);
16106 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16107 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
16108 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
16109 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 16110 inst.instruction |= mode << 8;
cc933301
JW
16111 if (flavour == neon_cvt_flavour_u16_f16
16112 || flavour == neon_cvt_flavour_s16_f16)
16113 /* Mask off the original size bits and reencode them. */
16114 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
16115
7e8e6784
MGD
16116 if (thumb_mode)
16117 inst.instruction |= 0xfc000000;
16118 else
16119 inst.instruction |= 0xf0000000;
16120 }
16121 else
16122 {
037e8744 16123 int_encode:
7e8e6784 16124 {
cc933301
JW
16125 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
16126 0x100, 0x180, 0x0, 0x080};
037e8744 16127
7e8e6784 16128 NEON_ENCODE (INTEGER, inst);
037e8744 16129
7e8e6784
MGD
16130 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16131 return;
037e8744 16132
7e8e6784
MGD
16133 if (flavour != neon_cvt_flavour_invalid)
16134 inst.instruction |= enctab[flavour];
037e8744 16135
7e8e6784
MGD
16136 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16137 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16138 inst.instruction |= LOW4 (inst.operands[1].reg);
16139 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16140 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
16141 if (flavour >= neon_cvt_flavour_s16_f16
16142 && flavour <= neon_cvt_flavour_f16_u16)
16143 /* Half precision. */
16144 inst.instruction |= 1 << 18;
16145 else
16146 inst.instruction |= 2 << 18;
037e8744 16147
7e8e6784
MGD
16148 neon_dp_fixup (&inst);
16149 }
16150 }
16151 break;
037e8744 16152
8e79c3df
CM
16153 /* Half-precision conversions for Advanced SIMD -- neon. */
16154 case NS_QD:
16155 case NS_DQ:
bc52d49c
MM
16156 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16157 return;
8e79c3df
CM
16158
16159 if ((rs == NS_DQ)
16160 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
16161 {
16162 as_bad (_("operand size must match register width"));
16163 break;
16164 }
16165
16166 if ((rs == NS_QD)
16167 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
16168 {
16169 as_bad (_("operand size must match register width"));
16170 break;
16171 }
16172
16173 if (rs == NS_DQ)
477330fc 16174 inst.instruction = 0x3b60600;
8e79c3df
CM
16175 else
16176 inst.instruction = 0x3b60700;
16177
16178 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16179 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16180 inst.instruction |= LOW4 (inst.operands[1].reg);
16181 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 16182 neon_dp_fixup (&inst);
8e79c3df
CM
16183 break;
16184
037e8744
JB
16185 default:
16186 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
16187 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
16188 do_vfp_nsyn_cvt (rs, flavour);
16189 else
16190 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 16191 }
5287ad62
JB
16192}
16193
e3e535bc
NC
16194static void
16195do_neon_cvtr (void)
16196{
7e8e6784 16197 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
16198}
16199
16200static void
16201do_neon_cvt (void)
16202{
7e8e6784
MGD
16203 do_neon_cvt_1 (neon_cvt_mode_z);
16204}
16205
16206static void
16207do_neon_cvta (void)
16208{
16209 do_neon_cvt_1 (neon_cvt_mode_a);
16210}
16211
16212static void
16213do_neon_cvtn (void)
16214{
16215 do_neon_cvt_1 (neon_cvt_mode_n);
16216}
16217
16218static void
16219do_neon_cvtp (void)
16220{
16221 do_neon_cvt_1 (neon_cvt_mode_p);
16222}
16223
16224static void
16225do_neon_cvtm (void)
16226{
16227 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
16228}
16229
8e79c3df 16230static void
c70a8987 16231do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 16232{
c70a8987
MGD
16233 if (is_double)
16234 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 16235
c70a8987
MGD
16236 encode_arm_vfp_reg (inst.operands[0].reg,
16237 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
16238 encode_arm_vfp_reg (inst.operands[1].reg,
16239 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
16240 inst.instruction |= to ? 0x10000 : 0;
16241 inst.instruction |= t ? 0x80 : 0;
16242 inst.instruction |= is_double ? 0x100 : 0;
16243 do_vfp_cond_or_thumb ();
16244}
8e79c3df 16245
c70a8987
MGD
16246static void
16247do_neon_cvttb_1 (bfd_boolean t)
16248{
d54af2d0
RL
16249 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
16250 NS_DF, NS_DH, NS_NULL);
8e79c3df 16251
c70a8987
MGD
16252 if (rs == NS_NULL)
16253 return;
16254 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
16255 {
16256 inst.error = NULL;
16257 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
16258 }
16259 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
16260 {
16261 inst.error = NULL;
16262 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
16263 }
16264 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
16265 {
a715796b
TG
16266 /* The VCVTB and VCVTT instructions with D-register operands
16267 don't work for SP only targets. */
16268 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16269 _(BAD_FPU));
16270
c70a8987
MGD
16271 inst.error = NULL;
16272 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
16273 }
16274 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
16275 {
a715796b
TG
16276 /* The VCVTB and VCVTT instructions with D-register operands
16277 don't work for SP only targets. */
16278 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16279 _(BAD_FPU));
16280
c70a8987
MGD
16281 inst.error = NULL;
16282 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
16283 }
16284 else
16285 return;
16286}
16287
16288static void
16289do_neon_cvtb (void)
16290{
16291 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
16292}
16293
16294
16295static void
16296do_neon_cvtt (void)
16297{
c70a8987 16298 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
16299}
16300
5287ad62
JB
16301static void
16302neon_move_immediate (void)
16303{
037e8744
JB
16304 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
16305 struct neon_type_el et = neon_check_type (2, rs,
16306 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 16307 unsigned immlo, immhi = 0, immbits;
c96612cc 16308 int op, cmode, float_p;
5287ad62 16309
037e8744 16310 constraint (et.type == NT_invtype,
477330fc 16311 _("operand size must be specified for immediate VMOV"));
037e8744 16312
5287ad62
JB
16313 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
16314 op = (inst.instruction & (1 << 5)) != 0;
16315
16316 immlo = inst.operands[1].imm;
16317 if (inst.operands[1].regisimm)
16318 immhi = inst.operands[1].reg;
16319
16320 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 16321 _("immediate has bits set outside the operand size"));
5287ad62 16322
c96612cc
JB
16323 float_p = inst.operands[1].immisfloat;
16324
16325 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 16326 et.size, et.type)) == FAIL)
5287ad62
JB
16327 {
16328 /* Invert relevant bits only. */
16329 neon_invert_size (&immlo, &immhi, et.size);
16330 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
16331 with one or the other; those cases are caught by
16332 neon_cmode_for_move_imm. */
5287ad62 16333 op = !op;
c96612cc
JB
16334 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16335 &op, et.size, et.type)) == FAIL)
477330fc
RM
16336 {
16337 first_error (_("immediate out of range"));
16338 return;
16339 }
5287ad62
JB
16340 }
16341
16342 inst.instruction &= ~(1 << 5);
16343 inst.instruction |= op << 5;
16344
16345 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16346 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 16347 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16348 inst.instruction |= cmode << 8;
16349
16350 neon_write_immbits (immbits);
16351}
16352
16353static void
16354do_neon_mvn (void)
16355{
16356 if (inst.operands[1].isreg)
16357 {
037e8744 16358 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16359
88714cb8 16360 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16361 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16362 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16363 inst.instruction |= LOW4 (inst.operands[1].reg);
16364 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16365 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16366 }
16367 else
16368 {
88714cb8 16369 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16370 neon_move_immediate ();
16371 }
16372
88714cb8 16373 neon_dp_fixup (&inst);
5287ad62
JB
16374}
16375
16376/* Encode instructions of form:
16377
16378 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16379 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16380
16381static void
16382neon_mixed_length (struct neon_type_el et, unsigned size)
16383{
16384 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16385 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16386 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16387 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16388 inst.instruction |= LOW4 (inst.operands[2].reg);
16389 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16390 inst.instruction |= (et.type == NT_unsigned) << 24;
16391 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16392
88714cb8 16393 neon_dp_fixup (&inst);
5287ad62
JB
16394}
16395
16396static void
16397do_neon_dyadic_long (void)
16398{
16399 /* FIXME: Type checking for lengthening op. */
16400 struct neon_type_el et = neon_check_type (3, NS_QDD,
16401 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16402 neon_mixed_length (et, et.size);
16403}
16404
16405static void
16406do_neon_abal (void)
16407{
16408 struct neon_type_el et = neon_check_type (3, NS_QDD,
16409 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16410 neon_mixed_length (et, et.size);
16411}
16412
16413static void
16414neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16415{
16416 if (inst.operands[2].isscalar)
16417 {
dcbf9037 16418 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16419 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16420 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16421 neon_mul_mac (et, et.type == NT_unsigned);
16422 }
16423 else
16424 {
16425 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16426 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16427 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16428 neon_mixed_length (et, et.size);
16429 }
16430}
16431
16432static void
16433do_neon_mac_maybe_scalar_long (void)
16434{
16435 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16436}
16437
dec41383
JW
16438/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
16439 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
16440
16441static unsigned
16442neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
16443{
16444 unsigned regno = NEON_SCALAR_REG (scalar);
16445 unsigned elno = NEON_SCALAR_INDEX (scalar);
16446
16447 if (quad_p)
16448 {
16449 if (regno > 7 || elno > 3)
16450 goto bad_scalar;
16451
16452 return ((regno & 0x7)
16453 | ((elno & 0x1) << 3)
16454 | (((elno >> 1) & 0x1) << 5));
16455 }
16456 else
16457 {
16458 if (regno > 15 || elno > 1)
16459 goto bad_scalar;
16460
16461 return (((regno & 0x1) << 5)
16462 | ((regno >> 1) & 0x7)
16463 | ((elno & 0x1) << 3));
16464 }
16465
16466bad_scalar:
16467 first_error (_("scalar out of range for multiply instruction"));
16468 return 0;
16469}
16470
16471static void
16472do_neon_fmac_maybe_scalar_long (int subtype)
16473{
16474 enum neon_shape rs;
16475 int high8;
16476 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
16477 field (bits[21:20]) has different meaning. For scalar index variant, it's
16478 used to differentiate add and subtract, otherwise it's with fixed value
16479 0x2. */
16480 int size = -1;
16481
16482 if (inst.cond != COND_ALWAYS)
16483 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
16484 "behaviour is UNPREDICTABLE"));
16485
01f48020 16486 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
dec41383
JW
16487 _(BAD_FP16));
16488
16489 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
16490 _(BAD_FPU));
16491
16492 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
16493 be a scalar index register. */
16494 if (inst.operands[2].isscalar)
16495 {
16496 high8 = 0xfe000000;
16497 if (subtype)
16498 size = 16;
16499 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
16500 }
16501 else
16502 {
16503 high8 = 0xfc000000;
16504 size = 32;
16505 if (subtype)
16506 inst.instruction |= (0x1 << 23);
16507 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
16508 }
16509
16510 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
16511
16512 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
16513 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
16514 so we simply pass -1 as size. */
16515 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
16516 neon_three_same (quad_p, 0, size);
16517
16518 /* Undo neon_dp_fixup. Redo the high eight bits. */
16519 inst.instruction &= 0x00ffffff;
16520 inst.instruction |= high8;
16521
16522#define LOW1(R) ((R) & 0x1)
16523#define HI4(R) (((R) >> 1) & 0xf)
16524 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
16525 whether the instruction is in Q form and whether Vm is a scalar indexed
16526 operand. */
16527 if (inst.operands[2].isscalar)
16528 {
16529 unsigned rm
16530 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
16531 inst.instruction &= 0xffffffd0;
16532 inst.instruction |= rm;
16533
16534 if (!quad_p)
16535 {
16536 /* Redo Rn as well. */
16537 inst.instruction &= 0xfff0ff7f;
16538 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16539 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16540 }
16541 }
16542 else if (!quad_p)
16543 {
16544 /* Redo Rn and Rm. */
16545 inst.instruction &= 0xfff0ff50;
16546 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16547 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16548 inst.instruction |= HI4 (inst.operands[2].reg);
16549 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
16550 }
16551}
16552
16553static void
16554do_neon_vfmal (void)
16555{
16556 return do_neon_fmac_maybe_scalar_long (0);
16557}
16558
16559static void
16560do_neon_vfmsl (void)
16561{
16562 return do_neon_fmac_maybe_scalar_long (1);
16563}
16564
5287ad62
JB
16565static void
16566do_neon_dyadic_wide (void)
16567{
16568 struct neon_type_el et = neon_check_type (3, NS_QQD,
16569 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16570 neon_mixed_length (et, et.size);
16571}
16572
16573static void
16574do_neon_dyadic_narrow (void)
16575{
16576 struct neon_type_el et = neon_check_type (3, NS_QDD,
16577 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16578 /* Operand sign is unimportant, and the U bit is part of the opcode,
16579 so force the operand type to integer. */
16580 et.type = NT_integer;
5287ad62
JB
16581 neon_mixed_length (et, et.size / 2);
16582}
16583
16584static void
16585do_neon_mul_sat_scalar_long (void)
16586{
16587 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16588}
16589
16590static void
16591do_neon_vmull (void)
16592{
16593 if (inst.operands[2].isscalar)
16594 do_neon_mac_maybe_scalar_long ();
16595 else
16596 {
16597 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16598 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16599
5287ad62 16600 if (et.type == NT_poly)
477330fc 16601 NEON_ENCODE (POLY, inst);
5287ad62 16602 else
477330fc 16603 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16604
16605 /* For polynomial encoding the U bit must be zero, and the size must
16606 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16607 obviously, as 0b10). */
16608 if (et.size == 64)
16609 {
16610 /* Check we're on the correct architecture. */
16611 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16612 inst.error =
16613 _("Instruction form not available on this architecture.");
16614
16615 et.size = 32;
16616 }
16617
5287ad62
JB
16618 neon_mixed_length (et, et.size);
16619 }
16620}
16621
16622static void
16623do_neon_ext (void)
16624{
037e8744 16625 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16626 struct neon_type_el et = neon_check_type (3, rs,
16627 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16628 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16629
16630 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16631 _("shift out of range"));
5287ad62
JB
16632 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16633 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16634 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16635 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16636 inst.instruction |= LOW4 (inst.operands[2].reg);
16637 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16638 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16639 inst.instruction |= imm << 8;
5f4273c7 16640
88714cb8 16641 neon_dp_fixup (&inst);
5287ad62
JB
16642}
16643
16644static void
16645do_neon_rev (void)
16646{
037e8744 16647 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16648 struct neon_type_el et = neon_check_type (2, rs,
16649 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16650 unsigned op = (inst.instruction >> 7) & 3;
16651 /* N (width of reversed regions) is encoded as part of the bitmask. We
16652 extract it here to check the elements to be reversed are smaller.
16653 Otherwise we'd get a reserved instruction. */
16654 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16655 gas_assert (elsize != 0);
5287ad62 16656 constraint (et.size >= elsize,
477330fc 16657 _("elements must be smaller than reversal region"));
037e8744 16658 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16659}
16660
16661static void
16662do_neon_dup (void)
16663{
16664 if (inst.operands[1].isscalar)
16665 {
037e8744 16666 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16667 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16668 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16669 unsigned sizebits = et.size >> 3;
dcbf9037 16670 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16671 int logsize = neon_logbits (et.size);
dcbf9037 16672 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16673
16674 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16675 return;
037e8744 16676
88714cb8 16677 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16678 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16679 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16680 inst.instruction |= LOW4 (dm);
16681 inst.instruction |= HI1 (dm) << 5;
037e8744 16682 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16683 inst.instruction |= x << 17;
16684 inst.instruction |= sizebits << 16;
5f4273c7 16685
88714cb8 16686 neon_dp_fixup (&inst);
5287ad62
JB
16687 }
16688 else
16689 {
037e8744
JB
16690 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16691 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16692 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16693 /* Duplicate ARM register to lanes of vector. */
88714cb8 16694 NEON_ENCODE (ARMREG, inst);
5287ad62 16695 switch (et.size)
477330fc
RM
16696 {
16697 case 8: inst.instruction |= 0x400000; break;
16698 case 16: inst.instruction |= 0x000020; break;
16699 case 32: inst.instruction |= 0x000000; break;
16700 default: break;
16701 }
5287ad62
JB
16702 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16703 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16704 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16705 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16706 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16707 variants, except for the condition field. */
037e8744 16708 do_vfp_cond_or_thumb ();
5287ad62
JB
16709 }
16710}
16711
16712/* VMOV has particularly many variations. It can be one of:
16713 0. VMOV<c><q> <Qd>, <Qm>
16714 1. VMOV<c><q> <Dd>, <Dm>
16715 (Register operations, which are VORR with Rm = Rn.)
16716 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16717 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16718 (Immediate loads.)
16719 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16720 (ARM register to scalar.)
16721 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16722 (Two ARM registers to vector.)
16723 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16724 (Scalar to ARM register.)
16725 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16726 (Vector to two ARM registers.)
037e8744
JB
16727 8. VMOV.F32 <Sd>, <Sm>
16728 9. VMOV.F64 <Dd>, <Dm>
16729 (VFP register moves.)
16730 10. VMOV.F32 <Sd>, #imm
16731 11. VMOV.F64 <Dd>, #imm
16732 (VFP float immediate load.)
16733 12. VMOV <Rd>, <Sm>
16734 (VFP single to ARM reg.)
16735 13. VMOV <Sd>, <Rm>
16736 (ARM reg to VFP single.)
16737 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16738 (Two ARM regs to two VFP singles.)
16739 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16740 (Two VFP singles to two ARM regs.)
5f4273c7 16741
037e8744
JB
16742 These cases can be disambiguated using neon_select_shape, except cases 1/9
16743 and 3/11 which depend on the operand type too.
5f4273c7 16744
5287ad62 16745 All the encoded bits are hardcoded by this function.
5f4273c7 16746
b7fc2769
JB
16747 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16748 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16749
5287ad62 16750 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16751 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16752
16753static void
16754do_neon_mov (void)
16755{
037e8744 16756 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16757 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16758 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16759 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16760 struct neon_type_el et;
16761 const char *ldconst = 0;
5287ad62 16762
037e8744 16763 switch (rs)
5287ad62 16764 {
037e8744
JB
16765 case NS_DD: /* case 1/9. */
16766 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16767 /* It is not an error here if no type is given. */
16768 inst.error = NULL;
16769 if (et.type == NT_float && et.size == 64)
477330fc
RM
16770 {
16771 do_vfp_nsyn_opcode ("fcpyd");
16772 break;
16773 }
037e8744 16774 /* fall through. */
5287ad62 16775
037e8744
JB
16776 case NS_QQ: /* case 0/1. */
16777 {
477330fc
RM
16778 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16779 return;
16780 /* The architecture manual I have doesn't explicitly state which
16781 value the U bit should have for register->register moves, but
16782 the equivalent VORR instruction has U = 0, so do that. */
16783 inst.instruction = 0x0200110;
16784 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16785 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16786 inst.instruction |= LOW4 (inst.operands[1].reg);
16787 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16788 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16789 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16790 inst.instruction |= neon_quad (rs) << 6;
16791
16792 neon_dp_fixup (&inst);
037e8744
JB
16793 }
16794 break;
5f4273c7 16795
037e8744
JB
16796 case NS_DI: /* case 3/11. */
16797 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16798 inst.error = NULL;
16799 if (et.type == NT_float && et.size == 64)
477330fc
RM
16800 {
16801 /* case 11 (fconstd). */
16802 ldconst = "fconstd";
16803 goto encode_fconstd;
16804 }
037e8744
JB
16805 /* fall through. */
16806
16807 case NS_QI: /* case 2/3. */
16808 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16809 return;
037e8744
JB
16810 inst.instruction = 0x0800010;
16811 neon_move_immediate ();
88714cb8 16812 neon_dp_fixup (&inst);
5287ad62 16813 break;
5f4273c7 16814
037e8744
JB
16815 case NS_SR: /* case 4. */
16816 {
477330fc
RM
16817 unsigned bcdebits = 0;
16818 int logsize;
16819 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16820 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16821
05ac0ffb
JB
16822 /* .<size> is optional here, defaulting to .32. */
16823 if (inst.vectype.elems == 0
16824 && inst.operands[0].vectype.type == NT_invtype
16825 && inst.operands[1].vectype.type == NT_invtype)
16826 {
16827 inst.vectype.el[0].type = NT_untyped;
16828 inst.vectype.el[0].size = 32;
16829 inst.vectype.elems = 1;
16830 }
16831
477330fc
RM
16832 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16833 logsize = neon_logbits (et.size);
16834
16835 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16836 _(BAD_FPU));
16837 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16838 && et.size != 32, _(BAD_FPU));
16839 constraint (et.type == NT_invtype, _("bad type for scalar"));
16840 constraint (x >= 64 / et.size, _("scalar index out of range"));
16841
16842 switch (et.size)
16843 {
16844 case 8: bcdebits = 0x8; break;
16845 case 16: bcdebits = 0x1; break;
16846 case 32: bcdebits = 0x0; break;
16847 default: ;
16848 }
16849
16850 bcdebits |= x << logsize;
16851
16852 inst.instruction = 0xe000b10;
16853 do_vfp_cond_or_thumb ();
16854 inst.instruction |= LOW4 (dn) << 16;
16855 inst.instruction |= HI1 (dn) << 7;
16856 inst.instruction |= inst.operands[1].reg << 12;
16857 inst.instruction |= (bcdebits & 3) << 5;
16858 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16859 }
16860 break;
5f4273c7 16861
037e8744 16862 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16863 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16864 _(BAD_FPU));
b7fc2769 16865
037e8744
JB
16866 inst.instruction = 0xc400b10;
16867 do_vfp_cond_or_thumb ();
16868 inst.instruction |= LOW4 (inst.operands[0].reg);
16869 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16870 inst.instruction |= inst.operands[1].reg << 12;
16871 inst.instruction |= inst.operands[2].reg << 16;
16872 break;
5f4273c7 16873
037e8744
JB
16874 case NS_RS: /* case 6. */
16875 {
477330fc
RM
16876 unsigned logsize;
16877 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16878 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16879 unsigned abcdebits = 0;
037e8744 16880
05ac0ffb
JB
16881 /* .<dt> is optional here, defaulting to .32. */
16882 if (inst.vectype.elems == 0
16883 && inst.operands[0].vectype.type == NT_invtype
16884 && inst.operands[1].vectype.type == NT_invtype)
16885 {
16886 inst.vectype.el[0].type = NT_untyped;
16887 inst.vectype.el[0].size = 32;
16888 inst.vectype.elems = 1;
16889 }
16890
91d6fa6a
NC
16891 et = neon_check_type (2, NS_NULL,
16892 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16893 logsize = neon_logbits (et.size);
16894
16895 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16896 _(BAD_FPU));
16897 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16898 && et.size != 32, _(BAD_FPU));
16899 constraint (et.type == NT_invtype, _("bad type for scalar"));
16900 constraint (x >= 64 / et.size, _("scalar index out of range"));
16901
16902 switch (et.size)
16903 {
16904 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16905 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16906 case 32: abcdebits = 0x00; break;
16907 default: ;
16908 }
16909
16910 abcdebits |= x << logsize;
16911 inst.instruction = 0xe100b10;
16912 do_vfp_cond_or_thumb ();
16913 inst.instruction |= LOW4 (dn) << 16;
16914 inst.instruction |= HI1 (dn) << 7;
16915 inst.instruction |= inst.operands[0].reg << 12;
16916 inst.instruction |= (abcdebits & 3) << 5;
16917 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16918 }
16919 break;
5f4273c7 16920
037e8744
JB
16921 case NS_RRD: /* case 7 (fmrrd). */
16922 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16923 _(BAD_FPU));
037e8744
JB
16924
16925 inst.instruction = 0xc500b10;
16926 do_vfp_cond_or_thumb ();
16927 inst.instruction |= inst.operands[0].reg << 12;
16928 inst.instruction |= inst.operands[1].reg << 16;
16929 inst.instruction |= LOW4 (inst.operands[2].reg);
16930 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16931 break;
5f4273c7 16932
037e8744
JB
16933 case NS_FF: /* case 8 (fcpys). */
16934 do_vfp_nsyn_opcode ("fcpys");
16935 break;
5f4273c7 16936
9db2f6b4 16937 case NS_HI:
037e8744
JB
16938 case NS_FI: /* case 10 (fconsts). */
16939 ldconst = "fconsts";
4ef4710f 16940 encode_fconstd:
58ed5c38
TC
16941 if (!inst.operands[1].immisfloat)
16942 {
4ef4710f 16943 unsigned new_imm;
58ed5c38 16944 /* Immediate has to fit in 8 bits so float is enough. */
4ef4710f
NC
16945 float imm = (float) inst.operands[1].imm;
16946 memcpy (&new_imm, &imm, sizeof (float));
16947 /* But the assembly may have been written to provide an integer
16948 bit pattern that equates to a float, so check that the
16949 conversion has worked. */
16950 if (is_quarter_float (new_imm))
16951 {
16952 if (is_quarter_float (inst.operands[1].imm))
16953 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
16954
16955 inst.operands[1].imm = new_imm;
16956 inst.operands[1].immisfloat = 1;
16957 }
58ed5c38
TC
16958 }
16959
037e8744 16960 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16961 {
16962 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16963 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16964
16965 /* ARMv8.2 fp16 vmov.f16 instruction. */
16966 if (rs == NS_HI)
16967 do_scalar_fp16_v82_encode ();
477330fc 16968 }
5287ad62 16969 else
477330fc 16970 first_error (_("immediate out of range"));
037e8744 16971 break;
5f4273c7 16972
9db2f6b4 16973 case NS_RH:
037e8744
JB
16974 case NS_RF: /* case 12 (fmrs). */
16975 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16976 /* ARMv8.2 fp16 vmov.f16 instruction. */
16977 if (rs == NS_RH)
16978 do_scalar_fp16_v82_encode ();
037e8744 16979 break;
5f4273c7 16980
9db2f6b4 16981 case NS_HR:
037e8744
JB
16982 case NS_FR: /* case 13 (fmsr). */
16983 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16984 /* ARMv8.2 fp16 vmov.f16 instruction. */
16985 if (rs == NS_HR)
16986 do_scalar_fp16_v82_encode ();
037e8744 16987 break;
5f4273c7 16988
037e8744
JB
16989 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16990 (one of which is a list), but we have parsed four. Do some fiddling to
16991 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16992 expect. */
16993 case NS_RRFF: /* case 14 (fmrrs). */
16994 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16995 _("VFP registers must be adjacent"));
037e8744
JB
16996 inst.operands[2].imm = 2;
16997 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16998 do_vfp_nsyn_opcode ("fmrrs");
16999 break;
5f4273c7 17000
037e8744
JB
17001 case NS_FFRR: /* case 15 (fmsrr). */
17002 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 17003 _("VFP registers must be adjacent"));
037e8744
JB
17004 inst.operands[1] = inst.operands[2];
17005 inst.operands[2] = inst.operands[3];
17006 inst.operands[0].imm = 2;
17007 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
17008 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 17009 break;
5f4273c7 17010
4c261dff
NC
17011 case NS_NULL:
17012 /* neon_select_shape has determined that the instruction
17013 shape is wrong and has already set the error message. */
17014 break;
17015
5287ad62
JB
17016 default:
17017 abort ();
17018 }
17019}
17020
17021static void
17022do_neon_rshift_round_imm (void)
17023{
037e8744 17024 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
17025 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
17026 int imm = inst.operands[2].imm;
17027
17028 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
17029 if (imm == 0)
17030 {
17031 inst.operands[2].present = 0;
17032 do_neon_mov ();
17033 return;
17034 }
17035
17036 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 17037 _("immediate out of range for shift"));
037e8744 17038 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 17039 et.size - imm);
5287ad62
JB
17040}
17041
9db2f6b4
RL
17042static void
17043do_neon_movhf (void)
17044{
17045 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
17046 constraint (rs != NS_HH, _("invalid suffix"));
17047
7bdf778b
ASDV
17048 if (inst.cond != COND_ALWAYS)
17049 {
17050 if (thumb_mode)
17051 {
17052 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
17053 " the behaviour is UNPREDICTABLE"));
17054 }
17055 else
17056 {
17057 inst.error = BAD_COND;
17058 return;
17059 }
17060 }
17061
9db2f6b4
RL
17062 do_vfp_sp_monadic ();
17063
17064 inst.is_neon = 1;
17065 inst.instruction |= 0xf0000000;
17066}
17067
5287ad62
JB
17068static void
17069do_neon_movl (void)
17070{
17071 struct neon_type_el et = neon_check_type (2, NS_QD,
17072 N_EQK | N_DBL, N_SU_32 | N_KEY);
17073 unsigned sizebits = et.size >> 3;
17074 inst.instruction |= sizebits << 19;
17075 neon_two_same (0, et.type == NT_unsigned, -1);
17076}
17077
17078static void
17079do_neon_trn (void)
17080{
037e8744 17081 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17082 struct neon_type_el et = neon_check_type (2, rs,
17083 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 17084 NEON_ENCODE (INTEGER, inst);
037e8744 17085 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17086}
17087
17088static void
17089do_neon_zip_uzp (void)
17090{
037e8744 17091 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17092 struct neon_type_el et = neon_check_type (2, rs,
17093 N_EQK, N_8 | N_16 | N_32 | N_KEY);
17094 if (rs == NS_DD && et.size == 32)
17095 {
17096 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
17097 inst.instruction = N_MNEM_vtrn;
17098 do_neon_trn ();
17099 return;
17100 }
037e8744 17101 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17102}
17103
17104static void
17105do_neon_sat_abs_neg (void)
17106{
037e8744 17107 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17108 struct neon_type_el et = neon_check_type (2, rs,
17109 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 17110 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17111}
17112
17113static void
17114do_neon_pair_long (void)
17115{
037e8744 17116 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17117 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
17118 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
17119 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 17120 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17121}
17122
17123static void
17124do_neon_recip_est (void)
17125{
037e8744 17126 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 17127 struct neon_type_el et = neon_check_type (2, rs,
cc933301 17128 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 17129 inst.instruction |= (et.type == NT_float) << 8;
037e8744 17130 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17131}
17132
17133static void
17134do_neon_cls (void)
17135{
037e8744 17136 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17137 struct neon_type_el et = neon_check_type (2, rs,
17138 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 17139 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17140}
17141
17142static void
17143do_neon_clz (void)
17144{
037e8744 17145 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17146 struct neon_type_el et = neon_check_type (2, rs,
17147 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 17148 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17149}
17150
17151static void
17152do_neon_cnt (void)
17153{
037e8744 17154 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
17155 struct neon_type_el et = neon_check_type (2, rs,
17156 N_EQK | N_INT, N_8 | N_KEY);
037e8744 17157 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
17158}
17159
17160static void
17161do_neon_swp (void)
17162{
037e8744
JB
17163 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
17164 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
17165}
17166
17167static void
17168do_neon_tbl_tbx (void)
17169{
17170 unsigned listlenbits;
dcbf9037 17171 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 17172
5287ad62
JB
17173 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
17174 {
dcbf9037 17175 first_error (_("bad list length for table lookup"));
5287ad62
JB
17176 return;
17177 }
5f4273c7 17178
5287ad62
JB
17179 listlenbits = inst.operands[1].imm - 1;
17180 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17181 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17182 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17183 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17184 inst.instruction |= LOW4 (inst.operands[2].reg);
17185 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
17186 inst.instruction |= listlenbits << 8;
5f4273c7 17187
88714cb8 17188 neon_dp_fixup (&inst);
5287ad62
JB
17189}
17190
17191static void
17192do_neon_ldm_stm (void)
17193{
17194 /* P, U and L bits are part of bitmask. */
17195 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
17196 unsigned offsetbits = inst.operands[1].imm * 2;
17197
037e8744
JB
17198 if (inst.operands[1].issingle)
17199 {
17200 do_vfp_nsyn_ldm_stm (is_dbmode);
17201 return;
17202 }
17203
5287ad62 17204 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 17205 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
17206
17207 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
17208 _("register list must contain at least 1 and at most 16 "
17209 "registers"));
5287ad62
JB
17210
17211 inst.instruction |= inst.operands[0].reg << 16;
17212 inst.instruction |= inst.operands[0].writeback << 21;
17213 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
17214 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
17215
17216 inst.instruction |= offsetbits;
5f4273c7 17217
037e8744 17218 do_vfp_cond_or_thumb ();
5287ad62
JB
17219}
17220
17221static void
17222do_neon_ldr_str (void)
17223{
5287ad62 17224 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 17225
6844b2c2
MGD
17226 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
17227 And is UNPREDICTABLE in thumb mode. */
fa94de6b 17228 if (!is_ldr
6844b2c2 17229 && inst.operands[1].reg == REG_PC
ba86b375 17230 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 17231 {
94dcf8bf 17232 if (thumb_mode)
6844b2c2 17233 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 17234 else if (warn_on_deprecated)
5c3696f8 17235 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
17236 }
17237
037e8744
JB
17238 if (inst.operands[0].issingle)
17239 {
cd2f129f 17240 if (is_ldr)
477330fc 17241 do_vfp_nsyn_opcode ("flds");
cd2f129f 17242 else
477330fc 17243 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
17244
17245 /* ARMv8.2 vldr.16/vstr.16 instruction. */
17246 if (inst.vectype.el[0].size == 16)
17247 do_scalar_fp16_v82_encode ();
5287ad62
JB
17248 }
17249 else
5287ad62 17250 {
cd2f129f 17251 if (is_ldr)
477330fc 17252 do_vfp_nsyn_opcode ("fldd");
5287ad62 17253 else
477330fc 17254 do_vfp_nsyn_opcode ("fstd");
5287ad62 17255 }
5287ad62
JB
17256}
17257
17258/* "interleave" version also handles non-interleaving register VLD1/VST1
17259 instructions. */
17260
17261static void
17262do_neon_ld_st_interleave (void)
17263{
037e8744 17264 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 17265 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
17266 unsigned alignbits = 0;
17267 unsigned idx;
17268 /* The bits in this table go:
17269 0: register stride of one (0) or two (1)
17270 1,2: register list length, minus one (1, 2, 3, 4).
17271 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
17272 We use -1 for invalid entries. */
17273 const int typetable[] =
17274 {
17275 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
17276 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
17277 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
17278 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
17279 };
17280 int typebits;
17281
dcbf9037
JB
17282 if (et.type == NT_invtype)
17283 return;
17284
5287ad62
JB
17285 if (inst.operands[1].immisalign)
17286 switch (inst.operands[1].imm >> 8)
17287 {
17288 case 64: alignbits = 1; break;
17289 case 128:
477330fc 17290 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 17291 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
17292 goto bad_alignment;
17293 alignbits = 2;
17294 break;
5287ad62 17295 case 256:
477330fc
RM
17296 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
17297 goto bad_alignment;
17298 alignbits = 3;
17299 break;
5287ad62
JB
17300 default:
17301 bad_alignment:
477330fc
RM
17302 first_error (_("bad alignment"));
17303 return;
5287ad62
JB
17304 }
17305
17306 inst.instruction |= alignbits << 4;
17307 inst.instruction |= neon_logbits (et.size) << 6;
17308
17309 /* Bits [4:6] of the immediate in a list specifier encode register stride
17310 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
17311 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
17312 up the right value for "type" in a table based on this value and the given
17313 list style, then stick it back. */
17314 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 17315 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
17316
17317 typebits = typetable[idx];
5f4273c7 17318
5287ad62 17319 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
17320 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
17321 _("bad element type for instruction"));
5287ad62
JB
17322
17323 inst.instruction &= ~0xf00;
17324 inst.instruction |= typebits << 8;
17325}
17326
17327/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
17328 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
17329 otherwise. The variable arguments are a list of pairs of legal (size, align)
17330 values, terminated with -1. */
17331
17332static int
aa8a0863 17333neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
17334{
17335 va_list ap;
17336 int result = FAIL, thissize, thisalign;
5f4273c7 17337
5287ad62
JB
17338 if (!inst.operands[1].immisalign)
17339 {
aa8a0863 17340 *do_alignment = 0;
5287ad62
JB
17341 return SUCCESS;
17342 }
5f4273c7 17343
aa8a0863 17344 va_start (ap, do_alignment);
5287ad62
JB
17345
17346 do
17347 {
17348 thissize = va_arg (ap, int);
17349 if (thissize == -1)
477330fc 17350 break;
5287ad62
JB
17351 thisalign = va_arg (ap, int);
17352
17353 if (size == thissize && align == thisalign)
477330fc 17354 result = SUCCESS;
5287ad62
JB
17355 }
17356 while (result != SUCCESS);
17357
17358 va_end (ap);
17359
17360 if (result == SUCCESS)
aa8a0863 17361 *do_alignment = 1;
5287ad62 17362 else
dcbf9037 17363 first_error (_("unsupported alignment for instruction"));
5f4273c7 17364
5287ad62
JB
17365 return result;
17366}
17367
17368static void
17369do_neon_ld_st_lane (void)
17370{
037e8744 17371 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17372 int align_good, do_alignment = 0;
5287ad62
JB
17373 int logsize = neon_logbits (et.size);
17374 int align = inst.operands[1].imm >> 8;
17375 int n = (inst.instruction >> 8) & 3;
17376 int max_el = 64 / et.size;
5f4273c7 17377
dcbf9037
JB
17378 if (et.type == NT_invtype)
17379 return;
5f4273c7 17380
5287ad62 17381 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 17382 _("bad list length"));
5287ad62 17383 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 17384 _("scalar index out of range"));
5287ad62 17385 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
17386 && et.size == 8,
17387 _("stride of 2 unavailable when element size is 8"));
5f4273c7 17388
5287ad62
JB
17389 switch (n)
17390 {
17391 case 0: /* VLD1 / VST1. */
aa8a0863 17392 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 17393 32, 32, -1);
5287ad62 17394 if (align_good == FAIL)
477330fc 17395 return;
aa8a0863 17396 if (do_alignment)
477330fc
RM
17397 {
17398 unsigned alignbits = 0;
17399 switch (et.size)
17400 {
17401 case 16: alignbits = 0x1; break;
17402 case 32: alignbits = 0x3; break;
17403 default: ;
17404 }
17405 inst.instruction |= alignbits << 4;
17406 }
5287ad62
JB
17407 break;
17408
17409 case 1: /* VLD2 / VST2. */
aa8a0863
TS
17410 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
17411 16, 32, 32, 64, -1);
5287ad62 17412 if (align_good == FAIL)
477330fc 17413 return;
aa8a0863 17414 if (do_alignment)
477330fc 17415 inst.instruction |= 1 << 4;
5287ad62
JB
17416 break;
17417
17418 case 2: /* VLD3 / VST3. */
17419 constraint (inst.operands[1].immisalign,
477330fc 17420 _("can't use alignment with this instruction"));
5287ad62
JB
17421 break;
17422
17423 case 3: /* VLD4 / VST4. */
aa8a0863 17424 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 17425 16, 64, 32, 64, 32, 128, -1);
5287ad62 17426 if (align_good == FAIL)
477330fc 17427 return;
aa8a0863 17428 if (do_alignment)
477330fc
RM
17429 {
17430 unsigned alignbits = 0;
17431 switch (et.size)
17432 {
17433 case 8: alignbits = 0x1; break;
17434 case 16: alignbits = 0x1; break;
17435 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
17436 default: ;
17437 }
17438 inst.instruction |= alignbits << 4;
17439 }
5287ad62
JB
17440 break;
17441
17442 default: ;
17443 }
17444
17445 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
17446 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17447 inst.instruction |= 1 << (4 + logsize);
5f4273c7 17448
5287ad62
JB
17449 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
17450 inst.instruction |= logsize << 10;
17451}
17452
17453/* Encode single n-element structure to all lanes VLD<n> instructions. */
17454
17455static void
17456do_neon_ld_dup (void)
17457{
037e8744 17458 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17459 int align_good, do_alignment = 0;
5287ad62 17460
dcbf9037
JB
17461 if (et.type == NT_invtype)
17462 return;
17463
5287ad62
JB
17464 switch ((inst.instruction >> 8) & 3)
17465 {
17466 case 0: /* VLD1. */
9c2799c2 17467 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 17468 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 17469 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 17470 if (align_good == FAIL)
477330fc 17471 return;
5287ad62 17472 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
17473 {
17474 case 1: break;
17475 case 2: inst.instruction |= 1 << 5; break;
17476 default: first_error (_("bad list length")); return;
17477 }
5287ad62
JB
17478 inst.instruction |= neon_logbits (et.size) << 6;
17479 break;
17480
17481 case 1: /* VLD2. */
17482 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
17483 &do_alignment, 8, 16, 16, 32, 32, 64,
17484 -1);
5287ad62 17485 if (align_good == FAIL)
477330fc 17486 return;
5287ad62 17487 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 17488 _("bad list length"));
5287ad62 17489 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17490 inst.instruction |= 1 << 5;
5287ad62
JB
17491 inst.instruction |= neon_logbits (et.size) << 6;
17492 break;
17493
17494 case 2: /* VLD3. */
17495 constraint (inst.operands[1].immisalign,
477330fc 17496 _("can't use alignment with this instruction"));
5287ad62 17497 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 17498 _("bad list length"));
5287ad62 17499 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17500 inst.instruction |= 1 << 5;
5287ad62
JB
17501 inst.instruction |= neon_logbits (et.size) << 6;
17502 break;
17503
17504 case 3: /* VLD4. */
17505 {
477330fc 17506 int align = inst.operands[1].imm >> 8;
aa8a0863 17507 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17508 16, 64, 32, 64, 32, 128, -1);
17509 if (align_good == FAIL)
17510 return;
17511 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17512 _("bad list length"));
17513 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17514 inst.instruction |= 1 << 5;
17515 if (et.size == 32 && align == 128)
17516 inst.instruction |= 0x3 << 6;
17517 else
17518 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
17519 }
17520 break;
17521
17522 default: ;
17523 }
17524
aa8a0863 17525 inst.instruction |= do_alignment << 4;
5287ad62
JB
17526}
17527
17528/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17529 apart from bits [11:4]. */
17530
17531static void
17532do_neon_ldx_stx (void)
17533{
b1a769ed
DG
17534 if (inst.operands[1].isreg)
17535 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17536
5287ad62
JB
17537 switch (NEON_LANE (inst.operands[0].imm))
17538 {
17539 case NEON_INTERLEAVE_LANES:
88714cb8 17540 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
17541 do_neon_ld_st_interleave ();
17542 break;
5f4273c7 17543
5287ad62 17544 case NEON_ALL_LANES:
88714cb8 17545 NEON_ENCODE (DUP, inst);
2d51fb74
JB
17546 if (inst.instruction == N_INV)
17547 {
17548 first_error ("only loads support such operands");
17549 break;
17550 }
5287ad62
JB
17551 do_neon_ld_dup ();
17552 break;
5f4273c7 17553
5287ad62 17554 default:
88714cb8 17555 NEON_ENCODE (LANE, inst);
5287ad62
JB
17556 do_neon_ld_st_lane ();
17557 }
17558
17559 /* L bit comes from bit mask. */
17560 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17561 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17562 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17563
5287ad62
JB
17564 if (inst.operands[1].postind)
17565 {
17566 int postreg = inst.operands[1].imm & 0xf;
17567 constraint (!inst.operands[1].immisreg,
477330fc 17568 _("post-index must be a register"));
5287ad62 17569 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17570 _("bad register for post-index"));
5287ad62
JB
17571 inst.instruction |= postreg;
17572 }
4f2374c7 17573 else
5287ad62 17574 {
4f2374c7 17575 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
e2b0ab59
AV
17576 constraint (inst.relocs[0].exp.X_op != O_constant
17577 || inst.relocs[0].exp.X_add_number != 0,
4f2374c7
WN
17578 BAD_ADDR_MODE);
17579
17580 if (inst.operands[1].writeback)
17581 {
17582 inst.instruction |= 0xd;
17583 }
17584 else
17585 inst.instruction |= 0xf;
5287ad62 17586 }
5f4273c7 17587
5287ad62
JB
17588 if (thumb_mode)
17589 inst.instruction |= 0xf9000000;
17590 else
17591 inst.instruction |= 0xf4000000;
17592}
33399f07
MGD
17593
17594/* FP v8. */
17595static void
17596do_vfp_nsyn_fpv8 (enum neon_shape rs)
17597{
a715796b
TG
17598 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17599 D register operands. */
17600 if (neon_shape_class[rs] == SC_DOUBLE)
17601 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17602 _(BAD_FPU));
17603
33399f07
MGD
17604 NEON_ENCODE (FPV8, inst);
17605
9db2f6b4
RL
17606 if (rs == NS_FFF || rs == NS_HHH)
17607 {
17608 do_vfp_sp_dyadic ();
17609
17610 /* ARMv8.2 fp16 instruction. */
17611 if (rs == NS_HHH)
17612 do_scalar_fp16_v82_encode ();
17613 }
33399f07
MGD
17614 else
17615 do_vfp_dp_rd_rn_rm ();
17616
17617 if (rs == NS_DDD)
17618 inst.instruction |= 0x100;
17619
17620 inst.instruction |= 0xf0000000;
17621}
17622
17623static void
17624do_vsel (void)
17625{
17626 set_it_insn_type (OUTSIDE_IT_INSN);
17627
17628 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17629 first_error (_("invalid instruction shape"));
17630}
17631
73924fbc
MGD
17632static void
17633do_vmaxnm (void)
17634{
17635 set_it_insn_type (OUTSIDE_IT_INSN);
17636
17637 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17638 return;
17639
17640 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17641 return;
17642
cc933301 17643 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17644}
17645
30bdf752
MGD
17646static void
17647do_vrint_1 (enum neon_cvt_mode mode)
17648{
9db2f6b4 17649 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17650 struct neon_type_el et;
17651
17652 if (rs == NS_NULL)
17653 return;
17654
a715796b
TG
17655 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17656 D register operands. */
17657 if (neon_shape_class[rs] == SC_DOUBLE)
17658 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17659 _(BAD_FPU));
17660
9db2f6b4
RL
17661 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17662 | N_VFP);
30bdf752
MGD
17663 if (et.type != NT_invtype)
17664 {
17665 /* VFP encodings. */
17666 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17667 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17668 set_it_insn_type (OUTSIDE_IT_INSN);
17669
17670 NEON_ENCODE (FPV8, inst);
9db2f6b4 17671 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17672 do_vfp_sp_monadic ();
17673 else
17674 do_vfp_dp_rd_rm ();
17675
17676 switch (mode)
17677 {
17678 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17679 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17680 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17681 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17682 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17683 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17684 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17685 default: abort ();
17686 }
17687
17688 inst.instruction |= (rs == NS_DD) << 8;
17689 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17690
17691 /* ARMv8.2 fp16 vrint instruction. */
17692 if (rs == NS_HH)
17693 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17694 }
17695 else
17696 {
17697 /* Neon encodings (or something broken...). */
17698 inst.error = NULL;
cc933301 17699 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17700
17701 if (et.type == NT_invtype)
17702 return;
17703
17704 set_it_insn_type (OUTSIDE_IT_INSN);
17705 NEON_ENCODE (FLOAT, inst);
17706
17707 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17708 return;
17709
17710 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17711 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17712 inst.instruction |= LOW4 (inst.operands[1].reg);
17713 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17714 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17715 /* Mask off the original size bits and reencode them. */
17716 inst.instruction = ((inst.instruction & 0xfff3ffff)
17717 | neon_logbits (et.size) << 18);
17718
30bdf752
MGD
17719 switch (mode)
17720 {
17721 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17722 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17723 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17724 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17725 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17726 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17727 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17728 default: abort ();
17729 }
17730
17731 if (thumb_mode)
17732 inst.instruction |= 0xfc000000;
17733 else
17734 inst.instruction |= 0xf0000000;
17735 }
17736}
17737
17738static void
17739do_vrintx (void)
17740{
17741 do_vrint_1 (neon_cvt_mode_x);
17742}
17743
17744static void
17745do_vrintz (void)
17746{
17747 do_vrint_1 (neon_cvt_mode_z);
17748}
17749
17750static void
17751do_vrintr (void)
17752{
17753 do_vrint_1 (neon_cvt_mode_r);
17754}
17755
17756static void
17757do_vrinta (void)
17758{
17759 do_vrint_1 (neon_cvt_mode_a);
17760}
17761
17762static void
17763do_vrintn (void)
17764{
17765 do_vrint_1 (neon_cvt_mode_n);
17766}
17767
17768static void
17769do_vrintp (void)
17770{
17771 do_vrint_1 (neon_cvt_mode_p);
17772}
17773
17774static void
17775do_vrintm (void)
17776{
17777 do_vrint_1 (neon_cvt_mode_m);
17778}
17779
c28eeff2
SN
17780static unsigned
17781neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17782{
17783 unsigned regno = NEON_SCALAR_REG (opnd);
17784 unsigned elno = NEON_SCALAR_INDEX (opnd);
17785
17786 if (elsize == 16 && elno < 2 && regno < 16)
17787 return regno | (elno << 4);
17788 else if (elsize == 32 && elno == 0)
17789 return regno;
17790
17791 first_error (_("scalar out of range"));
17792 return 0;
17793}
17794
17795static void
17796do_vcmla (void)
17797{
17798 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17799 _(BAD_FPU));
e2b0ab59
AV
17800 constraint (inst.relocs[0].exp.X_op != O_constant,
17801 _("expression too complex"));
17802 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
17803 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17804 _("immediate out of range"));
17805 rot /= 90;
17806 if (inst.operands[2].isscalar)
17807 {
17808 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17809 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17810 N_KEY | N_F16 | N_F32).size;
17811 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17812 inst.is_neon = 1;
17813 inst.instruction = 0xfe000800;
17814 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17815 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17816 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17817 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17818 inst.instruction |= LOW4 (m);
17819 inst.instruction |= HI1 (m) << 5;
17820 inst.instruction |= neon_quad (rs) << 6;
17821 inst.instruction |= rot << 20;
17822 inst.instruction |= (size == 32) << 23;
17823 }
17824 else
17825 {
17826 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17827 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17828 N_KEY | N_F16 | N_F32).size;
17829 neon_three_same (neon_quad (rs), 0, -1);
17830 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17831 inst.instruction |= 0xfc200800;
17832 inst.instruction |= rot << 23;
17833 inst.instruction |= (size == 32) << 20;
17834 }
17835}
17836
17837static void
17838do_vcadd (void)
17839{
17840 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17841 _(BAD_FPU));
e2b0ab59
AV
17842 constraint (inst.relocs[0].exp.X_op != O_constant,
17843 _("expression too complex"));
17844 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
17845 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17846 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17847 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17848 N_KEY | N_F16 | N_F32).size;
17849 neon_three_same (neon_quad (rs), 0, -1);
17850 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17851 inst.instruction |= 0xfc800800;
17852 inst.instruction |= (rot == 270) << 24;
17853 inst.instruction |= (size == 32) << 20;
17854}
17855
c604a79a
JW
17856/* Dot Product instructions encoding support. */
17857
17858static void
17859do_neon_dotproduct (int unsigned_p)
17860{
17861 enum neon_shape rs;
17862 unsigned scalar_oprd2 = 0;
17863 int high8;
17864
17865 if (inst.cond != COND_ALWAYS)
17866 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
17867 "is UNPREDICTABLE"));
17868
17869 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17870 _(BAD_FPU));
17871
17872 /* Dot Product instructions are in three-same D/Q register format or the third
17873 operand can be a scalar index register. */
17874 if (inst.operands[2].isscalar)
17875 {
17876 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
17877 high8 = 0xfe000000;
17878 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17879 }
17880 else
17881 {
17882 high8 = 0xfc000000;
17883 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17884 }
17885
17886 if (unsigned_p)
17887 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
17888 else
17889 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
17890
17891 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
17892 Product instruction, so we pass 0 as the "ubit" parameter. And the
17893 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
17894 neon_three_same (neon_quad (rs), 0, 32);
17895
17896 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
17897 different NEON three-same encoding. */
17898 inst.instruction &= 0x00ffffff;
17899 inst.instruction |= high8;
17900 /* Encode 'U' bit which indicates signedness. */
17901 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
17902 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
17903 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
17904 the instruction encoding. */
17905 if (inst.operands[2].isscalar)
17906 {
17907 inst.instruction &= 0xffffffd0;
17908 inst.instruction |= LOW4 (scalar_oprd2);
17909 inst.instruction |= HI1 (scalar_oprd2) << 5;
17910 }
17911}
17912
17913/* Dot Product instructions for signed integer. */
17914
17915static void
17916do_neon_dotproduct_s (void)
17917{
17918 return do_neon_dotproduct (0);
17919}
17920
17921/* Dot Product instructions for unsigned integer. */
17922
17923static void
17924do_neon_dotproduct_u (void)
17925{
17926 return do_neon_dotproduct (1);
17927}
17928
91ff7894
MGD
17929/* Crypto v1 instructions. */
17930static void
17931do_crypto_2op_1 (unsigned elttype, int op)
17932{
17933 set_it_insn_type (OUTSIDE_IT_INSN);
17934
17935 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17936 == NT_invtype)
17937 return;
17938
17939 inst.error = NULL;
17940
17941 NEON_ENCODE (INTEGER, inst);
17942 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17943 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17944 inst.instruction |= LOW4 (inst.operands[1].reg);
17945 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17946 if (op != -1)
17947 inst.instruction |= op << 6;
17948
17949 if (thumb_mode)
17950 inst.instruction |= 0xfc000000;
17951 else
17952 inst.instruction |= 0xf0000000;
17953}
17954
48adcd8e
MGD
17955static void
17956do_crypto_3op_1 (int u, int op)
17957{
17958 set_it_insn_type (OUTSIDE_IT_INSN);
17959
17960 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17961 N_32 | N_UNT | N_KEY).type == NT_invtype)
17962 return;
17963
17964 inst.error = NULL;
17965
17966 NEON_ENCODE (INTEGER, inst);
17967 neon_three_same (1, u, 8 << op);
17968}
17969
91ff7894
MGD
17970static void
17971do_aese (void)
17972{
17973 do_crypto_2op_1 (N_8, 0);
17974}
17975
17976static void
17977do_aesd (void)
17978{
17979 do_crypto_2op_1 (N_8, 1);
17980}
17981
17982static void
17983do_aesmc (void)
17984{
17985 do_crypto_2op_1 (N_8, 2);
17986}
17987
17988static void
17989do_aesimc (void)
17990{
17991 do_crypto_2op_1 (N_8, 3);
17992}
17993
48adcd8e
MGD
17994static void
17995do_sha1c (void)
17996{
17997 do_crypto_3op_1 (0, 0);
17998}
17999
18000static void
18001do_sha1p (void)
18002{
18003 do_crypto_3op_1 (0, 1);
18004}
18005
18006static void
18007do_sha1m (void)
18008{
18009 do_crypto_3op_1 (0, 2);
18010}
18011
18012static void
18013do_sha1su0 (void)
18014{
18015 do_crypto_3op_1 (0, 3);
18016}
91ff7894 18017
48adcd8e
MGD
18018static void
18019do_sha256h (void)
18020{
18021 do_crypto_3op_1 (1, 0);
18022}
18023
18024static void
18025do_sha256h2 (void)
18026{
18027 do_crypto_3op_1 (1, 1);
18028}
18029
18030static void
18031do_sha256su1 (void)
18032{
18033 do_crypto_3op_1 (1, 2);
18034}
3c9017d2
MGD
18035
18036static void
18037do_sha1h (void)
18038{
18039 do_crypto_2op_1 (N_32, -1);
18040}
18041
18042static void
18043do_sha1su1 (void)
18044{
18045 do_crypto_2op_1 (N_32, 0);
18046}
18047
18048static void
18049do_sha256su0 (void)
18050{
18051 do_crypto_2op_1 (N_32, 1);
18052}
dd5181d5
KT
18053
18054static void
18055do_crc32_1 (unsigned int poly, unsigned int sz)
18056{
18057 unsigned int Rd = inst.operands[0].reg;
18058 unsigned int Rn = inst.operands[1].reg;
18059 unsigned int Rm = inst.operands[2].reg;
18060
18061 set_it_insn_type (OUTSIDE_IT_INSN);
18062 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
18063 inst.instruction |= LOW4 (Rn) << 16;
18064 inst.instruction |= LOW4 (Rm);
18065 inst.instruction |= sz << (thumb_mode ? 4 : 21);
18066 inst.instruction |= poly << (thumb_mode ? 20 : 9);
18067
18068 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
18069 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
18070}
18071
18072static void
18073do_crc32b (void)
18074{
18075 do_crc32_1 (0, 0);
18076}
18077
18078static void
18079do_crc32h (void)
18080{
18081 do_crc32_1 (0, 1);
18082}
18083
18084static void
18085do_crc32w (void)
18086{
18087 do_crc32_1 (0, 2);
18088}
18089
18090static void
18091do_crc32cb (void)
18092{
18093 do_crc32_1 (1, 0);
18094}
18095
18096static void
18097do_crc32ch (void)
18098{
18099 do_crc32_1 (1, 1);
18100}
18101
18102static void
18103do_crc32cw (void)
18104{
18105 do_crc32_1 (1, 2);
18106}
18107
49e8a725
SN
18108static void
18109do_vjcvt (void)
18110{
18111 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18112 _(BAD_FPU));
18113 neon_check_type (2, NS_FD, N_S32, N_F64);
18114 do_vfp_sp_dp_cvt ();
18115 do_vfp_cond_or_thumb ();
18116}
18117
5287ad62
JB
18118\f
18119/* Overall per-instruction processing. */
18120
18121/* We need to be able to fix up arbitrary expressions in some statements.
18122 This is so that we can handle symbols that are an arbitrary distance from
18123 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
18124 which returns part of an address in a form which will be valid for
18125 a data instruction. We do this by pushing the expression into a symbol
18126 in the expr_section, and creating a fix for that. */
18127
18128static void
18129fix_new_arm (fragS * frag,
18130 int where,
18131 short int size,
18132 expressionS * exp,
18133 int pc_rel,
18134 int reloc)
18135{
18136 fixS * new_fix;
18137
18138 switch (exp->X_op)
18139 {
18140 case O_constant:
6e7ce2cd
PB
18141 if (pc_rel)
18142 {
18143 /* Create an absolute valued symbol, so we have something to
477330fc
RM
18144 refer to in the object file. Unfortunately for us, gas's
18145 generic expression parsing will already have folded out
18146 any use of .set foo/.type foo %function that may have
18147 been used to set type information of the target location,
18148 that's being specified symbolically. We have to presume
18149 the user knows what they are doing. */
6e7ce2cd
PB
18150 char name[16 + 8];
18151 symbolS *symbol;
18152
18153 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
18154
18155 symbol = symbol_find_or_make (name);
18156 S_SET_SEGMENT (symbol, absolute_section);
18157 symbol_set_frag (symbol, &zero_address_frag);
18158 S_SET_VALUE (symbol, exp->X_add_number);
18159 exp->X_op = O_symbol;
18160 exp->X_add_symbol = symbol;
18161 exp->X_add_number = 0;
18162 }
18163 /* FALLTHROUGH */
5287ad62
JB
18164 case O_symbol:
18165 case O_add:
18166 case O_subtract:
21d799b5 18167 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 18168 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
18169 break;
18170
18171 default:
21d799b5 18172 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 18173 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
18174 break;
18175 }
18176
18177 /* Mark whether the fix is to a THUMB instruction, or an ARM
18178 instruction. */
18179 new_fix->tc_fix_data = thumb_mode;
18180}
18181
18182/* Create a frg for an instruction requiring relaxation. */
18183static void
18184output_relax_insn (void)
18185{
18186 char * to;
18187 symbolS *sym;
0110f2b8
PB
18188 int offset;
18189
6e1cb1a6
PB
18190 /* The size of the instruction is unknown, so tie the debug info to the
18191 start of the instruction. */
18192 dwarf2_emit_insn (0);
6e1cb1a6 18193
e2b0ab59 18194 switch (inst.relocs[0].exp.X_op)
0110f2b8
PB
18195 {
18196 case O_symbol:
e2b0ab59
AV
18197 sym = inst.relocs[0].exp.X_add_symbol;
18198 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
18199 break;
18200 case O_constant:
18201 sym = NULL;
e2b0ab59 18202 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
18203 break;
18204 default:
e2b0ab59 18205 sym = make_expr_symbol (&inst.relocs[0].exp);
0110f2b8
PB
18206 offset = 0;
18207 break;
18208 }
18209 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
18210 inst.relax, sym, offset, NULL/*offset, opcode*/);
18211 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
18212}
18213
18214/* Write a 32-bit thumb instruction to buf. */
18215static void
18216put_thumb32_insn (char * buf, unsigned long insn)
18217{
18218 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
18219 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
18220}
18221
b99bd4ef 18222static void
c19d1205 18223output_inst (const char * str)
b99bd4ef 18224{
c19d1205 18225 char * to = NULL;
b99bd4ef 18226
c19d1205 18227 if (inst.error)
b99bd4ef 18228 {
c19d1205 18229 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
18230 return;
18231 }
5f4273c7
NC
18232 if (inst.relax)
18233 {
18234 output_relax_insn ();
0110f2b8 18235 return;
5f4273c7 18236 }
c19d1205
ZW
18237 if (inst.size == 0)
18238 return;
b99bd4ef 18239
c19d1205 18240 to = frag_more (inst.size);
8dc2430f
NC
18241 /* PR 9814: Record the thumb mode into the current frag so that we know
18242 what type of NOP padding to use, if necessary. We override any previous
18243 setting so that if the mode has changed then the NOPS that we use will
18244 match the encoding of the last instruction in the frag. */
cd000bff 18245 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
18246
18247 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 18248 {
9c2799c2 18249 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 18250 put_thumb32_insn (to, inst.instruction);
b99bd4ef 18251 }
c19d1205 18252 else if (inst.size > INSN_SIZE)
b99bd4ef 18253 {
9c2799c2 18254 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
18255 md_number_to_chars (to, inst.instruction, INSN_SIZE);
18256 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 18257 }
c19d1205
ZW
18258 else
18259 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 18260
e2b0ab59
AV
18261 int r;
18262 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
18263 {
18264 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
18265 fix_new_arm (frag_now, to - frag_now->fr_literal,
18266 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
18267 inst.relocs[r].type);
18268 }
b99bd4ef 18269
c19d1205 18270 dwarf2_emit_insn (inst.size);
c19d1205 18271}
b99bd4ef 18272
e07e6e58
NC
18273static char *
18274output_it_inst (int cond, int mask, char * to)
18275{
18276 unsigned long instruction = 0xbf00;
18277
18278 mask &= 0xf;
18279 instruction |= mask;
18280 instruction |= cond << 4;
18281
18282 if (to == NULL)
18283 {
18284 to = frag_more (2);
18285#ifdef OBJ_ELF
18286 dwarf2_emit_insn (2);
18287#endif
18288 }
18289
18290 md_number_to_chars (to, instruction, 2);
18291
18292 return to;
18293}
18294
c19d1205
ZW
18295/* Tag values used in struct asm_opcode's tag field. */
18296enum opcode_tag
18297{
18298 OT_unconditional, /* Instruction cannot be conditionalized.
18299 The ARM condition field is still 0xE. */
18300 OT_unconditionalF, /* Instruction cannot be conditionalized
18301 and carries 0xF in its ARM condition field. */
18302 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 18303 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
18304 suffix, others place 0xF where the condition field
18305 would be. */
c19d1205
ZW
18306 OT_cinfix3, /* Instruction takes a conditional infix,
18307 beginning at character index 3. (In
18308 unified mode, it becomes a suffix.) */
088fa78e
KH
18309 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
18310 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
18311 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
18312 character index 3, even in unified mode. Used for
18313 legacy instructions where suffix and infix forms
18314 may be ambiguous. */
c19d1205 18315 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 18316 suffix or an infix at character index 3. */
c19d1205
ZW
18317 OT_odd_infix_unc, /* This is the unconditional variant of an
18318 instruction that takes a conditional infix
18319 at an unusual position. In unified mode,
18320 this variant will accept a suffix. */
18321 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
18322 are the conditional variants of instructions that
18323 take conditional infixes in unusual positions.
18324 The infix appears at character index
18325 (tag - OT_odd_infix_0). These are not accepted
18326 in unified mode. */
18327};
b99bd4ef 18328
c19d1205
ZW
18329/* Subroutine of md_assemble, responsible for looking up the primary
18330 opcode from the mnemonic the user wrote. STR points to the
18331 beginning of the mnemonic.
18332
18333 This is not simply a hash table lookup, because of conditional
18334 variants. Most instructions have conditional variants, which are
18335 expressed with a _conditional affix_ to the mnemonic. If we were
18336 to encode each conditional variant as a literal string in the opcode
18337 table, it would have approximately 20,000 entries.
18338
18339 Most mnemonics take this affix as a suffix, and in unified syntax,
18340 'most' is upgraded to 'all'. However, in the divided syntax, some
18341 instructions take the affix as an infix, notably the s-variants of
18342 the arithmetic instructions. Of those instructions, all but six
18343 have the infix appear after the third character of the mnemonic.
18344
18345 Accordingly, the algorithm for looking up primary opcodes given
18346 an identifier is:
18347
18348 1. Look up the identifier in the opcode table.
18349 If we find a match, go to step U.
18350
18351 2. Look up the last two characters of the identifier in the
18352 conditions table. If we find a match, look up the first N-2
18353 characters of the identifier in the opcode table. If we
18354 find a match, go to step CE.
18355
18356 3. Look up the fourth and fifth characters of the identifier in
18357 the conditions table. If we find a match, extract those
18358 characters from the identifier, and look up the remaining
18359 characters in the opcode table. If we find a match, go
18360 to step CM.
18361
18362 4. Fail.
18363
18364 U. Examine the tag field of the opcode structure, in case this is
18365 one of the six instructions with its conditional infix in an
18366 unusual place. If it is, the tag tells us where to find the
18367 infix; look it up in the conditions table and set inst.cond
18368 accordingly. Otherwise, this is an unconditional instruction.
18369 Again set inst.cond accordingly. Return the opcode structure.
18370
18371 CE. Examine the tag field to make sure this is an instruction that
18372 should receive a conditional suffix. If it is not, fail.
18373 Otherwise, set inst.cond from the suffix we already looked up,
18374 and return the opcode structure.
18375
18376 CM. Examine the tag field to make sure this is an instruction that
18377 should receive a conditional infix after the third character.
18378 If it is not, fail. Otherwise, undo the edits to the current
18379 line of input and proceed as for case CE. */
18380
18381static const struct asm_opcode *
18382opcode_lookup (char **str)
18383{
18384 char *end, *base;
18385 char *affix;
18386 const struct asm_opcode *opcode;
18387 const struct asm_cond *cond;
e3cb604e 18388 char save[2];
c19d1205
ZW
18389
18390 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 18391 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 18392 for (base = end = *str; *end != '\0'; end++)
721a8186 18393 if (*end == ' ' || *end == '.')
c19d1205 18394 break;
b99bd4ef 18395
c19d1205 18396 if (end == base)
c921be7d 18397 return NULL;
b99bd4ef 18398
5287ad62 18399 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 18400 if (end[0] == '.')
b99bd4ef 18401 {
5287ad62 18402 int offset = 2;
5f4273c7 18403
267d2029 18404 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 18405 use. */
267d2029 18406 if (unified_syntax && end[1] == 'w')
c19d1205 18407 inst.size_req = 4;
267d2029 18408 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
18409 inst.size_req = 2;
18410 else
477330fc 18411 offset = 0;
5287ad62
JB
18412
18413 inst.vectype.elems = 0;
18414
18415 *str = end + offset;
b99bd4ef 18416
5f4273c7 18417 if (end[offset] == '.')
5287ad62 18418 {
267d2029 18419 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
18420 non-unified ARM syntax mode). */
18421 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 18422 return NULL;
477330fc 18423 }
5287ad62 18424 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 18425 return NULL;
b99bd4ef 18426 }
c19d1205
ZW
18427 else
18428 *str = end;
b99bd4ef 18429
c19d1205 18430 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 18431 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18432 end - base);
c19d1205 18433 if (opcode)
b99bd4ef 18434 {
c19d1205
ZW
18435 /* step U */
18436 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 18437 {
c19d1205
ZW
18438 inst.cond = COND_ALWAYS;
18439 return opcode;
b99bd4ef 18440 }
b99bd4ef 18441
278df34e 18442 if (warn_on_deprecated && unified_syntax)
5c3696f8 18443 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 18444 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 18445 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 18446 gas_assert (cond);
b99bd4ef 18447
c19d1205
ZW
18448 inst.cond = cond->value;
18449 return opcode;
18450 }
b99bd4ef 18451
c19d1205
ZW
18452 /* Cannot have a conditional suffix on a mnemonic of less than two
18453 characters. */
18454 if (end - base < 3)
c921be7d 18455 return NULL;
b99bd4ef 18456
c19d1205
ZW
18457 /* Look for suffixed mnemonic. */
18458 affix = end - 2;
21d799b5
NC
18459 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18460 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18461 affix - base);
c19d1205
ZW
18462 if (opcode && cond)
18463 {
18464 /* step CE */
18465 switch (opcode->tag)
18466 {
e3cb604e
PB
18467 case OT_cinfix3_legacy:
18468 /* Ignore conditional suffixes matched on infix only mnemonics. */
18469 break;
18470
c19d1205 18471 case OT_cinfix3:
088fa78e 18472 case OT_cinfix3_deprecated:
c19d1205
ZW
18473 case OT_odd_infix_unc:
18474 if (!unified_syntax)
0198d5e6 18475 return NULL;
1a0670f3 18476 /* Fall through. */
c19d1205
ZW
18477
18478 case OT_csuffix:
477330fc 18479 case OT_csuffixF:
c19d1205
ZW
18480 case OT_csuf_or_in3:
18481 inst.cond = cond->value;
18482 return opcode;
18483
18484 case OT_unconditional:
18485 case OT_unconditionalF:
dfa9f0d5 18486 if (thumb_mode)
c921be7d 18487 inst.cond = cond->value;
dfa9f0d5
PB
18488 else
18489 {
c921be7d 18490 /* Delayed diagnostic. */
dfa9f0d5
PB
18491 inst.error = BAD_COND;
18492 inst.cond = COND_ALWAYS;
18493 }
c19d1205 18494 return opcode;
b99bd4ef 18495
c19d1205 18496 default:
c921be7d 18497 return NULL;
c19d1205
ZW
18498 }
18499 }
b99bd4ef 18500
c19d1205
ZW
18501 /* Cannot have a usual-position infix on a mnemonic of less than
18502 six characters (five would be a suffix). */
18503 if (end - base < 6)
c921be7d 18504 return NULL;
b99bd4ef 18505
c19d1205
ZW
18506 /* Look for infixed mnemonic in the usual position. */
18507 affix = base + 3;
21d799b5 18508 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 18509 if (!cond)
c921be7d 18510 return NULL;
e3cb604e
PB
18511
18512 memcpy (save, affix, 2);
18513 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 18514 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18515 (end - base) - 2);
e3cb604e
PB
18516 memmove (affix + 2, affix, (end - affix) - 2);
18517 memcpy (affix, save, 2);
18518
088fa78e
KH
18519 if (opcode
18520 && (opcode->tag == OT_cinfix3
18521 || opcode->tag == OT_cinfix3_deprecated
18522 || opcode->tag == OT_csuf_or_in3
18523 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 18524 {
c921be7d 18525 /* Step CM. */
278df34e 18526 if (warn_on_deprecated && unified_syntax
088fa78e
KH
18527 && (opcode->tag == OT_cinfix3
18528 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 18529 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
18530
18531 inst.cond = cond->value;
18532 return opcode;
b99bd4ef
NC
18533 }
18534
c921be7d 18535 return NULL;
b99bd4ef
NC
18536}
18537
e07e6e58
NC
18538/* This function generates an initial IT instruction, leaving its block
18539 virtually open for the new instructions. Eventually,
18540 the mask will be updated by now_it_add_mask () each time
18541 a new instruction needs to be included in the IT block.
18542 Finally, the block is closed with close_automatic_it_block ().
18543 The block closure can be requested either from md_assemble (),
18544 a tencode (), or due to a label hook. */
18545
18546static void
18547new_automatic_it_block (int cond)
18548{
18549 now_it.state = AUTOMATIC_IT_BLOCK;
18550 now_it.mask = 0x18;
18551 now_it.cc = cond;
18552 now_it.block_length = 1;
cd000bff 18553 mapping_state (MAP_THUMB);
e07e6e58 18554 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
18555 now_it.warn_deprecated = FALSE;
18556 now_it.insn_cond = TRUE;
e07e6e58
NC
18557}
18558
18559/* Close an automatic IT block.
18560 See comments in new_automatic_it_block (). */
18561
18562static void
18563close_automatic_it_block (void)
18564{
18565 now_it.mask = 0x10;
18566 now_it.block_length = 0;
18567}
18568
18569/* Update the mask of the current automatically-generated IT
18570 instruction. See comments in new_automatic_it_block (). */
18571
18572static void
18573now_it_add_mask (int cond)
18574{
18575#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
18576#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 18577 | ((bitvalue) << (nbit)))
e07e6e58 18578 const int resulting_bit = (cond & 1);
c921be7d 18579
e07e6e58
NC
18580 now_it.mask &= 0xf;
18581 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18582 resulting_bit,
18583 (5 - now_it.block_length));
e07e6e58 18584 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18585 1,
18586 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
18587 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18588
18589#undef CLEAR_BIT
18590#undef SET_BIT_VALUE
e07e6e58
NC
18591}
18592
18593/* The IT blocks handling machinery is accessed through the these functions:
18594 it_fsm_pre_encode () from md_assemble ()
18595 set_it_insn_type () optional, from the tencode functions
18596 set_it_insn_type_last () ditto
18597 in_it_block () ditto
18598 it_fsm_post_encode () from md_assemble ()
33eaf5de 18599 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
18600
18601 Rationale:
18602 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
18603 initializing the IT insn type with a generic initial value depending
18604 on the inst.condition.
e07e6e58 18605 2) During the tencode function, two things may happen:
477330fc
RM
18606 a) The tencode function overrides the IT insn type by
18607 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18608 b) The tencode function queries the IT block state by
18609 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18610
18611 Both set_it_insn_type and in_it_block run the internal FSM state
18612 handling function (handle_it_state), because: a) setting the IT insn
18613 type may incur in an invalid state (exiting the function),
18614 and b) querying the state requires the FSM to be updated.
18615 Specifically we want to avoid creating an IT block for conditional
18616 branches, so it_fsm_pre_encode is actually a guess and we can't
18617 determine whether an IT block is required until the tencode () routine
18618 has decided what type of instruction this actually it.
18619 Because of this, if set_it_insn_type and in_it_block have to be used,
18620 set_it_insn_type has to be called first.
18621
18622 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18623 determines the insn IT type depending on the inst.cond code.
18624 When a tencode () routine encodes an instruction that can be
18625 either outside an IT block, or, in the case of being inside, has to be
18626 the last one, set_it_insn_type_last () will determine the proper
18627 IT instruction type based on the inst.cond code. Otherwise,
18628 set_it_insn_type can be called for overriding that logic or
18629 for covering other cases.
18630
18631 Calling handle_it_state () may not transition the IT block state to
2b0f3761 18632 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
477330fc
RM
18633 still queried. Instead, if the FSM determines that the state should
18634 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18635 after the tencode () function: that's what it_fsm_post_encode () does.
18636
18637 Since in_it_block () calls the state handling function to get an
18638 updated state, an error may occur (due to invalid insns combination).
18639 In that case, inst.error is set.
18640 Therefore, inst.error has to be checked after the execution of
18641 the tencode () routine.
e07e6e58
NC
18642
18643 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
18644 any pending state change (if any) that didn't take place in
18645 handle_it_state () as explained above. */
e07e6e58
NC
18646
18647static void
18648it_fsm_pre_encode (void)
18649{
18650 if (inst.cond != COND_ALWAYS)
18651 inst.it_insn_type = INSIDE_IT_INSN;
18652 else
18653 inst.it_insn_type = OUTSIDE_IT_INSN;
18654
18655 now_it.state_handled = 0;
18656}
18657
18658/* IT state FSM handling function. */
18659
18660static int
18661handle_it_state (void)
18662{
18663 now_it.state_handled = 1;
5a01bb1d 18664 now_it.insn_cond = FALSE;
e07e6e58
NC
18665
18666 switch (now_it.state)
18667 {
18668 case OUTSIDE_IT_BLOCK:
18669 switch (inst.it_insn_type)
18670 {
18671 case OUTSIDE_IT_INSN:
18672 break;
18673
18674 case INSIDE_IT_INSN:
18675 case INSIDE_IT_LAST_INSN:
18676 if (thumb_mode == 0)
18677 {
c921be7d 18678 if (unified_syntax
e07e6e58
NC
18679 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18680 as_tsktsk (_("Warning: conditional outside an IT block"\
18681 " for Thumb."));
18682 }
18683 else
18684 {
18685 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 18686 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
18687 {
18688 /* Automatically generate the IT instruction. */
18689 new_automatic_it_block (inst.cond);
18690 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18691 close_automatic_it_block ();
18692 }
18693 else
18694 {
18695 inst.error = BAD_OUT_IT;
18696 return FAIL;
18697 }
18698 }
18699 break;
18700
18701 case IF_INSIDE_IT_LAST_INSN:
18702 case NEUTRAL_IT_INSN:
18703 break;
18704
18705 case IT_INSN:
18706 now_it.state = MANUAL_IT_BLOCK;
18707 now_it.block_length = 0;
18708 break;
18709 }
18710 break;
18711
18712 case AUTOMATIC_IT_BLOCK:
18713 /* Three things may happen now:
18714 a) We should increment current it block size;
18715 b) We should close current it block (closing insn or 4 insns);
18716 c) We should close current it block and start a new one (due
18717 to incompatible conditions or
18718 4 insns-length block reached). */
18719
18720 switch (inst.it_insn_type)
18721 {
18722 case OUTSIDE_IT_INSN:
2b0f3761 18723 /* The closure of the block shall happen immediately,
e07e6e58
NC
18724 so any in_it_block () call reports the block as closed. */
18725 force_automatic_it_block_close ();
18726 break;
18727
18728 case INSIDE_IT_INSN:
18729 case INSIDE_IT_LAST_INSN:
18730 case IF_INSIDE_IT_LAST_INSN:
18731 now_it.block_length++;
18732
18733 if (now_it.block_length > 4
18734 || !now_it_compatible (inst.cond))
18735 {
18736 force_automatic_it_block_close ();
18737 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18738 new_automatic_it_block (inst.cond);
18739 }
18740 else
18741 {
5a01bb1d 18742 now_it.insn_cond = TRUE;
e07e6e58
NC
18743 now_it_add_mask (inst.cond);
18744 }
18745
18746 if (now_it.state == AUTOMATIC_IT_BLOCK
18747 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18748 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18749 close_automatic_it_block ();
18750 break;
18751
18752 case NEUTRAL_IT_INSN:
18753 now_it.block_length++;
5a01bb1d 18754 now_it.insn_cond = TRUE;
e07e6e58
NC
18755
18756 if (now_it.block_length > 4)
18757 force_automatic_it_block_close ();
18758 else
18759 now_it_add_mask (now_it.cc & 1);
18760 break;
18761
18762 case IT_INSN:
18763 close_automatic_it_block ();
18764 now_it.state = MANUAL_IT_BLOCK;
18765 break;
18766 }
18767 break;
18768
18769 case MANUAL_IT_BLOCK:
18770 {
18771 /* Check conditional suffixes. */
18772 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18773 int is_last;
18774 now_it.mask <<= 1;
18775 now_it.mask &= 0x1f;
18776 is_last = (now_it.mask == 0x10);
5a01bb1d 18777 now_it.insn_cond = TRUE;
e07e6e58
NC
18778
18779 switch (inst.it_insn_type)
18780 {
18781 case OUTSIDE_IT_INSN:
18782 inst.error = BAD_NOT_IT;
18783 return FAIL;
18784
18785 case INSIDE_IT_INSN:
18786 if (cond != inst.cond)
18787 {
18788 inst.error = BAD_IT_COND;
18789 return FAIL;
18790 }
18791 break;
18792
18793 case INSIDE_IT_LAST_INSN:
18794 case IF_INSIDE_IT_LAST_INSN:
18795 if (cond != inst.cond)
18796 {
18797 inst.error = BAD_IT_COND;
18798 return FAIL;
18799 }
18800 if (!is_last)
18801 {
18802 inst.error = BAD_BRANCH;
18803 return FAIL;
18804 }
18805 break;
18806
18807 case NEUTRAL_IT_INSN:
18808 /* The BKPT instruction is unconditional even in an IT block. */
18809 break;
18810
18811 case IT_INSN:
18812 inst.error = BAD_IT_IT;
18813 return FAIL;
18814 }
18815 }
18816 break;
18817 }
18818
18819 return SUCCESS;
18820}
18821
5a01bb1d
MGD
18822struct depr_insn_mask
18823{
18824 unsigned long pattern;
18825 unsigned long mask;
18826 const char* description;
18827};
18828
18829/* List of 16-bit instruction patterns deprecated in an IT block in
18830 ARMv8. */
18831static const struct depr_insn_mask depr_it_insns[] = {
18832 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18833 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18834 { 0xa000, 0xb800, N_("ADR") },
18835 { 0x4800, 0xf800, N_("Literal loads") },
18836 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18837 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18838 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18839 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18840 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18841 { 0, 0, NULL }
18842};
18843
e07e6e58
NC
18844static void
18845it_fsm_post_encode (void)
18846{
18847 int is_last;
18848
18849 if (!now_it.state_handled)
18850 handle_it_state ();
18851
5a01bb1d
MGD
18852 if (now_it.insn_cond
18853 && !now_it.warn_deprecated
18854 && warn_on_deprecated
df9909b8
TP
18855 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
18856 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
5a01bb1d
MGD
18857 {
18858 if (inst.instruction >= 0x10000)
18859 {
5c3696f8 18860 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
df9909b8 18861 "performance deprecated in ARMv8-A and ARMv8-R"));
5a01bb1d
MGD
18862 now_it.warn_deprecated = TRUE;
18863 }
18864 else
18865 {
18866 const struct depr_insn_mask *p = depr_it_insns;
18867
18868 while (p->mask != 0)
18869 {
18870 if ((inst.instruction & p->mask) == p->pattern)
18871 {
df9909b8
TP
18872 as_tsktsk (_("IT blocks containing 16-bit Thumb "
18873 "instructions of the following class are "
18874 "performance deprecated in ARMv8-A and "
18875 "ARMv8-R: %s"), p->description);
5a01bb1d
MGD
18876 now_it.warn_deprecated = TRUE;
18877 break;
18878 }
18879
18880 ++p;
18881 }
18882 }
18883
18884 if (now_it.block_length > 1)
18885 {
5c3696f8 18886 as_tsktsk (_("IT blocks containing more than one conditional "
df9909b8
TP
18887 "instruction are performance deprecated in ARMv8-A and "
18888 "ARMv8-R"));
5a01bb1d
MGD
18889 now_it.warn_deprecated = TRUE;
18890 }
18891 }
18892
e07e6e58
NC
18893 is_last = (now_it.mask == 0x10);
18894 if (is_last)
18895 {
18896 now_it.state = OUTSIDE_IT_BLOCK;
18897 now_it.mask = 0;
18898 }
18899}
18900
18901static void
18902force_automatic_it_block_close (void)
18903{
18904 if (now_it.state == AUTOMATIC_IT_BLOCK)
18905 {
18906 close_automatic_it_block ();
18907 now_it.state = OUTSIDE_IT_BLOCK;
18908 now_it.mask = 0;
18909 }
18910}
18911
18912static int
18913in_it_block (void)
18914{
18915 if (!now_it.state_handled)
18916 handle_it_state ();
18917
18918 return now_it.state != OUTSIDE_IT_BLOCK;
18919}
18920
ff8646ee
TP
18921/* Whether OPCODE only has T32 encoding. Since this function is only used by
18922 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18923 here, hence the "known" in the function name. */
fc289b0a
TP
18924
18925static bfd_boolean
ff8646ee 18926known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18927{
18928 /* Original Thumb-1 wide instruction. */
18929 if (opcode->tencode == do_t_blx
18930 || opcode->tencode == do_t_branch23
18931 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18932 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18933 return TRUE;
18934
16a1fa25
TP
18935 /* Wide-only instruction added to ARMv8-M Baseline. */
18936 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18937 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18938 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18939 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18940 return TRUE;
18941
18942 return FALSE;
18943}
18944
18945/* Whether wide instruction variant can be used if available for a valid OPCODE
18946 in ARCH. */
18947
18948static bfd_boolean
18949t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18950{
18951 if (known_t32_only_insn (opcode))
18952 return TRUE;
18953
18954 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18955 of variant T3 of B.W is checked in do_t_branch. */
18956 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18957 && opcode->tencode == do_t_branch)
18958 return TRUE;
18959
bada4342
JW
18960 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18961 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18962 && opcode->tencode == do_t_mov_cmp
18963 /* Make sure CMP instruction is not affected. */
18964 && opcode->aencode == do_mov)
18965 return TRUE;
18966
ff8646ee
TP
18967 /* Wide instruction variants of all instructions with narrow *and* wide
18968 variants become available with ARMv6t2. Other opcodes are either
18969 narrow-only or wide-only and are thus available if OPCODE is valid. */
18970 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18971 return TRUE;
18972
18973 /* OPCODE with narrow only instruction variant or wide variant not
18974 available. */
fc289b0a
TP
18975 return FALSE;
18976}
18977
c19d1205
ZW
18978void
18979md_assemble (char *str)
b99bd4ef 18980{
c19d1205
ZW
18981 char *p = str;
18982 const struct asm_opcode * opcode;
b99bd4ef 18983
c19d1205
ZW
18984 /* Align the previous label if needed. */
18985 if (last_label_seen != NULL)
b99bd4ef 18986 {
c19d1205
ZW
18987 symbol_set_frag (last_label_seen, frag_now);
18988 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18989 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18990 }
18991
c19d1205 18992 memset (&inst, '\0', sizeof (inst));
e2b0ab59
AV
18993 int r;
18994 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
18995 inst.relocs[r].type = BFD_RELOC_UNUSED;
b99bd4ef 18996
c19d1205
ZW
18997 opcode = opcode_lookup (&p);
18998 if (!opcode)
b99bd4ef 18999 {
c19d1205 19000 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 19001 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 19002 if (! create_register_alias (str, p)
477330fc 19003 && ! create_neon_reg_alias (str, p))
c19d1205 19004 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 19005
b99bd4ef
NC
19006 return;
19007 }
19008
278df34e 19009 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 19010 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 19011
037e8744
JB
19012 /* The value which unconditional instructions should have in place of the
19013 condition field. */
19014 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
19015
c19d1205 19016 if (thumb_mode)
b99bd4ef 19017 {
e74cfd16 19018 arm_feature_set variant;
8f06b2d8
PB
19019
19020 variant = cpu_variant;
19021 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
19022 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
19023 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 19024 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
19025 if (!opcode->tvariant
19026 || (thumb_mode == 1
19027 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 19028 {
173205ca
TP
19029 if (opcode->tencode == do_t_swi)
19030 as_bad (_("SVC is not permitted on this architecture"));
19031 else
19032 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
19033 return;
19034 }
c19d1205
ZW
19035 if (inst.cond != COND_ALWAYS && !unified_syntax
19036 && opcode->tencode != do_t_branch)
b99bd4ef 19037 {
c19d1205 19038 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
19039 return;
19040 }
19041
fc289b0a
TP
19042 /* Two things are addressed here:
19043 1) Implicit require narrow instructions on Thumb-1.
19044 This avoids relaxation accidentally introducing Thumb-2
19045 instructions.
19046 2) Reject wide instructions in non Thumb-2 cores.
19047
19048 Only instructions with narrow and wide variants need to be handled
19049 but selecting all non wide-only instructions is easier. */
19050 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 19051 && !t32_insn_ok (variant, opcode))
076d447c 19052 {
fc289b0a
TP
19053 if (inst.size_req == 0)
19054 inst.size_req = 2;
19055 else if (inst.size_req == 4)
752d5da4 19056 {
ff8646ee
TP
19057 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
19058 as_bad (_("selected processor does not support 32bit wide "
19059 "variant of instruction `%s'"), str);
19060 else
19061 as_bad (_("selected processor does not support `%s' in "
19062 "Thumb-2 mode"), str);
fc289b0a 19063 return;
752d5da4 19064 }
076d447c
PB
19065 }
19066
c19d1205
ZW
19067 inst.instruction = opcode->tvalue;
19068
5be8be5d 19069 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
19070 {
19071 /* Prepare the it_insn_type for those encodings that don't set
19072 it. */
19073 it_fsm_pre_encode ();
c19d1205 19074
477330fc 19075 opcode->tencode ();
e07e6e58 19076
477330fc
RM
19077 it_fsm_post_encode ();
19078 }
e27ec89e 19079
0110f2b8 19080 if (!(inst.error || inst.relax))
b99bd4ef 19081 {
9c2799c2 19082 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
19083 inst.size = (inst.instruction > 0xffff ? 4 : 2);
19084 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 19085 {
c19d1205 19086 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
19087 return;
19088 }
19089 }
076d447c
PB
19090
19091 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 19092 instruction. */
9c2799c2 19093 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 19094
e74cfd16
PB
19095 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
19096 *opcode->tvariant);
ee065d83 19097 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
19098 set those bits when Thumb-2 32-bit instructions are seen. The impact
19099 of relaxable instructions will be considered later after we finish all
19100 relaxation. */
ff8646ee
TP
19101 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
19102 variant = arm_arch_none;
19103 else
19104 variant = cpu_variant;
19105 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
19106 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
19107 arm_ext_v6t2);
cd000bff 19108
88714cb8
DG
19109 check_neon_suffixes;
19110
cd000bff 19111 if (!inst.error)
c877a2f2
NC
19112 {
19113 mapping_state (MAP_THUMB);
19114 }
c19d1205 19115 }
3e9e4fcf 19116 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 19117 {
845b51d6
PB
19118 bfd_boolean is_bx;
19119
19120 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
19121 is_bx = (opcode->aencode == do_bx);
19122
c19d1205 19123 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
19124 if (!(is_bx && fix_v4bx)
19125 && !(opcode->avariant &&
19126 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 19127 {
84b52b66 19128 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 19129 return;
b99bd4ef 19130 }
c19d1205 19131 if (inst.size_req)
b99bd4ef 19132 {
c19d1205
ZW
19133 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
19134 return;
b99bd4ef
NC
19135 }
19136
c19d1205
ZW
19137 inst.instruction = opcode->avalue;
19138 if (opcode->tag == OT_unconditionalF)
eff0bc54 19139 inst.instruction |= 0xFU << 28;
c19d1205
ZW
19140 else
19141 inst.instruction |= inst.cond << 28;
19142 inst.size = INSN_SIZE;
5be8be5d 19143 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
19144 {
19145 it_fsm_pre_encode ();
19146 opcode->aencode ();
19147 it_fsm_post_encode ();
19148 }
ee065d83 19149 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 19150 on a hypothetical non-thumb v5 core. */
845b51d6 19151 if (is_bx)
e74cfd16 19152 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 19153 else
e74cfd16
PB
19154 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
19155 *opcode->avariant);
88714cb8
DG
19156
19157 check_neon_suffixes;
19158
cd000bff 19159 if (!inst.error)
c877a2f2
NC
19160 {
19161 mapping_state (MAP_ARM);
19162 }
b99bd4ef 19163 }
3e9e4fcf
JB
19164 else
19165 {
19166 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
19167 "-- `%s'"), str);
19168 return;
19169 }
c19d1205
ZW
19170 output_inst (str);
19171}
b99bd4ef 19172
e07e6e58
NC
19173static void
19174check_it_blocks_finished (void)
19175{
19176#ifdef OBJ_ELF
19177 asection *sect;
19178
19179 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
19180 if (seg_info (sect)->tc_segment_info_data.current_it.state
19181 == MANUAL_IT_BLOCK)
19182 {
19183 as_warn (_("section '%s' finished with an open IT block."),
19184 sect->name);
19185 }
19186#else
19187 if (now_it.state == MANUAL_IT_BLOCK)
19188 as_warn (_("file finished with an open IT block."));
19189#endif
19190}
19191
c19d1205
ZW
19192/* Various frobbings of labels and their addresses. */
19193
19194void
19195arm_start_line_hook (void)
19196{
19197 last_label_seen = NULL;
b99bd4ef
NC
19198}
19199
c19d1205
ZW
19200void
19201arm_frob_label (symbolS * sym)
b99bd4ef 19202{
c19d1205 19203 last_label_seen = sym;
b99bd4ef 19204
c19d1205 19205 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 19206
c19d1205
ZW
19207#if defined OBJ_COFF || defined OBJ_ELF
19208 ARM_SET_INTERWORK (sym, support_interwork);
19209#endif
b99bd4ef 19210
e07e6e58
NC
19211 force_automatic_it_block_close ();
19212
5f4273c7 19213 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
19214 as Thumb functions. This is because these labels, whilst
19215 they exist inside Thumb code, are not the entry points for
19216 possible ARM->Thumb calls. Also, these labels can be used
19217 as part of a computed goto or switch statement. eg gcc
19218 can generate code that looks like this:
b99bd4ef 19219
c19d1205
ZW
19220 ldr r2, [pc, .Laaa]
19221 lsl r3, r3, #2
19222 ldr r2, [r3, r2]
19223 mov pc, r2
b99bd4ef 19224
c19d1205
ZW
19225 .Lbbb: .word .Lxxx
19226 .Lccc: .word .Lyyy
19227 ..etc...
19228 .Laaa: .word Lbbb
b99bd4ef 19229
c19d1205
ZW
19230 The first instruction loads the address of the jump table.
19231 The second instruction converts a table index into a byte offset.
19232 The third instruction gets the jump address out of the table.
19233 The fourth instruction performs the jump.
b99bd4ef 19234
c19d1205
ZW
19235 If the address stored at .Laaa is that of a symbol which has the
19236 Thumb_Func bit set, then the linker will arrange for this address
19237 to have the bottom bit set, which in turn would mean that the
19238 address computation performed by the third instruction would end
19239 up with the bottom bit set. Since the ARM is capable of unaligned
19240 word loads, the instruction would then load the incorrect address
19241 out of the jump table, and chaos would ensue. */
19242 if (label_is_thumb_function_name
19243 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
19244 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 19245 {
c19d1205
ZW
19246 /* When the address of a Thumb function is taken the bottom
19247 bit of that address should be set. This will allow
19248 interworking between Arm and Thumb functions to work
19249 correctly. */
b99bd4ef 19250
c19d1205 19251 THUMB_SET_FUNC (sym, 1);
b99bd4ef 19252
c19d1205 19253 label_is_thumb_function_name = FALSE;
b99bd4ef 19254 }
07a53e5c 19255
07a53e5c 19256 dwarf2_emit_label (sym);
b99bd4ef
NC
19257}
19258
c921be7d 19259bfd_boolean
c19d1205 19260arm_data_in_code (void)
b99bd4ef 19261{
c19d1205 19262 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 19263 {
c19d1205
ZW
19264 *input_line_pointer = '/';
19265 input_line_pointer += 5;
19266 *input_line_pointer = 0;
c921be7d 19267 return TRUE;
b99bd4ef
NC
19268 }
19269
c921be7d 19270 return FALSE;
b99bd4ef
NC
19271}
19272
c19d1205
ZW
19273char *
19274arm_canonicalize_symbol_name (char * name)
b99bd4ef 19275{
c19d1205 19276 int len;
b99bd4ef 19277
c19d1205
ZW
19278 if (thumb_mode && (len = strlen (name)) > 5
19279 && streq (name + len - 5, "/data"))
19280 *(name + len - 5) = 0;
b99bd4ef 19281
c19d1205 19282 return name;
b99bd4ef 19283}
c19d1205
ZW
19284\f
19285/* Table of all register names defined by default. The user can
19286 define additional names with .req. Note that all register names
19287 should appear in both upper and lowercase variants. Some registers
19288 also have mixed-case names. */
b99bd4ef 19289
dcbf9037 19290#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 19291#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 19292#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
19293#define REGSET(p,t) \
19294 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
19295 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
19296 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
19297 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
19298#define REGSETH(p,t) \
19299 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
19300 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
19301 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
19302 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
19303#define REGSET2(p,t) \
19304 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
19305 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
19306 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
19307 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
19308#define SPLRBANK(base,bank,t) \
19309 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
19310 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
19311 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
19312 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
19313 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
19314 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 19315
c19d1205 19316static const struct reg_entry reg_names[] =
7ed4c4c5 19317{
c19d1205
ZW
19318 /* ARM integer registers. */
19319 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 19320
c19d1205
ZW
19321 /* ATPCS synonyms. */
19322 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
19323 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
19324 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 19325
c19d1205
ZW
19326 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
19327 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
19328 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 19329
c19d1205
ZW
19330 /* Well-known aliases. */
19331 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
19332 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
19333
19334 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
19335 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
19336
19337 /* Coprocessor numbers. */
19338 REGSET(p, CP), REGSET(P, CP),
19339
19340 /* Coprocessor register numbers. The "cr" variants are for backward
19341 compatibility. */
19342 REGSET(c, CN), REGSET(C, CN),
19343 REGSET(cr, CN), REGSET(CR, CN),
19344
90ec0d68
MGD
19345 /* ARM banked registers. */
19346 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
19347 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
19348 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
19349 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
19350 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
19351 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
19352 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
19353
19354 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
19355 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
19356 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
19357 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
19358 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 19359 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
19360 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
19361 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
19362
19363 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
19364 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
19365 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
19366 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
19367 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
19368 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
19369 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 19370 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
19371 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
19372
c19d1205
ZW
19373 /* FPA registers. */
19374 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
19375 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
19376
19377 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
19378 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
19379
19380 /* VFP SP registers. */
5287ad62
JB
19381 REGSET(s,VFS), REGSET(S,VFS),
19382 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
19383
19384 /* VFP DP Registers. */
5287ad62
JB
19385 REGSET(d,VFD), REGSET(D,VFD),
19386 /* Extra Neon DP registers. */
19387 REGSETH(d,VFD), REGSETH(D,VFD),
19388
19389 /* Neon QP registers. */
19390 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
19391
19392 /* VFP control registers. */
19393 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
19394 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
19395 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
19396 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
19397 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
19398 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 19399 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
c19d1205
ZW
19400
19401 /* Maverick DSP coprocessor registers. */
19402 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
19403 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
19404
19405 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
19406 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
19407 REGDEF(dspsc,0,DSPSC),
19408
19409 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
19410 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
19411 REGDEF(DSPSC,0,DSPSC),
19412
19413 /* iWMMXt data registers - p0, c0-15. */
19414 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
19415
19416 /* iWMMXt control registers - p1, c0-3. */
19417 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
19418 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
19419 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
19420 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
19421
19422 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
19423 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
19424 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
19425 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
19426 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
19427
19428 /* XScale accumulator registers. */
19429 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
19430};
19431#undef REGDEF
19432#undef REGNUM
19433#undef REGSET
7ed4c4c5 19434
c19d1205
ZW
19435/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
19436 within psr_required_here. */
19437static const struct asm_psr psrs[] =
19438{
19439 /* Backward compatibility notation. Note that "all" is no longer
19440 truly all possible PSR bits. */
19441 {"all", PSR_c | PSR_f},
19442 {"flg", PSR_f},
19443 {"ctl", PSR_c},
19444
19445 /* Individual flags. */
19446 {"f", PSR_f},
19447 {"c", PSR_c},
19448 {"x", PSR_x},
19449 {"s", PSR_s},
59b42a0d 19450
c19d1205
ZW
19451 /* Combinations of flags. */
19452 {"fs", PSR_f | PSR_s},
19453 {"fx", PSR_f | PSR_x},
19454 {"fc", PSR_f | PSR_c},
19455 {"sf", PSR_s | PSR_f},
19456 {"sx", PSR_s | PSR_x},
19457 {"sc", PSR_s | PSR_c},
19458 {"xf", PSR_x | PSR_f},
19459 {"xs", PSR_x | PSR_s},
19460 {"xc", PSR_x | PSR_c},
19461 {"cf", PSR_c | PSR_f},
19462 {"cs", PSR_c | PSR_s},
19463 {"cx", PSR_c | PSR_x},
19464 {"fsx", PSR_f | PSR_s | PSR_x},
19465 {"fsc", PSR_f | PSR_s | PSR_c},
19466 {"fxs", PSR_f | PSR_x | PSR_s},
19467 {"fxc", PSR_f | PSR_x | PSR_c},
19468 {"fcs", PSR_f | PSR_c | PSR_s},
19469 {"fcx", PSR_f | PSR_c | PSR_x},
19470 {"sfx", PSR_s | PSR_f | PSR_x},
19471 {"sfc", PSR_s | PSR_f | PSR_c},
19472 {"sxf", PSR_s | PSR_x | PSR_f},
19473 {"sxc", PSR_s | PSR_x | PSR_c},
19474 {"scf", PSR_s | PSR_c | PSR_f},
19475 {"scx", PSR_s | PSR_c | PSR_x},
19476 {"xfs", PSR_x | PSR_f | PSR_s},
19477 {"xfc", PSR_x | PSR_f | PSR_c},
19478 {"xsf", PSR_x | PSR_s | PSR_f},
19479 {"xsc", PSR_x | PSR_s | PSR_c},
19480 {"xcf", PSR_x | PSR_c | PSR_f},
19481 {"xcs", PSR_x | PSR_c | PSR_s},
19482 {"cfs", PSR_c | PSR_f | PSR_s},
19483 {"cfx", PSR_c | PSR_f | PSR_x},
19484 {"csf", PSR_c | PSR_s | PSR_f},
19485 {"csx", PSR_c | PSR_s | PSR_x},
19486 {"cxf", PSR_c | PSR_x | PSR_f},
19487 {"cxs", PSR_c | PSR_x | PSR_s},
19488 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
19489 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
19490 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
19491 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
19492 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
19493 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
19494 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
19495 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
19496 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
19497 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
19498 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
19499 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
19500 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
19501 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
19502 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
19503 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
19504 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
19505 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
19506 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
19507 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
19508 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
19509 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
19510 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
19511 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
19512};
19513
62b3e311
PB
19514/* Table of V7M psr names. */
19515static const struct asm_psr v7m_psrs[] =
19516{
1a336194
TP
19517 {"apsr", 0x0 }, {"APSR", 0x0 },
19518 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
19519 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
19520 {"psr", 0x3 }, {"PSR", 0x3 },
19521 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
19522 {"ipsr", 0x5 }, {"IPSR", 0x5 },
19523 {"epsr", 0x6 }, {"EPSR", 0x6 },
19524 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
19525 {"msp", 0x8 }, {"MSP", 0x8 },
19526 {"psp", 0x9 }, {"PSP", 0x9 },
19527 {"msplim", 0xa }, {"MSPLIM", 0xa },
19528 {"psplim", 0xb }, {"PSPLIM", 0xb },
19529 {"primask", 0x10}, {"PRIMASK", 0x10},
19530 {"basepri", 0x11}, {"BASEPRI", 0x11},
19531 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
19532 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
19533 {"control", 0x14}, {"CONTROL", 0x14},
19534 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
19535 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
19536 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
19537 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
19538 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
19539 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
19540 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
19541 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
19542 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
19543};
19544
c19d1205
ZW
19545/* Table of all shift-in-operand names. */
19546static const struct asm_shift_name shift_names [] =
b99bd4ef 19547{
c19d1205
ZW
19548 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
19549 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
19550 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
19551 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
19552 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
19553 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
19554};
b99bd4ef 19555
c19d1205
ZW
19556/* Table of all explicit relocation names. */
19557#ifdef OBJ_ELF
19558static struct reloc_entry reloc_names[] =
19559{
19560 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
19561 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
19562 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
19563 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
19564 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
19565 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
19566 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
19567 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
19568 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
19569 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 19570 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
19571 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
19572 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 19573 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 19574 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 19575 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 19576 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
188fd7ae
CL
19577 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
19578 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
19579 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
19580 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
19581 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
19582 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
5c5a4843
CL
19583 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
19584 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
19585 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
19586 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
c19d1205
ZW
19587};
19588#endif
b99bd4ef 19589
c19d1205
ZW
19590/* Table of all conditional affixes. 0xF is not defined as a condition code. */
19591static const struct asm_cond conds[] =
19592{
19593 {"eq", 0x0},
19594 {"ne", 0x1},
19595 {"cs", 0x2}, {"hs", 0x2},
19596 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
19597 {"mi", 0x4},
19598 {"pl", 0x5},
19599 {"vs", 0x6},
19600 {"vc", 0x7},
19601 {"hi", 0x8},
19602 {"ls", 0x9},
19603 {"ge", 0xa},
19604 {"lt", 0xb},
19605 {"gt", 0xc},
19606 {"le", 0xd},
19607 {"al", 0xe}
19608};
bfae80f2 19609
e797f7e0 19610#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
19611 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19612 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 19613
62b3e311
PB
19614static struct asm_barrier_opt barrier_opt_names[] =
19615{
e797f7e0
MGD
19616 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19617 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19618 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19619 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19620 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19621 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19622 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19623 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19624 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19625 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19626 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19627 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19628 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19629 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19630 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19631 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
19632};
19633
e797f7e0
MGD
19634#undef UL_BARRIER
19635
c19d1205
ZW
19636/* Table of ARM-format instructions. */
19637
19638/* Macros for gluing together operand strings. N.B. In all cases
19639 other than OPS0, the trailing OP_stop comes from default
19640 zero-initialization of the unspecified elements of the array. */
19641#define OPS0() { OP_stop, }
19642#define OPS1(a) { OP_##a, }
19643#define OPS2(a,b) { OP_##a,OP_##b, }
19644#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19645#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19646#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19647#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19648
5be8be5d
DG
19649/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19650 This is useful when mixing operands for ARM and THUMB, i.e. using the
19651 MIX_ARM_THUMB_OPERANDS macro.
19652 In order to use these macros, prefix the number of operands with _
19653 e.g. _3. */
19654#define OPS_1(a) { a, }
19655#define OPS_2(a,b) { a,b, }
19656#define OPS_3(a,b,c) { a,b,c, }
19657#define OPS_4(a,b,c,d) { a,b,c,d, }
19658#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19659#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19660
c19d1205
ZW
19661/* These macros abstract out the exact format of the mnemonic table and
19662 save some repeated characters. */
19663
19664/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19665#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19666 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 19667 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19668
19669/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19670 a T_MNEM_xyz enumerator. */
19671#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19672 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19673#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19674 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
19675
19676/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19677 infix after the third character. */
19678#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 19679 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 19680 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 19681#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 19682 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 19683 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19684#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19685 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 19686#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19687 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19688#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19689 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 19690#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19691 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 19692
c19d1205 19693/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
19694 field is still 0xE. Many of the Thumb variants can be executed
19695 conditionally, so this is checked separately. */
c19d1205 19696#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19697 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19698 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19699
dd5181d5
KT
19700/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19701 Used by mnemonics that have very minimal differences in the encoding for
19702 ARM and Thumb variants and can be handled in a common function. */
19703#define TUEc(mnem, op, top, nops, ops, en) \
19704 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19705 THUMB_VARIANT, do_##en, do_##en }
19706
c19d1205
ZW
19707/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19708 condition code field. */
19709#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 19710 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19711 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19712
19713/* ARM-only variants of all the above. */
6a86118a 19714#define CE(mnem, op, nops, ops, ae) \
21d799b5 19715 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
19716
19717#define C3(mnem, op, nops, ops, ae) \
19718 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19719
cf3cf39d
TP
19720/* Thumb-only variants of TCE and TUE. */
19721#define ToC(mnem, top, nops, ops, te) \
19722 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
19723 do_##te }
cf3cf39d
TP
19724
19725#define ToU(mnem, top, nops, ops, te) \
19726 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
19727 NULL, do_##te }
cf3cf39d 19728
4389b29a
AV
19729/* T_MNEM_xyz enumerator variants of ToC. */
19730#define toC(mnem, top, nops, ops, te) \
19731 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
19732 do_##te }
19733
f6b2b12d
AV
19734/* T_MNEM_xyz enumerator variants of ToU. */
19735#define toU(mnem, top, nops, ops, te) \
19736 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
19737 NULL, do_##te }
19738
e3cb604e
PB
19739/* Legacy mnemonics that always have conditional infix after the third
19740 character. */
19741#define CL(mnem, op, nops, ops, ae) \
21d799b5 19742 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19743 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19744
8f06b2d8
PB
19745/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19746#define cCE(mnem, op, nops, ops, ae) \
21d799b5 19747 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19748
e3cb604e
PB
19749/* Legacy coprocessor instructions where conditional infix and conditional
19750 suffix are ambiguous. For consistency this includes all FPA instructions,
19751 not just the potentially ambiguous ones. */
19752#define cCL(mnem, op, nops, ops, ae) \
21d799b5 19753 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19754 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19755
19756/* Coprocessor, takes either a suffix or a position-3 infix
19757 (for an FPA corner case). */
19758#define C3E(mnem, op, nops, ops, ae) \
21d799b5 19759 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19760 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19761
6a86118a 19762#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19763 { m1 #m2 m3, OPS##nops ops, \
19764 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19765 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19766
19767#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19768 xCM_ (m1, , m2, op, nops, ops, ae), \
19769 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19770 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19771 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19772 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19773 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19774 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19775 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19776 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19777 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19778 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19779 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19780 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19781 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19782 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19783 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19784 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19785 xCM_ (m1, le, m2, op, nops, ops, ae), \
19786 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19787
19788#define UE(mnem, op, nops, ops, ae) \
19789 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19790
19791#define UF(mnem, op, nops, ops, ae) \
19792 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19793
5287ad62
JB
19794/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19795 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19796 use the same encoding function for each. */
19797#define NUF(mnem, op, nops, ops, enc) \
19798 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19799 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19800
19801/* Neon data processing, version which indirects through neon_enc_tab for
19802 the various overloaded versions of opcodes. */
19803#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19804 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19805 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19806
19807/* Neon insn with conditional suffix for the ARM version, non-overloaded
19808 version. */
037e8744
JB
19809#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19810 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19811 THUMB_VARIANT, do_##enc, do_##enc }
19812
037e8744 19813#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19814 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19815
19816#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19817 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19818
5287ad62 19819/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19820#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19821 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19822 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19823
037e8744 19824#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19825 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19826
19827#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19828 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19829
c19d1205
ZW
19830#define do_0 0
19831
c19d1205 19832static const struct asm_opcode insns[] =
bfae80f2 19833{
74db7efb
NC
19834#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19835#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19836 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19837 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19838 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19839 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19840 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19841 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19842 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19843 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19844 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19845 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19846 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19847 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19848 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19849 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19850 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19851 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19852
19853 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19854 for setting PSR flag bits. They are obsolete in V6 and do not
19855 have Thumb equivalents. */
21d799b5
NC
19856 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19857 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19858 CL("tstp", 110f000, 2, (RR, SH), cmp),
19859 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19860 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19861 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19862 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19863 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19864 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19865
19866 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19867 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19868 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19869 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19870
19871 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19872 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19873 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19874 OP_RRnpc),
19875 OP_ADDRGLDR),ldst, t_ldst),
19876 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19877
19878 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19879 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19880 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19881 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19882 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19883 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19884
21d799b5
NC
19885 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19886 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19887
c19d1205 19888 /* Pseudo ops. */
21d799b5 19889 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19890 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19891 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19892 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19893
19894 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19895 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19896 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19897 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19898 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19899 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19900 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19901 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19902 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19903 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19904 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19905 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19906 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19907
16a4cf17 19908 /* These may simplify to neg. */
21d799b5
NC
19909 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19910 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19911
173205ca
TP
19912#undef THUMB_VARIANT
19913#define THUMB_VARIANT & arm_ext_os
19914
19915 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19916 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19917
c921be7d
NC
19918#undef THUMB_VARIANT
19919#define THUMB_VARIANT & arm_ext_v6
19920
21d799b5 19921 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19922
19923 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19924#undef THUMB_VARIANT
19925#define THUMB_VARIANT & arm_ext_v6t2
19926
21d799b5
NC
19927 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19928 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19929 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19930
5be8be5d
DG
19931 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19932 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19933 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19934 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19935
21d799b5
NC
19936 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19937 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19938
21d799b5
NC
19939 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19940 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19941
19942 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19943 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19944 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19945
19946 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19947 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19948 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19949 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19950 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19951 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19952 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19953 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19954
c921be7d
NC
19955#undef ARM_VARIANT
19956#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19957#undef THUMB_VARIANT
19958#define THUMB_VARIANT & arm_ext_v4t
19959
21d799b5
NC
19960 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19961 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19962
c921be7d
NC
19963#undef THUMB_VARIANT
19964#define THUMB_VARIANT & arm_ext_v6t2
19965
21d799b5 19966 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19967 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19968
19969 /* Generic coprocessor instructions. */
21d799b5
NC
19970 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19971 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19972 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19973 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19974 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19975 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19976 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19977
c921be7d
NC
19978#undef ARM_VARIANT
19979#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19980
21d799b5 19981 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19982 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19983
c921be7d
NC
19984#undef ARM_VARIANT
19985#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19986#undef THUMB_VARIANT
19987#define THUMB_VARIANT & arm_ext_msr
19988
d2cd1205
JB
19989 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19990 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19991
c921be7d
NC
19992#undef ARM_VARIANT
19993#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19994#undef THUMB_VARIANT
19995#define THUMB_VARIANT & arm_ext_v6t2
19996
21d799b5
NC
19997 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19998 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19999 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20000 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
20001 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20002 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
20003 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20004 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 20005
c921be7d
NC
20006#undef ARM_VARIANT
20007#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
20008#undef THUMB_VARIANT
20009#define THUMB_VARIANT & arm_ext_v4t
20010
5be8be5d
DG
20011 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20012 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20013 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20014 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
20015 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20016 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 20017
c921be7d
NC
20018#undef ARM_VARIANT
20019#define ARM_VARIANT & arm_ext_v4t_5
20020
c19d1205
ZW
20021 /* ARM Architecture 4T. */
20022 /* Note: bx (and blx) are required on V5, even if the processor does
20023 not support Thumb. */
21d799b5 20024 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 20025
c921be7d
NC
20026#undef ARM_VARIANT
20027#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
20028#undef THUMB_VARIANT
20029#define THUMB_VARIANT & arm_ext_v5t
20030
c19d1205
ZW
20031 /* Note: blx has 2 variants; the .value coded here is for
20032 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
20033 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
20034 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 20035
c921be7d
NC
20036#undef THUMB_VARIANT
20037#define THUMB_VARIANT & arm_ext_v6t2
20038
21d799b5
NC
20039 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
20040 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20041 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20042 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20043 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20044 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
20045 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
20046 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 20047
c921be7d 20048#undef ARM_VARIANT
74db7efb
NC
20049#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
20050#undef THUMB_VARIANT
20051#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 20052
21d799b5
NC
20053 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20054 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20055 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20056 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 20057
21d799b5
NC
20058 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20059 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 20060
21d799b5
NC
20061 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
20062 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
20063 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
20064 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 20065
21d799b5
NC
20066 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20067 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20068 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20069 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 20070
21d799b5
NC
20071 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20072 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 20073
03ee1b7f
NC
20074 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
20075 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
20076 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
20077 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 20078
c921be7d 20079#undef ARM_VARIANT
74db7efb
NC
20080#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
20081#undef THUMB_VARIANT
20082#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 20083
21d799b5 20084 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
20085 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
20086 ldrd, t_ldstd),
20087 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
20088 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 20089
21d799b5
NC
20090 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
20091 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 20092
c921be7d
NC
20093#undef ARM_VARIANT
20094#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
20095
21d799b5 20096 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 20097
c921be7d
NC
20098#undef ARM_VARIANT
20099#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
20100#undef THUMB_VARIANT
20101#define THUMB_VARIANT & arm_ext_v6
20102
21d799b5
NC
20103 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
20104 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
20105 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
20106 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
20107 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
20108 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20109 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20110 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20111 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20112 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 20113
c921be7d 20114#undef THUMB_VARIANT
ff8646ee 20115#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 20116
5be8be5d
DG
20117 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
20118 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
20119 strex, t_strex),
ff8646ee
TP
20120#undef THUMB_VARIANT
20121#define THUMB_VARIANT & arm_ext_v6t2
20122
21d799b5
NC
20123 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
20124 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 20125
21d799b5
NC
20126 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
20127 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 20128
9e3c6df6 20129/* ARM V6 not included in V7M. */
c921be7d
NC
20130#undef THUMB_VARIANT
20131#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 20132 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 20133 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
20134 UF(rfeib, 9900a00, 1, (RRw), rfe),
20135 UF(rfeda, 8100a00, 1, (RRw), rfe),
20136 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
20137 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
20138 UF(rfefa, 8100a00, 1, (RRw), rfe),
20139 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
20140 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 20141 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
20142 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
20143 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 20144 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 20145 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 20146 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 20147 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 20148 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 20149 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 20150 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 20151
9e3c6df6
PB
20152/* ARM V6 not included in V7M (eg. integer SIMD). */
20153#undef THUMB_VARIANT
20154#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
20155 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
20156 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
20157 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20158 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20159 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20160 /* Old name for QASX. */
74db7efb 20161 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 20162 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20163 /* Old name for QSAX. */
74db7efb 20164 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20165 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20166 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20167 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20168 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20169 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20170 /* Old name for SASX. */
74db7efb 20171 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20172 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20173 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20174 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20175 /* Old name for SHASX. */
21d799b5 20176 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20177 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20178 /* Old name for SHSAX. */
21d799b5
NC
20179 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20180 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20181 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20182 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20183 /* Old name for SSAX. */
74db7efb 20184 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20185 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20186 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20187 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20188 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20189 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20190 /* Old name for UASX. */
74db7efb 20191 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20192 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20193 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20194 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20195 /* Old name for UHASX. */
21d799b5
NC
20196 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20197 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20198 /* Old name for UHSAX. */
21d799b5
NC
20199 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20200 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20201 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20202 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20203 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 20204 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20205 /* Old name for UQASX. */
21d799b5
NC
20206 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20207 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20208 /* Old name for UQSAX. */
21d799b5
NC
20209 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20210 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20211 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20212 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20213 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 20214 /* Old name for USAX. */
74db7efb 20215 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 20216 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
20217 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20218 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20219 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20220 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20221 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20222 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20223 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20224 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20225 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20226 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20227 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20228 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
20229 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
20230 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20231 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20232 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
20233 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
20234 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20235 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20236 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20237 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20238 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20239 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20240 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20241 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20242 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20243 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
20244 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
20245 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
20246 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20247 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20248 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 20249
c921be7d 20250#undef ARM_VARIANT
55e8aae7 20251#define ARM_VARIANT & arm_ext_v6k_v6t2
c921be7d 20252#undef THUMB_VARIANT
55e8aae7 20253#define THUMB_VARIANT & arm_ext_v6k_v6t2
c921be7d 20254
21d799b5
NC
20255 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
20256 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
20257 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
20258 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 20259
c921be7d
NC
20260#undef THUMB_VARIANT
20261#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
20262 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
20263 ldrexd, t_ldrexd),
20264 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
20265 RRnpcb), strexd, t_strexd),
ebdca51a 20266
c921be7d 20267#undef THUMB_VARIANT
ff8646ee 20268#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
20269 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
20270 rd_rn, rd_rn),
20271 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
20272 rd_rn, rd_rn),
20273 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 20274 strex, t_strexbh),
5be8be5d 20275 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 20276 strex, t_strexbh),
21d799b5 20277 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 20278
c921be7d 20279#undef ARM_VARIANT
f4c65163 20280#define ARM_VARIANT & arm_ext_sec
74db7efb 20281#undef THUMB_VARIANT
f4c65163 20282#define THUMB_VARIANT & arm_ext_sec
c921be7d 20283
21d799b5 20284 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 20285
90ec0d68
MGD
20286#undef ARM_VARIANT
20287#define ARM_VARIANT & arm_ext_virt
20288#undef THUMB_VARIANT
20289#define THUMB_VARIANT & arm_ext_virt
20290
20291 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
20292 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
20293
ddfded2f
MW
20294#undef ARM_VARIANT
20295#define ARM_VARIANT & arm_ext_pan
20296#undef THUMB_VARIANT
20297#define THUMB_VARIANT & arm_ext_pan
20298
20299 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
20300
c921be7d 20301#undef ARM_VARIANT
74db7efb 20302#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
20303#undef THUMB_VARIANT
20304#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 20305
21d799b5
NC
20306 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
20307 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
20308 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
20309 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 20310
21d799b5 20311 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 20312 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 20313
5be8be5d
DG
20314 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20315 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20316 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20317 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 20318
91d8b670
JG
20319#undef ARM_VARIANT
20320#define ARM_VARIANT & arm_ext_v3
20321#undef THUMB_VARIANT
20322#define THUMB_VARIANT & arm_ext_v6t2
20323
20324 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
c597cc3d
SD
20325 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
20326 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
91d8b670
JG
20327
20328#undef ARM_VARIANT
20329#define ARM_VARIANT & arm_ext_v6t2
ff8646ee
TP
20330#undef THUMB_VARIANT
20331#define THUMB_VARIANT & arm_ext_v6t2_v8m
20332 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
20333 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
20334
bf3eeda7 20335 /* Thumb-only instructions. */
74db7efb 20336#undef ARM_VARIANT
bf3eeda7
NS
20337#define ARM_VARIANT NULL
20338 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
20339 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
20340
20341 /* ARM does not really have an IT instruction, so always allow it.
20342 The opcode is copied from Thumb in order to allow warnings in
20343 -mimplicit-it=[never | arm] modes. */
20344#undef ARM_VARIANT
20345#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
20346#undef THUMB_VARIANT
20347#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 20348
21d799b5
NC
20349 TUE("it", bf08, bf08, 1, (COND), it, t_it),
20350 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
20351 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
20352 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
20353 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
20354 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
20355 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
20356 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
20357 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
20358 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
20359 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
20360 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
20361 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
20362 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
20363 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 20364 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
20365 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
20366 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 20367
92e90b6e 20368 /* Thumb2 only instructions. */
c921be7d
NC
20369#undef ARM_VARIANT
20370#define ARM_VARIANT NULL
92e90b6e 20371
21d799b5
NC
20372 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20373 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20374 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
20375 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
20376 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
20377 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 20378
eea54501
MGD
20379 /* Hardware division instructions. */
20380#undef ARM_VARIANT
20381#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
20382#undef THUMB_VARIANT
20383#define THUMB_VARIANT & arm_ext_div
20384
eea54501
MGD
20385 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
20386 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 20387
7e806470 20388 /* ARM V6M/V7 instructions. */
c921be7d
NC
20389#undef ARM_VARIANT
20390#define ARM_VARIANT & arm_ext_barrier
20391#undef THUMB_VARIANT
20392#define THUMB_VARIANT & arm_ext_barrier
20393
ccb84d65
JB
20394 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
20395 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
20396 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 20397
62b3e311 20398 /* ARM V7 instructions. */
c921be7d
NC
20399#undef ARM_VARIANT
20400#define ARM_VARIANT & arm_ext_v7
20401#undef THUMB_VARIANT
20402#define THUMB_VARIANT & arm_ext_v7
20403
21d799b5
NC
20404 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
20405 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 20406
74db7efb 20407#undef ARM_VARIANT
60e5ef9f 20408#define ARM_VARIANT & arm_ext_mp
74db7efb 20409#undef THUMB_VARIANT
60e5ef9f
MGD
20410#define THUMB_VARIANT & arm_ext_mp
20411
20412 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
20413
53c4b28b
MGD
20414 /* AArchv8 instructions. */
20415#undef ARM_VARIANT
20416#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
20417
20418/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 20419#undef THUMB_VARIANT
4ed7ed8d 20420#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 20421
4ed7ed8d
TP
20422 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20423 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20424 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20425 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20426 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20427 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 20428 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
20429 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
20430 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20431 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
20432 stlex, t_stlex),
4b8c8c02
RE
20433 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
20434 stlex, t_stlex),
20435 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
20436 stlex, t_stlex),
4ed7ed8d
TP
20437#undef THUMB_VARIANT
20438#define THUMB_VARIANT & arm_ext_v8
53c4b28b 20439
4ed7ed8d 20440 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
4ed7ed8d
TP
20441 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
20442 ldrexd, t_ldrexd),
20443 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
20444 strexd, t_strexd),
f7dd2fb2
TC
20445
20446/* Defined in V8 but is in undefined encoding space for earlier
20447 architectures. However earlier architectures are required to treat
20448 this instuction as a semihosting trap as well. Hence while not explicitly
20449 defined as such, it is in fact correct to define the instruction for all
20450 architectures. */
20451#undef THUMB_VARIANT
20452#define THUMB_VARIANT & arm_ext_v1
20453#undef ARM_VARIANT
20454#define ARM_VARIANT & arm_ext_v1
20455 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
20456
8884b720 20457 /* ARMv8 T32 only. */
74db7efb 20458#undef ARM_VARIANT
b79f7053
MGD
20459#define ARM_VARIANT NULL
20460 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
20461 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
20462 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
20463
33399f07
MGD
20464 /* FP for ARMv8. */
20465#undef ARM_VARIANT
a715796b 20466#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 20467#undef THUMB_VARIANT
a715796b 20468#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
20469
20470 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
20471 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
20472 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
20473 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
20474 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
20475 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
20476 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
20477 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
20478 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
20479 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
20480 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
20481 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
20482 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
20483 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
20484 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
20485 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
20486 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 20487
91ff7894
MGD
20488 /* Crypto v1 extensions. */
20489#undef ARM_VARIANT
20490#define ARM_VARIANT & fpu_crypto_ext_armv8
20491#undef THUMB_VARIANT
20492#define THUMB_VARIANT & fpu_crypto_ext_armv8
20493
20494 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
20495 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
20496 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
20497 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
20498 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
20499 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
20500 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
20501 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
20502 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
20503 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
20504 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
20505 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
20506 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
20507 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 20508
dd5181d5 20509#undef ARM_VARIANT
74db7efb 20510#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
20511#undef THUMB_VARIANT
20512#define THUMB_VARIANT & crc_ext_armv8
20513 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
20514 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
20515 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
20516 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
20517 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
20518 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
20519
105bde57
MW
20520 /* ARMv8.2 RAS extension. */
20521#undef ARM_VARIANT
4d1464f2 20522#define ARM_VARIANT & arm_ext_ras
105bde57 20523#undef THUMB_VARIANT
4d1464f2 20524#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
20525 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
20526
49e8a725
SN
20527#undef ARM_VARIANT
20528#define ARM_VARIANT & arm_ext_v8_3
20529#undef THUMB_VARIANT
20530#define THUMB_VARIANT & arm_ext_v8_3
20531 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
20532 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
20533 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 20534
c604a79a
JW
20535#undef ARM_VARIANT
20536#define ARM_VARIANT & fpu_neon_ext_dotprod
20537#undef THUMB_VARIANT
20538#define THUMB_VARIANT & fpu_neon_ext_dotprod
20539 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
20540 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
20541
c921be7d
NC
20542#undef ARM_VARIANT
20543#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
20544#undef THUMB_VARIANT
20545#define THUMB_VARIANT NULL
c921be7d 20546
21d799b5
NC
20547 cCE("wfs", e200110, 1, (RR), rd),
20548 cCE("rfs", e300110, 1, (RR), rd),
20549 cCE("wfc", e400110, 1, (RR), rd),
20550 cCE("rfc", e500110, 1, (RR), rd),
20551
20552 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
20553 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
20554 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
20555 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
20556
20557 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
20558 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
20559 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
20560 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
20561
20562 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
20563 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
20564 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
20565 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
20566 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
20567 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
20568 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
20569 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
20570 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
20571 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
20572 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
20573 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
20574
20575 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
20576 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
20577 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
20578 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
20579 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
20580 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
20581 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
20582 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
20583 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
20584 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
20585 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
20586 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
20587
20588 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
20589 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
20590 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
20591 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
20592 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
20593 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
20594 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
20595 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
20596 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
20597 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
20598 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
20599 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
20600
20601 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
20602 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
20603 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
20604 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
20605 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
20606 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
20607 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
20608 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
20609 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
20610 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
20611 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
20612 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
20613
20614 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
20615 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
20616 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
20617 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
20618 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
20619 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
20620 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
20621 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
20622 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
20623 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
20624 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
20625 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
20626
20627 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
20628 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
20629 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
20630 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
20631 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
20632 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
20633 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
20634 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
20635 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
20636 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
20637 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
20638 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
20639
20640 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
20641 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
20642 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
20643 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
20644 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
20645 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
20646 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
20647 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
20648 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
20649 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
20650 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
20651 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
20652
20653 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
20654 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20655 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20656 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20657 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20658 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20659 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20660 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20661 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20662 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20663 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20664 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20665
20666 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20667 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20668 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20669 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20670 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20671 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20672 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20673 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20674 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20675 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20676 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20677 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20678
20679 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20680 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20681 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20682 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20683 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20684 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20685 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20686 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20687 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20688 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20689 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20690 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20691
20692 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20693 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20694 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20695 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20696 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20697 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20698 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20699 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20700 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20701 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20702 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20703 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20704
20705 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20706 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20707 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20708 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20709 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20710 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20711 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20712 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20713 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20714 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20715 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20716 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20717
20718 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20719 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20720 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20721 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20722 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20723 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20724 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20725 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20726 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20727 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20728 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20729 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20730
20731 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20732 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20733 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20734 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20735 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20736 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20737 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20738 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20739 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20740 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20741 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20742 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20743
20744 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20745 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20746 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20747 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20748 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20749 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20750 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20751 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20752 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20753 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20754 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20755 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20756
20757 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20758 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20759 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20760 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20761 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20762 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20763 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20764 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20765 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20766 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20767 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20768 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20769
20770 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20771 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20772 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20773 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20774 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20775 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20776 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20777 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20778 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20779 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20780 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20781 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20782
20783 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20784 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20785 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20786 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20787 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20788 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20789 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20790 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20791 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20792 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20793 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20794 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20795
20796 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20797 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20798 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20799 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20800 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20801 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20802 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20803 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20804 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20805 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20806 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20807 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20808
20809 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20810 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20811 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20812 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20813 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20814 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20815 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20816 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20817 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20818 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20819 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20820 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20821
20822 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20823 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20824 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20825 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20826 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20827 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20828 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20829 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20830 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20831 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20832 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20833 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20834
20835 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20836 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20837 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20838 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20839 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20840 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20841 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20842 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20843 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20844 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20845 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20846 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20847
20848 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20849 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20850 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20851 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20852 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20853 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20854 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20855 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20856 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20857 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20858 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20859 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20860
20861 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20862 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20863 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20864 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20865 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20866 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20867 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20868 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20869 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20870 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20871 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20872 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20873
20874 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20875 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20876 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20877 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20878 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20879 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20880 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20881 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20882 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20883 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20884 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20885 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20886
20887 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20888 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20889 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20890 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20891 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20892 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20893 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20894 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20895 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20896 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20897 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20898 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20899
20900 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20901 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20902 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20903 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20904 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20905 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20906 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20907 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20908 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20909 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20910 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20911 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20912
20913 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20914 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20915 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20916 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20917 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20918 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20919 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20920 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20921 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20922 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20923 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20924 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20925
20926 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20927 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20928 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20929 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20930 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20931 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20932 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20933 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20934 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20935 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20936 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20937 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20938
20939 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20940 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20941 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20942 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20943
20944 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20945 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20946 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20947 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20948 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20949 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20950 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20951 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20952 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20953 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20954 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20955 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20956
c19d1205
ZW
20957 /* The implementation of the FIX instruction is broken on some
20958 assemblers, in that it accepts a precision specifier as well as a
20959 rounding specifier, despite the fact that this is meaningless.
20960 To be more compatible, we accept it as well, though of course it
20961 does not set any bits. */
21d799b5
NC
20962 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20963 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20964 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20965 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20966 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20967 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20968 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20969 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20970 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20971 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20972 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20973 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20974 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20975
c19d1205 20976 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20977#undef ARM_VARIANT
20978#define ARM_VARIANT & fpu_fpa_ext_v2
20979
21d799b5
NC
20980 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20981 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20982 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20983 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20984 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20985 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20986
c921be7d
NC
20987#undef ARM_VARIANT
20988#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20989
c19d1205 20990 /* Moves and type conversions. */
21d799b5
NC
20991 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20992 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20993 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20994 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20995 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20996 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20997 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20998 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20999 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
21000 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
21001 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
21002 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
21003 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
21004 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
21005
21006 /* Memory operations. */
21d799b5
NC
21007 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
21008 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
21009 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21010 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21011 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21012 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21013 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21014 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21015 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
21016 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
21017 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21018 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21019 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21020 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21021 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21022 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21023 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
21024 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 21025
c19d1205 21026 /* Monadic operations. */
21d799b5
NC
21027 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
21028 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
21029 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
21030
21031 /* Dyadic operations. */
21d799b5
NC
21032 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21033 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21034 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21035 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21036 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21037 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21038 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21039 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21040 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 21041
c19d1205 21042 /* Comparisons. */
21d799b5
NC
21043 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
21044 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
21045 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
21046 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 21047
62f3b8c8
PB
21048 /* Double precision load/store are still present on single precision
21049 implementations. */
21050 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
21051 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
21052 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21053 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21054 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
21055 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
21056 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21057 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21058 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
21059 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 21060
c921be7d
NC
21061#undef ARM_VARIANT
21062#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
21063
c19d1205 21064 /* Moves and type conversions. */
21d799b5
NC
21065 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
21066 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
21067 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
21068 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
21069 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
21070 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
21071 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
21072 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
21073 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
21074 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
21075 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
21076 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
21077 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 21078
c19d1205 21079 /* Monadic operations. */
21d799b5
NC
21080 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
21081 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
21082 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
21083
21084 /* Dyadic operations. */
21d799b5
NC
21085 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21086 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21087 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21088 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21089 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21090 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21091 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21092 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21093 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 21094
c19d1205 21095 /* Comparisons. */
21d799b5
NC
21096 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
21097 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
21098 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
21099 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 21100
c921be7d
NC
21101#undef ARM_VARIANT
21102#define ARM_VARIANT & fpu_vfp_ext_v2
21103
21d799b5
NC
21104 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
21105 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
21106 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
21107 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 21108
037e8744
JB
21109/* Instructions which may belong to either the Neon or VFP instruction sets.
21110 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
21111#undef ARM_VARIANT
21112#define ARM_VARIANT & fpu_vfp_ext_v1xd
21113#undef THUMB_VARIANT
21114#define THUMB_VARIANT & fpu_vfp_ext_v1xd
21115
037e8744
JB
21116 /* These mnemonics are unique to VFP. */
21117 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
21118 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
21119 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21120 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21121 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
21122 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
21123 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
21124 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
21125 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
21126 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
21127
21128 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
21129 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
21130 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
21131 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 21132
21d799b5
NC
21133 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
21134 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
21135
21136 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
21137 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
21138
55881a11
MGD
21139 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21140 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21141 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21142 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21143 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21144 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
21145 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
21146 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 21147
5f1af56b 21148 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 21149 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
21150 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
21151 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 21152
037e8744
JB
21153
21154 /* NOTE: All VMOV encoding is special-cased! */
21155 NCE(vmov, 0, 1, (VMOV), neon_mov),
21156 NCE(vmovq, 0, 1, (VMOV), neon_mov),
21157
9db2f6b4
RL
21158#undef ARM_VARIANT
21159#define ARM_VARIANT & arm_ext_fp16
21160#undef THUMB_VARIANT
21161#define THUMB_VARIANT & arm_ext_fp16
21162 /* New instructions added from v8.2, allowing the extraction and insertion of
21163 the upper 16 bits of a 32-bit vector register. */
21164 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
21165 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
21166
dec41383
JW
21167 /* New backported fma/fms instructions optional in v8.2. */
21168 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
21169 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
21170
c921be7d
NC
21171#undef THUMB_VARIANT
21172#define THUMB_VARIANT & fpu_neon_ext_v1
21173#undef ARM_VARIANT
21174#define ARM_VARIANT & fpu_neon_ext_v1
21175
5287ad62
JB
21176 /* Data processing with three registers of the same length. */
21177 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
21178 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
21179 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
21180 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21181 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21182 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21183 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21184 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21185 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21186 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
21187 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
21188 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
21189 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
21190 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
21191 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
21192 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
21193 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
21194 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
21195 /* If not immediate, fall back to neon_dyadic_i64_su.
21196 shl_imm should accept I8 I16 I32 I64,
21197 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
21198 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
21199 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
21200 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
21201 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 21202 /* Logic ops, types optional & ignored. */
4316f0d2
DG
21203 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21204 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21205 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21206 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21207 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21208 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21209 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21210 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21211 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
21212 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
21213 /* Bitfield ops, untyped. */
21214 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
21215 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
21216 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
21217 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
21218 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
21219 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 21220 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
21221 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
21222 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21223 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
21224 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21225 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
21226 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
21227 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
21228 back to neon_dyadic_if_su. */
21d799b5
NC
21229 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
21230 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
21231 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
21232 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
21233 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
21234 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
21235 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
21236 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 21237 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
21238 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
21239 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 21240 /* As above, D registers only. */
21d799b5
NC
21241 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
21242 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 21243 /* Int and float variants, signedness unimportant. */
21d799b5
NC
21244 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
21245 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
21246 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 21247 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
21248 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
21249 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
21250 /* vtst takes sizes 8, 16, 32. */
21251 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
21252 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
21253 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 21254 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 21255 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
21256 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
21257 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
21258 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
21259 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
21260 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
21261 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
21262 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
21263 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
21264 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
21265 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
21266 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
21267 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
21268 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
21269 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
21270 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
21271 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 21272 /* ARM v8.1 extension. */
643afb90
MW
21273 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
21274 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
21275 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
21276 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
21277
21278 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 21279 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
21280 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
21281
21282 /* Data processing with two registers and a shift amount. */
21283 /* Right shifts, and variants with rounding.
21284 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
21285 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
21286 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
21287 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
21288 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
21289 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
21290 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
21291 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
21292 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
21293 /* Shift and insert. Sizes accepted 8 16 32 64. */
21294 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
21295 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
21296 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
21297 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
21298 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
21299 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
21300 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
21301 /* Right shift immediate, saturating & narrowing, with rounding variants.
21302 Types accepted S16 S32 S64 U16 U32 U64. */
21303 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
21304 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
21305 /* As above, unsigned. Types accepted S16 S32 S64. */
21306 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
21307 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
21308 /* Right shift narrowing. Types accepted I16 I32 I64. */
21309 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
21310 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
21311 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 21312 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 21313 /* CVT with optional immediate for fixed-point variant. */
21d799b5 21314 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 21315
4316f0d2
DG
21316 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
21317 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
21318
21319 /* Data processing, three registers of different lengths. */
21320 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
21321 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
21322 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
21323 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
21324 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
21325 /* If not scalar, fall back to neon_dyadic_long.
21326 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
21327 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
21328 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
21329 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
21330 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
21331 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
21332 /* Dyadic, narrowing insns. Types I16 I32 I64. */
21333 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21334 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21335 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21336 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21337 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
21338 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21339 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21340 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
21341 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
21342 S16 S32 U16 U32. */
21d799b5 21343 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
21344
21345 /* Extract. Size 8. */
3b8d421e
PB
21346 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
21347 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
21348
21349 /* Two registers, miscellaneous. */
21350 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
21351 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
21352 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
21353 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
21354 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
21355 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
21356 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
21357 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
21358 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
21359 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
21360 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
21361 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
21362 /* VMOVN. Types I16 I32 I64. */
21d799b5 21363 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 21364 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 21365 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 21366 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 21367 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
21368 /* VZIP / VUZP. Sizes 8 16 32. */
21369 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
21370 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
21371 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
21372 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
21373 /* VQABS / VQNEG. Types S8 S16 S32. */
21374 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21375 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
21376 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21377 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
21378 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
21379 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
21380 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
21381 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
21382 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 21383 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
21384 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
21385 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
21386 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
21387 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
21388 /* VCLS. Types S8 S16 S32. */
21389 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
21390 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
21391 /* VCLZ. Types I8 I16 I32. */
21392 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
21393 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
21394 /* VCNT. Size 8. */
21395 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
21396 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
21397 /* Two address, untyped. */
21398 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
21399 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
21400 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
21401 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
21402 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
21403
21404 /* Table lookup. Size 8. */
21405 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21406 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21407
c921be7d
NC
21408#undef THUMB_VARIANT
21409#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
21410#undef ARM_VARIANT
21411#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
21412
5287ad62 21413 /* Neon element/structure load/store. */
21d799b5
NC
21414 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21415 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21416 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21417 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21418 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21419 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21420 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
21421 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 21422
c921be7d 21423#undef THUMB_VARIANT
74db7efb
NC
21424#define THUMB_VARIANT & fpu_vfp_ext_v3xd
21425#undef ARM_VARIANT
21426#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
21427 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
21428 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21429 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21430 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21431 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21432 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21433 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21434 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21435 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21436
74db7efb 21437#undef THUMB_VARIANT
c921be7d
NC
21438#define THUMB_VARIANT & fpu_vfp_ext_v3
21439#undef ARM_VARIANT
21440#define ARM_VARIANT & fpu_vfp_ext_v3
21441
21d799b5 21442 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 21443 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21444 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21445 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21446 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21447 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21448 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21449 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21450 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 21451
74db7efb
NC
21452#undef ARM_VARIANT
21453#define ARM_VARIANT & fpu_vfp_ext_fma
21454#undef THUMB_VARIANT
21455#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
21456 /* Mnemonics shared by Neon and VFP. These are included in the
21457 VFP FMA variant; NEON and VFP FMA always includes the NEON
21458 FMA instructions. */
21459 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21460 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21461 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
21462 the v form should always be used. */
21463 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21464 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21465 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21466 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21467 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21468 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21469
5287ad62 21470#undef THUMB_VARIANT
c921be7d
NC
21471#undef ARM_VARIANT
21472#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
21473
21d799b5
NC
21474 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21475 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21476 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21477 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21478 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21479 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21480 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
21481 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 21482
c921be7d
NC
21483#undef ARM_VARIANT
21484#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
21485
21d799b5
NC
21486 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
21487 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
21488 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
21489 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
21490 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
21491 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
21492 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
21493 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
21494 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
21495 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21496 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21497 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21498 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21499 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21500 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
21501 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21502 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21503 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21504 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
21505 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
21506 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21507 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21508 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21509 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21510 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21511 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
21512 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
21513 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
21514 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
21515 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
21516 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
21517 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
21518 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
21519 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
21520 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
21521 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
21522 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
21523 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21524 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21525 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21526 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21527 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21528 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21529 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21530 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21531 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21532 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
21533 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21534 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21535 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21536 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21537 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21538 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21539 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21540 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21541 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21542 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21543 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21544 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21545 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21546 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21547 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21548 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21549 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21550 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21551 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21552 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21553 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21554 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21555 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21556 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21557 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21558 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21559 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21560 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21561 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21562 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21563 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21564 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21565 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21566 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21567 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21568 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21569 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21570 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21571 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21572 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21573 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21574 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
21575 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21576 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21577 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21578 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21579 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21580 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21581 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21582 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21583 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21584 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21585 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21586 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21587 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21588 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21589 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21590 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21591 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21592 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21593 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21594 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21595 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21596 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
21597 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21598 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21599 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21600 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21601 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21602 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21603 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21604 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21605 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21606 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21607 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21608 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21609 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21610 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21611 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21612 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21613 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21614 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21615 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21616 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21617 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21618 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21619 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21620 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21621 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21622 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21623 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21624 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21625 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21626 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21627 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21628 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
21629 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
21630 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
21631 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
21632 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
21633 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
21634 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21635 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21636 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21637 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
21638 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
21639 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
21640 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
21641 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
21642 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
21643 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21644 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21645 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21646 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21647 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 21648
c921be7d
NC
21649#undef ARM_VARIANT
21650#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
21651
21d799b5
NC
21652 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
21653 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
21654 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
21655 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
21656 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
21657 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
21658 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21659 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21660 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21661 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21662 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21663 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21664 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21665 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21666 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21667 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21668 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21669 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21670 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21671 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21672 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21673 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21674 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21675 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21676 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21677 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21678 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21679 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21680 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21681 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21682 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21683 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21684 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21685 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21686 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21687 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21688 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21689 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21690 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21691 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21692 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21693 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21694 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21695 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21696 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21697 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21698 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21699 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21700 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21701 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21702 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21703 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21704 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21705 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21706 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21707 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21708 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 21709
c921be7d
NC
21710#undef ARM_VARIANT
21711#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21712
21d799b5
NC
21713 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21714 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21715 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21716 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21717 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21718 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21719 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21720 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21721 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21722 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21723 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21724 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21725 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21726 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
21727 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21728 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21729 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21730 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21731 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21732 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21733 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21734 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21735 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21736 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
21737 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21738 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21739 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21740 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
21741 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21742 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
21743 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21744 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21745 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21746 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
21747 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21748 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21749 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21750 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21751 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21752 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
21753 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21754 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
21755 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21756 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
21757 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21758 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21759 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21760 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21761 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21762 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21763 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21764 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21765 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21766 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21767 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21768 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21769 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21770 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21771 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21772 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21773 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21774 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21775 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21776 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21777 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21778 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21779 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21780 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21781 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21782 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21783 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21784 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
21785 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21786 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
21787 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21788 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 21789
7fadb25d
SD
21790 /* ARMv8.5-A instructions. */
21791#undef ARM_VARIANT
21792#define ARM_VARIANT & arm_ext_sb
21793#undef THUMB_VARIANT
21794#define THUMB_VARIANT & arm_ext_sb
21795 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
21796
dad0c3bf
SD
21797#undef ARM_VARIANT
21798#define ARM_VARIANT & arm_ext_predres
21799#undef THUMB_VARIANT
21800#define THUMB_VARIANT & arm_ext_predres
21801 CE("cfprctx", e070f93, 1, (RRnpc), rd),
21802 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
21803 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
21804
16a1fa25 21805 /* ARMv8-M instructions. */
4ed7ed8d
TP
21806#undef ARM_VARIANT
21807#define ARM_VARIANT NULL
21808#undef THUMB_VARIANT
21809#define THUMB_VARIANT & arm_ext_v8m
cf3cf39d
TP
21810 ToU("sg", e97fe97f, 0, (), noargs),
21811 ToC("blxns", 4784, 1, (RRnpc), t_blx),
21812 ToC("bxns", 4704, 1, (RRnpc), t_bx),
21813 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
21814 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
21815 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
21816 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
16a1fa25
TP
21817
21818 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21819 instructions behave as nop if no VFP is present. */
21820#undef THUMB_VARIANT
21821#define THUMB_VARIANT & arm_ext_v8m_main
cf3cf39d
TP
21822 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
21823 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
4389b29a
AV
21824
21825 /* Armv8.1-M Mainline instructions. */
21826#undef THUMB_VARIANT
21827#define THUMB_VARIANT & arm_ext_v8_1m_main
21828 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
f6b2b12d 21829 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
f1c7f421 21830 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
65d1bc05 21831 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
f1c7f421 21832 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
60f993ce
AV
21833
21834 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
21835 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
21836 toU("le", _le, 2, (oLR, EXP), t_loloop),
c19d1205
ZW
21837};
21838#undef ARM_VARIANT
21839#undef THUMB_VARIANT
21840#undef TCE
c19d1205
ZW
21841#undef TUE
21842#undef TUF
21843#undef TCC
8f06b2d8 21844#undef cCE
e3cb604e
PB
21845#undef cCL
21846#undef C3E
4389b29a 21847#undef C3
c19d1205
ZW
21848#undef CE
21849#undef CM
4389b29a 21850#undef CL
c19d1205
ZW
21851#undef UE
21852#undef UF
21853#undef UT
5287ad62
JB
21854#undef NUF
21855#undef nUF
21856#undef NCE
21857#undef nCE
c19d1205
ZW
21858#undef OPS0
21859#undef OPS1
21860#undef OPS2
21861#undef OPS3
21862#undef OPS4
21863#undef OPS5
21864#undef OPS6
21865#undef do_0
4389b29a
AV
21866#undef ToC
21867#undef toC
21868#undef ToU
f6b2b12d 21869#undef toU
c19d1205
ZW
21870\f
21871/* MD interface: bits in the object file. */
bfae80f2 21872
c19d1205
ZW
21873/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21874 for use in the a.out file, and stores them in the array pointed to by buf.
21875 This knows about the endian-ness of the target machine and does
21876 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21877 2 (short) and 4 (long) Floating numbers are put out as a series of
21878 LITTLENUMS (shorts, here at least). */
b99bd4ef 21879
c19d1205
ZW
21880void
21881md_number_to_chars (char * buf, valueT val, int n)
21882{
21883 if (target_big_endian)
21884 number_to_chars_bigendian (buf, val, n);
21885 else
21886 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21887}
21888
c19d1205
ZW
21889static valueT
21890md_chars_to_number (char * buf, int n)
bfae80f2 21891{
c19d1205
ZW
21892 valueT result = 0;
21893 unsigned char * where = (unsigned char *) buf;
bfae80f2 21894
c19d1205 21895 if (target_big_endian)
b99bd4ef 21896 {
c19d1205
ZW
21897 while (n--)
21898 {
21899 result <<= 8;
21900 result |= (*where++ & 255);
21901 }
b99bd4ef 21902 }
c19d1205 21903 else
b99bd4ef 21904 {
c19d1205
ZW
21905 while (n--)
21906 {
21907 result <<= 8;
21908 result |= (where[n] & 255);
21909 }
bfae80f2 21910 }
b99bd4ef 21911
c19d1205 21912 return result;
bfae80f2 21913}
b99bd4ef 21914
c19d1205 21915/* MD interface: Sections. */
b99bd4ef 21916
fa94de6b
RM
21917/* Calculate the maximum variable size (i.e., excluding fr_fix)
21918 that an rs_machine_dependent frag may reach. */
21919
21920unsigned int
21921arm_frag_max_var (fragS *fragp)
21922{
21923 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21924 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21925
21926 Note that we generate relaxable instructions even for cases that don't
21927 really need it, like an immediate that's a trivial constant. So we're
21928 overestimating the instruction size for some of those cases. Rather
21929 than putting more intelligence here, it would probably be better to
21930 avoid generating a relaxation frag in the first place when it can be
21931 determined up front that a short instruction will suffice. */
21932
21933 gas_assert (fragp->fr_type == rs_machine_dependent);
21934 return INSN_SIZE;
21935}
21936
0110f2b8
PB
21937/* Estimate the size of a frag before relaxing. Assume everything fits in
21938 2 bytes. */
21939
c19d1205 21940int
0110f2b8 21941md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21942 segT segtype ATTRIBUTE_UNUSED)
21943{
0110f2b8
PB
21944 fragp->fr_var = 2;
21945 return 2;
21946}
21947
21948/* Convert a machine dependent frag. */
21949
21950void
21951md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21952{
21953 unsigned long insn;
21954 unsigned long old_op;
21955 char *buf;
21956 expressionS exp;
21957 fixS *fixp;
21958 int reloc_type;
21959 int pc_rel;
21960 int opcode;
21961
21962 buf = fragp->fr_literal + fragp->fr_fix;
21963
21964 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21965 if (fragp->fr_symbol)
21966 {
0110f2b8
PB
21967 exp.X_op = O_symbol;
21968 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21969 }
21970 else
21971 {
0110f2b8 21972 exp.X_op = O_constant;
5f4273c7 21973 }
0110f2b8
PB
21974 exp.X_add_number = fragp->fr_offset;
21975 opcode = fragp->fr_subtype;
21976 switch (opcode)
21977 {
21978 case T_MNEM_ldr_pc:
21979 case T_MNEM_ldr_pc2:
21980 case T_MNEM_ldr_sp:
21981 case T_MNEM_str_sp:
21982 case T_MNEM_ldr:
21983 case T_MNEM_ldrb:
21984 case T_MNEM_ldrh:
21985 case T_MNEM_str:
21986 case T_MNEM_strb:
21987 case T_MNEM_strh:
21988 if (fragp->fr_var == 4)
21989 {
5f4273c7 21990 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21991 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21992 {
21993 insn |= (old_op & 0x700) << 4;
21994 }
21995 else
21996 {
21997 insn |= (old_op & 7) << 12;
21998 insn |= (old_op & 0x38) << 13;
21999 }
22000 insn |= 0x00000c00;
22001 put_thumb32_insn (buf, insn);
22002 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
22003 }
22004 else
22005 {
22006 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
22007 }
22008 pc_rel = (opcode == T_MNEM_ldr_pc2);
22009 break;
22010 case T_MNEM_adr:
22011 if (fragp->fr_var == 4)
22012 {
22013 insn = THUMB_OP32 (opcode);
22014 insn |= (old_op & 0xf0) << 4;
22015 put_thumb32_insn (buf, insn);
22016 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
22017 }
22018 else
22019 {
22020 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
22021 exp.X_add_number -= 4;
22022 }
22023 pc_rel = 1;
22024 break;
22025 case T_MNEM_mov:
22026 case T_MNEM_movs:
22027 case T_MNEM_cmp:
22028 case T_MNEM_cmn:
22029 if (fragp->fr_var == 4)
22030 {
22031 int r0off = (opcode == T_MNEM_mov
22032 || opcode == T_MNEM_movs) ? 0 : 8;
22033 insn = THUMB_OP32 (opcode);
22034 insn = (insn & 0xe1ffffff) | 0x10000000;
22035 insn |= (old_op & 0x700) << r0off;
22036 put_thumb32_insn (buf, insn);
22037 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
22038 }
22039 else
22040 {
22041 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
22042 }
22043 pc_rel = 0;
22044 break;
22045 case T_MNEM_b:
22046 if (fragp->fr_var == 4)
22047 {
22048 insn = THUMB_OP32(opcode);
22049 put_thumb32_insn (buf, insn);
22050 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
22051 }
22052 else
22053 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
22054 pc_rel = 1;
22055 break;
22056 case T_MNEM_bcond:
22057 if (fragp->fr_var == 4)
22058 {
22059 insn = THUMB_OP32(opcode);
22060 insn |= (old_op & 0xf00) << 14;
22061 put_thumb32_insn (buf, insn);
22062 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
22063 }
22064 else
22065 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
22066 pc_rel = 1;
22067 break;
22068 case T_MNEM_add_sp:
22069 case T_MNEM_add_pc:
22070 case T_MNEM_inc_sp:
22071 case T_MNEM_dec_sp:
22072 if (fragp->fr_var == 4)
22073 {
22074 /* ??? Choose between add and addw. */
22075 insn = THUMB_OP32 (opcode);
22076 insn |= (old_op & 0xf0) << 4;
22077 put_thumb32_insn (buf, insn);
16805f35
PB
22078 if (opcode == T_MNEM_add_pc)
22079 reloc_type = BFD_RELOC_ARM_T32_IMM12;
22080 else
22081 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
22082 }
22083 else
22084 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
22085 pc_rel = 0;
22086 break;
22087
22088 case T_MNEM_addi:
22089 case T_MNEM_addis:
22090 case T_MNEM_subi:
22091 case T_MNEM_subis:
22092 if (fragp->fr_var == 4)
22093 {
22094 insn = THUMB_OP32 (opcode);
22095 insn |= (old_op & 0xf0) << 4;
22096 insn |= (old_op & 0xf) << 16;
22097 put_thumb32_insn (buf, insn);
16805f35
PB
22098 if (insn & (1 << 20))
22099 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
22100 else
22101 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
22102 }
22103 else
22104 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
22105 pc_rel = 0;
22106 break;
22107 default:
5f4273c7 22108 abort ();
0110f2b8
PB
22109 }
22110 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 22111 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
22112 fixp->fx_file = fragp->fr_file;
22113 fixp->fx_line = fragp->fr_line;
22114 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
22115
22116 /* Set whether we use thumb-2 ISA based on final relaxation results. */
22117 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
22118 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
22119 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
22120}
22121
22122/* Return the size of a relaxable immediate operand instruction.
22123 SHIFT and SIZE specify the form of the allowable immediate. */
22124static int
22125relax_immediate (fragS *fragp, int size, int shift)
22126{
22127 offsetT offset;
22128 offsetT mask;
22129 offsetT low;
22130
22131 /* ??? Should be able to do better than this. */
22132 if (fragp->fr_symbol)
22133 return 4;
22134
22135 low = (1 << shift) - 1;
22136 mask = (1 << (shift + size)) - (1 << shift);
22137 offset = fragp->fr_offset;
22138 /* Force misaligned offsets to 32-bit variant. */
22139 if (offset & low)
5e77afaa 22140 return 4;
0110f2b8
PB
22141 if (offset & ~mask)
22142 return 4;
22143 return 2;
22144}
22145
5e77afaa
PB
22146/* Get the address of a symbol during relaxation. */
22147static addressT
5f4273c7 22148relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
22149{
22150 fragS *sym_frag;
22151 addressT addr;
22152 symbolS *sym;
22153
22154 sym = fragp->fr_symbol;
22155 sym_frag = symbol_get_frag (sym);
22156 know (S_GET_SEGMENT (sym) != absolute_section
22157 || sym_frag == &zero_address_frag);
22158 addr = S_GET_VALUE (sym) + fragp->fr_offset;
22159
22160 /* If frag has yet to be reached on this pass, assume it will
22161 move by STRETCH just as we did. If this is not so, it will
22162 be because some frag between grows, and that will force
22163 another pass. */
22164
22165 if (stretch != 0
22166 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
22167 {
22168 fragS *f;
22169
22170 /* Adjust stretch for any alignment frag. Note that if have
22171 been expanding the earlier code, the symbol may be
22172 defined in what appears to be an earlier frag. FIXME:
22173 This doesn't handle the fr_subtype field, which specifies
22174 a maximum number of bytes to skip when doing an
22175 alignment. */
22176 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
22177 {
22178 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
22179 {
22180 if (stretch < 0)
22181 stretch = - ((- stretch)
22182 & ~ ((1 << (int) f->fr_offset) - 1));
22183 else
22184 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
22185 if (stretch == 0)
22186 break;
22187 }
22188 }
22189 if (f != NULL)
22190 addr += stretch;
22191 }
5e77afaa
PB
22192
22193 return addr;
22194}
22195
0110f2b8
PB
22196/* Return the size of a relaxable adr pseudo-instruction or PC-relative
22197 load. */
22198static int
5e77afaa 22199relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
22200{
22201 addressT addr;
22202 offsetT val;
22203
22204 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
22205 if (fragp->fr_symbol == NULL
22206 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
22207 || sec != S_GET_SEGMENT (fragp->fr_symbol)
22208 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
22209 return 4;
22210
5f4273c7 22211 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
22212 addr = fragp->fr_address + fragp->fr_fix;
22213 addr = (addr + 4) & ~3;
5e77afaa 22214 /* Force misaligned targets to 32-bit variant. */
0110f2b8 22215 if (val & 3)
5e77afaa 22216 return 4;
0110f2b8
PB
22217 val -= addr;
22218 if (val < 0 || val > 1020)
22219 return 4;
22220 return 2;
22221}
22222
22223/* Return the size of a relaxable add/sub immediate instruction. */
22224static int
22225relax_addsub (fragS *fragp, asection *sec)
22226{
22227 char *buf;
22228 int op;
22229
22230 buf = fragp->fr_literal + fragp->fr_fix;
22231 op = bfd_get_16(sec->owner, buf);
22232 if ((op & 0xf) == ((op >> 4) & 0xf))
22233 return relax_immediate (fragp, 8, 0);
22234 else
22235 return relax_immediate (fragp, 3, 0);
22236}
22237
e83a675f
RE
22238/* Return TRUE iff the definition of symbol S could be pre-empted
22239 (overridden) at link or load time. */
22240static bfd_boolean
22241symbol_preemptible (symbolS *s)
22242{
22243 /* Weak symbols can always be pre-empted. */
22244 if (S_IS_WEAK (s))
22245 return TRUE;
22246
22247 /* Non-global symbols cannot be pre-empted. */
22248 if (! S_IS_EXTERNAL (s))
22249 return FALSE;
22250
22251#ifdef OBJ_ELF
22252 /* In ELF, a global symbol can be marked protected, or private. In that
22253 case it can't be pre-empted (other definitions in the same link unit
22254 would violate the ODR). */
22255 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
22256 return FALSE;
22257#endif
22258
22259 /* Other global symbols might be pre-empted. */
22260 return TRUE;
22261}
0110f2b8
PB
22262
22263/* Return the size of a relaxable branch instruction. BITS is the
22264 size of the offset field in the narrow instruction. */
22265
22266static int
5e77afaa 22267relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
22268{
22269 addressT addr;
22270 offsetT val;
22271 offsetT limit;
22272
22273 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 22274 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
22275 || sec != S_GET_SEGMENT (fragp->fr_symbol)
22276 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
22277 return 4;
22278
267bf995 22279#ifdef OBJ_ELF
e83a675f 22280 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
22281 if (S_IS_DEFINED (fragp->fr_symbol)
22282 && ARM_IS_FUNC (fragp->fr_symbol))
22283 return 4;
e83a675f 22284#endif
0d9b4b55 22285
e83a675f 22286 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 22287 return 4;
267bf995 22288
5f4273c7 22289 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
22290 addr = fragp->fr_address + fragp->fr_fix + 4;
22291 val -= addr;
22292
22293 /* Offset is a signed value *2 */
22294 limit = 1 << bits;
22295 if (val >= limit || val < -limit)
22296 return 4;
22297 return 2;
22298}
22299
22300
22301/* Relax a machine dependent frag. This returns the amount by which
22302 the current size of the frag should change. */
22303
22304int
5e77afaa 22305arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
22306{
22307 int oldsize;
22308 int newsize;
22309
22310 oldsize = fragp->fr_var;
22311 switch (fragp->fr_subtype)
22312 {
22313 case T_MNEM_ldr_pc2:
5f4273c7 22314 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
22315 break;
22316 case T_MNEM_ldr_pc:
22317 case T_MNEM_ldr_sp:
22318 case T_MNEM_str_sp:
5f4273c7 22319 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
22320 break;
22321 case T_MNEM_ldr:
22322 case T_MNEM_str:
5f4273c7 22323 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
22324 break;
22325 case T_MNEM_ldrh:
22326 case T_MNEM_strh:
5f4273c7 22327 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
22328 break;
22329 case T_MNEM_ldrb:
22330 case T_MNEM_strb:
5f4273c7 22331 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
22332 break;
22333 case T_MNEM_adr:
5f4273c7 22334 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
22335 break;
22336 case T_MNEM_mov:
22337 case T_MNEM_movs:
22338 case T_MNEM_cmp:
22339 case T_MNEM_cmn:
5f4273c7 22340 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
22341 break;
22342 case T_MNEM_b:
5f4273c7 22343 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
22344 break;
22345 case T_MNEM_bcond:
5f4273c7 22346 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
22347 break;
22348 case T_MNEM_add_sp:
22349 case T_MNEM_add_pc:
22350 newsize = relax_immediate (fragp, 8, 2);
22351 break;
22352 case T_MNEM_inc_sp:
22353 case T_MNEM_dec_sp:
22354 newsize = relax_immediate (fragp, 7, 2);
22355 break;
22356 case T_MNEM_addi:
22357 case T_MNEM_addis:
22358 case T_MNEM_subi:
22359 case T_MNEM_subis:
22360 newsize = relax_addsub (fragp, sec);
22361 break;
22362 default:
5f4273c7 22363 abort ();
0110f2b8 22364 }
5e77afaa
PB
22365
22366 fragp->fr_var = newsize;
22367 /* Freeze wide instructions that are at or before the same location as
22368 in the previous pass. This avoids infinite loops.
5f4273c7
NC
22369 Don't freeze them unconditionally because targets may be artificially
22370 misaligned by the expansion of preceding frags. */
5e77afaa 22371 if (stretch <= 0 && newsize > 2)
0110f2b8 22372 {
0110f2b8 22373 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 22374 frag_wane (fragp);
0110f2b8 22375 }
5e77afaa 22376
0110f2b8 22377 return newsize - oldsize;
c19d1205 22378}
b99bd4ef 22379
c19d1205 22380/* Round up a section size to the appropriate boundary. */
b99bd4ef 22381
c19d1205
ZW
22382valueT
22383md_section_align (segT segment ATTRIBUTE_UNUSED,
22384 valueT size)
22385{
6844c0cc 22386 return size;
bfae80f2 22387}
b99bd4ef 22388
c19d1205
ZW
22389/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
22390 of an rs_align_code fragment. */
22391
22392void
22393arm_handle_align (fragS * fragP)
bfae80f2 22394{
d9235011 22395 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
22396 {
22397 { /* ARMv1 */
22398 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
22399 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
22400 },
22401 { /* ARMv6k */
22402 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
22403 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
22404 },
22405 };
d9235011 22406 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
22407 {
22408 { /* Thumb-1 */
22409 {0xc0, 0x46}, /* LE */
22410 {0x46, 0xc0}, /* BE */
22411 },
22412 { /* Thumb-2 */
22413 {0x00, 0xbf}, /* LE */
22414 {0xbf, 0x00} /* BE */
22415 }
22416 };
d9235011 22417 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
22418 { /* Wide Thumb-2 */
22419 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
22420 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
22421 };
c921be7d 22422
e7495e45 22423 unsigned bytes, fix, noop_size;
c19d1205 22424 char * p;
d9235011
TS
22425 const unsigned char * noop;
22426 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
22427#ifdef OBJ_ELF
22428 enum mstate state;
22429#endif
bfae80f2 22430
c19d1205 22431 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
22432 return;
22433
c19d1205
ZW
22434 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
22435 p = fragP->fr_literal + fragP->fr_fix;
22436 fix = 0;
bfae80f2 22437
c19d1205
ZW
22438 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
22439 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 22440
cd000bff 22441 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 22442
cd000bff 22443 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 22444 {
7f78eb34
JW
22445 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22446 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
22447 {
22448 narrow_noop = thumb_noop[1][target_big_endian];
22449 noop = wide_thumb_noop[target_big_endian];
22450 }
c19d1205 22451 else
e7495e45
NS
22452 noop = thumb_noop[0][target_big_endian];
22453 noop_size = 2;
cd000bff
DJ
22454#ifdef OBJ_ELF
22455 state = MAP_THUMB;
22456#endif
7ed4c4c5
NC
22457 }
22458 else
22459 {
7f78eb34
JW
22460 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22461 ? selected_cpu : arm_arch_none,
22462 arm_ext_v6k) != 0]
e7495e45
NS
22463 [target_big_endian];
22464 noop_size = 4;
cd000bff
DJ
22465#ifdef OBJ_ELF
22466 state = MAP_ARM;
22467#endif
7ed4c4c5 22468 }
c921be7d 22469
e7495e45 22470 fragP->fr_var = noop_size;
c921be7d 22471
c19d1205 22472 if (bytes & (noop_size - 1))
7ed4c4c5 22473 {
c19d1205 22474 fix = bytes & (noop_size - 1);
cd000bff
DJ
22475#ifdef OBJ_ELF
22476 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
22477#endif
c19d1205
ZW
22478 memset (p, 0, fix);
22479 p += fix;
22480 bytes -= fix;
a737bd4d 22481 }
a737bd4d 22482
e7495e45
NS
22483 if (narrow_noop)
22484 {
22485 if (bytes & noop_size)
22486 {
22487 /* Insert a narrow noop. */
22488 memcpy (p, narrow_noop, noop_size);
22489 p += noop_size;
22490 bytes -= noop_size;
22491 fix += noop_size;
22492 }
22493
22494 /* Use wide noops for the remainder */
22495 noop_size = 4;
22496 }
22497
c19d1205 22498 while (bytes >= noop_size)
a737bd4d 22499 {
c19d1205
ZW
22500 memcpy (p, noop, noop_size);
22501 p += noop_size;
22502 bytes -= noop_size;
22503 fix += noop_size;
a737bd4d
NC
22504 }
22505
c19d1205 22506 fragP->fr_fix += fix;
a737bd4d
NC
22507}
22508
c19d1205
ZW
22509/* Called from md_do_align. Used to create an alignment
22510 frag in a code section. */
22511
22512void
22513arm_frag_align_code (int n, int max)
bfae80f2 22514{
c19d1205 22515 char * p;
7ed4c4c5 22516
c19d1205 22517 /* We assume that there will never be a requirement
6ec8e702 22518 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 22519 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
22520 {
22521 char err_msg[128];
22522
fa94de6b 22523 sprintf (err_msg,
477330fc
RM
22524 _("alignments greater than %d bytes not supported in .text sections."),
22525 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 22526 as_fatal ("%s", err_msg);
6ec8e702 22527 }
bfae80f2 22528
c19d1205
ZW
22529 p = frag_var (rs_align_code,
22530 MAX_MEM_FOR_RS_ALIGN_CODE,
22531 1,
22532 (relax_substateT) max,
22533 (symbolS *) NULL,
22534 (offsetT) n,
22535 (char *) NULL);
22536 *p = 0;
22537}
bfae80f2 22538
8dc2430f
NC
22539/* Perform target specific initialisation of a frag.
22540 Note - despite the name this initialisation is not done when the frag
22541 is created, but only when its type is assigned. A frag can be created
22542 and used a long time before its type is set, so beware of assuming that
33eaf5de 22543 this initialisation is performed first. */
bfae80f2 22544
cd000bff
DJ
22545#ifndef OBJ_ELF
22546void
22547arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
22548{
22549 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 22550 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
22551}
22552
22553#else /* OBJ_ELF is defined. */
c19d1205 22554void
cd000bff 22555arm_init_frag (fragS * fragP, int max_chars)
c19d1205 22556{
e8d84ca1 22557 bfd_boolean frag_thumb_mode;
b968d18a 22558
8dc2430f
NC
22559 /* If the current ARM vs THUMB mode has not already
22560 been recorded into this frag then do so now. */
cd000bff 22561 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
22562 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22563
e8d84ca1
NC
22564 /* PR 21809: Do not set a mapping state for debug sections
22565 - it just confuses other tools. */
22566 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
22567 return;
22568
b968d18a 22569 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 22570
f9c1b181
RL
22571 /* Record a mapping symbol for alignment frags. We will delete this
22572 later if the alignment ends up empty. */
22573 switch (fragP->fr_type)
22574 {
22575 case rs_align:
22576 case rs_align_test:
22577 case rs_fill:
22578 mapping_state_2 (MAP_DATA, max_chars);
22579 break;
22580 case rs_align_code:
b968d18a 22581 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
22582 break;
22583 default:
22584 break;
cd000bff 22585 }
bfae80f2
RE
22586}
22587
c19d1205
ZW
22588/* When we change sections we need to issue a new mapping symbol. */
22589
22590void
22591arm_elf_change_section (void)
bfae80f2 22592{
c19d1205
ZW
22593 /* Link an unlinked unwind index table section to the .text section. */
22594 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
22595 && elf_linked_to_section (now_seg) == NULL)
22596 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
22597}
22598
c19d1205
ZW
22599int
22600arm_elf_section_type (const char * str, size_t len)
e45d0630 22601{
c19d1205
ZW
22602 if (len == 5 && strncmp (str, "exidx", 5) == 0)
22603 return SHT_ARM_EXIDX;
e45d0630 22604
c19d1205
ZW
22605 return -1;
22606}
22607\f
22608/* Code to deal with unwinding tables. */
e45d0630 22609
c19d1205 22610static void add_unwind_adjustsp (offsetT);
e45d0630 22611
5f4273c7 22612/* Generate any deferred unwind frame offset. */
e45d0630 22613
bfae80f2 22614static void
c19d1205 22615flush_pending_unwind (void)
bfae80f2 22616{
c19d1205 22617 offsetT offset;
bfae80f2 22618
c19d1205
ZW
22619 offset = unwind.pending_offset;
22620 unwind.pending_offset = 0;
22621 if (offset != 0)
22622 add_unwind_adjustsp (offset);
bfae80f2
RE
22623}
22624
c19d1205
ZW
22625/* Add an opcode to this list for this function. Two-byte opcodes should
22626 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
22627 order. */
22628
bfae80f2 22629static void
c19d1205 22630add_unwind_opcode (valueT op, int length)
bfae80f2 22631{
c19d1205
ZW
22632 /* Add any deferred stack adjustment. */
22633 if (unwind.pending_offset)
22634 flush_pending_unwind ();
bfae80f2 22635
c19d1205 22636 unwind.sp_restored = 0;
bfae80f2 22637
c19d1205 22638 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 22639 {
c19d1205
ZW
22640 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
22641 if (unwind.opcodes)
325801bd
TS
22642 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
22643 unwind.opcode_alloc);
c19d1205 22644 else
325801bd 22645 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 22646 }
c19d1205 22647 while (length > 0)
bfae80f2 22648 {
c19d1205
ZW
22649 length--;
22650 unwind.opcodes[unwind.opcode_count] = op & 0xff;
22651 op >>= 8;
22652 unwind.opcode_count++;
bfae80f2 22653 }
bfae80f2
RE
22654}
22655
c19d1205
ZW
22656/* Add unwind opcodes to adjust the stack pointer. */
22657
bfae80f2 22658static void
c19d1205 22659add_unwind_adjustsp (offsetT offset)
bfae80f2 22660{
c19d1205 22661 valueT op;
bfae80f2 22662
c19d1205 22663 if (offset > 0x200)
bfae80f2 22664 {
c19d1205
ZW
22665 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
22666 char bytes[5];
22667 int n;
22668 valueT o;
bfae80f2 22669
c19d1205
ZW
22670 /* Long form: 0xb2, uleb128. */
22671 /* This might not fit in a word so add the individual bytes,
22672 remembering the list is built in reverse order. */
22673 o = (valueT) ((offset - 0x204) >> 2);
22674 if (o == 0)
22675 add_unwind_opcode (0, 1);
bfae80f2 22676
c19d1205
ZW
22677 /* Calculate the uleb128 encoding of the offset. */
22678 n = 0;
22679 while (o)
22680 {
22681 bytes[n] = o & 0x7f;
22682 o >>= 7;
22683 if (o)
22684 bytes[n] |= 0x80;
22685 n++;
22686 }
22687 /* Add the insn. */
22688 for (; n; n--)
22689 add_unwind_opcode (bytes[n - 1], 1);
22690 add_unwind_opcode (0xb2, 1);
22691 }
22692 else if (offset > 0x100)
bfae80f2 22693 {
c19d1205
ZW
22694 /* Two short opcodes. */
22695 add_unwind_opcode (0x3f, 1);
22696 op = (offset - 0x104) >> 2;
22697 add_unwind_opcode (op, 1);
bfae80f2 22698 }
c19d1205
ZW
22699 else if (offset > 0)
22700 {
22701 /* Short opcode. */
22702 op = (offset - 4) >> 2;
22703 add_unwind_opcode (op, 1);
22704 }
22705 else if (offset < 0)
bfae80f2 22706 {
c19d1205
ZW
22707 offset = -offset;
22708 while (offset > 0x100)
bfae80f2 22709 {
c19d1205
ZW
22710 add_unwind_opcode (0x7f, 1);
22711 offset -= 0x100;
bfae80f2 22712 }
c19d1205
ZW
22713 op = ((offset - 4) >> 2) | 0x40;
22714 add_unwind_opcode (op, 1);
bfae80f2 22715 }
bfae80f2
RE
22716}
22717
c19d1205 22718/* Finish the list of unwind opcodes for this function. */
0198d5e6 22719
c19d1205
ZW
22720static void
22721finish_unwind_opcodes (void)
bfae80f2 22722{
c19d1205 22723 valueT op;
bfae80f2 22724
c19d1205 22725 if (unwind.fp_used)
bfae80f2 22726 {
708587a4 22727 /* Adjust sp as necessary. */
c19d1205
ZW
22728 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22729 flush_pending_unwind ();
bfae80f2 22730
c19d1205
ZW
22731 /* After restoring sp from the frame pointer. */
22732 op = 0x90 | unwind.fp_reg;
22733 add_unwind_opcode (op, 1);
22734 }
22735 else
22736 flush_pending_unwind ();
bfae80f2
RE
22737}
22738
bfae80f2 22739
c19d1205
ZW
22740/* Start an exception table entry. If idx is nonzero this is an index table
22741 entry. */
bfae80f2
RE
22742
22743static void
c19d1205 22744start_unwind_section (const segT text_seg, int idx)
bfae80f2 22745{
c19d1205
ZW
22746 const char * text_name;
22747 const char * prefix;
22748 const char * prefix_once;
22749 const char * group_name;
c19d1205 22750 char * sec_name;
c19d1205
ZW
22751 int type;
22752 int flags;
22753 int linkonce;
bfae80f2 22754
c19d1205 22755 if (idx)
bfae80f2 22756 {
c19d1205
ZW
22757 prefix = ELF_STRING_ARM_unwind;
22758 prefix_once = ELF_STRING_ARM_unwind_once;
22759 type = SHT_ARM_EXIDX;
bfae80f2 22760 }
c19d1205 22761 else
bfae80f2 22762 {
c19d1205
ZW
22763 prefix = ELF_STRING_ARM_unwind_info;
22764 prefix_once = ELF_STRING_ARM_unwind_info_once;
22765 type = SHT_PROGBITS;
bfae80f2
RE
22766 }
22767
c19d1205
ZW
22768 text_name = segment_name (text_seg);
22769 if (streq (text_name, ".text"))
22770 text_name = "";
22771
22772 if (strncmp (text_name, ".gnu.linkonce.t.",
22773 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 22774 {
c19d1205
ZW
22775 prefix = prefix_once;
22776 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
22777 }
22778
29a2809e 22779 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 22780
c19d1205
ZW
22781 flags = SHF_ALLOC;
22782 linkonce = 0;
22783 group_name = 0;
bfae80f2 22784
c19d1205
ZW
22785 /* Handle COMDAT group. */
22786 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 22787 {
c19d1205
ZW
22788 group_name = elf_group_name (text_seg);
22789 if (group_name == NULL)
22790 {
bd3ba5d1 22791 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
22792 segment_name (text_seg));
22793 ignore_rest_of_line ();
22794 return;
22795 }
22796 flags |= SHF_GROUP;
22797 linkonce = 1;
bfae80f2
RE
22798 }
22799
a91e1603
L
22800 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
22801 linkonce, 0);
bfae80f2 22802
5f4273c7 22803 /* Set the section link for index tables. */
c19d1205
ZW
22804 if (idx)
22805 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
22806}
22807
bfae80f2 22808
c19d1205
ZW
22809/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22810 personality routine data. Returns zero, or the index table value for
cad0da33 22811 an inline entry. */
c19d1205
ZW
22812
22813static valueT
22814create_unwind_entry (int have_data)
bfae80f2 22815{
c19d1205
ZW
22816 int size;
22817 addressT where;
22818 char *ptr;
22819 /* The current word of data. */
22820 valueT data;
22821 /* The number of bytes left in this word. */
22822 int n;
bfae80f2 22823
c19d1205 22824 finish_unwind_opcodes ();
bfae80f2 22825
c19d1205
ZW
22826 /* Remember the current text section. */
22827 unwind.saved_seg = now_seg;
22828 unwind.saved_subseg = now_subseg;
bfae80f2 22829
c19d1205 22830 start_unwind_section (now_seg, 0);
bfae80f2 22831
c19d1205 22832 if (unwind.personality_routine == NULL)
bfae80f2 22833 {
c19d1205
ZW
22834 if (unwind.personality_index == -2)
22835 {
22836 if (have_data)
5f4273c7 22837 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22838 return 1; /* EXIDX_CANTUNWIND. */
22839 }
bfae80f2 22840
c19d1205
ZW
22841 /* Use a default personality routine if none is specified. */
22842 if (unwind.personality_index == -1)
22843 {
22844 if (unwind.opcode_count > 3)
22845 unwind.personality_index = 1;
22846 else
22847 unwind.personality_index = 0;
22848 }
bfae80f2 22849
c19d1205
ZW
22850 /* Space for the personality routine entry. */
22851 if (unwind.personality_index == 0)
22852 {
22853 if (unwind.opcode_count > 3)
22854 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22855
c19d1205
ZW
22856 if (!have_data)
22857 {
22858 /* All the data is inline in the index table. */
22859 data = 0x80;
22860 n = 3;
22861 while (unwind.opcode_count > 0)
22862 {
22863 unwind.opcode_count--;
22864 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22865 n--;
22866 }
bfae80f2 22867
c19d1205
ZW
22868 /* Pad with "finish" opcodes. */
22869 while (n--)
22870 data = (data << 8) | 0xb0;
bfae80f2 22871
c19d1205
ZW
22872 return data;
22873 }
22874 size = 0;
22875 }
22876 else
22877 /* We get two opcodes "free" in the first word. */
22878 size = unwind.opcode_count - 2;
22879 }
22880 else
5011093d 22881 {
cad0da33
NC
22882 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22883 if (unwind.personality_index != -1)
22884 {
22885 as_bad (_("attempt to recreate an unwind entry"));
22886 return 1;
22887 }
5011093d
NC
22888
22889 /* An extra byte is required for the opcode count. */
22890 size = unwind.opcode_count + 1;
22891 }
bfae80f2 22892
c19d1205
ZW
22893 size = (size + 3) >> 2;
22894 if (size > 0xff)
22895 as_bad (_("too many unwind opcodes"));
bfae80f2 22896
c19d1205
ZW
22897 frag_align (2, 0, 0);
22898 record_alignment (now_seg, 2);
22899 unwind.table_entry = expr_build_dot ();
22900
22901 /* Allocate the table entry. */
22902 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22903 /* PR 13449: Zero the table entries in case some of them are not used. */
22904 memset (ptr, 0, (size << 2) + 4);
c19d1205 22905 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22906
c19d1205 22907 switch (unwind.personality_index)
bfae80f2 22908 {
c19d1205
ZW
22909 case -1:
22910 /* ??? Should this be a PLT generating relocation? */
22911 /* Custom personality routine. */
22912 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22913 BFD_RELOC_ARM_PREL31);
bfae80f2 22914
c19d1205
ZW
22915 where += 4;
22916 ptr += 4;
bfae80f2 22917
c19d1205 22918 /* Set the first byte to the number of additional words. */
5011093d 22919 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22920 n = 3;
22921 break;
bfae80f2 22922
c19d1205
ZW
22923 /* ABI defined personality routines. */
22924 case 0:
22925 /* Three opcodes bytes are packed into the first word. */
22926 data = 0x80;
22927 n = 3;
22928 break;
bfae80f2 22929
c19d1205
ZW
22930 case 1:
22931 case 2:
22932 /* The size and first two opcode bytes go in the first word. */
22933 data = ((0x80 + unwind.personality_index) << 8) | size;
22934 n = 2;
22935 break;
bfae80f2 22936
c19d1205
ZW
22937 default:
22938 /* Should never happen. */
22939 abort ();
22940 }
bfae80f2 22941
c19d1205
ZW
22942 /* Pack the opcodes into words (MSB first), reversing the list at the same
22943 time. */
22944 while (unwind.opcode_count > 0)
22945 {
22946 if (n == 0)
22947 {
22948 md_number_to_chars (ptr, data, 4);
22949 ptr += 4;
22950 n = 4;
22951 data = 0;
22952 }
22953 unwind.opcode_count--;
22954 n--;
22955 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22956 }
22957
22958 /* Finish off the last word. */
22959 if (n < 4)
22960 {
22961 /* Pad with "finish" opcodes. */
22962 while (n--)
22963 data = (data << 8) | 0xb0;
22964
22965 md_number_to_chars (ptr, data, 4);
22966 }
22967
22968 if (!have_data)
22969 {
22970 /* Add an empty descriptor if there is no user-specified data. */
22971 ptr = frag_more (4);
22972 md_number_to_chars (ptr, 0, 4);
22973 }
22974
22975 return 0;
bfae80f2
RE
22976}
22977
f0927246
NC
22978
22979/* Initialize the DWARF-2 unwind information for this procedure. */
22980
22981void
22982tc_arm_frame_initial_instructions (void)
22983{
22984 cfi_add_CFA_def_cfa (REG_SP, 0);
22985}
22986#endif /* OBJ_ELF */
22987
c19d1205
ZW
22988/* Convert REGNAME to a DWARF-2 register number. */
22989
22990int
1df69f4f 22991tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22992{
1df69f4f 22993 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22994 if (reg != FAIL)
22995 return reg;
c19d1205 22996
1f5afe1c
NC
22997 /* PR 16694: Allow VFP registers as well. */
22998 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22999 if (reg != FAIL)
23000 return 64 + reg;
c19d1205 23001
1f5afe1c
NC
23002 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
23003 if (reg != FAIL)
23004 return reg + 256;
23005
0198d5e6 23006 return FAIL;
bfae80f2
RE
23007}
23008
f0927246 23009#ifdef TE_PE
c19d1205 23010void
f0927246 23011tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 23012{
91d6fa6a 23013 expressionS exp;
bfae80f2 23014
91d6fa6a
NC
23015 exp.X_op = O_secrel;
23016 exp.X_add_symbol = symbol;
23017 exp.X_add_number = 0;
23018 emit_expr (&exp, size);
f0927246
NC
23019}
23020#endif
bfae80f2 23021
c19d1205 23022/* MD interface: Symbol and relocation handling. */
bfae80f2 23023
2fc8bdac
ZW
23024/* Return the address within the segment that a PC-relative fixup is
23025 relative to. For ARM, PC-relative fixups applied to instructions
23026 are generally relative to the location of the fixup plus 8 bytes.
23027 Thumb branches are offset by 4, and Thumb loads relative to PC
23028 require special handling. */
bfae80f2 23029
c19d1205 23030long
2fc8bdac 23031md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 23032{
2fc8bdac
ZW
23033 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
23034
23035 /* If this is pc-relative and we are going to emit a relocation
23036 then we just want to put out any pipeline compensation that the linker
53baae48
NC
23037 will need. Otherwise we want to use the calculated base.
23038 For WinCE we skip the bias for externals as well, since this
23039 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 23040 if (fixP->fx_pcrel
2fc8bdac 23041 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
23042 || (arm_force_relocation (fixP)
23043#ifdef TE_WINCE
23044 && !S_IS_EXTERNAL (fixP->fx_addsy)
23045#endif
23046 )))
2fc8bdac 23047 base = 0;
bfae80f2 23048
267bf995 23049
c19d1205 23050 switch (fixP->fx_r_type)
bfae80f2 23051 {
2fc8bdac
ZW
23052 /* PC relative addressing on the Thumb is slightly odd as the
23053 bottom two bits of the PC are forced to zero for the
23054 calculation. This happens *after* application of the
23055 pipeline offset. However, Thumb adrl already adjusts for
23056 this, so we need not do it again. */
c19d1205 23057 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 23058 return base & ~3;
c19d1205
ZW
23059
23060 case BFD_RELOC_ARM_THUMB_OFFSET:
23061 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 23062 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 23063 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 23064 return (base + 4) & ~3;
c19d1205 23065
2fc8bdac 23066 /* Thumb branches are simply offset by +4. */
e12437dc 23067 case BFD_RELOC_THUMB_PCREL_BRANCH5:
2fc8bdac
ZW
23068 case BFD_RELOC_THUMB_PCREL_BRANCH7:
23069 case BFD_RELOC_THUMB_PCREL_BRANCH9:
23070 case BFD_RELOC_THUMB_PCREL_BRANCH12:
23071 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 23072 case BFD_RELOC_THUMB_PCREL_BRANCH25:
f6b2b12d 23073 case BFD_RELOC_THUMB_PCREL_BFCSEL:
e5d6e09e 23074 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 23075 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 23076 case BFD_RELOC_ARM_THUMB_BF13:
60f993ce 23077 case BFD_RELOC_ARM_THUMB_LOOP12:
2fc8bdac 23078 return base + 4;
bfae80f2 23079
267bf995 23080 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
23081 if (fixP->fx_addsy
23082 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23083 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 23084 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
23085 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23086 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
23087 return base + 4;
23088
00adf2d4
JB
23089 /* BLX is like branches above, but forces the low two bits of PC to
23090 zero. */
486499d0
CL
23091 case BFD_RELOC_THUMB_PCREL_BLX:
23092 if (fixP->fx_addsy
23093 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23094 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
23095 && THUMB_IS_FUNC (fixP->fx_addsy)
23096 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23097 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
23098 return (base + 4) & ~3;
23099
2fc8bdac
ZW
23100 /* ARM mode branches are offset by +8. However, the Windows CE
23101 loader expects the relocation not to take this into account. */
267bf995 23102 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
23103 if (fixP->fx_addsy
23104 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23105 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
23106 && ARM_IS_FUNC (fixP->fx_addsy)
23107 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23108 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 23109 return base + 8;
267bf995 23110
486499d0
CL
23111 case BFD_RELOC_ARM_PCREL_CALL:
23112 if (fixP->fx_addsy
23113 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23114 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
23115 && THUMB_IS_FUNC (fixP->fx_addsy)
23116 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23117 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 23118 return base + 8;
267bf995 23119
2fc8bdac 23120 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 23121 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 23122 case BFD_RELOC_ARM_PLT32:
c19d1205 23123#ifdef TE_WINCE
5f4273c7 23124 /* When handling fixups immediately, because we have already
477330fc 23125 discovered the value of a symbol, or the address of the frag involved
53baae48 23126 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
23127 see fixup_segment() in write.c
23128 The S_IS_EXTERNAL test handles the case of global symbols.
23129 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
23130 if (fixP->fx_pcrel
23131 && fixP->fx_addsy != NULL
23132 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23133 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
23134 return base + 8;
2fc8bdac 23135 return base;
c19d1205 23136#else
2fc8bdac 23137 return base + 8;
c19d1205 23138#endif
2fc8bdac 23139
267bf995 23140
2fc8bdac
ZW
23141 /* ARM mode loads relative to PC are also offset by +8. Unlike
23142 branches, the Windows CE loader *does* expect the relocation
23143 to take this into account. */
23144 case BFD_RELOC_ARM_OFFSET_IMM:
23145 case BFD_RELOC_ARM_OFFSET_IMM8:
23146 case BFD_RELOC_ARM_HWLITERAL:
23147 case BFD_RELOC_ARM_LITERAL:
23148 case BFD_RELOC_ARM_CP_OFF_IMM:
23149 return base + 8;
23150
23151
23152 /* Other PC-relative relocations are un-offset. */
23153 default:
23154 return base;
23155 }
bfae80f2
RE
23156}
23157
8b2d793c
NC
23158static bfd_boolean flag_warn_syms = TRUE;
23159
ae8714c2
NC
23160bfd_boolean
23161arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 23162{
8b2d793c
NC
23163 /* PR 18347 - Warn if the user attempts to create a symbol with the same
23164 name as an ARM instruction. Whilst strictly speaking it is allowed, it
23165 does mean that the resulting code might be very confusing to the reader.
23166 Also this warning can be triggered if the user omits an operand before
23167 an immediate address, eg:
23168
23169 LDR =foo
23170
23171 GAS treats this as an assignment of the value of the symbol foo to a
23172 symbol LDR, and so (without this code) it will not issue any kind of
23173 warning or error message.
23174
23175 Note - ARM instructions are case-insensitive but the strings in the hash
23176 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
23177 lower case too. */
23178 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
23179 {
23180 char * nbuf = strdup (name);
23181 char * p;
23182
23183 for (p = nbuf; *p; p++)
23184 *p = TOLOWER (*p);
23185 if (hash_find (arm_ops_hsh, nbuf) != NULL)
23186 {
23187 static struct hash_control * already_warned = NULL;
23188
23189 if (already_warned == NULL)
23190 already_warned = hash_new ();
23191 /* Only warn about the symbol once. To keep the code
23192 simple we let hash_insert do the lookup for us. */
23193 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 23194 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
23195 }
23196 else
23197 free (nbuf);
23198 }
3739860c 23199
ae8714c2
NC
23200 return FALSE;
23201}
23202
23203/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
23204 Otherwise we have no need to default values of symbols. */
23205
23206symbolS *
23207md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
23208{
23209#ifdef OBJ_ELF
23210 if (name[0] == '_' && name[1] == 'G'
23211 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
23212 {
23213 if (!GOT_symbol)
23214 {
23215 if (symbol_find (name))
23216 as_bad (_("GOT already in the symbol table"));
23217
23218 GOT_symbol = symbol_new (name, undefined_section,
23219 (valueT) 0, & zero_address_frag);
23220 }
23221
23222 return GOT_symbol;
23223 }
23224#endif
23225
c921be7d 23226 return NULL;
bfae80f2
RE
23227}
23228
55cf6793 23229/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
23230 computed as two separate immediate values, added together. We
23231 already know that this value cannot be computed by just one ARM
23232 instruction. */
23233
23234static unsigned int
23235validate_immediate_twopart (unsigned int val,
23236 unsigned int * highpart)
bfae80f2 23237{
c19d1205
ZW
23238 unsigned int a;
23239 unsigned int i;
bfae80f2 23240
c19d1205
ZW
23241 for (i = 0; i < 32; i += 2)
23242 if (((a = rotate_left (val, i)) & 0xff) != 0)
23243 {
23244 if (a & 0xff00)
23245 {
23246 if (a & ~ 0xffff)
23247 continue;
23248 * highpart = (a >> 8) | ((i + 24) << 7);
23249 }
23250 else if (a & 0xff0000)
23251 {
23252 if (a & 0xff000000)
23253 continue;
23254 * highpart = (a >> 16) | ((i + 16) << 7);
23255 }
23256 else
23257 {
9c2799c2 23258 gas_assert (a & 0xff000000);
c19d1205
ZW
23259 * highpart = (a >> 24) | ((i + 8) << 7);
23260 }
bfae80f2 23261
c19d1205
ZW
23262 return (a & 0xff) | (i << 7);
23263 }
bfae80f2 23264
c19d1205 23265 return FAIL;
bfae80f2
RE
23266}
23267
c19d1205
ZW
23268static int
23269validate_offset_imm (unsigned int val, int hwse)
23270{
23271 if ((hwse && val > 255) || val > 4095)
23272 return FAIL;
23273 return val;
23274}
bfae80f2 23275
55cf6793 23276/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
23277 negative immediate constant by altering the instruction. A bit of
23278 a hack really.
23279 MOV <-> MVN
23280 AND <-> BIC
23281 ADC <-> SBC
23282 by inverting the second operand, and
23283 ADD <-> SUB
23284 CMP <-> CMN
23285 by negating the second operand. */
bfae80f2 23286
c19d1205
ZW
23287static int
23288negate_data_op (unsigned long * instruction,
23289 unsigned long value)
bfae80f2 23290{
c19d1205
ZW
23291 int op, new_inst;
23292 unsigned long negated, inverted;
bfae80f2 23293
c19d1205
ZW
23294 negated = encode_arm_immediate (-value);
23295 inverted = encode_arm_immediate (~value);
bfae80f2 23296
c19d1205
ZW
23297 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
23298 switch (op)
bfae80f2 23299 {
c19d1205
ZW
23300 /* First negates. */
23301 case OPCODE_SUB: /* ADD <-> SUB */
23302 new_inst = OPCODE_ADD;
23303 value = negated;
23304 break;
bfae80f2 23305
c19d1205
ZW
23306 case OPCODE_ADD:
23307 new_inst = OPCODE_SUB;
23308 value = negated;
23309 break;
bfae80f2 23310
c19d1205
ZW
23311 case OPCODE_CMP: /* CMP <-> CMN */
23312 new_inst = OPCODE_CMN;
23313 value = negated;
23314 break;
bfae80f2 23315
c19d1205
ZW
23316 case OPCODE_CMN:
23317 new_inst = OPCODE_CMP;
23318 value = negated;
23319 break;
bfae80f2 23320
c19d1205
ZW
23321 /* Now Inverted ops. */
23322 case OPCODE_MOV: /* MOV <-> MVN */
23323 new_inst = OPCODE_MVN;
23324 value = inverted;
23325 break;
bfae80f2 23326
c19d1205
ZW
23327 case OPCODE_MVN:
23328 new_inst = OPCODE_MOV;
23329 value = inverted;
23330 break;
bfae80f2 23331
c19d1205
ZW
23332 case OPCODE_AND: /* AND <-> BIC */
23333 new_inst = OPCODE_BIC;
23334 value = inverted;
23335 break;
bfae80f2 23336
c19d1205
ZW
23337 case OPCODE_BIC:
23338 new_inst = OPCODE_AND;
23339 value = inverted;
23340 break;
bfae80f2 23341
c19d1205
ZW
23342 case OPCODE_ADC: /* ADC <-> SBC */
23343 new_inst = OPCODE_SBC;
23344 value = inverted;
23345 break;
bfae80f2 23346
c19d1205
ZW
23347 case OPCODE_SBC:
23348 new_inst = OPCODE_ADC;
23349 value = inverted;
23350 break;
bfae80f2 23351
c19d1205
ZW
23352 /* We cannot do anything. */
23353 default:
23354 return FAIL;
b99bd4ef
NC
23355 }
23356
c19d1205
ZW
23357 if (value == (unsigned) FAIL)
23358 return FAIL;
23359
23360 *instruction &= OPCODE_MASK;
23361 *instruction |= new_inst << DATA_OP_SHIFT;
23362 return value;
b99bd4ef
NC
23363}
23364
ef8d22e6
PB
23365/* Like negate_data_op, but for Thumb-2. */
23366
23367static unsigned int
16dd5e42 23368thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
23369{
23370 int op, new_inst;
23371 int rd;
16dd5e42 23372 unsigned int negated, inverted;
ef8d22e6
PB
23373
23374 negated = encode_thumb32_immediate (-value);
23375 inverted = encode_thumb32_immediate (~value);
23376
23377 rd = (*instruction >> 8) & 0xf;
23378 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
23379 switch (op)
23380 {
23381 /* ADD <-> SUB. Includes CMP <-> CMN. */
23382 case T2_OPCODE_SUB:
23383 new_inst = T2_OPCODE_ADD;
23384 value = negated;
23385 break;
23386
23387 case T2_OPCODE_ADD:
23388 new_inst = T2_OPCODE_SUB;
23389 value = negated;
23390 break;
23391
23392 /* ORR <-> ORN. Includes MOV <-> MVN. */
23393 case T2_OPCODE_ORR:
23394 new_inst = T2_OPCODE_ORN;
23395 value = inverted;
23396 break;
23397
23398 case T2_OPCODE_ORN:
23399 new_inst = T2_OPCODE_ORR;
23400 value = inverted;
23401 break;
23402
23403 /* AND <-> BIC. TST has no inverted equivalent. */
23404 case T2_OPCODE_AND:
23405 new_inst = T2_OPCODE_BIC;
23406 if (rd == 15)
23407 value = FAIL;
23408 else
23409 value = inverted;
23410 break;
23411
23412 case T2_OPCODE_BIC:
23413 new_inst = T2_OPCODE_AND;
23414 value = inverted;
23415 break;
23416
23417 /* ADC <-> SBC */
23418 case T2_OPCODE_ADC:
23419 new_inst = T2_OPCODE_SBC;
23420 value = inverted;
23421 break;
23422
23423 case T2_OPCODE_SBC:
23424 new_inst = T2_OPCODE_ADC;
23425 value = inverted;
23426 break;
23427
23428 /* We cannot do anything. */
23429 default:
23430 return FAIL;
23431 }
23432
16dd5e42 23433 if (value == (unsigned int)FAIL)
ef8d22e6
PB
23434 return FAIL;
23435
23436 *instruction &= T2_OPCODE_MASK;
23437 *instruction |= new_inst << T2_DATA_OP_SHIFT;
23438 return value;
23439}
23440
8f06b2d8 23441/* Read a 32-bit thumb instruction from buf. */
0198d5e6 23442
8f06b2d8
PB
23443static unsigned long
23444get_thumb32_insn (char * buf)
23445{
23446 unsigned long insn;
23447 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
23448 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23449
23450 return insn;
23451}
23452
a8bc6c78
PB
23453/* We usually want to set the low bit on the address of thumb function
23454 symbols. In particular .word foo - . should have the low bit set.
23455 Generic code tries to fold the difference of two symbols to
23456 a constant. Prevent this and force a relocation when the first symbols
23457 is a thumb function. */
c921be7d
NC
23458
23459bfd_boolean
a8bc6c78
PB
23460arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
23461{
23462 if (op == O_subtract
23463 && l->X_op == O_symbol
23464 && r->X_op == O_symbol
23465 && THUMB_IS_FUNC (l->X_add_symbol))
23466 {
23467 l->X_op = O_subtract;
23468 l->X_op_symbol = r->X_add_symbol;
23469 l->X_add_number -= r->X_add_number;
c921be7d 23470 return TRUE;
a8bc6c78 23471 }
c921be7d 23472
a8bc6c78 23473 /* Process as normal. */
c921be7d 23474 return FALSE;
a8bc6c78
PB
23475}
23476
4a42ebbc
RR
23477/* Encode Thumb2 unconditional branches and calls. The encoding
23478 for the 2 are identical for the immediate values. */
23479
23480static void
23481encode_thumb2_b_bl_offset (char * buf, offsetT value)
23482{
23483#define T2I1I2MASK ((1 << 13) | (1 << 11))
23484 offsetT newval;
23485 offsetT newval2;
23486 addressT S, I1, I2, lo, hi;
23487
23488 S = (value >> 24) & 0x01;
23489 I1 = (value >> 23) & 0x01;
23490 I2 = (value >> 22) & 0x01;
23491 hi = (value >> 12) & 0x3ff;
fa94de6b 23492 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
23493 newval = md_chars_to_number (buf, THUMB_SIZE);
23494 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23495 newval |= (S << 10) | hi;
23496 newval2 &= ~T2I1I2MASK;
23497 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
23498 md_number_to_chars (buf, newval, THUMB_SIZE);
23499 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23500}
23501
c19d1205 23502void
55cf6793 23503md_apply_fix (fixS * fixP,
c19d1205
ZW
23504 valueT * valP,
23505 segT seg)
23506{
23507 offsetT value = * valP;
23508 offsetT newval;
23509 unsigned int newimm;
23510 unsigned long temp;
23511 int sign;
23512 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 23513
9c2799c2 23514 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 23515
c19d1205 23516 /* Note whether this will delete the relocation. */
4962c51a 23517
c19d1205
ZW
23518 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
23519 fixP->fx_done = 1;
b99bd4ef 23520
adbaf948 23521 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 23522 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
23523 for emit_reloc. */
23524 value &= 0xffffffff;
23525 value ^= 0x80000000;
5f4273c7 23526 value -= 0x80000000;
adbaf948
ZW
23527
23528 *valP = value;
c19d1205 23529 fixP->fx_addnumber = value;
b99bd4ef 23530
adbaf948
ZW
23531 /* Same treatment for fixP->fx_offset. */
23532 fixP->fx_offset &= 0xffffffff;
23533 fixP->fx_offset ^= 0x80000000;
23534 fixP->fx_offset -= 0x80000000;
23535
c19d1205 23536 switch (fixP->fx_r_type)
b99bd4ef 23537 {
c19d1205
ZW
23538 case BFD_RELOC_NONE:
23539 /* This will need to go in the object file. */
23540 fixP->fx_done = 0;
23541 break;
b99bd4ef 23542
c19d1205
ZW
23543 case BFD_RELOC_ARM_IMMEDIATE:
23544 /* We claim that this fixup has been processed here,
23545 even if in fact we generate an error because we do
23546 not have a reloc for it, so tc_gen_reloc will reject it. */
23547 fixP->fx_done = 1;
b99bd4ef 23548
77db8e2e 23549 if (fixP->fx_addsy)
b99bd4ef 23550 {
77db8e2e 23551 const char *msg = 0;
b99bd4ef 23552
77db8e2e
NC
23553 if (! S_IS_DEFINED (fixP->fx_addsy))
23554 msg = _("undefined symbol %s used as an immediate value");
23555 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23556 msg = _("symbol %s is in a different section");
23557 else if (S_IS_WEAK (fixP->fx_addsy))
23558 msg = _("symbol %s is weak and may be overridden later");
23559
23560 if (msg)
23561 {
23562 as_bad_where (fixP->fx_file, fixP->fx_line,
23563 msg, S_GET_NAME (fixP->fx_addsy));
23564 break;
23565 }
42e5fcbf
AS
23566 }
23567
c19d1205
ZW
23568 temp = md_chars_to_number (buf, INSN_SIZE);
23569
5e73442d
SL
23570 /* If the offset is negative, we should use encoding A2 for ADR. */
23571 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
23572 newimm = negate_data_op (&temp, value);
23573 else
23574 {
23575 newimm = encode_arm_immediate (value);
23576
23577 /* If the instruction will fail, see if we can fix things up by
23578 changing the opcode. */
23579 if (newimm == (unsigned int) FAIL)
23580 newimm = negate_data_op (&temp, value);
bada4342
JW
23581 /* MOV accepts both ARM modified immediate (A1 encoding) and
23582 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
23583 When disassembling, MOV is preferred when there is no encoding
23584 overlap. */
23585 if (newimm == (unsigned int) FAIL
23586 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
23587 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
23588 && !((temp >> SBIT_SHIFT) & 0x1)
23589 && value >= 0 && value <= 0xffff)
23590 {
23591 /* Clear bits[23:20] to change encoding from A1 to A2. */
23592 temp &= 0xff0fffff;
23593 /* Encoding high 4bits imm. Code below will encode the remaining
23594 low 12bits. */
23595 temp |= (value & 0x0000f000) << 4;
23596 newimm = value & 0x00000fff;
23597 }
5e73442d
SL
23598 }
23599
23600 if (newimm == (unsigned int) FAIL)
b99bd4ef 23601 {
c19d1205
ZW
23602 as_bad_where (fixP->fx_file, fixP->fx_line,
23603 _("invalid constant (%lx) after fixup"),
23604 (unsigned long) value);
23605 break;
b99bd4ef 23606 }
b99bd4ef 23607
c19d1205
ZW
23608 newimm |= (temp & 0xfffff000);
23609 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
23610 break;
b99bd4ef 23611
c19d1205
ZW
23612 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23613 {
23614 unsigned int highpart = 0;
23615 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 23616
77db8e2e 23617 if (fixP->fx_addsy)
42e5fcbf 23618 {
77db8e2e 23619 const char *msg = 0;
42e5fcbf 23620
77db8e2e
NC
23621 if (! S_IS_DEFINED (fixP->fx_addsy))
23622 msg = _("undefined symbol %s used as an immediate value");
23623 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23624 msg = _("symbol %s is in a different section");
23625 else if (S_IS_WEAK (fixP->fx_addsy))
23626 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 23627
77db8e2e
NC
23628 if (msg)
23629 {
23630 as_bad_where (fixP->fx_file, fixP->fx_line,
23631 msg, S_GET_NAME (fixP->fx_addsy));
23632 break;
23633 }
23634 }
fa94de6b 23635
c19d1205
ZW
23636 newimm = encode_arm_immediate (value);
23637 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 23638
c19d1205
ZW
23639 /* If the instruction will fail, see if we can fix things up by
23640 changing the opcode. */
23641 if (newimm == (unsigned int) FAIL
23642 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
23643 {
23644 /* No ? OK - try using two ADD instructions to generate
23645 the value. */
23646 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 23647
c19d1205
ZW
23648 /* Yes - then make sure that the second instruction is
23649 also an add. */
23650 if (newimm != (unsigned int) FAIL)
23651 newinsn = temp;
23652 /* Still No ? Try using a negated value. */
23653 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
23654 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
23655 /* Otherwise - give up. */
23656 else
23657 {
23658 as_bad_where (fixP->fx_file, fixP->fx_line,
23659 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
23660 (long) value);
23661 break;
23662 }
b99bd4ef 23663
c19d1205
ZW
23664 /* Replace the first operand in the 2nd instruction (which
23665 is the PC) with the destination register. We have
23666 already added in the PC in the first instruction and we
23667 do not want to do it again. */
23668 newinsn &= ~ 0xf0000;
23669 newinsn |= ((newinsn & 0x0f000) << 4);
23670 }
b99bd4ef 23671
c19d1205
ZW
23672 newimm |= (temp & 0xfffff000);
23673 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 23674
c19d1205
ZW
23675 highpart |= (newinsn & 0xfffff000);
23676 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
23677 }
23678 break;
b99bd4ef 23679
c19d1205 23680 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23681 if (!fixP->fx_done && seg->use_rela_p)
23682 value = 0;
1a0670f3 23683 /* Fall through. */
00a97672 23684
c19d1205 23685 case BFD_RELOC_ARM_LITERAL:
26d97720 23686 sign = value > 0;
b99bd4ef 23687
c19d1205
ZW
23688 if (value < 0)
23689 value = - value;
b99bd4ef 23690
c19d1205 23691 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 23692 {
c19d1205
ZW
23693 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23694 as_bad_where (fixP->fx_file, fixP->fx_line,
23695 _("invalid literal constant: pool needs to be closer"));
23696 else
23697 as_bad_where (fixP->fx_file, fixP->fx_line,
23698 _("bad immediate value for offset (%ld)"),
23699 (long) value);
23700 break;
f03698e6
RE
23701 }
23702
c19d1205 23703 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23704 if (value == 0)
23705 newval &= 0xfffff000;
23706 else
23707 {
23708 newval &= 0xff7ff000;
23709 newval |= value | (sign ? INDEX_UP : 0);
23710 }
c19d1205
ZW
23711 md_number_to_chars (buf, newval, INSN_SIZE);
23712 break;
b99bd4ef 23713
c19d1205
ZW
23714 case BFD_RELOC_ARM_OFFSET_IMM8:
23715 case BFD_RELOC_ARM_HWLITERAL:
26d97720 23716 sign = value > 0;
b99bd4ef 23717
c19d1205
ZW
23718 if (value < 0)
23719 value = - value;
b99bd4ef 23720
c19d1205 23721 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 23722 {
c19d1205
ZW
23723 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23724 as_bad_where (fixP->fx_file, fixP->fx_line,
23725 _("invalid literal constant: pool needs to be closer"));
23726 else
427d0db6
RM
23727 as_bad_where (fixP->fx_file, fixP->fx_line,
23728 _("bad immediate value for 8-bit offset (%ld)"),
23729 (long) value);
c19d1205 23730 break;
b99bd4ef
NC
23731 }
23732
c19d1205 23733 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23734 if (value == 0)
23735 newval &= 0xfffff0f0;
23736 else
23737 {
23738 newval &= 0xff7ff0f0;
23739 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23740 }
c19d1205
ZW
23741 md_number_to_chars (buf, newval, INSN_SIZE);
23742 break;
b99bd4ef 23743
c19d1205
ZW
23744 case BFD_RELOC_ARM_T32_OFFSET_U8:
23745 if (value < 0 || value > 1020 || value % 4 != 0)
23746 as_bad_where (fixP->fx_file, fixP->fx_line,
23747 _("bad immediate value for offset (%ld)"), (long) value);
23748 value /= 4;
b99bd4ef 23749
c19d1205 23750 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
23751 newval |= value;
23752 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23753 break;
b99bd4ef 23754
c19d1205
ZW
23755 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23756 /* This is a complicated relocation used for all varieties of Thumb32
23757 load/store instruction with immediate offset:
23758
23759 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 23760 *4, optional writeback(W)
c19d1205
ZW
23761 (doubleword load/store)
23762
23763 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23764 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23765 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23766 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23767 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23768
23769 Uppercase letters indicate bits that are already encoded at
23770 this point. Lowercase letters are our problem. For the
23771 second block of instructions, the secondary opcode nybble
23772 (bits 8..11) is present, and bit 23 is zero, even if this is
23773 a PC-relative operation. */
23774 newval = md_chars_to_number (buf, THUMB_SIZE);
23775 newval <<= 16;
23776 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 23777
c19d1205 23778 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 23779 {
c19d1205
ZW
23780 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23781 if (value >= 0)
23782 newval |= (1 << 23);
23783 else
23784 value = -value;
23785 if (value % 4 != 0)
23786 {
23787 as_bad_where (fixP->fx_file, fixP->fx_line,
23788 _("offset not a multiple of 4"));
23789 break;
23790 }
23791 value /= 4;
216d22bc 23792 if (value > 0xff)
c19d1205
ZW
23793 {
23794 as_bad_where (fixP->fx_file, fixP->fx_line,
23795 _("offset out of range"));
23796 break;
23797 }
23798 newval &= ~0xff;
b99bd4ef 23799 }
c19d1205 23800 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 23801 {
c19d1205
ZW
23802 /* PC-relative, 12-bit offset. */
23803 if (value >= 0)
23804 newval |= (1 << 23);
23805 else
23806 value = -value;
216d22bc 23807 if (value > 0xfff)
c19d1205
ZW
23808 {
23809 as_bad_where (fixP->fx_file, fixP->fx_line,
23810 _("offset out of range"));
23811 break;
23812 }
23813 newval &= ~0xfff;
b99bd4ef 23814 }
c19d1205 23815 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 23816 {
c19d1205
ZW
23817 /* Writeback: 8-bit, +/- offset. */
23818 if (value >= 0)
23819 newval |= (1 << 9);
23820 else
23821 value = -value;
216d22bc 23822 if (value > 0xff)
c19d1205
ZW
23823 {
23824 as_bad_where (fixP->fx_file, fixP->fx_line,
23825 _("offset out of range"));
23826 break;
23827 }
23828 newval &= ~0xff;
b99bd4ef 23829 }
c19d1205 23830 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 23831 {
c19d1205 23832 /* T-instruction: positive 8-bit offset. */
216d22bc 23833 if (value < 0 || value > 0xff)
b99bd4ef 23834 {
c19d1205
ZW
23835 as_bad_where (fixP->fx_file, fixP->fx_line,
23836 _("offset out of range"));
23837 break;
b99bd4ef 23838 }
c19d1205
ZW
23839 newval &= ~0xff;
23840 newval |= value;
b99bd4ef
NC
23841 }
23842 else
b99bd4ef 23843 {
c19d1205
ZW
23844 /* Positive 12-bit or negative 8-bit offset. */
23845 int limit;
23846 if (value >= 0)
b99bd4ef 23847 {
c19d1205
ZW
23848 newval |= (1 << 23);
23849 limit = 0xfff;
23850 }
23851 else
23852 {
23853 value = -value;
23854 limit = 0xff;
23855 }
23856 if (value > limit)
23857 {
23858 as_bad_where (fixP->fx_file, fixP->fx_line,
23859 _("offset out of range"));
23860 break;
b99bd4ef 23861 }
c19d1205 23862 newval &= ~limit;
b99bd4ef 23863 }
b99bd4ef 23864
c19d1205
ZW
23865 newval |= value;
23866 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23867 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23868 break;
404ff6b5 23869
c19d1205
ZW
23870 case BFD_RELOC_ARM_SHIFT_IMM:
23871 newval = md_chars_to_number (buf, INSN_SIZE);
23872 if (((unsigned long) value) > 32
23873 || (value == 32
23874 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23875 {
23876 as_bad_where (fixP->fx_file, fixP->fx_line,
23877 _("shift expression is too large"));
23878 break;
23879 }
404ff6b5 23880
c19d1205
ZW
23881 if (value == 0)
23882 /* Shifts of zero must be done as lsl. */
23883 newval &= ~0x60;
23884 else if (value == 32)
23885 value = 0;
23886 newval &= 0xfffff07f;
23887 newval |= (value & 0x1f) << 7;
23888 md_number_to_chars (buf, newval, INSN_SIZE);
23889 break;
404ff6b5 23890
c19d1205 23891 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23892 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23893 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23894 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23895 /* We claim that this fixup has been processed here,
23896 even if in fact we generate an error because we do
23897 not have a reloc for it, so tc_gen_reloc will reject it. */
23898 fixP->fx_done = 1;
404ff6b5 23899
c19d1205
ZW
23900 if (fixP->fx_addsy
23901 && ! S_IS_DEFINED (fixP->fx_addsy))
23902 {
23903 as_bad_where (fixP->fx_file, fixP->fx_line,
23904 _("undefined symbol %s used as an immediate value"),
23905 S_GET_NAME (fixP->fx_addsy));
23906 break;
23907 }
404ff6b5 23908
c19d1205
ZW
23909 newval = md_chars_to_number (buf, THUMB_SIZE);
23910 newval <<= 16;
23911 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23912
16805f35 23913 newimm = FAIL;
bada4342
JW
23914 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23915 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23916 Thumb2 modified immediate encoding (T2). */
23917 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 23918 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23919 {
23920 newimm = encode_thumb32_immediate (value);
23921 if (newimm == (unsigned int) FAIL)
23922 newimm = thumb32_negate_data_op (&newval, value);
23923 }
bada4342 23924 if (newimm == (unsigned int) FAIL)
92e90b6e 23925 {
bada4342 23926 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 23927 {
bada4342
JW
23928 /* Turn add/sum into addw/subw. */
23929 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23930 newval = (newval & 0xfeffffff) | 0x02000000;
23931 /* No flat 12-bit imm encoding for addsw/subsw. */
23932 if ((newval & 0x00100000) == 0)
40f246e3 23933 {
bada4342
JW
23934 /* 12 bit immediate for addw/subw. */
23935 if (value < 0)
23936 {
23937 value = -value;
23938 newval ^= 0x00a00000;
23939 }
23940 if (value > 0xfff)
23941 newimm = (unsigned int) FAIL;
23942 else
23943 newimm = value;
23944 }
23945 }
23946 else
23947 {
23948 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23949 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23950 disassembling, MOV is preferred when there is no encoding
db7bf105 23951 overlap. */
bada4342 23952 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
db7bf105
NC
23953 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
23954 but with the Rn field [19:16] set to 1111. */
23955 && (((newval >> 16) & 0xf) == 0xf)
bada4342
JW
23956 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23957 && !((newval >> T2_SBIT_SHIFT) & 0x1)
db7bf105 23958 && value >= 0 && value <= 0xffff)
bada4342
JW
23959 {
23960 /* Toggle bit[25] to change encoding from T2 to T3. */
23961 newval ^= 1 << 25;
23962 /* Clear bits[19:16]. */
23963 newval &= 0xfff0ffff;
23964 /* Encoding high 4bits imm. Code below will encode the
23965 remaining low 12bits. */
23966 newval |= (value & 0x0000f000) << 4;
23967 newimm = value & 0x00000fff;
40f246e3 23968 }
e9f89963 23969 }
92e90b6e 23970 }
cc8a6dd0 23971
c19d1205 23972 if (newimm == (unsigned int)FAIL)
3631a3c8 23973 {
c19d1205
ZW
23974 as_bad_where (fixP->fx_file, fixP->fx_line,
23975 _("invalid constant (%lx) after fixup"),
23976 (unsigned long) value);
23977 break;
3631a3c8
NC
23978 }
23979
c19d1205
ZW
23980 newval |= (newimm & 0x800) << 15;
23981 newval |= (newimm & 0x700) << 4;
23982 newval |= (newimm & 0x0ff);
cc8a6dd0 23983
c19d1205
ZW
23984 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23985 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23986 break;
a737bd4d 23987
3eb17e6b 23988 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23989 if (((unsigned long) value) > 0xffff)
23990 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23991 _("invalid smc expression"));
2fc8bdac 23992 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23993 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23994 md_number_to_chars (buf, newval, INSN_SIZE);
23995 break;
a737bd4d 23996
90ec0d68
MGD
23997 case BFD_RELOC_ARM_HVC:
23998 if (((unsigned long) value) > 0xffff)
23999 as_bad_where (fixP->fx_file, fixP->fx_line,
24000 _("invalid hvc expression"));
24001 newval = md_chars_to_number (buf, INSN_SIZE);
24002 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
24003 md_number_to_chars (buf, newval, INSN_SIZE);
24004 break;
24005
c19d1205 24006 case BFD_RELOC_ARM_SWI:
adbaf948 24007 if (fixP->tc_fix_data != 0)
c19d1205
ZW
24008 {
24009 if (((unsigned long) value) > 0xff)
24010 as_bad_where (fixP->fx_file, fixP->fx_line,
24011 _("invalid swi expression"));
2fc8bdac 24012 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
24013 newval |= value;
24014 md_number_to_chars (buf, newval, THUMB_SIZE);
24015 }
24016 else
24017 {
24018 if (((unsigned long) value) > 0x00ffffff)
24019 as_bad_where (fixP->fx_file, fixP->fx_line,
24020 _("invalid swi expression"));
2fc8bdac 24021 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
24022 newval |= value;
24023 md_number_to_chars (buf, newval, INSN_SIZE);
24024 }
24025 break;
a737bd4d 24026
c19d1205
ZW
24027 case BFD_RELOC_ARM_MULTI:
24028 if (((unsigned long) value) > 0xffff)
24029 as_bad_where (fixP->fx_file, fixP->fx_line,
24030 _("invalid expression in load/store multiple"));
24031 newval = value | md_chars_to_number (buf, INSN_SIZE);
24032 md_number_to_chars (buf, newval, INSN_SIZE);
24033 break;
a737bd4d 24034
c19d1205 24035#ifdef OBJ_ELF
39b41c9c 24036 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
24037
24038 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
24039 && fixP->fx_addsy
34e77a92 24040 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24041 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24042 && THUMB_IS_FUNC (fixP->fx_addsy))
24043 /* Flip the bl to blx. This is a simple flip
24044 bit here because we generate PCREL_CALL for
24045 unconditional bls. */
24046 {
24047 newval = md_chars_to_number (buf, INSN_SIZE);
24048 newval = newval | 0x10000000;
24049 md_number_to_chars (buf, newval, INSN_SIZE);
24050 temp = 1;
24051 fixP->fx_done = 1;
24052 }
39b41c9c
PB
24053 else
24054 temp = 3;
24055 goto arm_branch_common;
24056
24057 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
24058 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
24059 && fixP->fx_addsy
34e77a92 24060 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24061 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24062 && THUMB_IS_FUNC (fixP->fx_addsy))
24063 {
24064 /* This would map to a bl<cond>, b<cond>,
24065 b<always> to a Thumb function. We
24066 need to force a relocation for this particular
24067 case. */
24068 newval = md_chars_to_number (buf, INSN_SIZE);
24069 fixP->fx_done = 0;
24070 }
1a0670f3 24071 /* Fall through. */
267bf995 24072
2fc8bdac 24073 case BFD_RELOC_ARM_PLT32:
c19d1205 24074#endif
39b41c9c
PB
24075 case BFD_RELOC_ARM_PCREL_BRANCH:
24076 temp = 3;
24077 goto arm_branch_common;
a737bd4d 24078
39b41c9c 24079 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 24080
39b41c9c 24081 temp = 1;
267bf995
RR
24082 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
24083 && fixP->fx_addsy
34e77a92 24084 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24085 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24086 && ARM_IS_FUNC (fixP->fx_addsy))
24087 {
24088 /* Flip the blx to a bl and warn. */
24089 const char *name = S_GET_NAME (fixP->fx_addsy);
24090 newval = 0xeb000000;
24091 as_warn_where (fixP->fx_file, fixP->fx_line,
24092 _("blx to '%s' an ARM ISA state function changed to bl"),
24093 name);
24094 md_number_to_chars (buf, newval, INSN_SIZE);
24095 temp = 3;
24096 fixP->fx_done = 1;
24097 }
24098
24099#ifdef OBJ_ELF
24100 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 24101 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
24102#endif
24103
39b41c9c 24104 arm_branch_common:
c19d1205 24105 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
24106 instruction, in a 24 bit, signed field. Bits 26 through 32 either
24107 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 24108 also be clear. */
39b41c9c 24109 if (value & temp)
c19d1205 24110 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
24111 _("misaligned branch destination"));
24112 if ((value & (offsetT)0xfe000000) != (offsetT)0
24113 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 24114 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 24115
2fc8bdac 24116 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 24117 {
2fc8bdac
ZW
24118 newval = md_chars_to_number (buf, INSN_SIZE);
24119 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
24120 /* Set the H bit on BLX instructions. */
24121 if (temp == 1)
24122 {
24123 if (value & 2)
24124 newval |= 0x01000000;
24125 else
24126 newval &= ~0x01000000;
24127 }
2fc8bdac 24128 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 24129 }
c19d1205 24130 break;
a737bd4d 24131
25fe350b
MS
24132 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
24133 /* CBZ can only branch forward. */
a737bd4d 24134
738755b0 24135 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
24136 (which, strictly speaking, are prohibited) will be turned into
24137 no-ops.
738755b0
MS
24138
24139 FIXME: It may be better to remove the instruction completely and
24140 perform relaxation. */
24141 if (value == -2)
2fc8bdac
ZW
24142 {
24143 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 24144 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
24145 md_number_to_chars (buf, newval, THUMB_SIZE);
24146 }
738755b0
MS
24147 else
24148 {
24149 if (value & ~0x7e)
08f10d51 24150 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 24151
477330fc 24152 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
24153 {
24154 newval = md_chars_to_number (buf, THUMB_SIZE);
24155 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
24156 md_number_to_chars (buf, newval, THUMB_SIZE);
24157 }
24158 }
c19d1205 24159 break;
a737bd4d 24160
c19d1205 24161 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 24162 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 24163 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 24164
2fc8bdac
ZW
24165 if (fixP->fx_done || !seg->use_rela_p)
24166 {
24167 newval = md_chars_to_number (buf, THUMB_SIZE);
24168 newval |= (value & 0x1ff) >> 1;
24169 md_number_to_chars (buf, newval, THUMB_SIZE);
24170 }
c19d1205 24171 break;
a737bd4d 24172
c19d1205 24173 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 24174 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 24175 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 24176
2fc8bdac
ZW
24177 if (fixP->fx_done || !seg->use_rela_p)
24178 {
24179 newval = md_chars_to_number (buf, THUMB_SIZE);
24180 newval |= (value & 0xfff) >> 1;
24181 md_number_to_chars (buf, newval, THUMB_SIZE);
24182 }
c19d1205 24183 break;
a737bd4d 24184
c19d1205 24185 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
24186 if (fixP->fx_addsy
24187 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 24188 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24189 && ARM_IS_FUNC (fixP->fx_addsy)
24190 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
24191 {
24192 /* Force a relocation for a branch 20 bits wide. */
24193 fixP->fx_done = 0;
24194 }
08f10d51 24195 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
24196 as_bad_where (fixP->fx_file, fixP->fx_line,
24197 _("conditional branch out of range"));
404ff6b5 24198
2fc8bdac
ZW
24199 if (fixP->fx_done || !seg->use_rela_p)
24200 {
24201 offsetT newval2;
24202 addressT S, J1, J2, lo, hi;
404ff6b5 24203
2fc8bdac
ZW
24204 S = (value & 0x00100000) >> 20;
24205 J2 = (value & 0x00080000) >> 19;
24206 J1 = (value & 0x00040000) >> 18;
24207 hi = (value & 0x0003f000) >> 12;
24208 lo = (value & 0x00000ffe) >> 1;
6c43fab6 24209
2fc8bdac
ZW
24210 newval = md_chars_to_number (buf, THUMB_SIZE);
24211 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24212 newval |= (S << 10) | hi;
24213 newval2 |= (J1 << 13) | (J2 << 11) | lo;
24214 md_number_to_chars (buf, newval, THUMB_SIZE);
24215 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
24216 }
c19d1205 24217 break;
6c43fab6 24218
c19d1205 24219 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
24220 /* If there is a blx from a thumb state function to
24221 another thumb function flip this to a bl and warn
24222 about it. */
24223
24224 if (fixP->fx_addsy
34e77a92 24225 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24226 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24227 && THUMB_IS_FUNC (fixP->fx_addsy))
24228 {
24229 const char *name = S_GET_NAME (fixP->fx_addsy);
24230 as_warn_where (fixP->fx_file, fixP->fx_line,
24231 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
24232 name);
24233 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24234 newval = newval | 0x1000;
24235 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
24236 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
24237 fixP->fx_done = 1;
24238 }
24239
24240
24241 goto thumb_bl_common;
24242
c19d1205 24243 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
24244 /* A bl from Thumb state ISA to an internal ARM state function
24245 is converted to a blx. */
24246 if (fixP->fx_addsy
24247 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 24248 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
24249 && ARM_IS_FUNC (fixP->fx_addsy)
24250 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
24251 {
24252 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24253 newval = newval & ~0x1000;
24254 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
24255 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
24256 fixP->fx_done = 1;
24257 }
24258
24259 thumb_bl_common:
24260
2fc8bdac
ZW
24261 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
24262 /* For a BLX instruction, make sure that the relocation is rounded up
24263 to a word boundary. This follows the semantics of the instruction
24264 which specifies that bit 1 of the target address will come from bit
24265 1 of the base address. */
d406f3e4
JB
24266 value = (value + 3) & ~ 3;
24267
24268#ifdef OBJ_ELF
24269 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
24270 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
24271 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
24272#endif
404ff6b5 24273
2b2f5df9
NC
24274 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
24275 {
fc289b0a 24276 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
24277 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
24278 else if ((value & ~0x1ffffff)
24279 && ((value & ~0x1ffffff) != ~0x1ffffff))
24280 as_bad_where (fixP->fx_file, fixP->fx_line,
24281 _("Thumb2 branch out of range"));
24282 }
4a42ebbc
RR
24283
24284 if (fixP->fx_done || !seg->use_rela_p)
24285 encode_thumb2_b_bl_offset (buf, value);
24286
c19d1205 24287 break;
404ff6b5 24288
c19d1205 24289 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
24290 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
24291 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 24292
2fc8bdac 24293 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 24294 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 24295
2fc8bdac 24296 break;
a737bd4d 24297
2fc8bdac
ZW
24298 case BFD_RELOC_8:
24299 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 24300 *buf = value;
c19d1205 24301 break;
a737bd4d 24302
c19d1205 24303 case BFD_RELOC_16:
2fc8bdac 24304 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 24305 md_number_to_chars (buf, value, 2);
c19d1205 24306 break;
a737bd4d 24307
c19d1205 24308#ifdef OBJ_ELF
0855e32b
NS
24309 case BFD_RELOC_ARM_TLS_CALL:
24310 case BFD_RELOC_ARM_THM_TLS_CALL:
24311 case BFD_RELOC_ARM_TLS_DESCSEQ:
24312 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 24313 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
24314 case BFD_RELOC_ARM_TLS_GD32:
24315 case BFD_RELOC_ARM_TLS_LE32:
24316 case BFD_RELOC_ARM_TLS_IE32:
24317 case BFD_RELOC_ARM_TLS_LDM32:
24318 case BFD_RELOC_ARM_TLS_LDO32:
24319 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 24320 break;
6c43fab6 24321
5c5a4843
CL
24322 /* Same handling as above, but with the arm_fdpic guard. */
24323 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
24324 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
24325 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
24326 if (arm_fdpic)
24327 {
24328 S_SET_THREAD_LOCAL (fixP->fx_addsy);
24329 }
24330 else
24331 {
24332 as_bad_where (fixP->fx_file, fixP->fx_line,
24333 _("Relocation supported only in FDPIC mode"));
24334 }
24335 break;
24336
c19d1205
ZW
24337 case BFD_RELOC_ARM_GOT32:
24338 case BFD_RELOC_ARM_GOTOFF:
c19d1205 24339 break;
b43420e6
NC
24340
24341 case BFD_RELOC_ARM_GOT_PREL:
24342 if (fixP->fx_done || !seg->use_rela_p)
477330fc 24343 md_number_to_chars (buf, value, 4);
b43420e6
NC
24344 break;
24345
9a6f4e97
NS
24346 case BFD_RELOC_ARM_TARGET2:
24347 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
24348 addend here for REL targets, because it won't be written out
24349 during reloc processing later. */
9a6f4e97
NS
24350 if (fixP->fx_done || !seg->use_rela_p)
24351 md_number_to_chars (buf, fixP->fx_offset, 4);
24352 break;
188fd7ae
CL
24353
24354 /* Relocations for FDPIC. */
24355 case BFD_RELOC_ARM_GOTFUNCDESC:
24356 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
24357 case BFD_RELOC_ARM_FUNCDESC:
24358 if (arm_fdpic)
24359 {
24360 if (fixP->fx_done || !seg->use_rela_p)
24361 md_number_to_chars (buf, 0, 4);
24362 }
24363 else
24364 {
24365 as_bad_where (fixP->fx_file, fixP->fx_line,
24366 _("Relocation supported only in FDPIC mode"));
24367 }
24368 break;
c19d1205 24369#endif
6c43fab6 24370
c19d1205
ZW
24371 case BFD_RELOC_RVA:
24372 case BFD_RELOC_32:
24373 case BFD_RELOC_ARM_TARGET1:
24374 case BFD_RELOC_ARM_ROSEGREL32:
24375 case BFD_RELOC_ARM_SBREL32:
24376 case BFD_RELOC_32_PCREL:
f0927246
NC
24377#ifdef TE_PE
24378 case BFD_RELOC_32_SECREL:
24379#endif
2fc8bdac 24380 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
24381#ifdef TE_WINCE
24382 /* For WinCE we only do this for pcrel fixups. */
24383 if (fixP->fx_done || fixP->fx_pcrel)
24384#endif
24385 md_number_to_chars (buf, value, 4);
c19d1205 24386 break;
6c43fab6 24387
c19d1205
ZW
24388#ifdef OBJ_ELF
24389 case BFD_RELOC_ARM_PREL31:
2fc8bdac 24390 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
24391 {
24392 newval = md_chars_to_number (buf, 4) & 0x80000000;
24393 if ((value ^ (value >> 1)) & 0x40000000)
24394 {
24395 as_bad_where (fixP->fx_file, fixP->fx_line,
24396 _("rel31 relocation overflow"));
24397 }
24398 newval |= value & 0x7fffffff;
24399 md_number_to_chars (buf, newval, 4);
24400 }
24401 break;
c19d1205 24402#endif
a737bd4d 24403
c19d1205 24404 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 24405 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
24406 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
24407 newval = md_chars_to_number (buf, INSN_SIZE);
24408 else
24409 newval = get_thumb32_insn (buf);
24410 if ((newval & 0x0f200f00) == 0x0d000900)
24411 {
24412 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
24413 has permitted values that are multiples of 2, in the range 0
24414 to 510. */
24415 if (value < -510 || value > 510 || (value & 1))
24416 as_bad_where (fixP->fx_file, fixP->fx_line,
24417 _("co-processor offset out of range"));
24418 }
24419 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
24420 as_bad_where (fixP->fx_file, fixP->fx_line,
24421 _("co-processor offset out of range"));
24422 cp_off_common:
26d97720 24423 sign = value > 0;
c19d1205
ZW
24424 if (value < 0)
24425 value = -value;
8f06b2d8
PB
24426 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24427 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24428 newval = md_chars_to_number (buf, INSN_SIZE);
24429 else
24430 newval = get_thumb32_insn (buf);
26d97720
NS
24431 if (value == 0)
24432 newval &= 0xffffff00;
24433 else
24434 {
24435 newval &= 0xff7fff00;
9db2f6b4
RL
24436 if ((newval & 0x0f200f00) == 0x0d000900)
24437 {
24438 /* This is a fp16 vstr/vldr.
24439
24440 It requires the immediate offset in the instruction is shifted
24441 left by 1 to be a half-word offset.
24442
24443 Here, left shift by 1 first, and later right shift by 2
24444 should get the right offset. */
24445 value <<= 1;
24446 }
26d97720
NS
24447 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
24448 }
8f06b2d8
PB
24449 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24450 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24451 md_number_to_chars (buf, newval, INSN_SIZE);
24452 else
24453 put_thumb32_insn (buf, newval);
c19d1205 24454 break;
a737bd4d 24455
c19d1205 24456 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 24457 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
24458 if (value < -255 || value > 255)
24459 as_bad_where (fixP->fx_file, fixP->fx_line,
24460 _("co-processor offset out of range"));
df7849c5 24461 value *= 4;
c19d1205 24462 goto cp_off_common;
6c43fab6 24463
c19d1205
ZW
24464 case BFD_RELOC_ARM_THUMB_OFFSET:
24465 newval = md_chars_to_number (buf, THUMB_SIZE);
24466 /* Exactly what ranges, and where the offset is inserted depends
24467 on the type of instruction, we can establish this from the
24468 top 4 bits. */
24469 switch (newval >> 12)
24470 {
24471 case 4: /* PC load. */
24472 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
24473 forced to zero for these loads; md_pcrel_from has already
24474 compensated for this. */
24475 if (value & 3)
24476 as_bad_where (fixP->fx_file, fixP->fx_line,
24477 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
24478 (((unsigned long) fixP->fx_frag->fr_address
24479 + (unsigned long) fixP->fx_where) & ~3)
24480 + (unsigned long) value);
a737bd4d 24481
c19d1205
ZW
24482 if (value & ~0x3fc)
24483 as_bad_where (fixP->fx_file, fixP->fx_line,
24484 _("invalid offset, value too big (0x%08lX)"),
24485 (long) value);
a737bd4d 24486
c19d1205
ZW
24487 newval |= value >> 2;
24488 break;
a737bd4d 24489
c19d1205
ZW
24490 case 9: /* SP load/store. */
24491 if (value & ~0x3fc)
24492 as_bad_where (fixP->fx_file, fixP->fx_line,
24493 _("invalid offset, value too big (0x%08lX)"),
24494 (long) value);
24495 newval |= value >> 2;
24496 break;
6c43fab6 24497
c19d1205
ZW
24498 case 6: /* Word load/store. */
24499 if (value & ~0x7c)
24500 as_bad_where (fixP->fx_file, fixP->fx_line,
24501 _("invalid offset, value too big (0x%08lX)"),
24502 (long) value);
24503 newval |= value << 4; /* 6 - 2. */
24504 break;
a737bd4d 24505
c19d1205
ZW
24506 case 7: /* Byte load/store. */
24507 if (value & ~0x1f)
24508 as_bad_where (fixP->fx_file, fixP->fx_line,
24509 _("invalid offset, value too big (0x%08lX)"),
24510 (long) value);
24511 newval |= value << 6;
24512 break;
a737bd4d 24513
c19d1205
ZW
24514 case 8: /* Halfword load/store. */
24515 if (value & ~0x3e)
24516 as_bad_where (fixP->fx_file, fixP->fx_line,
24517 _("invalid offset, value too big (0x%08lX)"),
24518 (long) value);
24519 newval |= value << 5; /* 6 - 1. */
24520 break;
a737bd4d 24521
c19d1205
ZW
24522 default:
24523 as_bad_where (fixP->fx_file, fixP->fx_line,
24524 "Unable to process relocation for thumb opcode: %lx",
24525 (unsigned long) newval);
24526 break;
24527 }
24528 md_number_to_chars (buf, newval, THUMB_SIZE);
24529 break;
a737bd4d 24530
c19d1205
ZW
24531 case BFD_RELOC_ARM_THUMB_ADD:
24532 /* This is a complicated relocation, since we use it for all of
24533 the following immediate relocations:
a737bd4d 24534
c19d1205
ZW
24535 3bit ADD/SUB
24536 8bit ADD/SUB
24537 9bit ADD/SUB SP word-aligned
24538 10bit ADD PC/SP word-aligned
a737bd4d 24539
c19d1205
ZW
24540 The type of instruction being processed is encoded in the
24541 instruction field:
a737bd4d 24542
c19d1205
ZW
24543 0x8000 SUB
24544 0x00F0 Rd
24545 0x000F Rs
24546 */
24547 newval = md_chars_to_number (buf, THUMB_SIZE);
24548 {
24549 int rd = (newval >> 4) & 0xf;
24550 int rs = newval & 0xf;
24551 int subtract = !!(newval & 0x8000);
a737bd4d 24552
c19d1205
ZW
24553 /* Check for HI regs, only very restricted cases allowed:
24554 Adjusting SP, and using PC or SP to get an address. */
24555 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
24556 || (rs > 7 && rs != REG_SP && rs != REG_PC))
24557 as_bad_where (fixP->fx_file, fixP->fx_line,
24558 _("invalid Hi register with immediate"));
a737bd4d 24559
c19d1205
ZW
24560 /* If value is negative, choose the opposite instruction. */
24561 if (value < 0)
24562 {
24563 value = -value;
24564 subtract = !subtract;
24565 if (value < 0)
24566 as_bad_where (fixP->fx_file, fixP->fx_line,
24567 _("immediate value out of range"));
24568 }
a737bd4d 24569
c19d1205
ZW
24570 if (rd == REG_SP)
24571 {
75c11999 24572 if (value & ~0x1fc)
c19d1205
ZW
24573 as_bad_where (fixP->fx_file, fixP->fx_line,
24574 _("invalid immediate for stack address calculation"));
24575 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
24576 newval |= value >> 2;
24577 }
24578 else if (rs == REG_PC || rs == REG_SP)
24579 {
c12d2c9d
NC
24580 /* PR gas/18541. If the addition is for a defined symbol
24581 within range of an ADR instruction then accept it. */
24582 if (subtract
24583 && value == 4
24584 && fixP->fx_addsy != NULL)
24585 {
24586 subtract = 0;
24587
24588 if (! S_IS_DEFINED (fixP->fx_addsy)
24589 || S_GET_SEGMENT (fixP->fx_addsy) != seg
24590 || S_IS_WEAK (fixP->fx_addsy))
24591 {
24592 as_bad_where (fixP->fx_file, fixP->fx_line,
24593 _("address calculation needs a strongly defined nearby symbol"));
24594 }
24595 else
24596 {
24597 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
24598
24599 /* Round up to the next 4-byte boundary. */
24600 if (v & 3)
24601 v = (v + 3) & ~ 3;
24602 else
24603 v += 4;
24604 v = S_GET_VALUE (fixP->fx_addsy) - v;
24605
24606 if (v & ~0x3fc)
24607 {
24608 as_bad_where (fixP->fx_file, fixP->fx_line,
24609 _("symbol too far away"));
24610 }
24611 else
24612 {
24613 fixP->fx_done = 1;
24614 value = v;
24615 }
24616 }
24617 }
24618
c19d1205
ZW
24619 if (subtract || value & ~0x3fc)
24620 as_bad_where (fixP->fx_file, fixP->fx_line,
24621 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 24622 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
24623 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
24624 newval |= rd << 8;
24625 newval |= value >> 2;
24626 }
24627 else if (rs == rd)
24628 {
24629 if (value & ~0xff)
24630 as_bad_where (fixP->fx_file, fixP->fx_line,
24631 _("immediate value out of range"));
24632 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
24633 newval |= (rd << 8) | value;
24634 }
24635 else
24636 {
24637 if (value & ~0x7)
24638 as_bad_where (fixP->fx_file, fixP->fx_line,
24639 _("immediate value out of range"));
24640 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
24641 newval |= rd | (rs << 3) | (value << 6);
24642 }
24643 }
24644 md_number_to_chars (buf, newval, THUMB_SIZE);
24645 break;
a737bd4d 24646
c19d1205
ZW
24647 case BFD_RELOC_ARM_THUMB_IMM:
24648 newval = md_chars_to_number (buf, THUMB_SIZE);
24649 if (value < 0 || value > 255)
24650 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 24651 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
24652 (long) value);
24653 newval |= value;
24654 md_number_to_chars (buf, newval, THUMB_SIZE);
24655 break;
a737bd4d 24656
c19d1205
ZW
24657 case BFD_RELOC_ARM_THUMB_SHIFT:
24658 /* 5bit shift value (0..32). LSL cannot take 32. */
24659 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
24660 temp = newval & 0xf800;
24661 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
24662 as_bad_where (fixP->fx_file, fixP->fx_line,
24663 _("invalid shift value: %ld"), (long) value);
24664 /* Shifts of zero must be encoded as LSL. */
24665 if (value == 0)
24666 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
24667 /* Shifts of 32 are encoded as zero. */
24668 else if (value == 32)
24669 value = 0;
24670 newval |= value << 6;
24671 md_number_to_chars (buf, newval, THUMB_SIZE);
24672 break;
a737bd4d 24673
c19d1205
ZW
24674 case BFD_RELOC_VTABLE_INHERIT:
24675 case BFD_RELOC_VTABLE_ENTRY:
24676 fixP->fx_done = 0;
24677 return;
6c43fab6 24678
b6895b4f
PB
24679 case BFD_RELOC_ARM_MOVW:
24680 case BFD_RELOC_ARM_MOVT:
24681 case BFD_RELOC_ARM_THUMB_MOVW:
24682 case BFD_RELOC_ARM_THUMB_MOVT:
24683 if (fixP->fx_done || !seg->use_rela_p)
24684 {
24685 /* REL format relocations are limited to a 16-bit addend. */
24686 if (!fixP->fx_done)
24687 {
39623e12 24688 if (value < -0x8000 || value > 0x7fff)
b6895b4f 24689 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 24690 _("offset out of range"));
b6895b4f
PB
24691 }
24692 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24693 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24694 {
24695 value >>= 16;
24696 }
24697
24698 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24699 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24700 {
24701 newval = get_thumb32_insn (buf);
24702 newval &= 0xfbf08f00;
24703 newval |= (value & 0xf000) << 4;
24704 newval |= (value & 0x0800) << 15;
24705 newval |= (value & 0x0700) << 4;
24706 newval |= (value & 0x00ff);
24707 put_thumb32_insn (buf, newval);
24708 }
24709 else
24710 {
24711 newval = md_chars_to_number (buf, 4);
24712 newval &= 0xfff0f000;
24713 newval |= value & 0x0fff;
24714 newval |= (value & 0xf000) << 4;
24715 md_number_to_chars (buf, newval, 4);
24716 }
24717 }
24718 return;
24719
72d98d16
MG
24720 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24721 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24722 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24723 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24724 gas_assert (!fixP->fx_done);
24725 {
24726 bfd_vma insn;
24727 bfd_boolean is_mov;
24728 bfd_vma encoded_addend = value;
24729
24730 /* Check that addend can be encoded in instruction. */
24731 if (!seg->use_rela_p && (value < 0 || value > 255))
24732 as_bad_where (fixP->fx_file, fixP->fx_line,
24733 _("the offset 0x%08lX is not representable"),
24734 (unsigned long) encoded_addend);
24735
24736 /* Extract the instruction. */
24737 insn = md_chars_to_number (buf, THUMB_SIZE);
24738 is_mov = (insn & 0xf800) == 0x2000;
24739
24740 /* Encode insn. */
24741 if (is_mov)
24742 {
24743 if (!seg->use_rela_p)
24744 insn |= encoded_addend;
24745 }
24746 else
24747 {
24748 int rd, rs;
24749
24750 /* Extract the instruction. */
24751 /* Encoding is the following
24752 0x8000 SUB
24753 0x00F0 Rd
24754 0x000F Rs
24755 */
24756 /* The following conditions must be true :
24757 - ADD
24758 - Rd == Rs
24759 - Rd <= 7
24760 */
24761 rd = (insn >> 4) & 0xf;
24762 rs = insn & 0xf;
24763 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24764 as_bad_where (fixP->fx_file, fixP->fx_line,
24765 _("Unable to process relocation for thumb opcode: %lx"),
24766 (unsigned long) insn);
24767
24768 /* Encode as ADD immediate8 thumb 1 code. */
24769 insn = 0x3000 | (rd << 8);
24770
24771 /* Place the encoded addend into the first 8 bits of the
24772 instruction. */
24773 if (!seg->use_rela_p)
24774 insn |= encoded_addend;
24775 }
24776
24777 /* Update the instruction. */
24778 md_number_to_chars (buf, insn, THUMB_SIZE);
24779 }
24780 break;
24781
4962c51a
MS
24782 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24783 case BFD_RELOC_ARM_ALU_PC_G0:
24784 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24785 case BFD_RELOC_ARM_ALU_PC_G1:
24786 case BFD_RELOC_ARM_ALU_PC_G2:
24787 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24788 case BFD_RELOC_ARM_ALU_SB_G0:
24789 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24790 case BFD_RELOC_ARM_ALU_SB_G1:
24791 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 24792 gas_assert (!fixP->fx_done);
4962c51a
MS
24793 if (!seg->use_rela_p)
24794 {
477330fc
RM
24795 bfd_vma insn;
24796 bfd_vma encoded_addend;
3ca4a8ec 24797 bfd_vma addend_abs = llabs (value);
477330fc
RM
24798
24799 /* Check that the absolute value of the addend can be
24800 expressed as an 8-bit constant plus a rotation. */
24801 encoded_addend = encode_arm_immediate (addend_abs);
24802 if (encoded_addend == (unsigned int) FAIL)
4962c51a 24803 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24804 _("the offset 0x%08lX is not representable"),
24805 (unsigned long) addend_abs);
24806
24807 /* Extract the instruction. */
24808 insn = md_chars_to_number (buf, INSN_SIZE);
24809
24810 /* If the addend is positive, use an ADD instruction.
24811 Otherwise use a SUB. Take care not to destroy the S bit. */
24812 insn &= 0xff1fffff;
24813 if (value < 0)
24814 insn |= 1 << 22;
24815 else
24816 insn |= 1 << 23;
24817
24818 /* Place the encoded addend into the first 12 bits of the
24819 instruction. */
24820 insn &= 0xfffff000;
24821 insn |= encoded_addend;
24822
24823 /* Update the instruction. */
24824 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
24825 }
24826 break;
24827
24828 case BFD_RELOC_ARM_LDR_PC_G0:
24829 case BFD_RELOC_ARM_LDR_PC_G1:
24830 case BFD_RELOC_ARM_LDR_PC_G2:
24831 case BFD_RELOC_ARM_LDR_SB_G0:
24832 case BFD_RELOC_ARM_LDR_SB_G1:
24833 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 24834 gas_assert (!fixP->fx_done);
4962c51a 24835 if (!seg->use_rela_p)
477330fc
RM
24836 {
24837 bfd_vma insn;
3ca4a8ec 24838 bfd_vma addend_abs = llabs (value);
4962c51a 24839
477330fc
RM
24840 /* Check that the absolute value of the addend can be
24841 encoded in 12 bits. */
24842 if (addend_abs >= 0x1000)
4962c51a 24843 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24844 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24845 (unsigned long) addend_abs);
24846
24847 /* Extract the instruction. */
24848 insn = md_chars_to_number (buf, INSN_SIZE);
24849
24850 /* If the addend is negative, clear bit 23 of the instruction.
24851 Otherwise set it. */
24852 if (value < 0)
24853 insn &= ~(1 << 23);
24854 else
24855 insn |= 1 << 23;
24856
24857 /* Place the absolute value of the addend into the first 12 bits
24858 of the instruction. */
24859 insn &= 0xfffff000;
24860 insn |= addend_abs;
24861
24862 /* Update the instruction. */
24863 md_number_to_chars (buf, insn, INSN_SIZE);
24864 }
4962c51a
MS
24865 break;
24866
24867 case BFD_RELOC_ARM_LDRS_PC_G0:
24868 case BFD_RELOC_ARM_LDRS_PC_G1:
24869 case BFD_RELOC_ARM_LDRS_PC_G2:
24870 case BFD_RELOC_ARM_LDRS_SB_G0:
24871 case BFD_RELOC_ARM_LDRS_SB_G1:
24872 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 24873 gas_assert (!fixP->fx_done);
4962c51a 24874 if (!seg->use_rela_p)
477330fc
RM
24875 {
24876 bfd_vma insn;
3ca4a8ec 24877 bfd_vma addend_abs = llabs (value);
4962c51a 24878
477330fc
RM
24879 /* Check that the absolute value of the addend can be
24880 encoded in 8 bits. */
24881 if (addend_abs >= 0x100)
4962c51a 24882 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24883 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24884 (unsigned long) addend_abs);
24885
24886 /* Extract the instruction. */
24887 insn = md_chars_to_number (buf, INSN_SIZE);
24888
24889 /* If the addend is negative, clear bit 23 of the instruction.
24890 Otherwise set it. */
24891 if (value < 0)
24892 insn &= ~(1 << 23);
24893 else
24894 insn |= 1 << 23;
24895
24896 /* Place the first four bits of the absolute value of the addend
24897 into the first 4 bits of the instruction, and the remaining
24898 four into bits 8 .. 11. */
24899 insn &= 0xfffff0f0;
24900 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24901
24902 /* Update the instruction. */
24903 md_number_to_chars (buf, insn, INSN_SIZE);
24904 }
4962c51a
MS
24905 break;
24906
24907 case BFD_RELOC_ARM_LDC_PC_G0:
24908 case BFD_RELOC_ARM_LDC_PC_G1:
24909 case BFD_RELOC_ARM_LDC_PC_G2:
24910 case BFD_RELOC_ARM_LDC_SB_G0:
24911 case BFD_RELOC_ARM_LDC_SB_G1:
24912 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 24913 gas_assert (!fixP->fx_done);
4962c51a 24914 if (!seg->use_rela_p)
477330fc
RM
24915 {
24916 bfd_vma insn;
3ca4a8ec 24917 bfd_vma addend_abs = llabs (value);
4962c51a 24918
477330fc
RM
24919 /* Check that the absolute value of the addend is a multiple of
24920 four and, when divided by four, fits in 8 bits. */
24921 if (addend_abs & 0x3)
4962c51a 24922 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24923 _("bad offset 0x%08lX (must be word-aligned)"),
24924 (unsigned long) addend_abs);
4962c51a 24925
477330fc 24926 if ((addend_abs >> 2) > 0xff)
4962c51a 24927 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24928 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24929 (unsigned long) addend_abs);
24930
24931 /* Extract the instruction. */
24932 insn = md_chars_to_number (buf, INSN_SIZE);
24933
24934 /* If the addend is negative, clear bit 23 of the instruction.
24935 Otherwise set it. */
24936 if (value < 0)
24937 insn &= ~(1 << 23);
24938 else
24939 insn |= 1 << 23;
24940
24941 /* Place the addend (divided by four) into the first eight
24942 bits of the instruction. */
24943 insn &= 0xfffffff0;
24944 insn |= addend_abs >> 2;
24945
24946 /* Update the instruction. */
24947 md_number_to_chars (buf, insn, INSN_SIZE);
24948 }
4962c51a
MS
24949 break;
24950
e12437dc
AV
24951 case BFD_RELOC_THUMB_PCREL_BRANCH5:
24952 if (fixP->fx_addsy
24953 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24954 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
24955 && ARM_IS_FUNC (fixP->fx_addsy)
24956 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
24957 {
24958 /* Force a relocation for a branch 5 bits wide. */
24959 fixP->fx_done = 0;
24960 }
24961 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
24962 as_bad_where (fixP->fx_file, fixP->fx_line,
24963 BAD_BRANCH_OFF);
24964
24965 if (fixP->fx_done || !seg->use_rela_p)
24966 {
24967 addressT boff = value >> 1;
24968
24969 newval = md_chars_to_number (buf, THUMB_SIZE);
24970 newval |= (boff << 7);
24971 md_number_to_chars (buf, newval, THUMB_SIZE);
24972 }
24973 break;
24974
f6b2b12d
AV
24975 case BFD_RELOC_THUMB_PCREL_BFCSEL:
24976 if (fixP->fx_addsy
24977 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24978 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
24979 && ARM_IS_FUNC (fixP->fx_addsy)
24980 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
24981 {
24982 fixP->fx_done = 0;
24983 }
24984 if ((value & ~0x7f) && ((value & ~0x3f) != ~0x3f))
24985 as_bad_where (fixP->fx_file, fixP->fx_line,
24986 _("branch out of range"));
24987
24988 if (fixP->fx_done || !seg->use_rela_p)
24989 {
24990 newval = md_chars_to_number (buf, THUMB_SIZE);
24991
24992 addressT boff = ((newval & 0x0780) >> 7) << 1;
24993 addressT diff = value - boff;
24994
24995 if (diff == 4)
24996 {
24997 newval |= 1 << 1; /* T bit. */
24998 }
24999 else if (diff != 2)
25000 {
25001 as_bad_where (fixP->fx_file, fixP->fx_line,
25002 _("out of range label-relative fixup value"));
25003 }
25004 md_number_to_chars (buf, newval, THUMB_SIZE);
25005 }
25006 break;
25007
e5d6e09e
AV
25008 case BFD_RELOC_ARM_THUMB_BF17:
25009 if (fixP->fx_addsy
25010 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25011 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25012 && ARM_IS_FUNC (fixP->fx_addsy)
25013 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25014 {
25015 /* Force a relocation for a branch 17 bits wide. */
25016 fixP->fx_done = 0;
25017 }
25018
25019 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
25020 as_bad_where (fixP->fx_file, fixP->fx_line,
25021 BAD_BRANCH_OFF);
25022
25023 if (fixP->fx_done || !seg->use_rela_p)
25024 {
25025 offsetT newval2;
25026 addressT immA, immB, immC;
25027
25028 immA = (value & 0x0001f000) >> 12;
25029 immB = (value & 0x00000ffc) >> 2;
25030 immC = (value & 0x00000002) >> 1;
25031
25032 newval = md_chars_to_number (buf, THUMB_SIZE);
25033 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25034 newval |= immA;
25035 newval2 |= (immC << 11) | (immB << 1);
25036 md_number_to_chars (buf, newval, THUMB_SIZE);
25037 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25038 }
25039 break;
25040
1caf72a5
AV
25041 case BFD_RELOC_ARM_THUMB_BF19:
25042 if (fixP->fx_addsy
25043 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25044 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25045 && ARM_IS_FUNC (fixP->fx_addsy)
25046 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25047 {
25048 /* Force a relocation for a branch 19 bits wide. */
25049 fixP->fx_done = 0;
25050 }
25051
25052 if (v8_1_branch_value_check (value, 19, TRUE) == FAIL)
25053 as_bad_where (fixP->fx_file, fixP->fx_line,
25054 BAD_BRANCH_OFF);
25055
25056 if (fixP->fx_done || !seg->use_rela_p)
25057 {
25058 offsetT newval2;
25059 addressT immA, immB, immC;
25060
25061 immA = (value & 0x0007f000) >> 12;
25062 immB = (value & 0x00000ffc) >> 2;
25063 immC = (value & 0x00000002) >> 1;
25064
25065 newval = md_chars_to_number (buf, THUMB_SIZE);
25066 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25067 newval |= immA;
25068 newval2 |= (immC << 11) | (immB << 1);
25069 md_number_to_chars (buf, newval, THUMB_SIZE);
25070 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25071 }
25072 break;
25073
1889da70
AV
25074 case BFD_RELOC_ARM_THUMB_BF13:
25075 if (fixP->fx_addsy
25076 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25077 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25078 && ARM_IS_FUNC (fixP->fx_addsy)
25079 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25080 {
25081 /* Force a relocation for a branch 13 bits wide. */
25082 fixP->fx_done = 0;
25083 }
25084
25085 if (v8_1_branch_value_check (value, 13, TRUE) == FAIL)
25086 as_bad_where (fixP->fx_file, fixP->fx_line,
25087 BAD_BRANCH_OFF);
25088
25089 if (fixP->fx_done || !seg->use_rela_p)
25090 {
25091 offsetT newval2;
25092 addressT immA, immB, immC;
25093
25094 immA = (value & 0x00001000) >> 12;
25095 immB = (value & 0x00000ffc) >> 2;
25096 immC = (value & 0x00000002) >> 1;
25097
25098 newval = md_chars_to_number (buf, THUMB_SIZE);
25099 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25100 newval |= immA;
25101 newval2 |= (immC << 11) | (immB << 1);
25102 md_number_to_chars (buf, newval, THUMB_SIZE);
25103 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25104 }
25105 break;
25106
60f993ce
AV
25107 case BFD_RELOC_ARM_THUMB_LOOP12:
25108 if (fixP->fx_addsy
25109 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25110 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25111 && ARM_IS_FUNC (fixP->fx_addsy)
25112 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25113 {
25114 /* Force a relocation for a branch 12 bits wide. */
25115 fixP->fx_done = 0;
25116 }
25117
25118 bfd_vma insn = get_thumb32_insn (buf);
25119 /* le lr, <label> or le <label> */
25120 if (((insn & 0xffffffff) == 0xf00fc001)
25121 || ((insn & 0xffffffff) == 0xf02fc001))
25122 value = -value;
25123
25124 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
25125 as_bad_where (fixP->fx_file, fixP->fx_line,
25126 BAD_BRANCH_OFF);
25127 if (fixP->fx_done || !seg->use_rela_p)
25128 {
25129 addressT imml, immh;
25130
25131 immh = (value & 0x00000ffc) >> 2;
25132 imml = (value & 0x00000002) >> 1;
25133
25134 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25135 newval |= (imml << 11) | (immh << 1);
25136 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
25137 }
25138 break;
25139
845b51d6
PB
25140 case BFD_RELOC_ARM_V4BX:
25141 /* This will need to go in the object file. */
25142 fixP->fx_done = 0;
25143 break;
25144
c19d1205
ZW
25145 case BFD_RELOC_UNUSED:
25146 default:
25147 as_bad_where (fixP->fx_file, fixP->fx_line,
25148 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
25149 }
6c43fab6
RE
25150}
25151
c19d1205
ZW
25152/* Translate internal representation of relocation info to BFD target
25153 format. */
a737bd4d 25154
c19d1205 25155arelent *
00a97672 25156tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 25157{
c19d1205
ZW
25158 arelent * reloc;
25159 bfd_reloc_code_real_type code;
a737bd4d 25160
325801bd 25161 reloc = XNEW (arelent);
a737bd4d 25162
325801bd 25163 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
25164 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
25165 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 25166
2fc8bdac 25167 if (fixp->fx_pcrel)
00a97672
RS
25168 {
25169 if (section->use_rela_p)
25170 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
25171 else
25172 fixp->fx_offset = reloc->address;
25173 }
c19d1205 25174 reloc->addend = fixp->fx_offset;
a737bd4d 25175
c19d1205 25176 switch (fixp->fx_r_type)
a737bd4d 25177 {
c19d1205
ZW
25178 case BFD_RELOC_8:
25179 if (fixp->fx_pcrel)
25180 {
25181 code = BFD_RELOC_8_PCREL;
25182 break;
25183 }
1a0670f3 25184 /* Fall through. */
a737bd4d 25185
c19d1205
ZW
25186 case BFD_RELOC_16:
25187 if (fixp->fx_pcrel)
25188 {
25189 code = BFD_RELOC_16_PCREL;
25190 break;
25191 }
1a0670f3 25192 /* Fall through. */
6c43fab6 25193
c19d1205
ZW
25194 case BFD_RELOC_32:
25195 if (fixp->fx_pcrel)
25196 {
25197 code = BFD_RELOC_32_PCREL;
25198 break;
25199 }
1a0670f3 25200 /* Fall through. */
a737bd4d 25201
b6895b4f
PB
25202 case BFD_RELOC_ARM_MOVW:
25203 if (fixp->fx_pcrel)
25204 {
25205 code = BFD_RELOC_ARM_MOVW_PCREL;
25206 break;
25207 }
1a0670f3 25208 /* Fall through. */
b6895b4f
PB
25209
25210 case BFD_RELOC_ARM_MOVT:
25211 if (fixp->fx_pcrel)
25212 {
25213 code = BFD_RELOC_ARM_MOVT_PCREL;
25214 break;
25215 }
1a0670f3 25216 /* Fall through. */
b6895b4f
PB
25217
25218 case BFD_RELOC_ARM_THUMB_MOVW:
25219 if (fixp->fx_pcrel)
25220 {
25221 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
25222 break;
25223 }
1a0670f3 25224 /* Fall through. */
b6895b4f
PB
25225
25226 case BFD_RELOC_ARM_THUMB_MOVT:
25227 if (fixp->fx_pcrel)
25228 {
25229 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
25230 break;
25231 }
1a0670f3 25232 /* Fall through. */
b6895b4f 25233
c19d1205
ZW
25234 case BFD_RELOC_NONE:
25235 case BFD_RELOC_ARM_PCREL_BRANCH:
25236 case BFD_RELOC_ARM_PCREL_BLX:
25237 case BFD_RELOC_RVA:
25238 case BFD_RELOC_THUMB_PCREL_BRANCH7:
25239 case BFD_RELOC_THUMB_PCREL_BRANCH9:
25240 case BFD_RELOC_THUMB_PCREL_BRANCH12:
25241 case BFD_RELOC_THUMB_PCREL_BRANCH20:
25242 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25243 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
25244 case BFD_RELOC_VTABLE_ENTRY:
25245 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
25246#ifdef TE_PE
25247 case BFD_RELOC_32_SECREL:
25248#endif
c19d1205
ZW
25249 code = fixp->fx_r_type;
25250 break;
a737bd4d 25251
00adf2d4
JB
25252 case BFD_RELOC_THUMB_PCREL_BLX:
25253#ifdef OBJ_ELF
25254 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
25255 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
25256 else
25257#endif
25258 code = BFD_RELOC_THUMB_PCREL_BLX;
25259 break;
25260
c19d1205
ZW
25261 case BFD_RELOC_ARM_LITERAL:
25262 case BFD_RELOC_ARM_HWLITERAL:
25263 /* If this is called then the a literal has
25264 been referenced across a section boundary. */
25265 as_bad_where (fixp->fx_file, fixp->fx_line,
25266 _("literal referenced across section boundary"));
25267 return NULL;
a737bd4d 25268
c19d1205 25269#ifdef OBJ_ELF
0855e32b
NS
25270 case BFD_RELOC_ARM_TLS_CALL:
25271 case BFD_RELOC_ARM_THM_TLS_CALL:
25272 case BFD_RELOC_ARM_TLS_DESCSEQ:
25273 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
25274 case BFD_RELOC_ARM_GOT32:
25275 case BFD_RELOC_ARM_GOTOFF:
b43420e6 25276 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
25277 case BFD_RELOC_ARM_PLT32:
25278 case BFD_RELOC_ARM_TARGET1:
25279 case BFD_RELOC_ARM_ROSEGREL32:
25280 case BFD_RELOC_ARM_SBREL32:
25281 case BFD_RELOC_ARM_PREL31:
25282 case BFD_RELOC_ARM_TARGET2:
c19d1205 25283 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
25284 case BFD_RELOC_ARM_PCREL_CALL:
25285 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
25286 case BFD_RELOC_ARM_ALU_PC_G0_NC:
25287 case BFD_RELOC_ARM_ALU_PC_G0:
25288 case BFD_RELOC_ARM_ALU_PC_G1_NC:
25289 case BFD_RELOC_ARM_ALU_PC_G1:
25290 case BFD_RELOC_ARM_ALU_PC_G2:
25291 case BFD_RELOC_ARM_LDR_PC_G0:
25292 case BFD_RELOC_ARM_LDR_PC_G1:
25293 case BFD_RELOC_ARM_LDR_PC_G2:
25294 case BFD_RELOC_ARM_LDRS_PC_G0:
25295 case BFD_RELOC_ARM_LDRS_PC_G1:
25296 case BFD_RELOC_ARM_LDRS_PC_G2:
25297 case BFD_RELOC_ARM_LDC_PC_G0:
25298 case BFD_RELOC_ARM_LDC_PC_G1:
25299 case BFD_RELOC_ARM_LDC_PC_G2:
25300 case BFD_RELOC_ARM_ALU_SB_G0_NC:
25301 case BFD_RELOC_ARM_ALU_SB_G0:
25302 case BFD_RELOC_ARM_ALU_SB_G1_NC:
25303 case BFD_RELOC_ARM_ALU_SB_G1:
25304 case BFD_RELOC_ARM_ALU_SB_G2:
25305 case BFD_RELOC_ARM_LDR_SB_G0:
25306 case BFD_RELOC_ARM_LDR_SB_G1:
25307 case BFD_RELOC_ARM_LDR_SB_G2:
25308 case BFD_RELOC_ARM_LDRS_SB_G0:
25309 case BFD_RELOC_ARM_LDRS_SB_G1:
25310 case BFD_RELOC_ARM_LDRS_SB_G2:
25311 case BFD_RELOC_ARM_LDC_SB_G0:
25312 case BFD_RELOC_ARM_LDC_SB_G1:
25313 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 25314 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
25315 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
25316 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
25317 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
25318 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
188fd7ae
CL
25319 case BFD_RELOC_ARM_GOTFUNCDESC:
25320 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
25321 case BFD_RELOC_ARM_FUNCDESC:
e5d6e09e 25322 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 25323 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 25324 case BFD_RELOC_ARM_THUMB_BF13:
c19d1205
ZW
25325 code = fixp->fx_r_type;
25326 break;
a737bd4d 25327
0855e32b 25328 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 25329 case BFD_RELOC_ARM_TLS_GD32:
5c5a4843 25330 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
75c11999 25331 case BFD_RELOC_ARM_TLS_LE32:
c19d1205 25332 case BFD_RELOC_ARM_TLS_IE32:
5c5a4843 25333 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
c19d1205 25334 case BFD_RELOC_ARM_TLS_LDM32:
5c5a4843 25335 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
c19d1205
ZW
25336 /* BFD will include the symbol's address in the addend.
25337 But we don't want that, so subtract it out again here. */
25338 if (!S_IS_COMMON (fixp->fx_addsy))
25339 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
25340 code = fixp->fx_r_type;
25341 break;
25342#endif
a737bd4d 25343
c19d1205
ZW
25344 case BFD_RELOC_ARM_IMMEDIATE:
25345 as_bad_where (fixp->fx_file, fixp->fx_line,
25346 _("internal relocation (type: IMMEDIATE) not fixed up"));
25347 return NULL;
a737bd4d 25348
c19d1205
ZW
25349 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
25350 as_bad_where (fixp->fx_file, fixp->fx_line,
25351 _("ADRL used for a symbol not defined in the same file"));
25352 return NULL;
a737bd4d 25353
e12437dc 25354 case BFD_RELOC_THUMB_PCREL_BRANCH5:
f6b2b12d 25355 case BFD_RELOC_THUMB_PCREL_BFCSEL:
60f993ce 25356 case BFD_RELOC_ARM_THUMB_LOOP12:
e12437dc
AV
25357 as_bad_where (fixp->fx_file, fixp->fx_line,
25358 _("%s used for a symbol not defined in the same file"),
25359 bfd_get_reloc_code_name (fixp->fx_r_type));
25360 return NULL;
25361
c19d1205 25362 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
25363 if (section->use_rela_p)
25364 {
25365 code = fixp->fx_r_type;
25366 break;
25367 }
25368
c19d1205
ZW
25369 if (fixp->fx_addsy != NULL
25370 && !S_IS_DEFINED (fixp->fx_addsy)
25371 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 25372 {
c19d1205
ZW
25373 as_bad_where (fixp->fx_file, fixp->fx_line,
25374 _("undefined local label `%s'"),
25375 S_GET_NAME (fixp->fx_addsy));
25376 return NULL;
a737bd4d
NC
25377 }
25378
c19d1205
ZW
25379 as_bad_where (fixp->fx_file, fixp->fx_line,
25380 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
25381 return NULL;
a737bd4d 25382
c19d1205
ZW
25383 default:
25384 {
e0471c16 25385 const char * type;
6c43fab6 25386
c19d1205
ZW
25387 switch (fixp->fx_r_type)
25388 {
25389 case BFD_RELOC_NONE: type = "NONE"; break;
25390 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
25391 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 25392 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
25393 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
25394 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
25395 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 25396 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 25397 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
25398 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
25399 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
25400 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
25401 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
25402 default: type = _("<unknown>"); break;
25403 }
25404 as_bad_where (fixp->fx_file, fixp->fx_line,
25405 _("cannot represent %s relocation in this object file format"),
25406 type);
25407 return NULL;
25408 }
a737bd4d 25409 }
6c43fab6 25410
c19d1205
ZW
25411#ifdef OBJ_ELF
25412 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
25413 && GOT_symbol
25414 && fixp->fx_addsy == GOT_symbol)
25415 {
25416 code = BFD_RELOC_ARM_GOTPC;
25417 reloc->addend = fixp->fx_offset = reloc->address;
25418 }
25419#endif
6c43fab6 25420
c19d1205 25421 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 25422
c19d1205
ZW
25423 if (reloc->howto == NULL)
25424 {
25425 as_bad_where (fixp->fx_file, fixp->fx_line,
25426 _("cannot represent %s relocation in this object file format"),
25427 bfd_get_reloc_code_name (code));
25428 return NULL;
25429 }
6c43fab6 25430
c19d1205
ZW
25431 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
25432 vtable entry to be used in the relocation's section offset. */
25433 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
25434 reloc->address = fixp->fx_offset;
6c43fab6 25435
c19d1205 25436 return reloc;
6c43fab6
RE
25437}
25438
c19d1205 25439/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 25440
c19d1205
ZW
25441void
25442cons_fix_new_arm (fragS * frag,
25443 int where,
25444 int size,
62ebcb5c
AM
25445 expressionS * exp,
25446 bfd_reloc_code_real_type reloc)
6c43fab6 25447{
c19d1205 25448 int pcrel = 0;
6c43fab6 25449
c19d1205
ZW
25450 /* Pick a reloc.
25451 FIXME: @@ Should look at CPU word size. */
25452 switch (size)
25453 {
25454 case 1:
62ebcb5c 25455 reloc = BFD_RELOC_8;
c19d1205
ZW
25456 break;
25457 case 2:
62ebcb5c 25458 reloc = BFD_RELOC_16;
c19d1205
ZW
25459 break;
25460 case 4:
25461 default:
62ebcb5c 25462 reloc = BFD_RELOC_32;
c19d1205
ZW
25463 break;
25464 case 8:
62ebcb5c 25465 reloc = BFD_RELOC_64;
c19d1205
ZW
25466 break;
25467 }
6c43fab6 25468
f0927246
NC
25469#ifdef TE_PE
25470 if (exp->X_op == O_secrel)
25471 {
25472 exp->X_op = O_symbol;
62ebcb5c 25473 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
25474 }
25475#endif
25476
62ebcb5c 25477 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 25478}
6c43fab6 25479
4343666d 25480#if defined (OBJ_COFF)
c19d1205
ZW
25481void
25482arm_validate_fix (fixS * fixP)
6c43fab6 25483{
c19d1205
ZW
25484 /* If the destination of the branch is a defined symbol which does not have
25485 the THUMB_FUNC attribute, then we must be calling a function which has
25486 the (interfacearm) attribute. We look for the Thumb entry point to that
25487 function and change the branch to refer to that function instead. */
25488 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
25489 && fixP->fx_addsy != NULL
25490 && S_IS_DEFINED (fixP->fx_addsy)
25491 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 25492 {
c19d1205 25493 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 25494 }
c19d1205
ZW
25495}
25496#endif
6c43fab6 25497
267bf995 25498
c19d1205
ZW
25499int
25500arm_force_relocation (struct fix * fixp)
25501{
25502#if defined (OBJ_COFF) && defined (TE_PE)
25503 if (fixp->fx_r_type == BFD_RELOC_RVA)
25504 return 1;
25505#endif
6c43fab6 25506
267bf995
RR
25507 /* In case we have a call or a branch to a function in ARM ISA mode from
25508 a thumb function or vice-versa force the relocation. These relocations
25509 are cleared off for some cores that might have blx and simple transformations
25510 are possible. */
25511
25512#ifdef OBJ_ELF
25513 switch (fixp->fx_r_type)
25514 {
25515 case BFD_RELOC_ARM_PCREL_JUMP:
25516 case BFD_RELOC_ARM_PCREL_CALL:
25517 case BFD_RELOC_THUMB_PCREL_BLX:
25518 if (THUMB_IS_FUNC (fixp->fx_addsy))
25519 return 1;
25520 break;
25521
25522 case BFD_RELOC_ARM_PCREL_BLX:
25523 case BFD_RELOC_THUMB_PCREL_BRANCH25:
25524 case BFD_RELOC_THUMB_PCREL_BRANCH20:
25525 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25526 if (ARM_IS_FUNC (fixp->fx_addsy))
25527 return 1;
25528 break;
25529
25530 default:
25531 break;
25532 }
25533#endif
25534
b5884301
PB
25535 /* Resolve these relocations even if the symbol is extern or weak.
25536 Technically this is probably wrong due to symbol preemption.
25537 In practice these relocations do not have enough range to be useful
25538 at dynamic link time, and some code (e.g. in the Linux kernel)
25539 expects these references to be resolved. */
c19d1205
ZW
25540 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
25541 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 25542 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 25543 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
25544 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
25545 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
25546 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 25547 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
25548 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
25549 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
25550 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
25551 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
25552 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
25553 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 25554 return 0;
a737bd4d 25555
4962c51a
MS
25556 /* Always leave these relocations for the linker. */
25557 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25558 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25559 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
25560 return 1;
25561
f0291e4c
PB
25562 /* Always generate relocations against function symbols. */
25563 if (fixp->fx_r_type == BFD_RELOC_32
25564 && fixp->fx_addsy
25565 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
25566 return 1;
25567
c19d1205 25568 return generic_force_reloc (fixp);
404ff6b5
AH
25569}
25570
0ffdc86c 25571#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
25572/* Relocations against function names must be left unadjusted,
25573 so that the linker can use this information to generate interworking
25574 stubs. The MIPS version of this function
c19d1205
ZW
25575 also prevents relocations that are mips-16 specific, but I do not
25576 know why it does this.
404ff6b5 25577
c19d1205
ZW
25578 FIXME:
25579 There is one other problem that ought to be addressed here, but
25580 which currently is not: Taking the address of a label (rather
25581 than a function) and then later jumping to that address. Such
25582 addresses also ought to have their bottom bit set (assuming that
25583 they reside in Thumb code), but at the moment they will not. */
404ff6b5 25584
c19d1205
ZW
25585bfd_boolean
25586arm_fix_adjustable (fixS * fixP)
404ff6b5 25587{
c19d1205
ZW
25588 if (fixP->fx_addsy == NULL)
25589 return 1;
404ff6b5 25590
e28387c3
PB
25591 /* Preserve relocations against symbols with function type. */
25592 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 25593 return FALSE;
e28387c3 25594
c19d1205
ZW
25595 if (THUMB_IS_FUNC (fixP->fx_addsy)
25596 && fixP->fx_subsy == NULL)
c921be7d 25597 return FALSE;
a737bd4d 25598
c19d1205
ZW
25599 /* We need the symbol name for the VTABLE entries. */
25600 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
25601 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 25602 return FALSE;
404ff6b5 25603
c19d1205
ZW
25604 /* Don't allow symbols to be discarded on GOT related relocs. */
25605 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
25606 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
25607 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
25608 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
5c5a4843 25609 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
c19d1205
ZW
25610 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
25611 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
5c5a4843 25612 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
c19d1205 25613 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
5c5a4843 25614 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
c19d1205 25615 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
25616 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
25617 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
25618 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
25619 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
25620 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 25621 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 25622 return FALSE;
a737bd4d 25623
4962c51a
MS
25624 /* Similarly for group relocations. */
25625 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25626 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25627 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 25628 return FALSE;
4962c51a 25629
79947c54
CD
25630 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
25631 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
25632 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
25633 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
25634 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
25635 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
25636 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
25637 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
25638 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 25639 return FALSE;
79947c54 25640
72d98d16
MG
25641 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
25642 offsets, so keep these symbols. */
25643 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
25644 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
25645 return FALSE;
25646
c921be7d 25647 return TRUE;
a737bd4d 25648}
0ffdc86c
NC
25649#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
25650
25651#ifdef OBJ_ELF
c19d1205
ZW
25652const char *
25653elf32_arm_target_format (void)
404ff6b5 25654{
c19d1205
ZW
25655#ifdef TE_SYMBIAN
25656 return (target_big_endian
25657 ? "elf32-bigarm-symbian"
25658 : "elf32-littlearm-symbian");
25659#elif defined (TE_VXWORKS)
25660 return (target_big_endian
25661 ? "elf32-bigarm-vxworks"
25662 : "elf32-littlearm-vxworks");
b38cadfb
NC
25663#elif defined (TE_NACL)
25664 return (target_big_endian
25665 ? "elf32-bigarm-nacl"
25666 : "elf32-littlearm-nacl");
c19d1205 25667#else
18a20338
CL
25668 if (arm_fdpic)
25669 {
25670 if (target_big_endian)
25671 return "elf32-bigarm-fdpic";
25672 else
25673 return "elf32-littlearm-fdpic";
25674 }
c19d1205 25675 else
18a20338
CL
25676 {
25677 if (target_big_endian)
25678 return "elf32-bigarm";
25679 else
25680 return "elf32-littlearm";
25681 }
c19d1205 25682#endif
404ff6b5
AH
25683}
25684
c19d1205
ZW
25685void
25686armelf_frob_symbol (symbolS * symp,
25687 int * puntp)
404ff6b5 25688{
c19d1205
ZW
25689 elf_frob_symbol (symp, puntp);
25690}
25691#endif
404ff6b5 25692
c19d1205 25693/* MD interface: Finalization. */
a737bd4d 25694
c19d1205
ZW
25695void
25696arm_cleanup (void)
25697{
25698 literal_pool * pool;
a737bd4d 25699
e07e6e58
NC
25700 /* Ensure that all the IT blocks are properly closed. */
25701 check_it_blocks_finished ();
25702
c19d1205
ZW
25703 for (pool = list_of_pools; pool; pool = pool->next)
25704 {
5f4273c7 25705 /* Put it at the end of the relevant section. */
c19d1205
ZW
25706 subseg_set (pool->section, pool->sub_section);
25707#ifdef OBJ_ELF
25708 arm_elf_change_section ();
25709#endif
25710 s_ltorg (0);
25711 }
404ff6b5
AH
25712}
25713
cd000bff
DJ
25714#ifdef OBJ_ELF
25715/* Remove any excess mapping symbols generated for alignment frags in
25716 SEC. We may have created a mapping symbol before a zero byte
25717 alignment; remove it if there's a mapping symbol after the
25718 alignment. */
25719static void
25720check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
25721 void *dummy ATTRIBUTE_UNUSED)
25722{
25723 segment_info_type *seginfo = seg_info (sec);
25724 fragS *fragp;
25725
25726 if (seginfo == NULL || seginfo->frchainP == NULL)
25727 return;
25728
25729 for (fragp = seginfo->frchainP->frch_root;
25730 fragp != NULL;
25731 fragp = fragp->fr_next)
25732 {
25733 symbolS *sym = fragp->tc_frag_data.last_map;
25734 fragS *next = fragp->fr_next;
25735
25736 /* Variable-sized frags have been converted to fixed size by
25737 this point. But if this was variable-sized to start with,
25738 there will be a fixed-size frag after it. So don't handle
25739 next == NULL. */
25740 if (sym == NULL || next == NULL)
25741 continue;
25742
25743 if (S_GET_VALUE (sym) < next->fr_address)
25744 /* Not at the end of this frag. */
25745 continue;
25746 know (S_GET_VALUE (sym) == next->fr_address);
25747
25748 do
25749 {
25750 if (next->tc_frag_data.first_map != NULL)
25751 {
25752 /* Next frag starts with a mapping symbol. Discard this
25753 one. */
25754 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25755 break;
25756 }
25757
25758 if (next->fr_next == NULL)
25759 {
25760 /* This mapping symbol is at the end of the section. Discard
25761 it. */
25762 know (next->fr_fix == 0 && next->fr_var == 0);
25763 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25764 break;
25765 }
25766
25767 /* As long as we have empty frags without any mapping symbols,
25768 keep looking. */
25769 /* If the next frag is non-empty and does not start with a
25770 mapping symbol, then this mapping symbol is required. */
25771 if (next->fr_address != next->fr_next->fr_address)
25772 break;
25773
25774 next = next->fr_next;
25775 }
25776 while (next != NULL);
25777 }
25778}
25779#endif
25780
c19d1205
ZW
25781/* Adjust the symbol table. This marks Thumb symbols as distinct from
25782 ARM ones. */
404ff6b5 25783
c19d1205
ZW
25784void
25785arm_adjust_symtab (void)
404ff6b5 25786{
c19d1205
ZW
25787#ifdef OBJ_COFF
25788 symbolS * sym;
404ff6b5 25789
c19d1205
ZW
25790 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
25791 {
25792 if (ARM_IS_THUMB (sym))
25793 {
25794 if (THUMB_IS_FUNC (sym))
25795 {
25796 /* Mark the symbol as a Thumb function. */
25797 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
25798 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
25799 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 25800
c19d1205
ZW
25801 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
25802 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
25803 else
25804 as_bad (_("%s: unexpected function type: %d"),
25805 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
25806 }
25807 else switch (S_GET_STORAGE_CLASS (sym))
25808 {
25809 case C_EXT:
25810 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
25811 break;
25812 case C_STAT:
25813 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
25814 break;
25815 case C_LABEL:
25816 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
25817 break;
25818 default:
25819 /* Do nothing. */
25820 break;
25821 }
25822 }
a737bd4d 25823
c19d1205
ZW
25824 if (ARM_IS_INTERWORK (sym))
25825 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 25826 }
c19d1205
ZW
25827#endif
25828#ifdef OBJ_ELF
25829 symbolS * sym;
25830 char bind;
404ff6b5 25831
c19d1205 25832 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 25833 {
c19d1205
ZW
25834 if (ARM_IS_THUMB (sym))
25835 {
25836 elf_symbol_type * elf_sym;
404ff6b5 25837
c19d1205
ZW
25838 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
25839 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 25840
b0796911
PB
25841 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
25842 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
25843 {
25844 /* If it's a .thumb_func, declare it as so,
25845 otherwise tag label as .code 16. */
25846 if (THUMB_IS_FUNC (sym))
39d911fc
TP
25847 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
25848 ST_BRANCH_TO_THUMB);
3ba67470 25849 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
25850 elf_sym->internal_elf_sym.st_info =
25851 ELF_ST_INFO (bind, STT_ARM_16BIT);
25852 }
25853 }
25854 }
cd000bff
DJ
25855
25856 /* Remove any overlapping mapping symbols generated by alignment frags. */
25857 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
25858 /* Now do generic ELF adjustments. */
25859 elf_adjust_symtab ();
c19d1205 25860#endif
404ff6b5
AH
25861}
25862
c19d1205 25863/* MD interface: Initialization. */
404ff6b5 25864
a737bd4d 25865static void
c19d1205 25866set_constant_flonums (void)
a737bd4d 25867{
c19d1205 25868 int i;
404ff6b5 25869
c19d1205
ZW
25870 for (i = 0; i < NUM_FLOAT_VALS; i++)
25871 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
25872 abort ();
a737bd4d 25873}
404ff6b5 25874
3e9e4fcf
JB
25875/* Auto-select Thumb mode if it's the only available instruction set for the
25876 given architecture. */
25877
25878static void
25879autoselect_thumb_from_cpu_variant (void)
25880{
25881 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
25882 opcode_select (16);
25883}
25884
c19d1205
ZW
25885void
25886md_begin (void)
a737bd4d 25887{
c19d1205
ZW
25888 unsigned mach;
25889 unsigned int i;
404ff6b5 25890
c19d1205
ZW
25891 if ( (arm_ops_hsh = hash_new ()) == NULL
25892 || (arm_cond_hsh = hash_new ()) == NULL
25893 || (arm_shift_hsh = hash_new ()) == NULL
25894 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 25895 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 25896 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
25897 || (arm_reloc_hsh = hash_new ()) == NULL
25898 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
25899 as_fatal (_("virtual memory exhausted"));
25900
25901 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 25902 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 25903 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 25904 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 25905 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 25906 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 25907 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25908 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 25909 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25910 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 25911 (void *) (v7m_psrs + i));
c19d1205 25912 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 25913 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
25914 for (i = 0;
25915 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
25916 i++)
d3ce72d0 25917 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 25918 (void *) (barrier_opt_names + i));
c19d1205 25919#ifdef OBJ_ELF
3da1d841
NC
25920 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
25921 {
25922 struct reloc_entry * entry = reloc_names + i;
25923
25924 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
25925 /* This makes encode_branch() use the EABI versions of this relocation. */
25926 entry->reloc = BFD_RELOC_UNUSED;
25927
25928 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
25929 }
c19d1205
ZW
25930#endif
25931
25932 set_constant_flonums ();
404ff6b5 25933
c19d1205
ZW
25934 /* Set the cpu variant based on the command-line options. We prefer
25935 -mcpu= over -march= if both are set (as for GCC); and we prefer
25936 -mfpu= over any other way of setting the floating point unit.
25937 Use of legacy options with new options are faulted. */
e74cfd16 25938 if (legacy_cpu)
404ff6b5 25939 {
e74cfd16 25940 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
25941 as_bad (_("use of old and new-style options to set CPU type"));
25942
4d354d8b 25943 selected_arch = *legacy_cpu;
404ff6b5 25944 }
4d354d8b
TP
25945 else if (mcpu_cpu_opt)
25946 {
25947 selected_arch = *mcpu_cpu_opt;
25948 selected_ext = *mcpu_ext_opt;
25949 }
25950 else if (march_cpu_opt)
c168ce07 25951 {
4d354d8b
TP
25952 selected_arch = *march_cpu_opt;
25953 selected_ext = *march_ext_opt;
c168ce07 25954 }
4d354d8b 25955 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
404ff6b5 25956
e74cfd16 25957 if (legacy_fpu)
c19d1205 25958 {
e74cfd16 25959 if (mfpu_opt)
c19d1205 25960 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f 25961
4d354d8b 25962 selected_fpu = *legacy_fpu;
03b1477f 25963 }
4d354d8b
TP
25964 else if (mfpu_opt)
25965 selected_fpu = *mfpu_opt;
25966 else
03b1477f 25967 {
45eb4c1b
NS
25968#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25969 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
25970 /* Some environments specify a default FPU. If they don't, infer it
25971 from the processor. */
e74cfd16 25972 if (mcpu_fpu_opt)
4d354d8b 25973 selected_fpu = *mcpu_fpu_opt;
e7da50fa 25974 else if (march_fpu_opt)
4d354d8b 25975 selected_fpu = *march_fpu_opt;
39c2da32 25976#else
4d354d8b 25977 selected_fpu = fpu_default;
39c2da32 25978#endif
03b1477f
RE
25979 }
25980
4d354d8b 25981 if (ARM_FEATURE_ZERO (selected_fpu))
03b1477f 25982 {
4d354d8b
TP
25983 if (!no_cpu_selected ())
25984 selected_fpu = fpu_default;
03b1477f 25985 else
4d354d8b 25986 selected_fpu = fpu_arch_fpa;
03b1477f
RE
25987 }
25988
ee065d83 25989#ifdef CPU_DEFAULT
4d354d8b 25990 if (ARM_FEATURE_ZERO (selected_arch))
ee065d83 25991 {
4d354d8b
TP
25992 selected_arch = cpu_default;
25993 selected_cpu = selected_arch;
ee065d83 25994 }
4d354d8b 25995 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
e74cfd16 25996#else
4d354d8b
TP
25997 /* Autodection of feature mode: allow all features in cpu_variant but leave
25998 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
25999 after all instruction have been processed and we can decide what CPU
26000 should be selected. */
26001 if (ARM_FEATURE_ZERO (selected_arch))
26002 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
ee065d83 26003 else
4d354d8b 26004 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83 26005#endif
03b1477f 26006
3e9e4fcf
JB
26007 autoselect_thumb_from_cpu_variant ();
26008
e74cfd16 26009 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 26010
f17c130b 26011#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 26012 {
7cc69913
NC
26013 unsigned int flags = 0;
26014
26015#if defined OBJ_ELF
26016 flags = meabi_flags;
d507cf36
PB
26017
26018 switch (meabi_flags)
33a392fb 26019 {
d507cf36 26020 case EF_ARM_EABI_UNKNOWN:
7cc69913 26021#endif
d507cf36
PB
26022 /* Set the flags in the private structure. */
26023 if (uses_apcs_26) flags |= F_APCS26;
26024 if (support_interwork) flags |= F_INTERWORK;
26025 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 26026 if (pic_code) flags |= F_PIC;
e74cfd16 26027 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
26028 flags |= F_SOFT_FLOAT;
26029
d507cf36
PB
26030 switch (mfloat_abi_opt)
26031 {
26032 case ARM_FLOAT_ABI_SOFT:
26033 case ARM_FLOAT_ABI_SOFTFP:
26034 flags |= F_SOFT_FLOAT;
26035 break;
33a392fb 26036
d507cf36
PB
26037 case ARM_FLOAT_ABI_HARD:
26038 if (flags & F_SOFT_FLOAT)
26039 as_bad (_("hard-float conflicts with specified fpu"));
26040 break;
26041 }
03b1477f 26042
e74cfd16
PB
26043 /* Using pure-endian doubles (even if soft-float). */
26044 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 26045 flags |= F_VFP_FLOAT;
f17c130b 26046
fde78edd 26047#if defined OBJ_ELF
e74cfd16 26048 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 26049 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
26050 break;
26051
8cb51566 26052 case EF_ARM_EABI_VER4:
3a4a14e9 26053 case EF_ARM_EABI_VER5:
c19d1205 26054 /* No additional flags to set. */
d507cf36
PB
26055 break;
26056
26057 default:
26058 abort ();
26059 }
7cc69913 26060#endif
b99bd4ef
NC
26061 bfd_set_private_flags (stdoutput, flags);
26062
26063 /* We have run out flags in the COFF header to encode the
26064 status of ATPCS support, so instead we create a dummy,
c19d1205 26065 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
26066 if (atpcs)
26067 {
26068 asection * sec;
26069
26070 sec = bfd_make_section (stdoutput, ".arm.atpcs");
26071
26072 if (sec != NULL)
26073 {
26074 bfd_set_section_flags
26075 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
26076 bfd_set_section_size (stdoutput, sec, 0);
26077 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
26078 }
26079 }
7cc69913 26080 }
f17c130b 26081#endif
b99bd4ef
NC
26082
26083 /* Record the CPU type as well. */
2d447fca
JM
26084 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
26085 mach = bfd_mach_arm_iWMMXt2;
26086 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 26087 mach = bfd_mach_arm_iWMMXt;
e74cfd16 26088 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 26089 mach = bfd_mach_arm_XScale;
e74cfd16 26090 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 26091 mach = bfd_mach_arm_ep9312;
e74cfd16 26092 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 26093 mach = bfd_mach_arm_5TE;
e74cfd16 26094 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 26095 {
e74cfd16 26096 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
26097 mach = bfd_mach_arm_5T;
26098 else
26099 mach = bfd_mach_arm_5;
26100 }
e74cfd16 26101 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 26102 {
e74cfd16 26103 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
26104 mach = bfd_mach_arm_4T;
26105 else
26106 mach = bfd_mach_arm_4;
26107 }
e74cfd16 26108 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 26109 mach = bfd_mach_arm_3M;
e74cfd16
PB
26110 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
26111 mach = bfd_mach_arm_3;
26112 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
26113 mach = bfd_mach_arm_2a;
26114 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
26115 mach = bfd_mach_arm_2;
26116 else
26117 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
26118
26119 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
26120}
26121
c19d1205 26122/* Command line processing. */
b99bd4ef 26123
c19d1205
ZW
26124/* md_parse_option
26125 Invocation line includes a switch not recognized by the base assembler.
26126 See if it's a processor-specific option.
b99bd4ef 26127
c19d1205
ZW
26128 This routine is somewhat complicated by the need for backwards
26129 compatibility (since older releases of gcc can't be changed).
26130 The new options try to make the interface as compatible as
26131 possible with GCC.
b99bd4ef 26132
c19d1205 26133 New options (supported) are:
b99bd4ef 26134
c19d1205
ZW
26135 -mcpu=<cpu name> Assemble for selected processor
26136 -march=<architecture name> Assemble for selected architecture
26137 -mfpu=<fpu architecture> Assemble for selected FPU.
26138 -EB/-mbig-endian Big-endian
26139 -EL/-mlittle-endian Little-endian
26140 -k Generate PIC code
26141 -mthumb Start in Thumb mode
26142 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 26143
278df34e 26144 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 26145 -m[no-]warn-syms Warn when symbols match instructions
267bf995 26146
c19d1205 26147 For now we will also provide support for:
b99bd4ef 26148
c19d1205
ZW
26149 -mapcs-32 32-bit Program counter
26150 -mapcs-26 26-bit Program counter
26151 -macps-float Floats passed in FP registers
26152 -mapcs-reentrant Reentrant code
26153 -matpcs
26154 (sometime these will probably be replaced with -mapcs=<list of options>
26155 and -matpcs=<list of options>)
b99bd4ef 26156
c19d1205
ZW
26157 The remaining options are only supported for back-wards compatibility.
26158 Cpu variants, the arm part is optional:
26159 -m[arm]1 Currently not supported.
26160 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
26161 -m[arm]3 Arm 3 processor
26162 -m[arm]6[xx], Arm 6 processors
26163 -m[arm]7[xx][t][[d]m] Arm 7 processors
26164 -m[arm]8[10] Arm 8 processors
26165 -m[arm]9[20][tdmi] Arm 9 processors
26166 -mstrongarm[110[0]] StrongARM processors
26167 -mxscale XScale processors
26168 -m[arm]v[2345[t[e]]] Arm architectures
26169 -mall All (except the ARM1)
26170 FP variants:
26171 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
26172 -mfpe-old (No float load/store multiples)
26173 -mvfpxd VFP Single precision
26174 -mvfp All VFP
26175 -mno-fpu Disable all floating point instructions
b99bd4ef 26176
c19d1205
ZW
26177 The following CPU names are recognized:
26178 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
26179 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
26180 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
26181 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
26182 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
26183 arm10t arm10e, arm1020t, arm1020e, arm10200e,
26184 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 26185
c19d1205 26186 */
b99bd4ef 26187
c19d1205 26188const char * md_shortopts = "m:k";
b99bd4ef 26189
c19d1205
ZW
26190#ifdef ARM_BI_ENDIAN
26191#define OPTION_EB (OPTION_MD_BASE + 0)
26192#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 26193#else
c19d1205
ZW
26194#if TARGET_BYTES_BIG_ENDIAN
26195#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 26196#else
c19d1205
ZW
26197#define OPTION_EL (OPTION_MD_BASE + 1)
26198#endif
b99bd4ef 26199#endif
845b51d6 26200#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
18a20338 26201#define OPTION_FDPIC (OPTION_MD_BASE + 3)
b99bd4ef 26202
c19d1205 26203struct option md_longopts[] =
b99bd4ef 26204{
c19d1205
ZW
26205#ifdef OPTION_EB
26206 {"EB", no_argument, NULL, OPTION_EB},
26207#endif
26208#ifdef OPTION_EL
26209 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 26210#endif
845b51d6 26211 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
18a20338
CL
26212#ifdef OBJ_ELF
26213 {"fdpic", no_argument, NULL, OPTION_FDPIC},
26214#endif
c19d1205
ZW
26215 {NULL, no_argument, NULL, 0}
26216};
b99bd4ef 26217
c19d1205 26218size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 26219
c19d1205 26220struct arm_option_table
b99bd4ef 26221{
0198d5e6
TC
26222 const char * option; /* Option name to match. */
26223 const char * help; /* Help information. */
26224 int * var; /* Variable to change. */
26225 int value; /* What to change it to. */
26226 const char * deprecated; /* If non-null, print this message. */
c19d1205 26227};
b99bd4ef 26228
c19d1205
ZW
26229struct arm_option_table arm_opts[] =
26230{
26231 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
26232 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
26233 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
26234 &support_interwork, 1, NULL},
26235 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
26236 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
26237 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
26238 1, NULL},
26239 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
26240 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
26241 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
26242 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
26243 NULL},
b99bd4ef 26244
c19d1205
ZW
26245 /* These are recognized by the assembler, but have no affect on code. */
26246 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
26247 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
26248
26249 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
26250 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
26251 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
26252 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
26253 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
26254 {NULL, NULL, NULL, 0, NULL}
26255};
26256
26257struct arm_legacy_option_table
26258{
0198d5e6
TC
26259 const char * option; /* Option name to match. */
26260 const arm_feature_set ** var; /* Variable to change. */
26261 const arm_feature_set value; /* What to change it to. */
26262 const char * deprecated; /* If non-null, print this message. */
e74cfd16 26263};
b99bd4ef 26264
e74cfd16
PB
26265const struct arm_legacy_option_table arm_legacy_opts[] =
26266{
c19d1205
ZW
26267 /* DON'T add any new processors to this list -- we want the whole list
26268 to go away... Add them to the processors table instead. */
e74cfd16
PB
26269 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
26270 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
26271 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
26272 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
26273 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
26274 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
26275 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
26276 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
26277 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
26278 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
26279 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
26280 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
26281 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
26282 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
26283 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
26284 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
26285 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
26286 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
26287 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
26288 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
26289 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
26290 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
26291 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
26292 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
26293 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
26294 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
26295 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
26296 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
26297 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
26298 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
26299 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
26300 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
26301 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
26302 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
26303 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
26304 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
26305 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
26306 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
26307 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
26308 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
26309 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
26310 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
26311 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
26312 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
26313 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
26314 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
26315 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
26316 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
26317 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
26318 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
26319 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
26320 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
26321 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
26322 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
26323 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
26324 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
26325 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
26326 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
26327 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
26328 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
26329 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
26330 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
26331 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
26332 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
26333 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
26334 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
26335 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
26336 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
26337 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
26338 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 26339 N_("use -mcpu=strongarm110")},
e74cfd16 26340 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 26341 N_("use -mcpu=strongarm1100")},
e74cfd16 26342 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 26343 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
26344 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
26345 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
26346 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 26347
c19d1205 26348 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
26349 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
26350 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
26351 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
26352 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
26353 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
26354 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
26355 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
26356 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
26357 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
26358 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
26359 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
26360 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
26361 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
26362 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
26363 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
26364 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
26365 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
26366 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 26367
c19d1205 26368 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
26369 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
26370 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
26371 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
26372 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 26373 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 26374
e74cfd16 26375 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 26376};
7ed4c4c5 26377
c19d1205 26378struct arm_cpu_option_table
7ed4c4c5 26379{
0198d5e6
TC
26380 const char * name;
26381 size_t name_len;
26382 const arm_feature_set value;
26383 const arm_feature_set ext;
c19d1205
ZW
26384 /* For some CPUs we assume an FPU unless the user explicitly sets
26385 -mfpu=... */
0198d5e6 26386 const arm_feature_set default_fpu;
ee065d83
PB
26387 /* The canonical name of the CPU, or NULL to use NAME converted to upper
26388 case. */
0198d5e6 26389 const char * canonical_name;
c19d1205 26390};
7ed4c4c5 26391
c19d1205
ZW
26392/* This list should, at a minimum, contain all the cpu names
26393 recognized by GCC. */
996b5569 26394#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 26395
e74cfd16 26396static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 26397{
996b5569
TP
26398 ARM_CPU_OPT ("all", NULL, ARM_ANY,
26399 ARM_ARCH_NONE,
26400 FPU_ARCH_FPA),
26401 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
26402 ARM_ARCH_NONE,
26403 FPU_ARCH_FPA),
26404 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
26405 ARM_ARCH_NONE,
26406 FPU_ARCH_FPA),
26407 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
26408 ARM_ARCH_NONE,
26409 FPU_ARCH_FPA),
26410 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
26411 ARM_ARCH_NONE,
26412 FPU_ARCH_FPA),
26413 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
26414 ARM_ARCH_NONE,
26415 FPU_ARCH_FPA),
26416 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
26417 ARM_ARCH_NONE,
26418 FPU_ARCH_FPA),
26419 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
26420 ARM_ARCH_NONE,
26421 FPU_ARCH_FPA),
26422 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
26423 ARM_ARCH_NONE,
26424 FPU_ARCH_FPA),
26425 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
26426 ARM_ARCH_NONE,
26427 FPU_ARCH_FPA),
26428 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
26429 ARM_ARCH_NONE,
26430 FPU_ARCH_FPA),
26431 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
26432 ARM_ARCH_NONE,
26433 FPU_ARCH_FPA),
26434 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
26435 ARM_ARCH_NONE,
26436 FPU_ARCH_FPA),
26437 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
26438 ARM_ARCH_NONE,
26439 FPU_ARCH_FPA),
26440 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
26441 ARM_ARCH_NONE,
26442 FPU_ARCH_FPA),
26443 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
26444 ARM_ARCH_NONE,
26445 FPU_ARCH_FPA),
26446 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
26447 ARM_ARCH_NONE,
26448 FPU_ARCH_FPA),
26449 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
26450 ARM_ARCH_NONE,
26451 FPU_ARCH_FPA),
26452 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
26453 ARM_ARCH_NONE,
26454 FPU_ARCH_FPA),
26455 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
26456 ARM_ARCH_NONE,
26457 FPU_ARCH_FPA),
26458 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
26459 ARM_ARCH_NONE,
26460 FPU_ARCH_FPA),
26461 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
26462 ARM_ARCH_NONE,
26463 FPU_ARCH_FPA),
26464 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
26465 ARM_ARCH_NONE,
26466 FPU_ARCH_FPA),
26467 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
26468 ARM_ARCH_NONE,
26469 FPU_ARCH_FPA),
26470 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
26471 ARM_ARCH_NONE,
26472 FPU_ARCH_FPA),
26473 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
26474 ARM_ARCH_NONE,
26475 FPU_ARCH_FPA),
26476 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
26477 ARM_ARCH_NONE,
26478 FPU_ARCH_FPA),
26479 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
26480 ARM_ARCH_NONE,
26481 FPU_ARCH_FPA),
26482 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
26483 ARM_ARCH_NONE,
26484 FPU_ARCH_FPA),
26485 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
26486 ARM_ARCH_NONE,
26487 FPU_ARCH_FPA),
26488 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
26489 ARM_ARCH_NONE,
26490 FPU_ARCH_FPA),
26491 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
26492 ARM_ARCH_NONE,
26493 FPU_ARCH_FPA),
26494 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
26495 ARM_ARCH_NONE,
26496 FPU_ARCH_FPA),
26497 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
26498 ARM_ARCH_NONE,
26499 FPU_ARCH_FPA),
26500 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
26501 ARM_ARCH_NONE,
26502 FPU_ARCH_FPA),
26503 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
26504 ARM_ARCH_NONE,
26505 FPU_ARCH_FPA),
26506 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
26507 ARM_ARCH_NONE,
26508 FPU_ARCH_FPA),
26509 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
26510 ARM_ARCH_NONE,
26511 FPU_ARCH_FPA),
26512 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
26513 ARM_ARCH_NONE,
26514 FPU_ARCH_FPA),
26515 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
26516 ARM_ARCH_NONE,
26517 FPU_ARCH_FPA),
26518 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
26519 ARM_ARCH_NONE,
26520 FPU_ARCH_FPA),
26521 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
26522 ARM_ARCH_NONE,
26523 FPU_ARCH_FPA),
26524 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
26525 ARM_ARCH_NONE,
26526 FPU_ARCH_FPA),
26527 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
26528 ARM_ARCH_NONE,
26529 FPU_ARCH_FPA),
26530 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
26531 ARM_ARCH_NONE,
26532 FPU_ARCH_FPA),
26533 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
26534 ARM_ARCH_NONE,
26535 FPU_ARCH_FPA),
26536
c19d1205
ZW
26537 /* For V5 or later processors we default to using VFP; but the user
26538 should really set the FPU type explicitly. */
996b5569
TP
26539 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
26540 ARM_ARCH_NONE,
26541 FPU_ARCH_VFP_V2),
26542 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
26543 ARM_ARCH_NONE,
26544 FPU_ARCH_VFP_V2),
26545 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
26546 ARM_ARCH_NONE,
26547 FPU_ARCH_VFP_V2),
26548 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
26549 ARM_ARCH_NONE,
26550 FPU_ARCH_VFP_V2),
26551 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
26552 ARM_ARCH_NONE,
26553 FPU_ARCH_VFP_V2),
26554 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
26555 ARM_ARCH_NONE,
26556 FPU_ARCH_VFP_V2),
26557 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
26558 ARM_ARCH_NONE,
26559 FPU_ARCH_VFP_V2),
26560 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
26561 ARM_ARCH_NONE,
26562 FPU_ARCH_VFP_V2),
26563 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
26564 ARM_ARCH_NONE,
26565 FPU_ARCH_VFP_V2),
26566 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
26567 ARM_ARCH_NONE,
26568 FPU_ARCH_VFP_V2),
26569 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
26570 ARM_ARCH_NONE,
26571 FPU_ARCH_VFP_V2),
26572 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
26573 ARM_ARCH_NONE,
26574 FPU_ARCH_VFP_V2),
26575 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
26576 ARM_ARCH_NONE,
26577 FPU_ARCH_VFP_V1),
26578 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
26579 ARM_ARCH_NONE,
26580 FPU_ARCH_VFP_V1),
26581 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
26582 ARM_ARCH_NONE,
26583 FPU_ARCH_VFP_V2),
26584 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
26585 ARM_ARCH_NONE,
26586 FPU_ARCH_VFP_V2),
26587 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
26588 ARM_ARCH_NONE,
26589 FPU_ARCH_VFP_V1),
26590 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
26591 ARM_ARCH_NONE,
26592 FPU_ARCH_VFP_V2),
26593 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
26594 ARM_ARCH_NONE,
26595 FPU_ARCH_VFP_V2),
26596 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
26597 ARM_ARCH_NONE,
26598 FPU_ARCH_VFP_V2),
26599 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
26600 ARM_ARCH_NONE,
26601 FPU_ARCH_VFP_V2),
26602 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
26603 ARM_ARCH_NONE,
26604 FPU_ARCH_VFP_V2),
26605 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
26606 ARM_ARCH_NONE,
26607 FPU_ARCH_VFP_V2),
26608 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
26609 ARM_ARCH_NONE,
26610 FPU_ARCH_VFP_V2),
26611 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
26612 ARM_ARCH_NONE,
26613 FPU_ARCH_VFP_V2),
26614 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
26615 ARM_ARCH_NONE,
26616 FPU_ARCH_VFP_V2),
26617 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
26618 ARM_ARCH_NONE,
26619 FPU_NONE),
26620 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
26621 ARM_ARCH_NONE,
26622 FPU_NONE),
26623 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
26624 ARM_ARCH_NONE,
26625 FPU_ARCH_VFP_V2),
26626 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
26627 ARM_ARCH_NONE,
26628 FPU_ARCH_VFP_V2),
26629 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
26630 ARM_ARCH_NONE,
26631 FPU_ARCH_VFP_V2),
26632 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
26633 ARM_ARCH_NONE,
26634 FPU_NONE),
26635 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
26636 ARM_ARCH_NONE,
26637 FPU_NONE),
26638 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
26639 ARM_ARCH_NONE,
26640 FPU_ARCH_VFP_V2),
26641 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
26642 ARM_ARCH_NONE,
26643 FPU_NONE),
26644 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
26645 ARM_ARCH_NONE,
26646 FPU_ARCH_VFP_V2),
26647 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
26648 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26649 FPU_NONE),
26650 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
26651 ARM_ARCH_NONE,
26652 FPU_ARCH_NEON_VFP_V4),
26653 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
26654 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
26655 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26656 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
26657 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26658 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26659 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
26660 ARM_ARCH_NONE,
26661 FPU_ARCH_NEON_VFP_V4),
26662 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
26663 ARM_ARCH_NONE,
26664 FPU_ARCH_NEON_VFP_V4),
26665 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
26666 ARM_ARCH_NONE,
26667 FPU_ARCH_NEON_VFP_V4),
26668 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
26669 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26670 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26671 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
26672 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26673 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26674 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
26675 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26676 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
26677 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
26678 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 26679 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
26680 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
26681 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26682 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26683 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
26684 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26685 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26686 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
26687 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26688 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
26689 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
26690 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 26691 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
7ebd1359 26692 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
26693 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26694 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
ef8df4ca
KT
26695 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
26696 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26697 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
26698 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
26699 ARM_ARCH_NONE,
26700 FPU_NONE),
26701 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
26702 ARM_ARCH_NONE,
26703 FPU_ARCH_VFP_V3D16),
26704 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
26705 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26706 FPU_NONE),
26707 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
26708 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26709 FPU_ARCH_VFP_V3D16),
26710 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
26711 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26712 FPU_ARCH_VFP_V3D16),
0cda1e19
TP
26713 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
26714 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26715 FPU_ARCH_NEON_VFP_ARMV8),
996b5569
TP
26716 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
26717 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26718 FPU_NONE),
26719 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
26720 ARM_ARCH_NONE,
26721 FPU_NONE),
26722 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
26723 ARM_ARCH_NONE,
26724 FPU_NONE),
26725 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
26726 ARM_ARCH_NONE,
26727 FPU_NONE),
26728 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
26729 ARM_ARCH_NONE,
26730 FPU_NONE),
26731 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
26732 ARM_ARCH_NONE,
26733 FPU_NONE),
26734 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
26735 ARM_ARCH_NONE,
26736 FPU_NONE),
26737 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
26738 ARM_ARCH_NONE,
26739 FPU_NONE),
26740 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
26741 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26742 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
83f43c83
KT
26743 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
26744 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26745 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
c19d1205 26746 /* ??? XSCALE is really an architecture. */
996b5569
TP
26747 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
26748 ARM_ARCH_NONE,
26749 FPU_ARCH_VFP_V2),
26750
c19d1205 26751 /* ??? iwmmxt is not a processor. */
996b5569
TP
26752 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
26753 ARM_ARCH_NONE,
26754 FPU_ARCH_VFP_V2),
26755 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
26756 ARM_ARCH_NONE,
26757 FPU_ARCH_VFP_V2),
26758 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
26759 ARM_ARCH_NONE,
26760 FPU_ARCH_VFP_V2),
26761
0198d5e6 26762 /* Maverick. */
996b5569
TP
26763 ARM_CPU_OPT ("ep9312", "ARM920T",
26764 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
26765 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
26766
da4339ed 26767 /* Marvell processors. */
996b5569
TP
26768 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
26769 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26770 FPU_ARCH_VFP_V3D16),
26771 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
26772 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26773 FPU_ARCH_NEON_VFP_V4),
da4339ed 26774
996b5569
TP
26775 /* APM X-Gene family. */
26776 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
26777 ARM_ARCH_NONE,
26778 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26779 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
26780 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26781 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26782
26783 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 26784};
f3bad469 26785#undef ARM_CPU_OPT
7ed4c4c5 26786
34ef62f4
AV
26787struct arm_ext_table
26788{
26789 const char * name;
26790 size_t name_len;
26791 const arm_feature_set merge;
26792 const arm_feature_set clear;
26793};
26794
c19d1205 26795struct arm_arch_option_table
7ed4c4c5 26796{
34ef62f4
AV
26797 const char * name;
26798 size_t name_len;
26799 const arm_feature_set value;
26800 const arm_feature_set default_fpu;
26801 const struct arm_ext_table * ext_table;
26802};
26803
26804/* Used to add support for +E and +noE extension. */
26805#define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
26806/* Used to add support for a +E extension. */
26807#define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
26808/* Used to add support for a +noE extension. */
26809#define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
26810
26811#define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
26812 ~0 & ~FPU_ENDIAN_PURE)
26813
26814static const struct arm_ext_table armv5te_ext_table[] =
26815{
26816 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
26817 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26818};
26819
26820static const struct arm_ext_table armv7_ext_table[] =
26821{
26822 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
26823 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26824};
26825
26826static const struct arm_ext_table armv7ve_ext_table[] =
26827{
26828 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
26829 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
26830 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
26831 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
26832 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
26833 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
26834 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
26835
26836 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
26837 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
26838
26839 /* Aliases for +simd. */
26840 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
26841
26842 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
26843 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
26844 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
26845
26846 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26847};
26848
26849static const struct arm_ext_table armv7a_ext_table[] =
26850{
26851 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
26852 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
26853 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
26854 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
26855 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
26856 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
26857 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
26858
26859 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
26860 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
26861
26862 /* Aliases for +simd. */
26863 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
26864 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
26865
26866 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
26867 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
26868
26869 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
26870 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
26871 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26872};
26873
26874static const struct arm_ext_table armv7r_ext_table[] =
26875{
26876 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
26877 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
26878 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
26879 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
26880 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
26881 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
26882 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
26883 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
26884 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26885};
26886
26887static const struct arm_ext_table armv7em_ext_table[] =
26888{
26889 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
26890 /* Alias for +fp, used to be known as fpv4-sp-d16. */
26891 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
26892 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
26893 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
26894 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
26895 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26896};
26897
26898static const struct arm_ext_table armv8a_ext_table[] =
26899{
26900 ARM_ADD ("crc", ARCH_CRC_ARMV8),
26901 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
26902 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
26903 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26904
26905 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26906 should use the +simd option to turn on FP. */
26907 ARM_REMOVE ("fp", ALL_FP),
26908 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
26909 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
26910 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26911};
26912
26913
26914static const struct arm_ext_table armv81a_ext_table[] =
26915{
26916 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
26917 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
26918 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26919
26920 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26921 should use the +simd option to turn on FP. */
26922 ARM_REMOVE ("fp", ALL_FP),
26923 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
26924 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
26925 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26926};
26927
26928static const struct arm_ext_table armv82a_ext_table[] =
26929{
26930 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
26931 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
26932 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
26933 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
26934 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26935 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
26936
26937 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26938 should use the +simd option to turn on FP. */
26939 ARM_REMOVE ("fp", ALL_FP),
26940 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
26941 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
26942 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26943};
26944
26945static const struct arm_ext_table armv84a_ext_table[] =
26946{
26947 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
26948 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
26949 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
26950 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26951
26952 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26953 should use the +simd option to turn on FP. */
26954 ARM_REMOVE ("fp", ALL_FP),
26955 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
26956 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
26957 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26958};
26959
26960static const struct arm_ext_table armv85a_ext_table[] =
26961{
26962 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
26963 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
26964 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
26965 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26966
26967 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26968 should use the +simd option to turn on FP. */
26969 ARM_REMOVE ("fp", ALL_FP),
26970 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26971};
26972
26973static const struct arm_ext_table armv8m_main_ext_table[] =
26974{
26975 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26976 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
26977 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
26978 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
26979 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26980};
26981
e0991585
AV
26982static const struct arm_ext_table armv8_1m_main_ext_table[] =
26983{
26984 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26985 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
26986 ARM_EXT ("fp",
26987 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
26988 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
26989 ALL_FP),
26990 ARM_ADD ("fp.dp",
26991 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
26992 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
26993 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26994};
26995
34ef62f4
AV
26996static const struct arm_ext_table armv8r_ext_table[] =
26997{
26998 ARM_ADD ("crc", ARCH_CRC_ARMV8),
26999 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
27000 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
27001 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27002 ARM_REMOVE ("fp", ALL_FP),
27003 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
27004 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 27005};
7ed4c4c5 27006
c19d1205
ZW
27007/* This list should, at a minimum, contain all the architecture names
27008 recognized by GCC. */
34ef62f4
AV
27009#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
27010#define ARM_ARCH_OPT2(N, V, DF, ext) \
27011 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
0198d5e6 27012
e74cfd16 27013static const struct arm_arch_option_table arm_archs[] =
c19d1205 27014{
497d849d
TP
27015 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
27016 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
27017 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
27018 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
27019 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
27020 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
27021 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
27022 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
27023 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
27024 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
27025 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
27026 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
27027 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
27028 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
34ef62f4
AV
27029 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
27030 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
27031 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
27032 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
27033 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
27034 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
27035 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
f33026a9
MW
27036 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
27037 kept to preserve existing behaviour. */
34ef62f4
AV
27038 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
27039 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
27040 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
27041 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
27042 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
f33026a9
MW
27043 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
27044 kept to preserve existing behaviour. */
34ef62f4
AV
27045 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
27046 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
497d849d
TP
27047 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
27048 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
34ef62f4 27049 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
c450d570
PB
27050 /* The official spelling of the ARMv7 profile variants is the dashed form.
27051 Accept the non-dashed form for compatibility with old toolchains. */
34ef62f4
AV
27052 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
27053 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
27054 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 27055 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4
AV
27056 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
27057 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 27058 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4 27059 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
497d849d 27060 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
34ef62f4
AV
27061 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
27062 armv8m_main),
e0991585
AV
27063 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
27064 armv8_1m_main),
34ef62f4
AV
27065 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
27066 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
27067 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
27068 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
27069 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
27070 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
27071 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
497d849d
TP
27072 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
27073 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
27074 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
34ef62f4 27075 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 27076};
f3bad469 27077#undef ARM_ARCH_OPT
7ed4c4c5 27078
69133863 27079/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 27080
69133863 27081struct arm_option_extension_value_table
c19d1205 27082{
0198d5e6
TC
27083 const char * name;
27084 size_t name_len;
27085 const arm_feature_set merge_value;
27086 const arm_feature_set clear_value;
d942732e
TP
27087 /* List of architectures for which an extension is available. ARM_ARCH_NONE
27088 indicates that an extension is available for all architectures while
27089 ARM_ANY marks an empty entry. */
0198d5e6 27090 const arm_feature_set allowed_archs[2];
c19d1205 27091};
7ed4c4c5 27092
0198d5e6
TC
27093/* The following table must be in alphabetical order with a NULL last entry. */
27094
d942732e
TP
27095#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
27096#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 27097
34ef62f4
AV
27098/* DEPRECATED: Refrain from using this table to add any new extensions, instead
27099 use the context sensitive approach using arm_ext_table's. */
69133863 27100static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 27101{
823d2571
TG
27102 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27103 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 27104 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
27105 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
27106 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
27107 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
27108 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
27109 ARM_ARCH_V8_2A),
15afaa63
TP
27110 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27111 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27112 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
27113 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
27114 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
27115 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27116 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27117 ARM_ARCH_V8_2A),
01f48020
TC
27118 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
27119 | ARM_EXT2_FP16_FML),
27120 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
27121 | ARM_EXT2_FP16_FML),
27122 ARM_ARCH_V8_2A),
d942732e 27123 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 27124 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
27125 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
27126 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
27127 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
27128 Thumb divide instruction. Due to this having the same name as the
27129 previous entry, this will be ignored when doing command-line parsing and
27130 only considered by build attribute selection code. */
27131 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
27132 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
27133 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 27134 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 27135 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 27136 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 27137 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 27138 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
27139 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
27140 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 27141 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
27142 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
27143 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
27144 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
27145 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
27146 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
27147 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
27148 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 27149 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
dad0c3bf
SD
27150 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
27151 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
27152 ARM_ARCH_V8A),
4d1464f2
MW
27153 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
27154 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 27155 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
27156 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
27157 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 27158 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
7fadb25d
SD
27159 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
27160 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
27161 ARM_ARCH_V8A),
d942732e 27162 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 27163 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
27164 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
27165 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
27166 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
27167 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
27168 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
27169 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
27170 | ARM_EXT_DIV),
27171 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
27172 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
27173 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
27174 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
27175 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 27176};
f3bad469 27177#undef ARM_EXT_OPT
69133863
MGD
27178
27179/* ISA floating-point and Advanced SIMD extensions. */
27180struct arm_option_fpu_value_table
27181{
0198d5e6
TC
27182 const char * name;
27183 const arm_feature_set value;
c19d1205 27184};
7ed4c4c5 27185
c19d1205
ZW
27186/* This list should, at a minimum, contain all the fpu names
27187 recognized by GCC. */
69133863 27188static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
27189{
27190 {"softfpa", FPU_NONE},
27191 {"fpe", FPU_ARCH_FPE},
27192 {"fpe2", FPU_ARCH_FPE},
27193 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
27194 {"fpa", FPU_ARCH_FPA},
27195 {"fpa10", FPU_ARCH_FPA},
27196 {"fpa11", FPU_ARCH_FPA},
27197 {"arm7500fe", FPU_ARCH_FPA},
27198 {"softvfp", FPU_ARCH_VFP},
27199 {"softvfp+vfp", FPU_ARCH_VFP_V2},
27200 {"vfp", FPU_ARCH_VFP_V2},
27201 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 27202 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
27203 {"vfp10", FPU_ARCH_VFP_V2},
27204 {"vfp10-r0", FPU_ARCH_VFP_V1},
27205 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
27206 {"vfpv2", FPU_ARCH_VFP_V2},
27207 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 27208 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 27209 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
27210 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
27211 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
27212 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
27213 {"arm1020t", FPU_ARCH_VFP_V1},
27214 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 27215 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
27216 {"arm1136jf-s", FPU_ARCH_VFP_V2},
27217 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 27218 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 27219 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 27220 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
27221 {"vfpv4", FPU_ARCH_VFP_V4},
27222 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 27223 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
27224 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
27225 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 27226 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
27227 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
27228 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
27229 {"crypto-neon-fp-armv8",
27230 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 27231 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
27232 {"crypto-neon-fp-armv8.1",
27233 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
27234 {NULL, ARM_ARCH_NONE}
27235};
27236
27237struct arm_option_value_table
27238{
e0471c16 27239 const char *name;
e74cfd16 27240 long value;
c19d1205 27241};
7ed4c4c5 27242
e74cfd16 27243static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
27244{
27245 {"hard", ARM_FLOAT_ABI_HARD},
27246 {"softfp", ARM_FLOAT_ABI_SOFTFP},
27247 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 27248 {NULL, 0}
c19d1205 27249};
7ed4c4c5 27250
c19d1205 27251#ifdef OBJ_ELF
3a4a14e9 27252/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 27253static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
27254{
27255 {"gnu", EF_ARM_EABI_UNKNOWN},
27256 {"4", EF_ARM_EABI_VER4},
3a4a14e9 27257 {"5", EF_ARM_EABI_VER5},
e74cfd16 27258 {NULL, 0}
c19d1205
ZW
27259};
27260#endif
7ed4c4c5 27261
c19d1205
ZW
27262struct arm_long_option_table
27263{
0198d5e6 27264 const char * option; /* Substring to match. */
e0471c16 27265 const char * help; /* Help information. */
17b9d67d 27266 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 27267 const char * deprecated; /* If non-null, print this message. */
c19d1205 27268};
7ed4c4c5 27269
c921be7d 27270static bfd_boolean
c168ce07 27271arm_parse_extension (const char *str, const arm_feature_set *opt_set,
34ef62f4
AV
27272 arm_feature_set *ext_set,
27273 const struct arm_ext_table *ext_table)
7ed4c4c5 27274{
69133863 27275 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
27276 extensions being added before being removed. We achieve this by having
27277 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 27278 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 27279 or removing it (0) and only allowing it to change in the order
69133863
MGD
27280 -1 -> 1 -> 0. */
27281 const struct arm_option_extension_value_table * opt = NULL;
d942732e 27282 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
27283 int adding_value = -1;
27284
c19d1205 27285 while (str != NULL && *str != 0)
7ed4c4c5 27286 {
82b8a785 27287 const char *ext;
f3bad469 27288 size_t len;
7ed4c4c5 27289
c19d1205
ZW
27290 if (*str != '+')
27291 {
27292 as_bad (_("invalid architectural extension"));
c921be7d 27293 return FALSE;
c19d1205 27294 }
7ed4c4c5 27295
c19d1205
ZW
27296 str++;
27297 ext = strchr (str, '+');
7ed4c4c5 27298
c19d1205 27299 if (ext != NULL)
f3bad469 27300 len = ext - str;
c19d1205 27301 else
f3bad469 27302 len = strlen (str);
7ed4c4c5 27303
f3bad469 27304 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
27305 {
27306 if (adding_value != 0)
27307 {
27308 adding_value = 0;
27309 opt = arm_extensions;
27310 }
27311
f3bad469 27312 len -= 2;
69133863
MGD
27313 str += 2;
27314 }
f3bad469 27315 else if (len > 0)
69133863
MGD
27316 {
27317 if (adding_value == -1)
27318 {
27319 adding_value = 1;
27320 opt = arm_extensions;
27321 }
27322 else if (adding_value != 1)
27323 {
27324 as_bad (_("must specify extensions to add before specifying "
27325 "those to remove"));
27326 return FALSE;
27327 }
27328 }
27329
f3bad469 27330 if (len == 0)
c19d1205
ZW
27331 {
27332 as_bad (_("missing architectural extension"));
c921be7d 27333 return FALSE;
c19d1205 27334 }
7ed4c4c5 27335
69133863
MGD
27336 gas_assert (adding_value != -1);
27337 gas_assert (opt != NULL);
27338
34ef62f4
AV
27339 if (ext_table != NULL)
27340 {
27341 const struct arm_ext_table * ext_opt = ext_table;
27342 bfd_boolean found = FALSE;
27343 for (; ext_opt->name != NULL; ext_opt++)
27344 if (ext_opt->name_len == len
27345 && strncmp (ext_opt->name, str, len) == 0)
27346 {
27347 if (adding_value)
27348 {
27349 if (ARM_FEATURE_ZERO (ext_opt->merge))
27350 /* TODO: Option not supported. When we remove the
27351 legacy table this case should error out. */
27352 continue;
27353
27354 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
27355 }
27356 else
27357 {
27358 if (ARM_FEATURE_ZERO (ext_opt->clear))
27359 /* TODO: Option not supported. When we remove the
27360 legacy table this case should error out. */
27361 continue;
27362 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
27363 }
27364 found = TRUE;
27365 break;
27366 }
27367 if (found)
27368 {
27369 str = ext;
27370 continue;
27371 }
27372 }
27373
69133863
MGD
27374 /* Scan over the options table trying to find an exact match. */
27375 for (; opt->name != NULL; opt++)
f3bad469 27376 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 27377 {
d942732e
TP
27378 int i, nb_allowed_archs =
27379 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 27380 /* Check we can apply the extension to this architecture. */
d942732e
TP
27381 for (i = 0; i < nb_allowed_archs; i++)
27382 {
27383 /* Empty entry. */
27384 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
27385 continue;
c168ce07 27386 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
27387 break;
27388 }
27389 if (i == nb_allowed_archs)
69133863
MGD
27390 {
27391 as_bad (_("extension does not apply to the base architecture"));
27392 return FALSE;
27393 }
27394
27395 /* Add or remove the extension. */
27396 if (adding_value)
4d354d8b 27397 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 27398 else
4d354d8b 27399 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 27400
3d030cdb
TP
27401 /* Allowing Thumb division instructions for ARMv7 in autodetection
27402 rely on this break so that duplicate extensions (extensions
27403 with the same name as a previous extension in the list) are not
27404 considered for command-line parsing. */
c19d1205
ZW
27405 break;
27406 }
7ed4c4c5 27407
c19d1205
ZW
27408 if (opt->name == NULL)
27409 {
69133863
MGD
27410 /* Did we fail to find an extension because it wasn't specified in
27411 alphabetical order, or because it does not exist? */
27412
27413 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 27414 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
27415 break;
27416
27417 if (opt->name == NULL)
27418 as_bad (_("unknown architectural extension `%s'"), str);
27419 else
27420 as_bad (_("architectural extensions must be specified in "
27421 "alphabetical order"));
27422
c921be7d 27423 return FALSE;
c19d1205 27424 }
69133863
MGD
27425 else
27426 {
27427 /* We should skip the extension we've just matched the next time
27428 round. */
27429 opt++;
27430 }
7ed4c4c5 27431
c19d1205
ZW
27432 str = ext;
27433 };
7ed4c4c5 27434
c921be7d 27435 return TRUE;
c19d1205 27436}
7ed4c4c5 27437
c921be7d 27438static bfd_boolean
17b9d67d 27439arm_parse_cpu (const char *str)
7ed4c4c5 27440{
f3bad469 27441 const struct arm_cpu_option_table *opt;
82b8a785 27442 const char *ext = strchr (str, '+');
f3bad469 27443 size_t len;
7ed4c4c5 27444
c19d1205 27445 if (ext != NULL)
f3bad469 27446 len = ext - str;
7ed4c4c5 27447 else
f3bad469 27448 len = strlen (str);
7ed4c4c5 27449
f3bad469 27450 if (len == 0)
7ed4c4c5 27451 {
c19d1205 27452 as_bad (_("missing cpu name `%s'"), str);
c921be7d 27453 return FALSE;
7ed4c4c5
NC
27454 }
27455
c19d1205 27456 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 27457 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 27458 {
c168ce07 27459 mcpu_cpu_opt = &opt->value;
4d354d8b
TP
27460 if (mcpu_ext_opt == NULL)
27461 mcpu_ext_opt = XNEW (arm_feature_set);
27462 *mcpu_ext_opt = opt->ext;
e74cfd16 27463 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 27464 if (opt->canonical_name)
ef8e6722
JW
27465 {
27466 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
27467 strcpy (selected_cpu_name, opt->canonical_name);
27468 }
ee065d83
PB
27469 else
27470 {
f3bad469 27471 size_t i;
c921be7d 27472
ef8e6722
JW
27473 if (len >= sizeof selected_cpu_name)
27474 len = (sizeof selected_cpu_name) - 1;
27475
f3bad469 27476 for (i = 0; i < len; i++)
ee065d83
PB
27477 selected_cpu_name[i] = TOUPPER (opt->name[i]);
27478 selected_cpu_name[i] = 0;
27479 }
7ed4c4c5 27480
c19d1205 27481 if (ext != NULL)
34ef62f4 27482 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
7ed4c4c5 27483
c921be7d 27484 return TRUE;
c19d1205 27485 }
7ed4c4c5 27486
c19d1205 27487 as_bad (_("unknown cpu `%s'"), str);
c921be7d 27488 return FALSE;
7ed4c4c5
NC
27489}
27490
c921be7d 27491static bfd_boolean
17b9d67d 27492arm_parse_arch (const char *str)
7ed4c4c5 27493{
e74cfd16 27494 const struct arm_arch_option_table *opt;
82b8a785 27495 const char *ext = strchr (str, '+');
f3bad469 27496 size_t len;
7ed4c4c5 27497
c19d1205 27498 if (ext != NULL)
f3bad469 27499 len = ext - str;
7ed4c4c5 27500 else
f3bad469 27501 len = strlen (str);
7ed4c4c5 27502
f3bad469 27503 if (len == 0)
7ed4c4c5 27504 {
c19d1205 27505 as_bad (_("missing architecture name `%s'"), str);
c921be7d 27506 return FALSE;
7ed4c4c5
NC
27507 }
27508
c19d1205 27509 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 27510 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 27511 {
e74cfd16 27512 march_cpu_opt = &opt->value;
4d354d8b
TP
27513 if (march_ext_opt == NULL)
27514 march_ext_opt = XNEW (arm_feature_set);
27515 *march_ext_opt = arm_arch_none;
e74cfd16 27516 march_fpu_opt = &opt->default_fpu;
5f4273c7 27517 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 27518
c19d1205 27519 if (ext != NULL)
34ef62f4
AV
27520 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
27521 opt->ext_table);
7ed4c4c5 27522
c921be7d 27523 return TRUE;
c19d1205
ZW
27524 }
27525
27526 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 27527 return FALSE;
7ed4c4c5 27528}
eb043451 27529
c921be7d 27530static bfd_boolean
17b9d67d 27531arm_parse_fpu (const char * str)
c19d1205 27532{
69133863 27533 const struct arm_option_fpu_value_table * opt;
b99bd4ef 27534
c19d1205
ZW
27535 for (opt = arm_fpus; opt->name != NULL; opt++)
27536 if (streq (opt->name, str))
27537 {
e74cfd16 27538 mfpu_opt = &opt->value;
c921be7d 27539 return TRUE;
c19d1205 27540 }
b99bd4ef 27541
c19d1205 27542 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 27543 return FALSE;
c19d1205
ZW
27544}
27545
c921be7d 27546static bfd_boolean
17b9d67d 27547arm_parse_float_abi (const char * str)
b99bd4ef 27548{
e74cfd16 27549 const struct arm_option_value_table * opt;
b99bd4ef 27550
c19d1205
ZW
27551 for (opt = arm_float_abis; opt->name != NULL; opt++)
27552 if (streq (opt->name, str))
27553 {
27554 mfloat_abi_opt = opt->value;
c921be7d 27555 return TRUE;
c19d1205 27556 }
cc8a6dd0 27557
c19d1205 27558 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 27559 return FALSE;
c19d1205 27560}
b99bd4ef 27561
c19d1205 27562#ifdef OBJ_ELF
c921be7d 27563static bfd_boolean
17b9d67d 27564arm_parse_eabi (const char * str)
c19d1205 27565{
e74cfd16 27566 const struct arm_option_value_table *opt;
cc8a6dd0 27567
c19d1205
ZW
27568 for (opt = arm_eabis; opt->name != NULL; opt++)
27569 if (streq (opt->name, str))
27570 {
27571 meabi_flags = opt->value;
c921be7d 27572 return TRUE;
c19d1205
ZW
27573 }
27574 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 27575 return FALSE;
c19d1205
ZW
27576}
27577#endif
cc8a6dd0 27578
c921be7d 27579static bfd_boolean
17b9d67d 27580arm_parse_it_mode (const char * str)
e07e6e58 27581{
c921be7d 27582 bfd_boolean ret = TRUE;
e07e6e58
NC
27583
27584 if (streq ("arm", str))
27585 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
27586 else if (streq ("thumb", str))
27587 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
27588 else if (streq ("always", str))
27589 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
27590 else if (streq ("never", str))
27591 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
27592 else
27593 {
27594 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 27595 "arm, thumb, always, or never."), str);
c921be7d 27596 ret = FALSE;
e07e6e58
NC
27597 }
27598
27599 return ret;
27600}
27601
2e6976a8 27602static bfd_boolean
17b9d67d 27603arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
27604{
27605 codecomposer_syntax = TRUE;
27606 arm_comment_chars[0] = ';';
27607 arm_line_separator_chars[0] = 0;
27608 return TRUE;
27609}
27610
c19d1205
ZW
27611struct arm_long_option_table arm_long_opts[] =
27612{
27613 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
27614 arm_parse_cpu, NULL},
27615 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
27616 arm_parse_arch, NULL},
27617 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
27618 arm_parse_fpu, NULL},
27619 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
27620 arm_parse_float_abi, NULL},
27621#ifdef OBJ_ELF
7fac0536 27622 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
27623 arm_parse_eabi, NULL},
27624#endif
e07e6e58
NC
27625 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
27626 arm_parse_it_mode, NULL},
2e6976a8
DG
27627 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
27628 arm_ccs_mode, NULL},
c19d1205
ZW
27629 {NULL, NULL, 0, NULL}
27630};
cc8a6dd0 27631
c19d1205 27632int
17b9d67d 27633md_parse_option (int c, const char * arg)
c19d1205
ZW
27634{
27635 struct arm_option_table *opt;
e74cfd16 27636 const struct arm_legacy_option_table *fopt;
c19d1205 27637 struct arm_long_option_table *lopt;
b99bd4ef 27638
c19d1205 27639 switch (c)
b99bd4ef 27640 {
c19d1205
ZW
27641#ifdef OPTION_EB
27642 case OPTION_EB:
27643 target_big_endian = 1;
27644 break;
27645#endif
cc8a6dd0 27646
c19d1205
ZW
27647#ifdef OPTION_EL
27648 case OPTION_EL:
27649 target_big_endian = 0;
27650 break;
27651#endif
b99bd4ef 27652
845b51d6
PB
27653 case OPTION_FIX_V4BX:
27654 fix_v4bx = TRUE;
27655 break;
27656
18a20338
CL
27657#ifdef OBJ_ELF
27658 case OPTION_FDPIC:
27659 arm_fdpic = TRUE;
27660 break;
27661#endif /* OBJ_ELF */
27662
c19d1205
ZW
27663 case 'a':
27664 /* Listing option. Just ignore these, we don't support additional
27665 ones. */
27666 return 0;
b99bd4ef 27667
c19d1205
ZW
27668 default:
27669 for (opt = arm_opts; opt->option != NULL; opt++)
27670 {
27671 if (c == opt->option[0]
27672 && ((arg == NULL && opt->option[1] == 0)
27673 || streq (arg, opt->option + 1)))
27674 {
c19d1205 27675 /* If the option is deprecated, tell the user. */
278df34e 27676 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
27677 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
27678 arg ? arg : "", _(opt->deprecated));
b99bd4ef 27679
c19d1205
ZW
27680 if (opt->var != NULL)
27681 *opt->var = opt->value;
cc8a6dd0 27682
c19d1205
ZW
27683 return 1;
27684 }
27685 }
b99bd4ef 27686
e74cfd16
PB
27687 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
27688 {
27689 if (c == fopt->option[0]
27690 && ((arg == NULL && fopt->option[1] == 0)
27691 || streq (arg, fopt->option + 1)))
27692 {
e74cfd16 27693 /* If the option is deprecated, tell the user. */
278df34e 27694 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
27695 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
27696 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
27697
27698 if (fopt->var != NULL)
27699 *fopt->var = &fopt->value;
27700
27701 return 1;
27702 }
27703 }
27704
c19d1205
ZW
27705 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
27706 {
27707 /* These options are expected to have an argument. */
27708 if (c == lopt->option[0]
27709 && arg != NULL
27710 && strncmp (arg, lopt->option + 1,
27711 strlen (lopt->option + 1)) == 0)
27712 {
c19d1205 27713 /* If the option is deprecated, tell the user. */
278df34e 27714 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
27715 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
27716 _(lopt->deprecated));
b99bd4ef 27717
c19d1205
ZW
27718 /* Call the sup-option parser. */
27719 return lopt->func (arg + strlen (lopt->option) - 1);
27720 }
27721 }
a737bd4d 27722
c19d1205
ZW
27723 return 0;
27724 }
a394c00f 27725
c19d1205
ZW
27726 return 1;
27727}
a394c00f 27728
c19d1205
ZW
27729void
27730md_show_usage (FILE * fp)
a394c00f 27731{
c19d1205
ZW
27732 struct arm_option_table *opt;
27733 struct arm_long_option_table *lopt;
a394c00f 27734
c19d1205 27735 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 27736
c19d1205
ZW
27737 for (opt = arm_opts; opt->option != NULL; opt++)
27738 if (opt->help != NULL)
27739 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 27740
c19d1205
ZW
27741 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
27742 if (lopt->help != NULL)
27743 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 27744
c19d1205
ZW
27745#ifdef OPTION_EB
27746 fprintf (fp, _("\
27747 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
27748#endif
27749
c19d1205
ZW
27750#ifdef OPTION_EL
27751 fprintf (fp, _("\
27752 -EL assemble code for a little-endian cpu\n"));
a737bd4d 27753#endif
845b51d6
PB
27754
27755 fprintf (fp, _("\
27756 --fix-v4bx Allow BX in ARMv4 code\n"));
18a20338
CL
27757
27758#ifdef OBJ_ELF
27759 fprintf (fp, _("\
27760 --fdpic generate an FDPIC object file\n"));
27761#endif /* OBJ_ELF */
c19d1205 27762}
ee065d83 27763
ee065d83 27764#ifdef OBJ_ELF
0198d5e6 27765
62b3e311
PB
27766typedef struct
27767{
27768 int val;
27769 arm_feature_set flags;
27770} cpu_arch_ver_table;
27771
2c6b98ea
TP
27772/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
27773 chronologically for architectures, with an exception for ARMv6-M and
27774 ARMv6S-M due to legacy reasons. No new architecture should have a
27775 special case. This allows for build attribute selection results to be
27776 stable when new architectures are added. */
62b3e311
PB
27777static const cpu_arch_ver_table cpu_arch_ver[] =
27778{
031254f2
AV
27779 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
27780 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
27781 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
27782 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
27783 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
27784 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
27785 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
27786 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
27787 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
27788 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
27789 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
27790 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
27791 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
27792 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
27793 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
27794 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
27795 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
27796 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
27797 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
27798 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
27799 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
27800 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
27801 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
27802 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
2c6b98ea
TP
27803
27804 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
27805 always selected build attributes to match those of ARMv6-M
27806 (resp. ARMv6S-M). However, due to these architectures being a strict
27807 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
27808 would be selected when fully respecting chronology of architectures.
27809 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
27810 move them before ARMv7 architectures. */
031254f2
AV
27811 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
27812 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
27813
27814 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
27815 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
27816 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
27817 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
27818 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
27819 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
27820 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
27821 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
27822 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
27823 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
27824 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
27825 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
27826 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
27827 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
27828 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
27829 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
27830 {-1, ARM_ARCH_NONE}
62b3e311
PB
27831};
27832
ee3c0378 27833/* Set an attribute if it has not already been set by the user. */
0198d5e6 27834
ee3c0378
AS
27835static void
27836aeabi_set_attribute_int (int tag, int value)
27837{
27838 if (tag < 1
27839 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
27840 || !attributes_set_explicitly[tag])
27841 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
27842}
27843
27844static void
27845aeabi_set_attribute_string (int tag, const char *value)
27846{
27847 if (tag < 1
27848 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
27849 || !attributes_set_explicitly[tag])
27850 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
27851}
27852
2c6b98ea
TP
27853/* Return whether features in the *NEEDED feature set are available via
27854 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 27855
2c6b98ea
TP
27856static bfd_boolean
27857have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
27858 const arm_feature_set *needed)
27859{
27860 int i, nb_allowed_archs;
27861 arm_feature_set ext_fset;
27862 const struct arm_option_extension_value_table *opt;
27863
27864 ext_fset = arm_arch_none;
27865 for (opt = arm_extensions; opt->name != NULL; opt++)
27866 {
27867 /* Extension does not provide any feature we need. */
27868 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
27869 continue;
27870
27871 nb_allowed_archs =
27872 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
27873 for (i = 0; i < nb_allowed_archs; i++)
27874 {
27875 /* Empty entry. */
27876 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
27877 break;
27878
27879 /* Extension is available, add it. */
27880 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
27881 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
27882 }
27883 }
27884
27885 /* Can we enable all features in *needed? */
27886 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
27887}
27888
27889/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
27890 a given architecture feature set *ARCH_EXT_FSET including extension feature
27891 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
27892 - if true, check for an exact match of the architecture modulo extensions;
27893 - otherwise, select build attribute value of the first superset
27894 architecture released so that results remains stable when new architectures
27895 are added.
27896 For -march/-mcpu=all the build attribute value of the most featureful
27897 architecture is returned. Tag_CPU_arch_profile result is returned in
27898 PROFILE. */
0198d5e6 27899
2c6b98ea
TP
27900static int
27901get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
27902 const arm_feature_set *ext_fset,
27903 char *profile, int exact_match)
27904{
27905 arm_feature_set arch_fset;
27906 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
27907
27908 /* Select most featureful architecture with all its extensions if building
27909 for -march=all as the feature sets used to set build attributes. */
27910 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
27911 {
27912 /* Force revisiting of decision for each new architecture. */
031254f2 27913 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
2c6b98ea
TP
27914 *profile = 'A';
27915 return TAG_CPU_ARCH_V8;
27916 }
27917
27918 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
27919
27920 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
27921 {
27922 arm_feature_set known_arch_fset;
27923
27924 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
27925 if (exact_match)
27926 {
27927 /* Base architecture match user-specified architecture and
27928 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
27929 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
27930 {
27931 p_ver_ret = p_ver;
27932 goto found;
27933 }
27934 /* Base architecture match user-specified architecture only
27935 (eg. ARMv6-M in the same case as above). Record it in case we
27936 find a match with above condition. */
27937 else if (p_ver_ret == NULL
27938 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
27939 p_ver_ret = p_ver;
27940 }
27941 else
27942 {
27943
27944 /* Architecture has all features wanted. */
27945 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
27946 {
27947 arm_feature_set added_fset;
27948
27949 /* Compute features added by this architecture over the one
27950 recorded in p_ver_ret. */
27951 if (p_ver_ret != NULL)
27952 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
27953 p_ver_ret->flags);
27954 /* First architecture that match incl. with extensions, or the
27955 only difference in features over the recorded match is
27956 features that were optional and are now mandatory. */
27957 if (p_ver_ret == NULL
27958 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
27959 {
27960 p_ver_ret = p_ver;
27961 goto found;
27962 }
27963 }
27964 else if (p_ver_ret == NULL)
27965 {
27966 arm_feature_set needed_ext_fset;
27967
27968 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
27969
27970 /* Architecture has all features needed when using some
27971 extensions. Record it and continue searching in case there
27972 exist an architecture providing all needed features without
27973 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
27974 OS extension). */
27975 if (have_ext_for_needed_feat_p (&known_arch_fset,
27976 &needed_ext_fset))
27977 p_ver_ret = p_ver;
27978 }
27979 }
27980 }
27981
27982 if (p_ver_ret == NULL)
27983 return -1;
27984
27985found:
27986 /* Tag_CPU_arch_profile. */
27987 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
27988 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
27989 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
27990 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
27991 *profile = 'A';
27992 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
27993 *profile = 'R';
27994 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
27995 *profile = 'M';
27996 else
27997 *profile = '\0';
27998 return p_ver_ret->val;
27999}
28000
ee065d83 28001/* Set the public EABI object attributes. */
0198d5e6 28002
c168ce07 28003static void
ee065d83
PB
28004aeabi_set_public_attributes (void)
28005{
b90d5ba0 28006 char profile = '\0';
2c6b98ea 28007 int arch = -1;
90ec0d68 28008 int virt_sec = 0;
bca38921 28009 int fp16_optional = 0;
2c6b98ea
TP
28010 int skip_exact_match = 0;
28011 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 28012
54bab281
TP
28013 /* Autodetection mode, choose the architecture based the instructions
28014 actually used. */
28015 if (no_cpu_selected ())
28016 {
28017 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 28018
54bab281
TP
28019 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
28020 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 28021
54bab281
TP
28022 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
28023 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 28024
54bab281 28025 /* Code run during relaxation relies on selected_cpu being set. */
4d354d8b
TP
28026 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
28027 flags_ext = arm_arch_none;
28028 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
28029 selected_ext = flags_ext;
54bab281
TP
28030 selected_cpu = flags;
28031 }
28032 /* Otherwise, choose the architecture based on the capabilities of the
28033 requested cpu. */
28034 else
4d354d8b
TP
28035 {
28036 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
28037 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
28038 flags_ext = selected_ext;
28039 flags = selected_cpu;
28040 }
28041 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
7f78eb34 28042
ddd7f988 28043 /* Allow the user to override the reported architecture. */
4d354d8b 28044 if (!ARM_FEATURE_ZERO (selected_object_arch))
7a1d4c38 28045 {
4d354d8b 28046 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
2c6b98ea 28047 flags_ext = arm_arch_none;
7a1d4c38 28048 }
2c6b98ea 28049 else
4d354d8b 28050 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
2c6b98ea
TP
28051
28052 /* When this function is run again after relaxation has happened there is no
28053 way to determine whether an architecture or CPU was specified by the user:
28054 - selected_cpu is set above for relaxation to work;
28055 - march_cpu_opt is not set if only -mcpu or .cpu is used;
28056 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
28057 Therefore, if not in -march=all case we first try an exact match and fall
28058 back to autodetection. */
28059 if (!skip_exact_match)
28060 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
28061 if (arch == -1)
28062 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
28063 if (arch == -1)
28064 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 28065
ee065d83
PB
28066 /* Tag_CPU_name. */
28067 if (selected_cpu_name[0])
28068 {
91d6fa6a 28069 char *q;
ee065d83 28070
91d6fa6a
NC
28071 q = selected_cpu_name;
28072 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
28073 {
28074 int i;
5f4273c7 28075
91d6fa6a
NC
28076 q += 4;
28077 for (i = 0; q[i]; i++)
28078 q[i] = TOUPPER (q[i]);
ee065d83 28079 }
91d6fa6a 28080 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 28081 }
62f3b8c8 28082
ee065d83 28083 /* Tag_CPU_arch. */
ee3c0378 28084 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 28085
62b3e311 28086 /* Tag_CPU_arch_profile. */
69239280
MGD
28087 if (profile != '\0')
28088 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 28089
15afaa63 28090 /* Tag_DSP_extension. */
4d354d8b 28091 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
6c290d53 28092 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 28093
2c6b98ea 28094 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 28095 /* Tag_ARM_ISA_use. */
ee3c0378 28096 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 28097 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 28098 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 28099
ee065d83 28100 /* Tag_THUMB_ISA_use. */
ee3c0378 28101 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 28102 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
28103 {
28104 int thumb_isa_use;
28105
28106 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 28107 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
28108 thumb_isa_use = 3;
28109 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
28110 thumb_isa_use = 2;
28111 else
28112 thumb_isa_use = 1;
28113 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
28114 }
62f3b8c8 28115
ee065d83 28116 /* Tag_VFP_arch. */
a715796b
TG
28117 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
28118 aeabi_set_attribute_int (Tag_VFP_arch,
28119 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
28120 ? 7 : 8);
bca38921 28121 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
28122 aeabi_set_attribute_int (Tag_VFP_arch,
28123 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
28124 ? 5 : 6);
28125 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
28126 {
28127 fp16_optional = 1;
28128 aeabi_set_attribute_int (Tag_VFP_arch, 3);
28129 }
ada65aa3 28130 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
28131 {
28132 aeabi_set_attribute_int (Tag_VFP_arch, 4);
28133 fp16_optional = 1;
28134 }
ee3c0378
AS
28135 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
28136 aeabi_set_attribute_int (Tag_VFP_arch, 2);
28137 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 28138 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 28139 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 28140
4547cb56
NC
28141 /* Tag_ABI_HardFP_use. */
28142 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
28143 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
28144 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
28145
ee065d83 28146 /* Tag_WMMX_arch. */
ee3c0378
AS
28147 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
28148 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
28149 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
28150 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 28151
ee3c0378 28152 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
28153 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
28154 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
28155 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
28156 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
28157 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
28158 {
28159 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
28160 {
28161 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
28162 }
28163 else
28164 {
28165 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
28166 fp16_optional = 1;
28167 }
28168 }
fa94de6b 28169
ee3c0378 28170 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 28171 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 28172 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 28173
69239280
MGD
28174 /* Tag_DIV_use.
28175
28176 We set Tag_DIV_use to two when integer divide instructions have been used
28177 in ARM state, or when Thumb integer divide instructions have been used,
28178 but we have no architecture profile set, nor have we any ARM instructions.
28179
4ed7ed8d
TP
28180 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
28181 by the base architecture.
bca38921 28182
69239280 28183 For new architectures we will have to check these tests. */
031254f2 28184 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
4ed7ed8d
TP
28185 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
28186 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
28187 aeabi_set_attribute_int (Tag_DIV_use, 0);
28188 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
28189 || (profile == '\0'
28190 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
28191 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 28192 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
28193
28194 /* Tag_MP_extension_use. */
28195 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
28196 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
28197
28198 /* Tag Virtualization_use. */
28199 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
28200 virt_sec |= 1;
28201 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
28202 virt_sec |= 2;
28203 if (virt_sec != 0)
28204 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
28205}
28206
c168ce07
TP
28207/* Post relaxation hook. Recompute ARM attributes now that relaxation is
28208 finished and free extension feature bits which will not be used anymore. */
0198d5e6 28209
c168ce07
TP
28210void
28211arm_md_post_relax (void)
28212{
28213 aeabi_set_public_attributes ();
4d354d8b
TP
28214 XDELETE (mcpu_ext_opt);
28215 mcpu_ext_opt = NULL;
28216 XDELETE (march_ext_opt);
28217 march_ext_opt = NULL;
c168ce07
TP
28218}
28219
104d59d1 28220/* Add the default contents for the .ARM.attributes section. */
0198d5e6 28221
ee065d83
PB
28222void
28223arm_md_end (void)
28224{
ee065d83
PB
28225 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
28226 return;
28227
28228 aeabi_set_public_attributes ();
ee065d83 28229}
8463be01 28230#endif /* OBJ_ELF */
ee065d83 28231
ee065d83
PB
28232/* Parse a .cpu directive. */
28233
28234static void
28235s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
28236{
e74cfd16 28237 const struct arm_cpu_option_table *opt;
ee065d83
PB
28238 char *name;
28239 char saved_char;
28240
28241 name = input_line_pointer;
5f4273c7 28242 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
28243 input_line_pointer++;
28244 saved_char = *input_line_pointer;
28245 *input_line_pointer = 0;
28246
28247 /* Skip the first "all" entry. */
28248 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
28249 if (streq (opt->name, name))
28250 {
4d354d8b
TP
28251 selected_arch = opt->value;
28252 selected_ext = opt->ext;
28253 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
ee065d83 28254 if (opt->canonical_name)
5f4273c7 28255 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
28256 else
28257 {
28258 int i;
28259 for (i = 0; opt->name[i]; i++)
28260 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 28261
ee065d83
PB
28262 selected_cpu_name[i] = 0;
28263 }
4d354d8b
TP
28264 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
28265
ee065d83
PB
28266 *input_line_pointer = saved_char;
28267 demand_empty_rest_of_line ();
28268 return;
28269 }
28270 as_bad (_("unknown cpu `%s'"), name);
28271 *input_line_pointer = saved_char;
28272 ignore_rest_of_line ();
28273}
28274
ee065d83
PB
28275/* Parse a .arch directive. */
28276
28277static void
28278s_arm_arch (int ignored ATTRIBUTE_UNUSED)
28279{
e74cfd16 28280 const struct arm_arch_option_table *opt;
ee065d83
PB
28281 char saved_char;
28282 char *name;
28283
28284 name = input_line_pointer;
5f4273c7 28285 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
28286 input_line_pointer++;
28287 saved_char = *input_line_pointer;
28288 *input_line_pointer = 0;
28289
28290 /* Skip the first "all" entry. */
28291 for (opt = arm_archs + 1; opt->name != NULL; opt++)
28292 if (streq (opt->name, name))
28293 {
4d354d8b
TP
28294 selected_arch = opt->value;
28295 selected_ext = arm_arch_none;
28296 selected_cpu = selected_arch;
5f4273c7 28297 strcpy (selected_cpu_name, opt->name);
4d354d8b 28298 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
28299 *input_line_pointer = saved_char;
28300 demand_empty_rest_of_line ();
28301 return;
28302 }
28303
28304 as_bad (_("unknown architecture `%s'\n"), name);
28305 *input_line_pointer = saved_char;
28306 ignore_rest_of_line ();
28307}
28308
7a1d4c38
PB
28309/* Parse a .object_arch directive. */
28310
28311static void
28312s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
28313{
28314 const struct arm_arch_option_table *opt;
28315 char saved_char;
28316 char *name;
28317
28318 name = input_line_pointer;
5f4273c7 28319 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
28320 input_line_pointer++;
28321 saved_char = *input_line_pointer;
28322 *input_line_pointer = 0;
28323
28324 /* Skip the first "all" entry. */
28325 for (opt = arm_archs + 1; opt->name != NULL; opt++)
28326 if (streq (opt->name, name))
28327 {
4d354d8b 28328 selected_object_arch = opt->value;
7a1d4c38
PB
28329 *input_line_pointer = saved_char;
28330 demand_empty_rest_of_line ();
28331 return;
28332 }
28333
28334 as_bad (_("unknown architecture `%s'\n"), name);
28335 *input_line_pointer = saved_char;
28336 ignore_rest_of_line ();
28337}
28338
69133863
MGD
28339/* Parse a .arch_extension directive. */
28340
28341static void
28342s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
28343{
28344 const struct arm_option_extension_value_table *opt;
28345 char saved_char;
28346 char *name;
28347 int adding_value = 1;
28348
28349 name = input_line_pointer;
28350 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
28351 input_line_pointer++;
28352 saved_char = *input_line_pointer;
28353 *input_line_pointer = 0;
28354
28355 if (strlen (name) >= 2
28356 && strncmp (name, "no", 2) == 0)
28357 {
28358 adding_value = 0;
28359 name += 2;
28360 }
28361
28362 for (opt = arm_extensions; opt->name != NULL; opt++)
28363 if (streq (opt->name, name))
28364 {
d942732e
TP
28365 int i, nb_allowed_archs =
28366 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
28367 for (i = 0; i < nb_allowed_archs; i++)
28368 {
28369 /* Empty entry. */
4d354d8b 28370 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
d942732e 28371 continue;
4d354d8b 28372 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
d942732e
TP
28373 break;
28374 }
28375
28376 if (i == nb_allowed_archs)
69133863
MGD
28377 {
28378 as_bad (_("architectural extension `%s' is not allowed for the "
28379 "current base architecture"), name);
28380 break;
28381 }
28382
28383 if (adding_value)
4d354d8b 28384 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
5a70a223 28385 opt->merge_value);
69133863 28386 else
4d354d8b 28387 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
69133863 28388
4d354d8b
TP
28389 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
28390 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
69133863
MGD
28391 *input_line_pointer = saved_char;
28392 demand_empty_rest_of_line ();
3d030cdb
TP
28393 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
28394 on this return so that duplicate extensions (extensions with the
28395 same name as a previous extension in the list) are not considered
28396 for command-line parsing. */
69133863
MGD
28397 return;
28398 }
28399
28400 if (opt->name == NULL)
e673710a 28401 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
28402
28403 *input_line_pointer = saved_char;
28404 ignore_rest_of_line ();
28405}
28406
ee065d83
PB
28407/* Parse a .fpu directive. */
28408
28409static void
28410s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
28411{
69133863 28412 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
28413 char saved_char;
28414 char *name;
28415
28416 name = input_line_pointer;
5f4273c7 28417 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
28418 input_line_pointer++;
28419 saved_char = *input_line_pointer;
28420 *input_line_pointer = 0;
5f4273c7 28421
ee065d83
PB
28422 for (opt = arm_fpus; opt->name != NULL; opt++)
28423 if (streq (opt->name, name))
28424 {
4d354d8b
TP
28425 selected_fpu = opt->value;
28426#ifndef CPU_DEFAULT
28427 if (no_cpu_selected ())
28428 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
28429 else
28430#endif
28431 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
28432 *input_line_pointer = saved_char;
28433 demand_empty_rest_of_line ();
28434 return;
28435 }
28436
28437 as_bad (_("unknown floating point format `%s'\n"), name);
28438 *input_line_pointer = saved_char;
28439 ignore_rest_of_line ();
28440}
ee065d83 28441
794ba86a 28442/* Copy symbol information. */
f31fef98 28443
794ba86a
DJ
28444void
28445arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
28446{
28447 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
28448}
e04befd0 28449
f31fef98 28450#ifdef OBJ_ELF
e04befd0
AS
28451/* Given a symbolic attribute NAME, return the proper integer value.
28452 Returns -1 if the attribute is not known. */
f31fef98 28453
e04befd0
AS
28454int
28455arm_convert_symbolic_attribute (const char *name)
28456{
f31fef98
NC
28457 static const struct
28458 {
28459 const char * name;
28460 const int tag;
28461 }
28462 attribute_table[] =
28463 {
28464 /* When you modify this table you should
28465 also modify the list in doc/c-arm.texi. */
e04befd0 28466#define T(tag) {#tag, tag}
f31fef98
NC
28467 T (Tag_CPU_raw_name),
28468 T (Tag_CPU_name),
28469 T (Tag_CPU_arch),
28470 T (Tag_CPU_arch_profile),
28471 T (Tag_ARM_ISA_use),
28472 T (Tag_THUMB_ISA_use),
75375b3e 28473 T (Tag_FP_arch),
f31fef98
NC
28474 T (Tag_VFP_arch),
28475 T (Tag_WMMX_arch),
28476 T (Tag_Advanced_SIMD_arch),
28477 T (Tag_PCS_config),
28478 T (Tag_ABI_PCS_R9_use),
28479 T (Tag_ABI_PCS_RW_data),
28480 T (Tag_ABI_PCS_RO_data),
28481 T (Tag_ABI_PCS_GOT_use),
28482 T (Tag_ABI_PCS_wchar_t),
28483 T (Tag_ABI_FP_rounding),
28484 T (Tag_ABI_FP_denormal),
28485 T (Tag_ABI_FP_exceptions),
28486 T (Tag_ABI_FP_user_exceptions),
28487 T (Tag_ABI_FP_number_model),
75375b3e 28488 T (Tag_ABI_align_needed),
f31fef98 28489 T (Tag_ABI_align8_needed),
75375b3e 28490 T (Tag_ABI_align_preserved),
f31fef98
NC
28491 T (Tag_ABI_align8_preserved),
28492 T (Tag_ABI_enum_size),
28493 T (Tag_ABI_HardFP_use),
28494 T (Tag_ABI_VFP_args),
28495 T (Tag_ABI_WMMX_args),
28496 T (Tag_ABI_optimization_goals),
28497 T (Tag_ABI_FP_optimization_goals),
28498 T (Tag_compatibility),
28499 T (Tag_CPU_unaligned_access),
75375b3e 28500 T (Tag_FP_HP_extension),
f31fef98
NC
28501 T (Tag_VFP_HP_extension),
28502 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
28503 T (Tag_MPextension_use),
28504 T (Tag_DIV_use),
f31fef98
NC
28505 T (Tag_nodefaults),
28506 T (Tag_also_compatible_with),
28507 T (Tag_conformance),
28508 T (Tag_T2EE_use),
28509 T (Tag_Virtualization_use),
15afaa63 28510 T (Tag_DSP_extension),
cd21e546 28511 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 28512#undef T
f31fef98 28513 };
e04befd0
AS
28514 unsigned int i;
28515
28516 if (name == NULL)
28517 return -1;
28518
f31fef98 28519 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 28520 if (streq (name, attribute_table[i].name))
e04befd0
AS
28521 return attribute_table[i].tag;
28522
28523 return -1;
28524}
267bf995 28525
93ef582d
NC
28526/* Apply sym value for relocations only in the case that they are for
28527 local symbols in the same segment as the fixup and you have the
28528 respective architectural feature for blx and simple switches. */
0198d5e6 28529
267bf995 28530int
93ef582d 28531arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
28532{
28533 if (fixP->fx_addsy
28534 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
28535 /* PR 17444: If the local symbol is in a different section then a reloc
28536 will always be generated for it, so applying the symbol value now
28537 will result in a double offset being stored in the relocation. */
28538 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 28539 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
28540 {
28541 switch (fixP->fx_r_type)
28542 {
28543 case BFD_RELOC_ARM_PCREL_BLX:
28544 case BFD_RELOC_THUMB_PCREL_BRANCH23:
28545 if (ARM_IS_FUNC (fixP->fx_addsy))
28546 return 1;
28547 break;
28548
28549 case BFD_RELOC_ARM_PCREL_CALL:
28550 case BFD_RELOC_THUMB_PCREL_BLX:
28551 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 28552 return 1;
267bf995
RR
28553 break;
28554
28555 default:
28556 break;
28557 }
28558
28559 }
28560 return 0;
28561}
f31fef98 28562#endif /* OBJ_ELF */