]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
Add gdb.Value.format_string ()
[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);
238/* Instructions in ARMv8-M only found in M profile architectures. */
239static const arm_feature_set arm_ext_v8m_m_only =
240 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
241static const arm_feature_set arm_ext_v6t2_v8m =
242 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
243/* Instructions shared between ARMv8-A and ARMv8-M. */
244static const arm_feature_set arm_ext_atomics =
245 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 246#ifdef OBJ_ELF
15afaa63
TP
247/* DSP instructions Tag_DSP_extension refers to. */
248static const arm_feature_set arm_ext_dsp =
249 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 250#endif
4d1464f2
MW
251static const arm_feature_set arm_ext_ras =
252 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
253/* FP16 instructions. */
254static const arm_feature_set arm_ext_fp16 =
255 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
01f48020
TC
256static const arm_feature_set arm_ext_fp16_fml =
257 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
dec41383
JW
258static const arm_feature_set arm_ext_v8_2 =
259 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
49e8a725
SN
260static const arm_feature_set arm_ext_v8_3 =
261 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
7fadb25d
SD
262static const arm_feature_set arm_ext_sb =
263 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
dad0c3bf
SD
264static const arm_feature_set arm_ext_predres =
265 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
e74cfd16
PB
266
267static const arm_feature_set arm_arch_any = ARM_ANY;
49fa50ef 268#ifdef OBJ_ELF
2c6b98ea 269static const arm_feature_set fpu_any = FPU_ANY;
49fa50ef 270#endif
f85d59c3 271static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
272static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
273static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
274
2d447fca 275static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 276 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 277static const arm_feature_set arm_cext_iwmmxt =
823d2571 278 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 279static const arm_feature_set arm_cext_xscale =
823d2571 280 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 281static const arm_feature_set arm_cext_maverick =
823d2571
TG
282 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
283static const arm_feature_set fpu_fpa_ext_v1 =
284 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
285static const arm_feature_set fpu_fpa_ext_v2 =
286 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 287static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
288 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
289static const arm_feature_set fpu_vfp_ext_v1 =
290 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
291static const arm_feature_set fpu_vfp_ext_v2 =
292 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
293static const arm_feature_set fpu_vfp_ext_v3xd =
294 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
295static const arm_feature_set fpu_vfp_ext_v3 =
296 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 297static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
298 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
299static const arm_feature_set fpu_neon_ext_v1 =
300 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 301static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 302 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
69c9e028 303#ifdef OBJ_ELF
823d2571
TG
304static const arm_feature_set fpu_vfp_fp16 =
305 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
306static const arm_feature_set fpu_neon_ext_fma =
307 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 308#endif
823d2571
TG
309static const arm_feature_set fpu_vfp_ext_fma =
310 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 311static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 312 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 313static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 314 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 315static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 316 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 317static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 318 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 319static const arm_feature_set crc_ext_armv8 =
823d2571 320 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 321static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 322 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
323static const arm_feature_set fpu_neon_ext_dotprod =
324 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 325
33a392fb 326static int mfloat_abi_opt = -1;
4d354d8b
TP
327/* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
328 directive. */
329static arm_feature_set selected_arch = ARM_ARCH_NONE;
330/* Extension feature bits selected by the last -mcpu/-march or .arch_extension
331 directive. */
332static arm_feature_set selected_ext = ARM_ARCH_NONE;
333/* Feature bits selected by the last -mcpu/-march or by the combination of the
334 last .cpu/.arch directive .arch_extension directives since that
335 directive. */
e74cfd16 336static arm_feature_set selected_cpu = ARM_ARCH_NONE;
4d354d8b
TP
337/* FPU feature bits selected by the last -mfpu or .fpu directive. */
338static arm_feature_set selected_fpu = FPU_NONE;
339/* Feature bits selected by the last .object_arch directive. */
340static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
ee065d83 341/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 342static char selected_cpu_name[20];
8d67f500 343
aacf0b33
KT
344extern FLONUM_TYPE generic_floating_point_number;
345
8d67f500
NC
346/* Return if no cpu was selected on command-line. */
347static bfd_boolean
348no_cpu_selected (void)
349{
823d2571 350 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
351}
352
7cc69913 353#ifdef OBJ_ELF
deeaaff8
DJ
354# ifdef EABI_DEFAULT
355static int meabi_flags = EABI_DEFAULT;
356# else
d507cf36 357static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 358# endif
e1da3f5b 359
ee3c0378
AS
360static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
361
e1da3f5b 362bfd_boolean
5f4273c7 363arm_is_eabi (void)
e1da3f5b
PB
364{
365 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
366}
7cc69913 367#endif
b99bd4ef 368
b99bd4ef 369#ifdef OBJ_ELF
c19d1205 370/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
371symbolS * GOT_symbol;
372#endif
373
b99bd4ef
NC
374/* 0: assemble for ARM,
375 1: assemble for Thumb,
376 2: assemble for Thumb even though target CPU does not support thumb
377 instructions. */
378static int thumb_mode = 0;
8dc2430f
NC
379/* A value distinct from the possible values for thumb_mode that we
380 can use to record whether thumb_mode has been copied into the
381 tc_frag_data field of a frag. */
382#define MODE_RECORDED (1 << 4)
b99bd4ef 383
e07e6e58
NC
384/* Specifies the intrinsic IT insn behavior mode. */
385enum implicit_it_mode
386{
387 IMPLICIT_IT_MODE_NEVER = 0x00,
388 IMPLICIT_IT_MODE_ARM = 0x01,
389 IMPLICIT_IT_MODE_THUMB = 0x02,
390 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
391};
392static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
393
c19d1205
ZW
394/* If unified_syntax is true, we are processing the new unified
395 ARM/Thumb syntax. Important differences from the old ARM mode:
396
397 - Immediate operands do not require a # prefix.
398 - Conditional affixes always appear at the end of the
399 instruction. (For backward compatibility, those instructions
400 that formerly had them in the middle, continue to accept them
401 there.)
402 - The IT instruction may appear, and if it does is validated
403 against subsequent conditional affixes. It does not generate
404 machine code.
405
406 Important differences from the old Thumb mode:
407
408 - Immediate operands do not require a # prefix.
409 - Most of the V6T2 instructions are only available in unified mode.
410 - The .N and .W suffixes are recognized and honored (it is an error
411 if they cannot be honored).
412 - All instructions set the flags if and only if they have an 's' affix.
413 - Conditional affixes may be used. They are validated against
414 preceding IT instructions. Unlike ARM mode, you cannot use a
415 conditional affix except in the scope of an IT instruction. */
416
417static bfd_boolean unified_syntax = FALSE;
b99bd4ef 418
bacebabc
RM
419/* An immediate operand can start with #, and ld*, st*, pld operands
420 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
421 before a [, which can appear as the first operand for pld.
422 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
423const char arm_symbol_chars[] = "#[]{}";
bacebabc 424
5287ad62
JB
425enum neon_el_type
426{
dcbf9037 427 NT_invtype,
5287ad62
JB
428 NT_untyped,
429 NT_integer,
430 NT_float,
431 NT_poly,
432 NT_signed,
dcbf9037 433 NT_unsigned
5287ad62
JB
434};
435
436struct neon_type_el
437{
438 enum neon_el_type type;
439 unsigned size;
440};
441
442#define NEON_MAX_TYPE_ELS 4
443
444struct neon_type
445{
446 struct neon_type_el el[NEON_MAX_TYPE_ELS];
447 unsigned elems;
448};
449
e07e6e58
NC
450enum it_instruction_type
451{
452 OUTSIDE_IT_INSN,
453 INSIDE_IT_INSN,
454 INSIDE_IT_LAST_INSN,
455 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 456 if inside, should be the last one. */
e07e6e58 457 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 458 i.e. BKPT and NOP. */
e07e6e58
NC
459 IT_INSN /* The IT insn has been parsed. */
460};
461
ad6cec43
MGD
462/* The maximum number of operands we need. */
463#define ARM_IT_MAX_OPERANDS 6
464
b99bd4ef
NC
465struct arm_it
466{
c19d1205 467 const char * error;
b99bd4ef 468 unsigned long instruction;
c19d1205
ZW
469 int size;
470 int size_req;
471 int cond;
037e8744
JB
472 /* "uncond_value" is set to the value in place of the conditional field in
473 unconditional versions of the instruction, or -1 if nothing is
474 appropriate. */
475 int uncond_value;
5287ad62 476 struct neon_type vectype;
88714cb8
DG
477 /* This does not indicate an actual NEON instruction, only that
478 the mnemonic accepts neon-style type suffixes. */
479 int is_neon;
0110f2b8
PB
480 /* Set to the opcode if the instruction needs relaxation.
481 Zero if the instruction is not relaxed. */
482 unsigned long relax;
b99bd4ef
NC
483 struct
484 {
485 bfd_reloc_code_real_type type;
c19d1205
ZW
486 expressionS exp;
487 int pc_rel;
b99bd4ef 488 } reloc;
b99bd4ef 489
e07e6e58
NC
490 enum it_instruction_type it_insn_type;
491
c19d1205
ZW
492 struct
493 {
494 unsigned reg;
ca3f61f7 495 signed int imm;
dcbf9037 496 struct neon_type_el vectype;
ca3f61f7
NC
497 unsigned present : 1; /* Operand present. */
498 unsigned isreg : 1; /* Operand was a register. */
499 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
500 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
501 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 502 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
503 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
504 instructions. This allows us to disambiguate ARM <-> vector insns. */
505 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 506 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 507 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 508 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
509 unsigned hasreloc : 1; /* Operand has relocation suffix. */
510 unsigned writeback : 1; /* Operand has trailing ! */
511 unsigned preind : 1; /* Preindexed address. */
512 unsigned postind : 1; /* Postindexed address. */
513 unsigned negative : 1; /* Index register was negated. */
514 unsigned shifted : 1; /* Shift applied to operation. */
515 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 516 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
517};
518
c19d1205 519static struct arm_it inst;
b99bd4ef
NC
520
521#define NUM_FLOAT_VALS 8
522
05d2d07e 523const char * fp_const[] =
b99bd4ef
NC
524{
525 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
526};
527
c19d1205 528/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
529#define MAX_LITTLENUMS 6
530
531LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
532
533#define FAIL (-1)
534#define SUCCESS (0)
535
536#define SUFF_S 1
537#define SUFF_D 2
538#define SUFF_E 3
539#define SUFF_P 4
540
c19d1205
ZW
541#define CP_T_X 0x00008000
542#define CP_T_Y 0x00400000
b99bd4ef 543
c19d1205
ZW
544#define CONDS_BIT 0x00100000
545#define LOAD_BIT 0x00100000
b99bd4ef
NC
546
547#define DOUBLE_LOAD_FLAG 0x00000001
548
549struct asm_cond
550{
d3ce72d0 551 const char * template_name;
c921be7d 552 unsigned long value;
b99bd4ef
NC
553};
554
c19d1205 555#define COND_ALWAYS 0xE
b99bd4ef 556
b99bd4ef
NC
557struct asm_psr
558{
d3ce72d0 559 const char * template_name;
c921be7d 560 unsigned long field;
b99bd4ef
NC
561};
562
62b3e311
PB
563struct asm_barrier_opt
564{
e797f7e0
MGD
565 const char * template_name;
566 unsigned long value;
567 const arm_feature_set arch;
62b3e311
PB
568};
569
2d2255b5 570/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
571#define SPSR_BIT (1 << 22)
572
c19d1205
ZW
573/* The individual PSR flag bits. */
574#define PSR_c (1 << 16)
575#define PSR_x (1 << 17)
576#define PSR_s (1 << 18)
577#define PSR_f (1 << 19)
b99bd4ef 578
c19d1205 579struct reloc_entry
bfae80f2 580{
0198d5e6 581 const char * name;
c921be7d 582 bfd_reloc_code_real_type reloc;
bfae80f2
RE
583};
584
5287ad62 585enum vfp_reg_pos
bfae80f2 586{
5287ad62
JB
587 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
588 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
589};
590
591enum vfp_ldstm_type
592{
593 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
594};
595
dcbf9037
JB
596/* Bits for DEFINED field in neon_typed_alias. */
597#define NTA_HASTYPE 1
598#define NTA_HASINDEX 2
599
600struct neon_typed_alias
601{
c921be7d
NC
602 unsigned char defined;
603 unsigned char index;
604 struct neon_type_el eltype;
dcbf9037
JB
605};
606
c19d1205 607/* ARM register categories. This includes coprocessor numbers and various
5aa75429
TP
608 architecture extensions' registers. Each entry should have an error message
609 in reg_expected_msgs below. */
c19d1205 610enum arm_reg_type
bfae80f2 611{
c19d1205
ZW
612 REG_TYPE_RN,
613 REG_TYPE_CP,
614 REG_TYPE_CN,
615 REG_TYPE_FN,
616 REG_TYPE_VFS,
617 REG_TYPE_VFD,
5287ad62 618 REG_TYPE_NQ,
037e8744 619 REG_TYPE_VFSD,
5287ad62 620 REG_TYPE_NDQ,
dec41383 621 REG_TYPE_NSD,
037e8744 622 REG_TYPE_NSDQ,
c19d1205
ZW
623 REG_TYPE_VFC,
624 REG_TYPE_MVF,
625 REG_TYPE_MVD,
626 REG_TYPE_MVFX,
627 REG_TYPE_MVDX,
628 REG_TYPE_MVAX,
629 REG_TYPE_DSPSC,
630 REG_TYPE_MMXWR,
631 REG_TYPE_MMXWC,
632 REG_TYPE_MMXWCG,
633 REG_TYPE_XSCALE,
90ec0d68 634 REG_TYPE_RNB
bfae80f2
RE
635};
636
dcbf9037
JB
637/* Structure for a hash table entry for a register.
638 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
639 information which states whether a vector type or index is specified (for a
640 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
641struct reg_entry
642{
c921be7d 643 const char * name;
90ec0d68 644 unsigned int number;
c921be7d
NC
645 unsigned char type;
646 unsigned char builtin;
647 struct neon_typed_alias * neon;
6c43fab6
RE
648};
649
c19d1205 650/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 651const char * const reg_expected_msgs[] =
c19d1205 652{
5aa75429
TP
653 [REG_TYPE_RN] = N_("ARM register expected"),
654 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
655 [REG_TYPE_CN] = N_("co-processor register expected"),
656 [REG_TYPE_FN] = N_("FPA register expected"),
657 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
658 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
659 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
660 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
661 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
662 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
663 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
664 " expected"),
665 [REG_TYPE_VFC] = N_("VFP system register expected"),
666 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
667 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
668 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
669 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
670 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
671 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
672 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
673 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
674 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
675 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
676 [REG_TYPE_RNB] = N_("")
6c43fab6
RE
677};
678
c19d1205 679/* Some well known registers that we refer to directly elsewhere. */
bd340a04 680#define REG_R12 12
c19d1205
ZW
681#define REG_SP 13
682#define REG_LR 14
683#define REG_PC 15
404ff6b5 684
b99bd4ef
NC
685/* ARM instructions take 4bytes in the object file, Thumb instructions
686 take 2: */
c19d1205 687#define INSN_SIZE 4
b99bd4ef
NC
688
689struct asm_opcode
690{
691 /* Basic string to match. */
d3ce72d0 692 const char * template_name;
c19d1205
ZW
693
694 /* Parameters to instruction. */
5be8be5d 695 unsigned int operands[8];
c19d1205
ZW
696
697 /* Conditional tag - see opcode_lookup. */
698 unsigned int tag : 4;
b99bd4ef
NC
699
700 /* Basic instruction code. */
c19d1205 701 unsigned int avalue : 28;
b99bd4ef 702
c19d1205
ZW
703 /* Thumb-format instruction code. */
704 unsigned int tvalue;
b99bd4ef 705
90e4755a 706 /* Which architecture variant provides this instruction. */
c921be7d
NC
707 const arm_feature_set * avariant;
708 const arm_feature_set * tvariant;
c19d1205
ZW
709
710 /* Function to call to encode instruction in ARM format. */
711 void (* aencode) (void);
b99bd4ef 712
c19d1205
ZW
713 /* Function to call to encode instruction in Thumb format. */
714 void (* tencode) (void);
b99bd4ef
NC
715};
716
a737bd4d
NC
717/* Defines for various bits that we will want to toggle. */
718#define INST_IMMEDIATE 0x02000000
719#define OFFSET_REG 0x02000000
c19d1205 720#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
721#define SHIFT_BY_REG 0x00000010
722#define PRE_INDEX 0x01000000
723#define INDEX_UP 0x00800000
724#define WRITE_BACK 0x00200000
725#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 726#define CPSI_MMOD 0x00020000
90e4755a 727
a737bd4d
NC
728#define LITERAL_MASK 0xf000f000
729#define OPCODE_MASK 0xfe1fffff
730#define V4_STR_BIT 0x00000020
8335d6aa 731#define VLDR_VMOV_SAME 0x0040f000
90e4755a 732
efd81785
PB
733#define T2_SUBS_PC_LR 0xf3de8f00
734
a737bd4d 735#define DATA_OP_SHIFT 21
bada4342 736#define SBIT_SHIFT 20
90e4755a 737
ef8d22e6
PB
738#define T2_OPCODE_MASK 0xfe1fffff
739#define T2_DATA_OP_SHIFT 21
bada4342 740#define T2_SBIT_SHIFT 20
ef8d22e6 741
6530b175
NC
742#define A_COND_MASK 0xf0000000
743#define A_PUSH_POP_OP_MASK 0x0fff0000
744
745/* Opcodes for pushing/poping registers to/from the stack. */
746#define A1_OPCODE_PUSH 0x092d0000
747#define A2_OPCODE_PUSH 0x052d0004
748#define A2_OPCODE_POP 0x049d0004
749
a737bd4d
NC
750/* Codes to distinguish the arithmetic instructions. */
751#define OPCODE_AND 0
752#define OPCODE_EOR 1
753#define OPCODE_SUB 2
754#define OPCODE_RSB 3
755#define OPCODE_ADD 4
756#define OPCODE_ADC 5
757#define OPCODE_SBC 6
758#define OPCODE_RSC 7
759#define OPCODE_TST 8
760#define OPCODE_TEQ 9
761#define OPCODE_CMP 10
762#define OPCODE_CMN 11
763#define OPCODE_ORR 12
764#define OPCODE_MOV 13
765#define OPCODE_BIC 14
766#define OPCODE_MVN 15
90e4755a 767
ef8d22e6
PB
768#define T2_OPCODE_AND 0
769#define T2_OPCODE_BIC 1
770#define T2_OPCODE_ORR 2
771#define T2_OPCODE_ORN 3
772#define T2_OPCODE_EOR 4
773#define T2_OPCODE_ADD 8
774#define T2_OPCODE_ADC 10
775#define T2_OPCODE_SBC 11
776#define T2_OPCODE_SUB 13
777#define T2_OPCODE_RSB 14
778
a737bd4d
NC
779#define T_OPCODE_MUL 0x4340
780#define T_OPCODE_TST 0x4200
781#define T_OPCODE_CMN 0x42c0
782#define T_OPCODE_NEG 0x4240
783#define T_OPCODE_MVN 0x43c0
90e4755a 784
a737bd4d
NC
785#define T_OPCODE_ADD_R3 0x1800
786#define T_OPCODE_SUB_R3 0x1a00
787#define T_OPCODE_ADD_HI 0x4400
788#define T_OPCODE_ADD_ST 0xb000
789#define T_OPCODE_SUB_ST 0xb080
790#define T_OPCODE_ADD_SP 0xa800
791#define T_OPCODE_ADD_PC 0xa000
792#define T_OPCODE_ADD_I8 0x3000
793#define T_OPCODE_SUB_I8 0x3800
794#define T_OPCODE_ADD_I3 0x1c00
795#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 796
a737bd4d
NC
797#define T_OPCODE_ASR_R 0x4100
798#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
799#define T_OPCODE_LSR_R 0x40c0
800#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
801#define T_OPCODE_ASR_I 0x1000
802#define T_OPCODE_LSL_I 0x0000
803#define T_OPCODE_LSR_I 0x0800
b99bd4ef 804
a737bd4d
NC
805#define T_OPCODE_MOV_I8 0x2000
806#define T_OPCODE_CMP_I8 0x2800
807#define T_OPCODE_CMP_LR 0x4280
808#define T_OPCODE_MOV_HR 0x4600
809#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 810
a737bd4d
NC
811#define T_OPCODE_LDR_PC 0x4800
812#define T_OPCODE_LDR_SP 0x9800
813#define T_OPCODE_STR_SP 0x9000
814#define T_OPCODE_LDR_IW 0x6800
815#define T_OPCODE_STR_IW 0x6000
816#define T_OPCODE_LDR_IH 0x8800
817#define T_OPCODE_STR_IH 0x8000
818#define T_OPCODE_LDR_IB 0x7800
819#define T_OPCODE_STR_IB 0x7000
820#define T_OPCODE_LDR_RW 0x5800
821#define T_OPCODE_STR_RW 0x5000
822#define T_OPCODE_LDR_RH 0x5a00
823#define T_OPCODE_STR_RH 0x5200
824#define T_OPCODE_LDR_RB 0x5c00
825#define T_OPCODE_STR_RB 0x5400
c9b604bd 826
a737bd4d
NC
827#define T_OPCODE_PUSH 0xb400
828#define T_OPCODE_POP 0xbc00
b99bd4ef 829
2fc8bdac 830#define T_OPCODE_BRANCH 0xe000
b99bd4ef 831
a737bd4d 832#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 833#define THUMB_PP_PC_LR 0x0100
c19d1205 834#define THUMB_LOAD_BIT 0x0800
53365c0d 835#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
836
837#define BAD_ARGS _("bad arguments to instruction")
fdfde340 838#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
839#define BAD_PC _("r15 not allowed here")
840#define BAD_COND _("instruction cannot be conditional")
841#define BAD_OVERLAP _("registers may not be the same")
842#define BAD_HIREG _("lo register required")
843#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 844#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
845#define BAD_BRANCH _("branch must be last instruction in IT block")
846#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 847#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
848#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
849#define BAD_IT_COND _("incorrect condition in IT block")
850#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 851#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
852#define BAD_PC_ADDRESSING \
853 _("cannot use register index with PC-relative addressing")
854#define BAD_PC_WRITEBACK \
855 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
856#define BAD_RANGE _("branch out of range")
857#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 858#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 859#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
c19d1205 860
c921be7d
NC
861static struct hash_control * arm_ops_hsh;
862static struct hash_control * arm_cond_hsh;
863static struct hash_control * arm_shift_hsh;
864static struct hash_control * arm_psr_hsh;
865static struct hash_control * arm_v7m_psr_hsh;
866static struct hash_control * arm_reg_hsh;
867static struct hash_control * arm_reloc_hsh;
868static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 869
b99bd4ef
NC
870/* Stuff needed to resolve the label ambiguity
871 As:
872 ...
873 label: <insn>
874 may differ from:
875 ...
876 label:
5f4273c7 877 <insn> */
b99bd4ef
NC
878
879symbolS * last_label_seen;
b34976b6 880static int label_is_thumb_function_name = FALSE;
e07e6e58 881
3d0c9500
NC
882/* Literal pool structure. Held on a per-section
883 and per-sub-section basis. */
a737bd4d 884
c19d1205 885#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 886typedef struct literal_pool
b99bd4ef 887{
c921be7d
NC
888 expressionS literals [MAX_LITERAL_POOL_SIZE];
889 unsigned int next_free_entry;
890 unsigned int id;
891 symbolS * symbol;
892 segT section;
893 subsegT sub_section;
a8040cf2
NC
894#ifdef OBJ_ELF
895 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
896#endif
c921be7d 897 struct literal_pool * next;
8335d6aa 898 unsigned int alignment;
3d0c9500 899} literal_pool;
b99bd4ef 900
3d0c9500
NC
901/* Pointer to a linked list of literal pools. */
902literal_pool * list_of_pools = NULL;
e27ec89e 903
2e6976a8
DG
904typedef enum asmfunc_states
905{
906 OUTSIDE_ASMFUNC,
907 WAITING_ASMFUNC_NAME,
908 WAITING_ENDASMFUNC
909} asmfunc_states;
910
911static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
912
e07e6e58
NC
913#ifdef OBJ_ELF
914# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
915#else
916static struct current_it now_it;
917#endif
918
919static inline int
920now_it_compatible (int cond)
921{
922 return (cond & ~1) == (now_it.cc & ~1);
923}
924
925static inline int
926conditional_insn (void)
927{
928 return inst.cond != COND_ALWAYS;
929}
930
931static int in_it_block (void);
932
933static int handle_it_state (void);
934
935static void force_automatic_it_block_close (void);
936
c921be7d
NC
937static void it_fsm_post_encode (void);
938
e07e6e58
NC
939#define set_it_insn_type(type) \
940 do \
941 { \
942 inst.it_insn_type = type; \
943 if (handle_it_state () == FAIL) \
477330fc 944 return; \
e07e6e58
NC
945 } \
946 while (0)
947
c921be7d
NC
948#define set_it_insn_type_nonvoid(type, failret) \
949 do \
950 { \
951 inst.it_insn_type = type; \
952 if (handle_it_state () == FAIL) \
477330fc 953 return failret; \
c921be7d
NC
954 } \
955 while(0)
956
e07e6e58
NC
957#define set_it_insn_type_last() \
958 do \
959 { \
960 if (inst.cond == COND_ALWAYS) \
477330fc 961 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 962 else \
477330fc 963 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
964 } \
965 while (0)
966
c19d1205 967/* Pure syntax. */
b99bd4ef 968
c19d1205
ZW
969/* This array holds the chars that always start a comment. If the
970 pre-processor is disabled, these aren't very useful. */
2e6976a8 971char arm_comment_chars[] = "@";
3d0c9500 972
c19d1205
ZW
973/* This array holds the chars that only start a comment at the beginning of
974 a line. If the line seems to have the form '# 123 filename'
975 .line and .file directives will appear in the pre-processed output. */
976/* Note that input_file.c hand checks for '#' at the beginning of the
977 first line of the input file. This is because the compiler outputs
978 #NO_APP at the beginning of its output. */
979/* Also note that comments like this one will always work. */
980const char line_comment_chars[] = "#";
3d0c9500 981
2e6976a8 982char arm_line_separator_chars[] = ";";
b99bd4ef 983
c19d1205
ZW
984/* Chars that can be used to separate mant
985 from exp in floating point numbers. */
986const char EXP_CHARS[] = "eE";
3d0c9500 987
c19d1205
ZW
988/* Chars that mean this number is a floating point constant. */
989/* As in 0f12.456 */
990/* or 0d1.2345e12 */
b99bd4ef 991
c19d1205 992const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 993
c19d1205
ZW
994/* Prefix characters that indicate the start of an immediate
995 value. */
996#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 997
c19d1205
ZW
998/* Separator character handling. */
999
1000#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1001
1002static inline int
1003skip_past_char (char ** str, char c)
1004{
8ab8155f
NC
1005 /* PR gas/14987: Allow for whitespace before the expected character. */
1006 skip_whitespace (*str);
427d0db6 1007
c19d1205
ZW
1008 if (**str == c)
1009 {
1010 (*str)++;
1011 return SUCCESS;
3d0c9500 1012 }
c19d1205
ZW
1013 else
1014 return FAIL;
1015}
c921be7d 1016
c19d1205 1017#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 1018
c19d1205
ZW
1019/* Arithmetic expressions (possibly involving symbols). */
1020
1021/* Return TRUE if anything in the expression is a bignum. */
1022
0198d5e6 1023static bfd_boolean
c19d1205
ZW
1024walk_no_bignums (symbolS * sp)
1025{
1026 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 1027 return TRUE;
c19d1205
ZW
1028
1029 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 1030 {
c19d1205
ZW
1031 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1032 || (symbol_get_value_expression (sp)->X_op_symbol
1033 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
1034 }
1035
0198d5e6 1036 return FALSE;
3d0c9500
NC
1037}
1038
0198d5e6 1039static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
1040
1041/* Third argument to my_get_expression. */
1042#define GE_NO_PREFIX 0
1043#define GE_IMM_PREFIX 1
1044#define GE_OPT_PREFIX 2
5287ad62
JB
1045/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1046 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1047#define GE_OPT_PREFIX_BIG 3
a737bd4d 1048
b99bd4ef 1049static int
c19d1205 1050my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1051{
c19d1205 1052 char * save_in;
b99bd4ef 1053
c19d1205
ZW
1054 /* In unified syntax, all prefixes are optional. */
1055 if (unified_syntax)
5287ad62 1056 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1057 : GE_OPT_PREFIX;
b99bd4ef 1058
c19d1205 1059 switch (prefix_mode)
b99bd4ef 1060 {
c19d1205
ZW
1061 case GE_NO_PREFIX: break;
1062 case GE_IMM_PREFIX:
1063 if (!is_immediate_prefix (**str))
1064 {
1065 inst.error = _("immediate expression requires a # prefix");
1066 return FAIL;
1067 }
1068 (*str)++;
1069 break;
1070 case GE_OPT_PREFIX:
5287ad62 1071 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1072 if (is_immediate_prefix (**str))
1073 (*str)++;
1074 break;
0198d5e6
TC
1075 default:
1076 abort ();
c19d1205 1077 }
b99bd4ef 1078
c19d1205 1079 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1080
c19d1205
ZW
1081 save_in = input_line_pointer;
1082 input_line_pointer = *str;
0198d5e6 1083 in_my_get_expression = TRUE;
2ac93be7 1084 expression (ep);
0198d5e6 1085 in_my_get_expression = FALSE;
c19d1205 1086
f86adc07 1087 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1088 {
f86adc07 1089 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1090 *str = input_line_pointer;
1091 input_line_pointer = save_in;
1092 if (inst.error == NULL)
f86adc07
NS
1093 inst.error = (ep->X_op == O_absent
1094 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1095 return 1;
1096 }
b99bd4ef 1097
c19d1205
ZW
1098 /* Get rid of any bignums now, so that we don't generate an error for which
1099 we can't establish a line number later on. Big numbers are never valid
1100 in instructions, which is where this routine is always called. */
5287ad62
JB
1101 if (prefix_mode != GE_OPT_PREFIX_BIG
1102 && (ep->X_op == O_big
477330fc 1103 || (ep->X_add_symbol
5287ad62 1104 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1105 || (ep->X_op_symbol
5287ad62 1106 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1107 {
1108 inst.error = _("invalid constant");
1109 *str = input_line_pointer;
1110 input_line_pointer = save_in;
1111 return 1;
1112 }
b99bd4ef 1113
c19d1205
ZW
1114 *str = input_line_pointer;
1115 input_line_pointer = save_in;
0198d5e6 1116 return SUCCESS;
b99bd4ef
NC
1117}
1118
c19d1205
ZW
1119/* Turn a string in input_line_pointer into a floating point constant
1120 of type TYPE, and store the appropriate bytes in *LITP. The number
1121 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1122 returned, or NULL on OK.
b99bd4ef 1123
c19d1205
ZW
1124 Note that fp constants aren't represent in the normal way on the ARM.
1125 In big endian mode, things are as expected. However, in little endian
1126 mode fp constants are big-endian word-wise, and little-endian byte-wise
1127 within the words. For example, (double) 1.1 in big endian mode is
1128 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1129 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1130
c19d1205 1131 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1132
6d4af3c2 1133const char *
c19d1205
ZW
1134md_atof (int type, char * litP, int * sizeP)
1135{
1136 int prec;
1137 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1138 char *t;
1139 int i;
b99bd4ef 1140
c19d1205
ZW
1141 switch (type)
1142 {
1143 case 'f':
1144 case 'F':
1145 case 's':
1146 case 'S':
1147 prec = 2;
1148 break;
b99bd4ef 1149
c19d1205
ZW
1150 case 'd':
1151 case 'D':
1152 case 'r':
1153 case 'R':
1154 prec = 4;
1155 break;
b99bd4ef 1156
c19d1205
ZW
1157 case 'x':
1158 case 'X':
499ac353 1159 prec = 5;
c19d1205 1160 break;
b99bd4ef 1161
c19d1205
ZW
1162 case 'p':
1163 case 'P':
499ac353 1164 prec = 5;
c19d1205 1165 break;
a737bd4d 1166
c19d1205
ZW
1167 default:
1168 *sizeP = 0;
499ac353 1169 return _("Unrecognized or unsupported floating point constant");
c19d1205 1170 }
b99bd4ef 1171
c19d1205
ZW
1172 t = atof_ieee (input_line_pointer, type, words);
1173 if (t)
1174 input_line_pointer = t;
499ac353 1175 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1176
c19d1205
ZW
1177 if (target_big_endian)
1178 {
1179 for (i = 0; i < prec; i++)
1180 {
499ac353
NC
1181 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1182 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1183 }
1184 }
1185 else
1186 {
e74cfd16 1187 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1188 for (i = prec - 1; i >= 0; i--)
1189 {
499ac353
NC
1190 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1191 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1192 }
1193 else
1194 /* For a 4 byte float the order of elements in `words' is 1 0.
1195 For an 8 byte float the order is 1 0 3 2. */
1196 for (i = 0; i < prec; i += 2)
1197 {
499ac353
NC
1198 md_number_to_chars (litP, (valueT) words[i + 1],
1199 sizeof (LITTLENUM_TYPE));
1200 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1201 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1202 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1203 }
1204 }
b99bd4ef 1205
499ac353 1206 return NULL;
c19d1205 1207}
b99bd4ef 1208
c19d1205
ZW
1209/* We handle all bad expressions here, so that we can report the faulty
1210 instruction in the error message. */
0198d5e6 1211
c19d1205 1212void
91d6fa6a 1213md_operand (expressionS * exp)
c19d1205
ZW
1214{
1215 if (in_my_get_expression)
91d6fa6a 1216 exp->X_op = O_illegal;
b99bd4ef
NC
1217}
1218
c19d1205 1219/* Immediate values. */
b99bd4ef 1220
0198d5e6 1221#ifdef OBJ_ELF
c19d1205
ZW
1222/* Generic immediate-value read function for use in directives.
1223 Accepts anything that 'expression' can fold to a constant.
1224 *val receives the number. */
0198d5e6 1225
c19d1205
ZW
1226static int
1227immediate_for_directive (int *val)
b99bd4ef 1228{
c19d1205
ZW
1229 expressionS exp;
1230 exp.X_op = O_illegal;
b99bd4ef 1231
c19d1205
ZW
1232 if (is_immediate_prefix (*input_line_pointer))
1233 {
1234 input_line_pointer++;
1235 expression (&exp);
1236 }
b99bd4ef 1237
c19d1205
ZW
1238 if (exp.X_op != O_constant)
1239 {
1240 as_bad (_("expected #constant"));
1241 ignore_rest_of_line ();
1242 return FAIL;
1243 }
1244 *val = exp.X_add_number;
1245 return SUCCESS;
b99bd4ef 1246}
c19d1205 1247#endif
b99bd4ef 1248
c19d1205 1249/* Register parsing. */
b99bd4ef 1250
c19d1205
ZW
1251/* Generic register parser. CCP points to what should be the
1252 beginning of a register name. If it is indeed a valid register
1253 name, advance CCP over it and return the reg_entry structure;
1254 otherwise return NULL. Does not issue diagnostics. */
1255
1256static struct reg_entry *
1257arm_reg_parse_multi (char **ccp)
b99bd4ef 1258{
c19d1205
ZW
1259 char *start = *ccp;
1260 char *p;
1261 struct reg_entry *reg;
b99bd4ef 1262
477330fc
RM
1263 skip_whitespace (start);
1264
c19d1205
ZW
1265#ifdef REGISTER_PREFIX
1266 if (*start != REGISTER_PREFIX)
01cfc07f 1267 return NULL;
c19d1205
ZW
1268 start++;
1269#endif
1270#ifdef OPTIONAL_REGISTER_PREFIX
1271 if (*start == OPTIONAL_REGISTER_PREFIX)
1272 start++;
1273#endif
b99bd4ef 1274
c19d1205
ZW
1275 p = start;
1276 if (!ISALPHA (*p) || !is_name_beginner (*p))
1277 return NULL;
b99bd4ef 1278
c19d1205
ZW
1279 do
1280 p++;
1281 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1282
1283 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1284
1285 if (!reg)
1286 return NULL;
1287
1288 *ccp = p;
1289 return reg;
b99bd4ef
NC
1290}
1291
1292static int
dcbf9037 1293arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1294 enum arm_reg_type type)
b99bd4ef 1295{
c19d1205
ZW
1296 /* Alternative syntaxes are accepted for a few register classes. */
1297 switch (type)
1298 {
1299 case REG_TYPE_MVF:
1300 case REG_TYPE_MVD:
1301 case REG_TYPE_MVFX:
1302 case REG_TYPE_MVDX:
1303 /* Generic coprocessor register names are allowed for these. */
79134647 1304 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1305 return reg->number;
1306 break;
69b97547 1307
c19d1205
ZW
1308 case REG_TYPE_CP:
1309 /* For backward compatibility, a bare number is valid here. */
1310 {
1311 unsigned long processor = strtoul (start, ccp, 10);
1312 if (*ccp != start && processor <= 15)
1313 return processor;
1314 }
1a0670f3 1315 /* Fall through. */
6057a28f 1316
c19d1205
ZW
1317 case REG_TYPE_MMXWC:
1318 /* WC includes WCG. ??? I'm not sure this is true for all
1319 instructions that take WC registers. */
79134647 1320 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1321 return reg->number;
6057a28f 1322 break;
c19d1205 1323
6057a28f 1324 default:
c19d1205 1325 break;
6057a28f
NC
1326 }
1327
dcbf9037
JB
1328 return FAIL;
1329}
1330
1331/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1332 return value is the register number or FAIL. */
1333
1334static int
1335arm_reg_parse (char **ccp, enum arm_reg_type type)
1336{
1337 char *start = *ccp;
1338 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1339 int ret;
1340
1341 /* Do not allow a scalar (reg+index) to parse as a register. */
1342 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1343 return FAIL;
1344
1345 if (reg && reg->type == type)
1346 return reg->number;
1347
1348 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1349 return ret;
1350
c19d1205
ZW
1351 *ccp = start;
1352 return FAIL;
1353}
69b97547 1354
dcbf9037
JB
1355/* Parse a Neon type specifier. *STR should point at the leading '.'
1356 character. Does no verification at this stage that the type fits the opcode
1357 properly. E.g.,
1358
1359 .i32.i32.s16
1360 .s32.f32
1361 .u16
1362
1363 Can all be legally parsed by this function.
1364
1365 Fills in neon_type struct pointer with parsed information, and updates STR
1366 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1367 type, FAIL if not. */
1368
1369static int
1370parse_neon_type (struct neon_type *type, char **str)
1371{
1372 char *ptr = *str;
1373
1374 if (type)
1375 type->elems = 0;
1376
1377 while (type->elems < NEON_MAX_TYPE_ELS)
1378 {
1379 enum neon_el_type thistype = NT_untyped;
1380 unsigned thissize = -1u;
1381
1382 if (*ptr != '.')
1383 break;
1384
1385 ptr++;
1386
1387 /* Just a size without an explicit type. */
1388 if (ISDIGIT (*ptr))
1389 goto parsesize;
1390
1391 switch (TOLOWER (*ptr))
1392 {
1393 case 'i': thistype = NT_integer; break;
1394 case 'f': thistype = NT_float; break;
1395 case 'p': thistype = NT_poly; break;
1396 case 's': thistype = NT_signed; break;
1397 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1398 case 'd':
1399 thistype = NT_float;
1400 thissize = 64;
1401 ptr++;
1402 goto done;
dcbf9037
JB
1403 default:
1404 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1405 return FAIL;
1406 }
1407
1408 ptr++;
1409
1410 /* .f is an abbreviation for .f32. */
1411 if (thistype == NT_float && !ISDIGIT (*ptr))
1412 thissize = 32;
1413 else
1414 {
1415 parsesize:
1416 thissize = strtoul (ptr, &ptr, 10);
1417
1418 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1419 && thissize != 64)
1420 {
1421 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1422 return FAIL;
1423 }
1424 }
1425
037e8744 1426 done:
dcbf9037 1427 if (type)
477330fc
RM
1428 {
1429 type->el[type->elems].type = thistype;
dcbf9037
JB
1430 type->el[type->elems].size = thissize;
1431 type->elems++;
1432 }
1433 }
1434
1435 /* Empty/missing type is not a successful parse. */
1436 if (type->elems == 0)
1437 return FAIL;
1438
1439 *str = ptr;
1440
1441 return SUCCESS;
1442}
1443
1444/* Errors may be set multiple times during parsing or bit encoding
1445 (particularly in the Neon bits), but usually the earliest error which is set
1446 will be the most meaningful. Avoid overwriting it with later (cascading)
1447 errors by calling this function. */
1448
1449static void
1450first_error (const char *err)
1451{
1452 if (!inst.error)
1453 inst.error = err;
1454}
1455
1456/* Parse a single type, e.g. ".s32", leading period included. */
1457static int
1458parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1459{
1460 char *str = *ccp;
1461 struct neon_type optype;
1462
1463 if (*str == '.')
1464 {
1465 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1466 {
1467 if (optype.elems == 1)
1468 *vectype = optype.el[0];
1469 else
1470 {
1471 first_error (_("only one type should be specified for operand"));
1472 return FAIL;
1473 }
1474 }
dcbf9037 1475 else
477330fc
RM
1476 {
1477 first_error (_("vector type expected"));
1478 return FAIL;
1479 }
dcbf9037
JB
1480 }
1481 else
1482 return FAIL;
5f4273c7 1483
dcbf9037 1484 *ccp = str;
5f4273c7 1485
dcbf9037
JB
1486 return SUCCESS;
1487}
1488
1489/* Special meanings for indices (which have a range of 0-7), which will fit into
1490 a 4-bit integer. */
1491
1492#define NEON_ALL_LANES 15
1493#define NEON_INTERLEAVE_LANES 14
1494
1495/* Parse either a register or a scalar, with an optional type. Return the
1496 register number, and optionally fill in the actual type of the register
1497 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1498 type/index information in *TYPEINFO. */
1499
1500static int
1501parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1502 enum arm_reg_type *rtype,
1503 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1504{
1505 char *str = *ccp;
1506 struct reg_entry *reg = arm_reg_parse_multi (&str);
1507 struct neon_typed_alias atype;
1508 struct neon_type_el parsetype;
1509
1510 atype.defined = 0;
1511 atype.index = -1;
1512 atype.eltype.type = NT_invtype;
1513 atype.eltype.size = -1;
1514
1515 /* Try alternate syntax for some types of register. Note these are mutually
1516 exclusive with the Neon syntax extensions. */
1517 if (reg == NULL)
1518 {
1519 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1520 if (altreg != FAIL)
477330fc 1521 *ccp = str;
dcbf9037 1522 if (typeinfo)
477330fc 1523 *typeinfo = atype;
dcbf9037
JB
1524 return altreg;
1525 }
1526
037e8744
JB
1527 /* Undo polymorphism when a set of register types may be accepted. */
1528 if ((type == REG_TYPE_NDQ
1529 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1530 || (type == REG_TYPE_VFSD
477330fc 1531 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1532 || (type == REG_TYPE_NSDQ
477330fc
RM
1533 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1534 || reg->type == REG_TYPE_NQ))
dec41383
JW
1535 || (type == REG_TYPE_NSD
1536 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
f512f76f
NC
1537 || (type == REG_TYPE_MMXWC
1538 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1539 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1540
1541 if (type != reg->type)
1542 return FAIL;
1543
1544 if (reg->neon)
1545 atype = *reg->neon;
5f4273c7 1546
dcbf9037
JB
1547 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1548 {
1549 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1550 {
1551 first_error (_("can't redefine type for operand"));
1552 return FAIL;
1553 }
dcbf9037
JB
1554 atype.defined |= NTA_HASTYPE;
1555 atype.eltype = parsetype;
1556 }
5f4273c7 1557
dcbf9037
JB
1558 if (skip_past_char (&str, '[') == SUCCESS)
1559 {
dec41383
JW
1560 if (type != REG_TYPE_VFD
1561 && !(type == REG_TYPE_VFS
1562 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2)))
477330fc
RM
1563 {
1564 first_error (_("only D registers may be indexed"));
1565 return FAIL;
1566 }
5f4273c7 1567
dcbf9037 1568 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1569 {
1570 first_error (_("can't change index for operand"));
1571 return FAIL;
1572 }
dcbf9037
JB
1573
1574 atype.defined |= NTA_HASINDEX;
1575
1576 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1577 atype.index = NEON_ALL_LANES;
dcbf9037 1578 else
477330fc
RM
1579 {
1580 expressionS exp;
dcbf9037 1581
477330fc 1582 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1583
477330fc
RM
1584 if (exp.X_op != O_constant)
1585 {
1586 first_error (_("constant expression required"));
1587 return FAIL;
1588 }
dcbf9037 1589
477330fc
RM
1590 if (skip_past_char (&str, ']') == FAIL)
1591 return FAIL;
dcbf9037 1592
477330fc
RM
1593 atype.index = exp.X_add_number;
1594 }
dcbf9037 1595 }
5f4273c7 1596
dcbf9037
JB
1597 if (typeinfo)
1598 *typeinfo = atype;
5f4273c7 1599
dcbf9037
JB
1600 if (rtype)
1601 *rtype = type;
5f4273c7 1602
dcbf9037 1603 *ccp = str;
5f4273c7 1604
dcbf9037
JB
1605 return reg->number;
1606}
1607
1608/* Like arm_reg_parse, but allow allow the following extra features:
1609 - If RTYPE is non-zero, return the (possibly restricted) type of the
1610 register (e.g. Neon double or quad reg when either has been requested).
1611 - If this is a Neon vector type with additional type information, fill
1612 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1613 This function will fault on encountering a scalar. */
dcbf9037
JB
1614
1615static int
1616arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1617 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1618{
1619 struct neon_typed_alias atype;
1620 char *str = *ccp;
1621 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1622
1623 if (reg == FAIL)
1624 return FAIL;
1625
0855e32b
NS
1626 /* Do not allow regname(... to parse as a register. */
1627 if (*str == '(')
1628 return FAIL;
1629
dcbf9037
JB
1630 /* Do not allow a scalar (reg+index) to parse as a register. */
1631 if ((atype.defined & NTA_HASINDEX) != 0)
1632 {
1633 first_error (_("register operand expected, but got scalar"));
1634 return FAIL;
1635 }
1636
1637 if (vectype)
1638 *vectype = atype.eltype;
1639
1640 *ccp = str;
1641
1642 return reg;
1643}
1644
1645#define NEON_SCALAR_REG(X) ((X) >> 4)
1646#define NEON_SCALAR_INDEX(X) ((X) & 15)
1647
5287ad62
JB
1648/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1649 have enough information to be able to do a good job bounds-checking. So, we
1650 just do easy checks here, and do further checks later. */
1651
1652static int
dcbf9037 1653parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1654{
dcbf9037 1655 int reg;
5287ad62 1656 char *str = *ccp;
dcbf9037 1657 struct neon_typed_alias atype;
dec41383
JW
1658 enum arm_reg_type reg_type = REG_TYPE_VFD;
1659
1660 if (elsize == 4)
1661 reg_type = REG_TYPE_VFS;
5f4273c7 1662
dec41383 1663 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
5f4273c7 1664
dcbf9037 1665 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1666 return FAIL;
5f4273c7 1667
dcbf9037 1668 if (atype.index == NEON_ALL_LANES)
5287ad62 1669 {
dcbf9037 1670 first_error (_("scalar must have an index"));
5287ad62
JB
1671 return FAIL;
1672 }
dcbf9037 1673 else if (atype.index >= 64 / elsize)
5287ad62 1674 {
dcbf9037 1675 first_error (_("scalar index out of range"));
5287ad62
JB
1676 return FAIL;
1677 }
5f4273c7 1678
dcbf9037
JB
1679 if (type)
1680 *type = atype.eltype;
5f4273c7 1681
5287ad62 1682 *ccp = str;
5f4273c7 1683
dcbf9037 1684 return reg * 16 + atype.index;
5287ad62
JB
1685}
1686
c19d1205 1687/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1688
c19d1205
ZW
1689static long
1690parse_reg_list (char ** strp)
1691{
1692 char * str = * strp;
1693 long range = 0;
1694 int another_range;
a737bd4d 1695
c19d1205
ZW
1696 /* We come back here if we get ranges concatenated by '+' or '|'. */
1697 do
6057a28f 1698 {
477330fc
RM
1699 skip_whitespace (str);
1700
c19d1205 1701 another_range = 0;
a737bd4d 1702
c19d1205
ZW
1703 if (*str == '{')
1704 {
1705 int in_range = 0;
1706 int cur_reg = -1;
a737bd4d 1707
c19d1205
ZW
1708 str++;
1709 do
1710 {
1711 int reg;
6057a28f 1712
dcbf9037 1713 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1714 {
dcbf9037 1715 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1716 return FAIL;
1717 }
a737bd4d 1718
c19d1205
ZW
1719 if (in_range)
1720 {
1721 int i;
a737bd4d 1722
c19d1205
ZW
1723 if (reg <= cur_reg)
1724 {
dcbf9037 1725 first_error (_("bad range in register list"));
c19d1205
ZW
1726 return FAIL;
1727 }
40a18ebd 1728
c19d1205
ZW
1729 for (i = cur_reg + 1; i < reg; i++)
1730 {
1731 if (range & (1 << i))
1732 as_tsktsk
1733 (_("Warning: duplicated register (r%d) in register list"),
1734 i);
1735 else
1736 range |= 1 << i;
1737 }
1738 in_range = 0;
1739 }
a737bd4d 1740
c19d1205
ZW
1741 if (range & (1 << reg))
1742 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1743 reg);
1744 else if (reg <= cur_reg)
1745 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1746
c19d1205
ZW
1747 range |= 1 << reg;
1748 cur_reg = reg;
1749 }
1750 while (skip_past_comma (&str) != FAIL
1751 || (in_range = 1, *str++ == '-'));
1752 str--;
a737bd4d 1753
d996d970 1754 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1755 {
dcbf9037 1756 first_error (_("missing `}'"));
c19d1205
ZW
1757 return FAIL;
1758 }
1759 }
1760 else
1761 {
91d6fa6a 1762 expressionS exp;
40a18ebd 1763
91d6fa6a 1764 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1765 return FAIL;
40a18ebd 1766
91d6fa6a 1767 if (exp.X_op == O_constant)
c19d1205 1768 {
91d6fa6a
NC
1769 if (exp.X_add_number
1770 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1771 {
1772 inst.error = _("invalid register mask");
1773 return FAIL;
1774 }
a737bd4d 1775
91d6fa6a 1776 if ((range & exp.X_add_number) != 0)
c19d1205 1777 {
91d6fa6a 1778 int regno = range & exp.X_add_number;
a737bd4d 1779
c19d1205
ZW
1780 regno &= -regno;
1781 regno = (1 << regno) - 1;
1782 as_tsktsk
1783 (_("Warning: duplicated register (r%d) in register list"),
1784 regno);
1785 }
a737bd4d 1786
91d6fa6a 1787 range |= exp.X_add_number;
c19d1205
ZW
1788 }
1789 else
1790 {
1791 if (inst.reloc.type != 0)
1792 {
1793 inst.error = _("expression too complex");
1794 return FAIL;
1795 }
a737bd4d 1796
91d6fa6a 1797 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1798 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1799 inst.reloc.pc_rel = 0;
1800 }
1801 }
a737bd4d 1802
c19d1205
ZW
1803 if (*str == '|' || *str == '+')
1804 {
1805 str++;
1806 another_range = 1;
1807 }
a737bd4d 1808 }
c19d1205 1809 while (another_range);
a737bd4d 1810
c19d1205
ZW
1811 *strp = str;
1812 return range;
a737bd4d
NC
1813}
1814
5287ad62
JB
1815/* Types of registers in a list. */
1816
1817enum reg_list_els
1818{
1819 REGLIST_VFP_S,
1820 REGLIST_VFP_D,
1821 REGLIST_NEON_D
1822};
1823
c19d1205
ZW
1824/* Parse a VFP register list. If the string is invalid return FAIL.
1825 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1826 register. Parses registers of type ETYPE.
1827 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1828 - Q registers can be used to specify pairs of D registers
1829 - { } can be omitted from around a singleton register list
477330fc
RM
1830 FIXME: This is not implemented, as it would require backtracking in
1831 some cases, e.g.:
1832 vtbl.8 d3,d4,d5
1833 This could be done (the meaning isn't really ambiguous), but doesn't
1834 fit in well with the current parsing framework.
dcbf9037
JB
1835 - 32 D registers may be used (also true for VFPv3).
1836 FIXME: Types are ignored in these register lists, which is probably a
1837 bug. */
6057a28f 1838
c19d1205 1839static int
037e8744 1840parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1841{
037e8744 1842 char *str = *ccp;
c19d1205
ZW
1843 int base_reg;
1844 int new_base;
21d799b5 1845 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1846 int max_regs = 0;
c19d1205
ZW
1847 int count = 0;
1848 int warned = 0;
1849 unsigned long mask = 0;
a737bd4d 1850 int i;
6057a28f 1851
477330fc 1852 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1853 {
1854 inst.error = _("expecting {");
1855 return FAIL;
1856 }
6057a28f 1857
5287ad62 1858 switch (etype)
c19d1205 1859 {
5287ad62 1860 case REGLIST_VFP_S:
c19d1205
ZW
1861 regtype = REG_TYPE_VFS;
1862 max_regs = 32;
5287ad62 1863 break;
5f4273c7 1864
5287ad62
JB
1865 case REGLIST_VFP_D:
1866 regtype = REG_TYPE_VFD;
b7fc2769 1867 break;
5f4273c7 1868
b7fc2769
JB
1869 case REGLIST_NEON_D:
1870 regtype = REG_TYPE_NDQ;
1871 break;
1872 }
1873
1874 if (etype != REGLIST_VFP_S)
1875 {
b1cc4aeb
PB
1876 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1877 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1878 {
1879 max_regs = 32;
1880 if (thumb_mode)
1881 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1882 fpu_vfp_ext_d32);
1883 else
1884 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1885 fpu_vfp_ext_d32);
1886 }
5287ad62 1887 else
477330fc 1888 max_regs = 16;
c19d1205 1889 }
6057a28f 1890
c19d1205 1891 base_reg = max_regs;
a737bd4d 1892
c19d1205
ZW
1893 do
1894 {
5287ad62 1895 int setmask = 1, addregs = 1;
dcbf9037 1896
037e8744 1897 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1898
c19d1205 1899 if (new_base == FAIL)
a737bd4d 1900 {
dcbf9037 1901 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1902 return FAIL;
1903 }
5f4273c7 1904
b7fc2769 1905 if (new_base >= max_regs)
477330fc
RM
1906 {
1907 first_error (_("register out of range in list"));
1908 return FAIL;
1909 }
5f4273c7 1910
5287ad62
JB
1911 /* Note: a value of 2 * n is returned for the register Q<n>. */
1912 if (regtype == REG_TYPE_NQ)
477330fc
RM
1913 {
1914 setmask = 3;
1915 addregs = 2;
1916 }
5287ad62 1917
c19d1205
ZW
1918 if (new_base < base_reg)
1919 base_reg = new_base;
a737bd4d 1920
5287ad62 1921 if (mask & (setmask << new_base))
c19d1205 1922 {
dcbf9037 1923 first_error (_("invalid register list"));
c19d1205 1924 return FAIL;
a737bd4d 1925 }
a737bd4d 1926
c19d1205
ZW
1927 if ((mask >> new_base) != 0 && ! warned)
1928 {
1929 as_tsktsk (_("register list not in ascending order"));
1930 warned = 1;
1931 }
0bbf2aa4 1932
5287ad62
JB
1933 mask |= setmask << new_base;
1934 count += addregs;
0bbf2aa4 1935
037e8744 1936 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1937 {
1938 int high_range;
0bbf2aa4 1939
037e8744 1940 str++;
0bbf2aa4 1941
037e8744 1942 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1943 == FAIL)
c19d1205
ZW
1944 {
1945 inst.error = gettext (reg_expected_msgs[regtype]);
1946 return FAIL;
1947 }
0bbf2aa4 1948
477330fc
RM
1949 if (high_range >= max_regs)
1950 {
1951 first_error (_("register out of range in list"));
1952 return FAIL;
1953 }
b7fc2769 1954
477330fc
RM
1955 if (regtype == REG_TYPE_NQ)
1956 high_range = high_range + 1;
5287ad62 1957
c19d1205
ZW
1958 if (high_range <= new_base)
1959 {
1960 inst.error = _("register range not in ascending order");
1961 return FAIL;
1962 }
0bbf2aa4 1963
5287ad62 1964 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1965 {
5287ad62 1966 if (mask & (setmask << new_base))
0bbf2aa4 1967 {
c19d1205
ZW
1968 inst.error = _("invalid register list");
1969 return FAIL;
0bbf2aa4 1970 }
c19d1205 1971
5287ad62
JB
1972 mask |= setmask << new_base;
1973 count += addregs;
0bbf2aa4 1974 }
0bbf2aa4 1975 }
0bbf2aa4 1976 }
037e8744 1977 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1978
037e8744 1979 str++;
0bbf2aa4 1980
c19d1205
ZW
1981 /* Sanity check -- should have raised a parse error above. */
1982 if (count == 0 || count > max_regs)
1983 abort ();
1984
1985 *pbase = base_reg;
1986
1987 /* Final test -- the registers must be consecutive. */
1988 mask >>= base_reg;
1989 for (i = 0; i < count; i++)
1990 {
1991 if ((mask & (1u << i)) == 0)
1992 {
1993 inst.error = _("non-contiguous register range");
1994 return FAIL;
1995 }
1996 }
1997
037e8744
JB
1998 *ccp = str;
1999
c19d1205 2000 return count;
b99bd4ef
NC
2001}
2002
dcbf9037
JB
2003/* True if two alias types are the same. */
2004
c921be7d 2005static bfd_boolean
dcbf9037
JB
2006neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2007{
2008 if (!a && !b)
c921be7d 2009 return TRUE;
5f4273c7 2010
dcbf9037 2011 if (!a || !b)
c921be7d 2012 return FALSE;
dcbf9037
JB
2013
2014 if (a->defined != b->defined)
c921be7d 2015 return FALSE;
5f4273c7 2016
dcbf9037
JB
2017 if ((a->defined & NTA_HASTYPE) != 0
2018 && (a->eltype.type != b->eltype.type
477330fc 2019 || a->eltype.size != b->eltype.size))
c921be7d 2020 return FALSE;
dcbf9037
JB
2021
2022 if ((a->defined & NTA_HASINDEX) != 0
2023 && (a->index != b->index))
c921be7d 2024 return FALSE;
5f4273c7 2025
c921be7d 2026 return TRUE;
dcbf9037
JB
2027}
2028
5287ad62
JB
2029/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2030 The base register is put in *PBASE.
dcbf9037 2031 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
2032 the return value.
2033 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2034 Bits [6:5] encode the list length (minus one).
2035 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2036
5287ad62 2037#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2038#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2039#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2040
2041static int
dcbf9037 2042parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 2043 struct neon_type_el *eltype)
5287ad62
JB
2044{
2045 char *ptr = *str;
2046 int base_reg = -1;
2047 int reg_incr = -1;
2048 int count = 0;
2049 int lane = -1;
2050 int leading_brace = 0;
2051 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
2052 const char *const incr_error = _("register stride must be 1 or 2");
2053 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2054 struct neon_typed_alias firsttype;
f85d59c3
KT
2055 firsttype.defined = 0;
2056 firsttype.eltype.type = NT_invtype;
2057 firsttype.eltype.size = -1;
2058 firsttype.index = -1;
5f4273c7 2059
5287ad62
JB
2060 if (skip_past_char (&ptr, '{') == SUCCESS)
2061 leading_brace = 1;
5f4273c7 2062
5287ad62
JB
2063 do
2064 {
dcbf9037
JB
2065 struct neon_typed_alias atype;
2066 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2067
5287ad62 2068 if (getreg == FAIL)
477330fc
RM
2069 {
2070 first_error (_(reg_expected_msgs[rtype]));
2071 return FAIL;
2072 }
5f4273c7 2073
5287ad62 2074 if (base_reg == -1)
477330fc
RM
2075 {
2076 base_reg = getreg;
2077 if (rtype == REG_TYPE_NQ)
2078 {
2079 reg_incr = 1;
2080 }
2081 firsttype = atype;
2082 }
5287ad62 2083 else if (reg_incr == -1)
477330fc
RM
2084 {
2085 reg_incr = getreg - base_reg;
2086 if (reg_incr < 1 || reg_incr > 2)
2087 {
2088 first_error (_(incr_error));
2089 return FAIL;
2090 }
2091 }
5287ad62 2092 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2093 {
2094 first_error (_(incr_error));
2095 return FAIL;
2096 }
dcbf9037 2097
c921be7d 2098 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2099 {
2100 first_error (_(type_error));
2101 return FAIL;
2102 }
5f4273c7 2103
5287ad62 2104 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2105 modes. */
5287ad62 2106 if (ptr[0] == '-')
477330fc
RM
2107 {
2108 struct neon_typed_alias htype;
2109 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2110 if (lane == -1)
2111 lane = NEON_INTERLEAVE_LANES;
2112 else if (lane != NEON_INTERLEAVE_LANES)
2113 {
2114 first_error (_(type_error));
2115 return FAIL;
2116 }
2117 if (reg_incr == -1)
2118 reg_incr = 1;
2119 else if (reg_incr != 1)
2120 {
2121 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2122 return FAIL;
2123 }
2124 ptr++;
2125 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2126 if (hireg == FAIL)
2127 {
2128 first_error (_(reg_expected_msgs[rtype]));
2129 return FAIL;
2130 }
2131 if (! neon_alias_types_same (&htype, &firsttype))
2132 {
2133 first_error (_(type_error));
2134 return FAIL;
2135 }
2136 count += hireg + dregs - getreg;
2137 continue;
2138 }
5f4273c7 2139
5287ad62
JB
2140 /* If we're using Q registers, we can't use [] or [n] syntax. */
2141 if (rtype == REG_TYPE_NQ)
477330fc
RM
2142 {
2143 count += 2;
2144 continue;
2145 }
5f4273c7 2146
dcbf9037 2147 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2148 {
2149 if (lane == -1)
2150 lane = atype.index;
2151 else if (lane != atype.index)
2152 {
2153 first_error (_(type_error));
2154 return FAIL;
2155 }
2156 }
5287ad62 2157 else if (lane == -1)
477330fc 2158 lane = NEON_INTERLEAVE_LANES;
5287ad62 2159 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2160 {
2161 first_error (_(type_error));
2162 return FAIL;
2163 }
5287ad62
JB
2164 count++;
2165 }
2166 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2167
5287ad62
JB
2168 /* No lane set by [x]. We must be interleaving structures. */
2169 if (lane == -1)
2170 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2171
5287ad62
JB
2172 /* Sanity check. */
2173 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2174 || (count > 1 && reg_incr == -1))
2175 {
dcbf9037 2176 first_error (_("error parsing element/structure list"));
5287ad62
JB
2177 return FAIL;
2178 }
2179
2180 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2181 {
dcbf9037 2182 first_error (_("expected }"));
5287ad62
JB
2183 return FAIL;
2184 }
5f4273c7 2185
5287ad62
JB
2186 if (reg_incr == -1)
2187 reg_incr = 1;
2188
dcbf9037
JB
2189 if (eltype)
2190 *eltype = firsttype.eltype;
2191
5287ad62
JB
2192 *pbase = base_reg;
2193 *str = ptr;
5f4273c7 2194
5287ad62
JB
2195 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2196}
2197
c19d1205
ZW
2198/* Parse an explicit relocation suffix on an expression. This is
2199 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2200 arm_reloc_hsh contains no entries, so this function can only
2201 succeed if there is no () after the word. Returns -1 on error,
2202 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2203
c19d1205
ZW
2204static int
2205parse_reloc (char **str)
b99bd4ef 2206{
c19d1205
ZW
2207 struct reloc_entry *r;
2208 char *p, *q;
b99bd4ef 2209
c19d1205
ZW
2210 if (**str != '(')
2211 return BFD_RELOC_UNUSED;
b99bd4ef 2212
c19d1205
ZW
2213 p = *str + 1;
2214 q = p;
2215
2216 while (*q && *q != ')' && *q != ',')
2217 q++;
2218 if (*q != ')')
2219 return -1;
2220
21d799b5
NC
2221 if ((r = (struct reloc_entry *)
2222 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2223 return -1;
2224
2225 *str = q + 1;
2226 return r->reloc;
b99bd4ef
NC
2227}
2228
c19d1205
ZW
2229/* Directives: register aliases. */
2230
dcbf9037 2231static struct reg_entry *
90ec0d68 2232insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2233{
d3ce72d0 2234 struct reg_entry *new_reg;
c19d1205 2235 const char *name;
b99bd4ef 2236
d3ce72d0 2237 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2238 {
d3ce72d0 2239 if (new_reg->builtin)
c19d1205 2240 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2241
c19d1205
ZW
2242 /* Only warn about a redefinition if it's not defined as the
2243 same register. */
d3ce72d0 2244 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2245 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2246
d929913e 2247 return NULL;
c19d1205 2248 }
b99bd4ef 2249
c19d1205 2250 name = xstrdup (str);
325801bd 2251 new_reg = XNEW (struct reg_entry);
b99bd4ef 2252
d3ce72d0
NC
2253 new_reg->name = name;
2254 new_reg->number = number;
2255 new_reg->type = type;
2256 new_reg->builtin = FALSE;
2257 new_reg->neon = NULL;
b99bd4ef 2258
d3ce72d0 2259 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2260 abort ();
5f4273c7 2261
d3ce72d0 2262 return new_reg;
dcbf9037
JB
2263}
2264
2265static void
2266insert_neon_reg_alias (char *str, int number, int type,
477330fc 2267 struct neon_typed_alias *atype)
dcbf9037
JB
2268{
2269 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2270
dcbf9037
JB
2271 if (!reg)
2272 {
2273 first_error (_("attempt to redefine typed alias"));
2274 return;
2275 }
5f4273c7 2276
dcbf9037
JB
2277 if (atype)
2278 {
325801bd 2279 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2280 *reg->neon = *atype;
2281 }
c19d1205 2282}
b99bd4ef 2283
c19d1205 2284/* Look for the .req directive. This is of the form:
b99bd4ef 2285
c19d1205 2286 new_register_name .req existing_register_name
b99bd4ef 2287
c19d1205 2288 If we find one, or if it looks sufficiently like one that we want to
d929913e 2289 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2290
d929913e 2291static bfd_boolean
c19d1205
ZW
2292create_register_alias (char * newname, char *p)
2293{
2294 struct reg_entry *old;
2295 char *oldname, *nbuf;
2296 size_t nlen;
b99bd4ef 2297
c19d1205
ZW
2298 /* The input scrubber ensures that whitespace after the mnemonic is
2299 collapsed to single spaces. */
2300 oldname = p;
2301 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2302 return FALSE;
b99bd4ef 2303
c19d1205
ZW
2304 oldname += 6;
2305 if (*oldname == '\0')
d929913e 2306 return FALSE;
b99bd4ef 2307
21d799b5 2308 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2309 if (!old)
b99bd4ef 2310 {
c19d1205 2311 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2312 return TRUE;
b99bd4ef
NC
2313 }
2314
c19d1205
ZW
2315 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2316 the desired alias name, and p points to its end. If not, then
2317 the desired alias name is in the global original_case_string. */
2318#ifdef TC_CASE_SENSITIVE
2319 nlen = p - newname;
2320#else
2321 newname = original_case_string;
2322 nlen = strlen (newname);
2323#endif
b99bd4ef 2324
29a2809e 2325 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2326
c19d1205
ZW
2327 /* Create aliases under the new name as stated; an all-lowercase
2328 version of the new name; and an all-uppercase version of the new
2329 name. */
d929913e
NC
2330 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2331 {
2332 for (p = nbuf; *p; p++)
2333 *p = TOUPPER (*p);
c19d1205 2334
d929913e
NC
2335 if (strncmp (nbuf, newname, nlen))
2336 {
2337 /* If this attempt to create an additional alias fails, do not bother
2338 trying to create the all-lower case alias. We will fail and issue
2339 a second, duplicate error message. This situation arises when the
2340 programmer does something like:
2341 foo .req r0
2342 Foo .req r1
2343 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2344 the artificial FOO alias because it has already been created by the
d929913e
NC
2345 first .req. */
2346 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2347 {
2348 free (nbuf);
2349 return TRUE;
2350 }
d929913e 2351 }
c19d1205 2352
d929913e
NC
2353 for (p = nbuf; *p; p++)
2354 *p = TOLOWER (*p);
c19d1205 2355
d929913e
NC
2356 if (strncmp (nbuf, newname, nlen))
2357 insert_reg_alias (nbuf, old->number, old->type);
2358 }
c19d1205 2359
e1fa0163 2360 free (nbuf);
d929913e 2361 return TRUE;
b99bd4ef
NC
2362}
2363
dcbf9037
JB
2364/* Create a Neon typed/indexed register alias using directives, e.g.:
2365 X .dn d5.s32[1]
2366 Y .qn 6.s16
2367 Z .dn d7
2368 T .dn Z[0]
2369 These typed registers can be used instead of the types specified after the
2370 Neon mnemonic, so long as all operands given have types. Types can also be
2371 specified directly, e.g.:
5f4273c7 2372 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2373
c921be7d 2374static bfd_boolean
dcbf9037
JB
2375create_neon_reg_alias (char *newname, char *p)
2376{
2377 enum arm_reg_type basetype;
2378 struct reg_entry *basereg;
2379 struct reg_entry mybasereg;
2380 struct neon_type ntype;
2381 struct neon_typed_alias typeinfo;
12d6b0b7 2382 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2383 int namelen;
5f4273c7 2384
dcbf9037
JB
2385 typeinfo.defined = 0;
2386 typeinfo.eltype.type = NT_invtype;
2387 typeinfo.eltype.size = -1;
2388 typeinfo.index = -1;
5f4273c7 2389
dcbf9037 2390 nameend = p;
5f4273c7 2391
dcbf9037
JB
2392 if (strncmp (p, " .dn ", 5) == 0)
2393 basetype = REG_TYPE_VFD;
2394 else if (strncmp (p, " .qn ", 5) == 0)
2395 basetype = REG_TYPE_NQ;
2396 else
c921be7d 2397 return FALSE;
5f4273c7 2398
dcbf9037 2399 p += 5;
5f4273c7 2400
dcbf9037 2401 if (*p == '\0')
c921be7d 2402 return FALSE;
5f4273c7 2403
dcbf9037
JB
2404 basereg = arm_reg_parse_multi (&p);
2405
2406 if (basereg && basereg->type != basetype)
2407 {
2408 as_bad (_("bad type for register"));
c921be7d 2409 return FALSE;
dcbf9037
JB
2410 }
2411
2412 if (basereg == NULL)
2413 {
2414 expressionS exp;
2415 /* Try parsing as an integer. */
2416 my_get_expression (&exp, &p, GE_NO_PREFIX);
2417 if (exp.X_op != O_constant)
477330fc
RM
2418 {
2419 as_bad (_("expression must be constant"));
2420 return FALSE;
2421 }
dcbf9037
JB
2422 basereg = &mybasereg;
2423 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2424 : exp.X_add_number;
dcbf9037
JB
2425 basereg->neon = 0;
2426 }
2427
2428 if (basereg->neon)
2429 typeinfo = *basereg->neon;
2430
2431 if (parse_neon_type (&ntype, &p) == SUCCESS)
2432 {
2433 /* We got a type. */
2434 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2435 {
2436 as_bad (_("can't redefine the type of a register alias"));
2437 return FALSE;
2438 }
5f4273c7 2439
dcbf9037
JB
2440 typeinfo.defined |= NTA_HASTYPE;
2441 if (ntype.elems != 1)
477330fc
RM
2442 {
2443 as_bad (_("you must specify a single type only"));
2444 return FALSE;
2445 }
dcbf9037
JB
2446 typeinfo.eltype = ntype.el[0];
2447 }
5f4273c7 2448
dcbf9037
JB
2449 if (skip_past_char (&p, '[') == SUCCESS)
2450 {
2451 expressionS exp;
2452 /* We got a scalar index. */
5f4273c7 2453
dcbf9037 2454 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2455 {
2456 as_bad (_("can't redefine the index of a scalar alias"));
2457 return FALSE;
2458 }
5f4273c7 2459
dcbf9037 2460 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2461
dcbf9037 2462 if (exp.X_op != O_constant)
477330fc
RM
2463 {
2464 as_bad (_("scalar index must be constant"));
2465 return FALSE;
2466 }
5f4273c7 2467
dcbf9037
JB
2468 typeinfo.defined |= NTA_HASINDEX;
2469 typeinfo.index = exp.X_add_number;
5f4273c7 2470
dcbf9037 2471 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2472 {
2473 as_bad (_("expecting ]"));
2474 return FALSE;
2475 }
dcbf9037
JB
2476 }
2477
15735687
NS
2478 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2479 the desired alias name, and p points to its end. If not, then
2480 the desired alias name is in the global original_case_string. */
2481#ifdef TC_CASE_SENSITIVE
dcbf9037 2482 namelen = nameend - newname;
15735687
NS
2483#else
2484 newname = original_case_string;
2485 namelen = strlen (newname);
2486#endif
2487
29a2809e 2488 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2489
dcbf9037 2490 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2491 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2492
dcbf9037
JB
2493 /* Insert name in all uppercase. */
2494 for (p = namebuf; *p; p++)
2495 *p = TOUPPER (*p);
5f4273c7 2496
dcbf9037
JB
2497 if (strncmp (namebuf, newname, namelen))
2498 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2499 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2500
dcbf9037
JB
2501 /* Insert name in all lowercase. */
2502 for (p = namebuf; *p; p++)
2503 *p = TOLOWER (*p);
5f4273c7 2504
dcbf9037
JB
2505 if (strncmp (namebuf, newname, namelen))
2506 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2507 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2508
e1fa0163 2509 free (namebuf);
c921be7d 2510 return TRUE;
dcbf9037
JB
2511}
2512
c19d1205
ZW
2513/* Should never be called, as .req goes between the alias and the
2514 register name, not at the beginning of the line. */
c921be7d 2515
b99bd4ef 2516static void
c19d1205 2517s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2518{
c19d1205
ZW
2519 as_bad (_("invalid syntax for .req directive"));
2520}
b99bd4ef 2521
dcbf9037
JB
2522static void
2523s_dn (int a ATTRIBUTE_UNUSED)
2524{
2525 as_bad (_("invalid syntax for .dn directive"));
2526}
2527
2528static void
2529s_qn (int a ATTRIBUTE_UNUSED)
2530{
2531 as_bad (_("invalid syntax for .qn directive"));
2532}
2533
c19d1205
ZW
2534/* The .unreq directive deletes an alias which was previously defined
2535 by .req. For example:
b99bd4ef 2536
c19d1205
ZW
2537 my_alias .req r11
2538 .unreq my_alias */
b99bd4ef
NC
2539
2540static void
c19d1205 2541s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2542{
c19d1205
ZW
2543 char * name;
2544 char saved_char;
b99bd4ef 2545
c19d1205
ZW
2546 name = input_line_pointer;
2547
2548 while (*input_line_pointer != 0
2549 && *input_line_pointer != ' '
2550 && *input_line_pointer != '\n')
2551 ++input_line_pointer;
2552
2553 saved_char = *input_line_pointer;
2554 *input_line_pointer = 0;
2555
2556 if (!*name)
2557 as_bad (_("invalid syntax for .unreq directive"));
2558 else
2559 {
21d799b5 2560 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2561 name);
c19d1205
ZW
2562
2563 if (!reg)
2564 as_bad (_("unknown register alias '%s'"), name);
2565 else if (reg->builtin)
a1727c1a 2566 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2567 name);
2568 else
2569 {
d929913e
NC
2570 char * p;
2571 char * nbuf;
2572
db0bc284 2573 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2574 free ((char *) reg->name);
477330fc
RM
2575 if (reg->neon)
2576 free (reg->neon);
c19d1205 2577 free (reg);
d929913e
NC
2578
2579 /* Also locate the all upper case and all lower case versions.
2580 Do not complain if we cannot find one or the other as it
2581 was probably deleted above. */
5f4273c7 2582
d929913e
NC
2583 nbuf = strdup (name);
2584 for (p = nbuf; *p; p++)
2585 *p = TOUPPER (*p);
21d799b5 2586 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2587 if (reg)
2588 {
db0bc284 2589 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2590 free ((char *) reg->name);
2591 if (reg->neon)
2592 free (reg->neon);
2593 free (reg);
2594 }
2595
2596 for (p = nbuf; *p; p++)
2597 *p = TOLOWER (*p);
21d799b5 2598 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2599 if (reg)
2600 {
db0bc284 2601 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2602 free ((char *) reg->name);
2603 if (reg->neon)
2604 free (reg->neon);
2605 free (reg);
2606 }
2607
2608 free (nbuf);
c19d1205
ZW
2609 }
2610 }
b99bd4ef 2611
c19d1205 2612 *input_line_pointer = saved_char;
b99bd4ef
NC
2613 demand_empty_rest_of_line ();
2614}
2615
c19d1205
ZW
2616/* Directives: Instruction set selection. */
2617
2618#ifdef OBJ_ELF
2619/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2620 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2621 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2622 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2623
cd000bff
DJ
2624/* Create a new mapping symbol for the transition to STATE. */
2625
2626static void
2627make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2628{
a737bd4d 2629 symbolS * symbolP;
c19d1205
ZW
2630 const char * symname;
2631 int type;
b99bd4ef 2632
c19d1205 2633 switch (state)
b99bd4ef 2634 {
c19d1205
ZW
2635 case MAP_DATA:
2636 symname = "$d";
2637 type = BSF_NO_FLAGS;
2638 break;
2639 case MAP_ARM:
2640 symname = "$a";
2641 type = BSF_NO_FLAGS;
2642 break;
2643 case MAP_THUMB:
2644 symname = "$t";
2645 type = BSF_NO_FLAGS;
2646 break;
c19d1205
ZW
2647 default:
2648 abort ();
2649 }
2650
cd000bff 2651 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2652 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2653
2654 switch (state)
2655 {
2656 case MAP_ARM:
2657 THUMB_SET_FUNC (symbolP, 0);
2658 ARM_SET_THUMB (symbolP, 0);
2659 ARM_SET_INTERWORK (symbolP, support_interwork);
2660 break;
2661
2662 case MAP_THUMB:
2663 THUMB_SET_FUNC (symbolP, 1);
2664 ARM_SET_THUMB (symbolP, 1);
2665 ARM_SET_INTERWORK (symbolP, support_interwork);
2666 break;
2667
2668 case MAP_DATA:
2669 default:
cd000bff
DJ
2670 break;
2671 }
2672
2673 /* Save the mapping symbols for future reference. Also check that
2674 we do not place two mapping symbols at the same offset within a
2675 frag. We'll handle overlap between frags in
2de7820f
JZ
2676 check_mapping_symbols.
2677
2678 If .fill or other data filling directive generates zero sized data,
2679 the mapping symbol for the following code will have the same value
2680 as the one generated for the data filling directive. In this case,
2681 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2682 if (value == 0)
2683 {
2de7820f
JZ
2684 if (frag->tc_frag_data.first_map != NULL)
2685 {
2686 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2687 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2688 }
cd000bff
DJ
2689 frag->tc_frag_data.first_map = symbolP;
2690 }
2691 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2692 {
2693 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2694 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2695 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2696 }
cd000bff
DJ
2697 frag->tc_frag_data.last_map = symbolP;
2698}
2699
2700/* We must sometimes convert a region marked as code to data during
2701 code alignment, if an odd number of bytes have to be padded. The
2702 code mapping symbol is pushed to an aligned address. */
2703
2704static void
2705insert_data_mapping_symbol (enum mstate state,
2706 valueT value, fragS *frag, offsetT bytes)
2707{
2708 /* If there was already a mapping symbol, remove it. */
2709 if (frag->tc_frag_data.last_map != NULL
2710 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2711 {
2712 symbolS *symp = frag->tc_frag_data.last_map;
2713
2714 if (value == 0)
2715 {
2716 know (frag->tc_frag_data.first_map == symp);
2717 frag->tc_frag_data.first_map = NULL;
2718 }
2719 frag->tc_frag_data.last_map = NULL;
2720 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2721 }
cd000bff
DJ
2722
2723 make_mapping_symbol (MAP_DATA, value, frag);
2724 make_mapping_symbol (state, value + bytes, frag);
2725}
2726
2727static void mapping_state_2 (enum mstate state, int max_chars);
2728
2729/* Set the mapping state to STATE. Only call this when about to
2730 emit some STATE bytes to the file. */
2731
4e9aaefb 2732#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2733void
2734mapping_state (enum mstate state)
2735{
940b5ce0
DJ
2736 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2737
cd000bff
DJ
2738 if (mapstate == state)
2739 /* The mapping symbol has already been emitted.
2740 There is nothing else to do. */
2741 return;
49c62a33
NC
2742
2743 if (state == MAP_ARM || state == MAP_THUMB)
2744 /* PR gas/12931
2745 All ARM instructions require 4-byte alignment.
2746 (Almost) all Thumb instructions require 2-byte alignment.
2747
2748 When emitting instructions into any section, mark the section
2749 appropriately.
2750
2751 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2752 but themselves require 2-byte alignment; this applies to some
33eaf5de 2753 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
2754 literal pool generation or an explicit .align >=2, both of
2755 which will cause the section to me marked with sufficient
2756 alignment. Thus, we don't handle those cases here. */
2757 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2758
2759 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2760 /* This case will be evaluated later. */
cd000bff 2761 return;
cd000bff
DJ
2762
2763 mapping_state_2 (state, 0);
cd000bff
DJ
2764}
2765
2766/* Same as mapping_state, but MAX_CHARS bytes have already been
2767 allocated. Put the mapping symbol that far back. */
2768
2769static void
2770mapping_state_2 (enum mstate state, int max_chars)
2771{
940b5ce0
DJ
2772 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2773
2774 if (!SEG_NORMAL (now_seg))
2775 return;
2776
cd000bff
DJ
2777 if (mapstate == state)
2778 /* The mapping symbol has already been emitted.
2779 There is nothing else to do. */
2780 return;
2781
4e9aaefb
SA
2782 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2783 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2784 {
2785 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2786 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2787
2788 if (add_symbol)
2789 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2790 }
2791
cd000bff
DJ
2792 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2793 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2794}
4e9aaefb 2795#undef TRANSITION
c19d1205 2796#else
d3106081
NS
2797#define mapping_state(x) ((void)0)
2798#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2799#endif
2800
2801/* Find the real, Thumb encoded start of a Thumb function. */
2802
4343666d 2803#ifdef OBJ_COFF
c19d1205
ZW
2804static symbolS *
2805find_real_start (symbolS * symbolP)
2806{
2807 char * real_start;
2808 const char * name = S_GET_NAME (symbolP);
2809 symbolS * new_target;
2810
2811 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2812#define STUB_NAME ".real_start_of"
2813
2814 if (name == NULL)
2815 abort ();
2816
37f6032b
ZW
2817 /* The compiler may generate BL instructions to local labels because
2818 it needs to perform a branch to a far away location. These labels
2819 do not have a corresponding ".real_start_of" label. We check
2820 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2821 the ".real_start_of" convention for nonlocal branches. */
2822 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2823 return symbolP;
2824
e1fa0163 2825 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2826 new_target = symbol_find (real_start);
e1fa0163 2827 free (real_start);
c19d1205
ZW
2828
2829 if (new_target == NULL)
2830 {
bd3ba5d1 2831 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2832 new_target = symbolP;
2833 }
2834
c19d1205
ZW
2835 return new_target;
2836}
4343666d 2837#endif
c19d1205
ZW
2838
2839static void
2840opcode_select (int width)
2841{
2842 switch (width)
2843 {
2844 case 16:
2845 if (! thumb_mode)
2846 {
e74cfd16 2847 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2848 as_bad (_("selected processor does not support THUMB opcodes"));
2849
2850 thumb_mode = 1;
2851 /* No need to force the alignment, since we will have been
2852 coming from ARM mode, which is word-aligned. */
2853 record_alignment (now_seg, 1);
2854 }
c19d1205
ZW
2855 break;
2856
2857 case 32:
2858 if (thumb_mode)
2859 {
e74cfd16 2860 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2861 as_bad (_("selected processor does not support ARM opcodes"));
2862
2863 thumb_mode = 0;
2864
2865 if (!need_pass_2)
2866 frag_align (2, 0, 0);
2867
2868 record_alignment (now_seg, 1);
2869 }
c19d1205
ZW
2870 break;
2871
2872 default:
2873 as_bad (_("invalid instruction size selected (%d)"), width);
2874 }
2875}
2876
2877static void
2878s_arm (int ignore ATTRIBUTE_UNUSED)
2879{
2880 opcode_select (32);
2881 demand_empty_rest_of_line ();
2882}
2883
2884static void
2885s_thumb (int ignore ATTRIBUTE_UNUSED)
2886{
2887 opcode_select (16);
2888 demand_empty_rest_of_line ();
2889}
2890
2891static void
2892s_code (int unused ATTRIBUTE_UNUSED)
2893{
2894 int temp;
2895
2896 temp = get_absolute_expression ();
2897 switch (temp)
2898 {
2899 case 16:
2900 case 32:
2901 opcode_select (temp);
2902 break;
2903
2904 default:
2905 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2906 }
2907}
2908
2909static void
2910s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2911{
2912 /* If we are not already in thumb mode go into it, EVEN if
2913 the target processor does not support thumb instructions.
2914 This is used by gcc/config/arm/lib1funcs.asm for example
2915 to compile interworking support functions even if the
2916 target processor should not support interworking. */
2917 if (! thumb_mode)
2918 {
2919 thumb_mode = 2;
2920 record_alignment (now_seg, 1);
2921 }
2922
2923 demand_empty_rest_of_line ();
2924}
2925
2926static void
2927s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2928{
2929 s_thumb (0);
2930
2931 /* The following label is the name/address of the start of a Thumb function.
2932 We need to know this for the interworking support. */
2933 label_is_thumb_function_name = TRUE;
2934}
2935
2936/* Perform a .set directive, but also mark the alias as
2937 being a thumb function. */
2938
2939static void
2940s_thumb_set (int equiv)
2941{
2942 /* XXX the following is a duplicate of the code for s_set() in read.c
2943 We cannot just call that code as we need to get at the symbol that
2944 is created. */
2945 char * name;
2946 char delim;
2947 char * end_name;
2948 symbolS * symbolP;
2949
2950 /* Especial apologies for the random logic:
2951 This just grew, and could be parsed much more simply!
2952 Dean - in haste. */
d02603dc 2953 delim = get_symbol_name (& name);
c19d1205 2954 end_name = input_line_pointer;
d02603dc 2955 (void) restore_line_pointer (delim);
c19d1205
ZW
2956
2957 if (*input_line_pointer != ',')
2958 {
2959 *end_name = 0;
2960 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2961 *end_name = delim;
2962 ignore_rest_of_line ();
2963 return;
2964 }
2965
2966 input_line_pointer++;
2967 *end_name = 0;
2968
2969 if (name[0] == '.' && name[1] == '\0')
2970 {
2971 /* XXX - this should not happen to .thumb_set. */
2972 abort ();
2973 }
2974
2975 if ((symbolP = symbol_find (name)) == NULL
2976 && (symbolP = md_undefined_symbol (name)) == NULL)
2977 {
2978#ifndef NO_LISTING
2979 /* When doing symbol listings, play games with dummy fragments living
2980 outside the normal fragment chain to record the file and line info
c19d1205 2981 for this symbol. */
b99bd4ef
NC
2982 if (listing & LISTING_SYMBOLS)
2983 {
2984 extern struct list_info_struct * listing_tail;
21d799b5 2985 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2986
2987 memset (dummy_frag, 0, sizeof (fragS));
2988 dummy_frag->fr_type = rs_fill;
2989 dummy_frag->line = listing_tail;
2990 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2991 dummy_frag->fr_symbol = symbolP;
2992 }
2993 else
2994#endif
2995 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2996
2997#ifdef OBJ_COFF
2998 /* "set" symbols are local unless otherwise specified. */
2999 SF_SET_LOCAL (symbolP);
3000#endif /* OBJ_COFF */
3001 } /* Make a new symbol. */
3002
3003 symbol_table_insert (symbolP);
3004
3005 * end_name = delim;
3006
3007 if (equiv
3008 && S_IS_DEFINED (symbolP)
3009 && S_GET_SEGMENT (symbolP) != reg_section)
3010 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3011
3012 pseudo_set (symbolP);
3013
3014 demand_empty_rest_of_line ();
3015
c19d1205 3016 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
3017
3018 THUMB_SET_FUNC (symbolP, 1);
3019 ARM_SET_THUMB (symbolP, 1);
3020#if defined OBJ_ELF || defined OBJ_COFF
3021 ARM_SET_INTERWORK (symbolP, support_interwork);
3022#endif
3023}
3024
c19d1205 3025/* Directives: Mode selection. */
b99bd4ef 3026
c19d1205
ZW
3027/* .syntax [unified|divided] - choose the new unified syntax
3028 (same for Arm and Thumb encoding, modulo slight differences in what
3029 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 3030static void
c19d1205 3031s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 3032{
c19d1205
ZW
3033 char *name, delim;
3034
d02603dc 3035 delim = get_symbol_name (& name);
c19d1205
ZW
3036
3037 if (!strcasecmp (name, "unified"))
3038 unified_syntax = TRUE;
3039 else if (!strcasecmp (name, "divided"))
3040 unified_syntax = FALSE;
3041 else
3042 {
3043 as_bad (_("unrecognized syntax mode \"%s\""), name);
3044 return;
3045 }
d02603dc 3046 (void) restore_line_pointer (delim);
b99bd4ef
NC
3047 demand_empty_rest_of_line ();
3048}
3049
c19d1205
ZW
3050/* Directives: sectioning and alignment. */
3051
c19d1205
ZW
3052static void
3053s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3054{
c19d1205
ZW
3055 /* We don't support putting frags in the BSS segment, we fake it by
3056 marking in_bss, then looking at s_skip for clues. */
3057 subseg_set (bss_section, 0);
3058 demand_empty_rest_of_line ();
cd000bff
DJ
3059
3060#ifdef md_elf_section_change_hook
3061 md_elf_section_change_hook ();
3062#endif
c19d1205 3063}
b99bd4ef 3064
c19d1205
ZW
3065static void
3066s_even (int ignore ATTRIBUTE_UNUSED)
3067{
3068 /* Never make frag if expect extra pass. */
3069 if (!need_pass_2)
3070 frag_align (1, 0, 0);
b99bd4ef 3071
c19d1205 3072 record_alignment (now_seg, 1);
b99bd4ef 3073
c19d1205 3074 demand_empty_rest_of_line ();
b99bd4ef
NC
3075}
3076
2e6976a8
DG
3077/* Directives: CodeComposer Studio. */
3078
3079/* .ref (for CodeComposer Studio syntax only). */
3080static void
3081s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3082{
3083 if (codecomposer_syntax)
3084 ignore_rest_of_line ();
3085 else
3086 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3087}
3088
3089/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3090 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3091static void
3092asmfunc_debug (const char * name)
3093{
3094 static const char * last_name = NULL;
3095
3096 if (name != NULL)
3097 {
3098 gas_assert (last_name == NULL);
3099 last_name = name;
3100
3101 if (debug_type == DEBUG_STABS)
3102 stabs_generate_asm_func (name, name);
3103 }
3104 else
3105 {
3106 gas_assert (last_name != NULL);
3107
3108 if (debug_type == DEBUG_STABS)
3109 stabs_generate_asm_endfunc (last_name, last_name);
3110
3111 last_name = NULL;
3112 }
3113}
3114
3115static void
3116s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3117{
3118 if (codecomposer_syntax)
3119 {
3120 switch (asmfunc_state)
3121 {
3122 case OUTSIDE_ASMFUNC:
3123 asmfunc_state = WAITING_ASMFUNC_NAME;
3124 break;
3125
3126 case WAITING_ASMFUNC_NAME:
3127 as_bad (_(".asmfunc repeated."));
3128 break;
3129
3130 case WAITING_ENDASMFUNC:
3131 as_bad (_(".asmfunc without function."));
3132 break;
3133 }
3134 demand_empty_rest_of_line ();
3135 }
3136 else
3137 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3138}
3139
3140static void
3141s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3142{
3143 if (codecomposer_syntax)
3144 {
3145 switch (asmfunc_state)
3146 {
3147 case OUTSIDE_ASMFUNC:
3148 as_bad (_(".endasmfunc without a .asmfunc."));
3149 break;
3150
3151 case WAITING_ASMFUNC_NAME:
3152 as_bad (_(".endasmfunc without function."));
3153 break;
3154
3155 case WAITING_ENDASMFUNC:
3156 asmfunc_state = OUTSIDE_ASMFUNC;
3157 asmfunc_debug (NULL);
3158 break;
3159 }
3160 demand_empty_rest_of_line ();
3161 }
3162 else
3163 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3164}
3165
3166static void
3167s_ccs_def (int name)
3168{
3169 if (codecomposer_syntax)
3170 s_globl (name);
3171 else
3172 as_bad (_(".def pseudo-op only available with -mccs flag."));
3173}
3174
c19d1205 3175/* Directives: Literal pools. */
a737bd4d 3176
c19d1205
ZW
3177static literal_pool *
3178find_literal_pool (void)
a737bd4d 3179{
c19d1205 3180 literal_pool * pool;
a737bd4d 3181
c19d1205 3182 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3183 {
c19d1205
ZW
3184 if (pool->section == now_seg
3185 && pool->sub_section == now_subseg)
3186 break;
a737bd4d
NC
3187 }
3188
c19d1205 3189 return pool;
a737bd4d
NC
3190}
3191
c19d1205
ZW
3192static literal_pool *
3193find_or_make_literal_pool (void)
a737bd4d 3194{
c19d1205
ZW
3195 /* Next literal pool ID number. */
3196 static unsigned int latest_pool_num = 1;
3197 literal_pool * pool;
a737bd4d 3198
c19d1205 3199 pool = find_literal_pool ();
a737bd4d 3200
c19d1205 3201 if (pool == NULL)
a737bd4d 3202 {
c19d1205 3203 /* Create a new pool. */
325801bd 3204 pool = XNEW (literal_pool);
c19d1205
ZW
3205 if (! pool)
3206 return NULL;
a737bd4d 3207
c19d1205
ZW
3208 pool->next_free_entry = 0;
3209 pool->section = now_seg;
3210 pool->sub_section = now_subseg;
3211 pool->next = list_of_pools;
3212 pool->symbol = NULL;
8335d6aa 3213 pool->alignment = 2;
c19d1205
ZW
3214
3215 /* Add it to the list. */
3216 list_of_pools = pool;
a737bd4d 3217 }
a737bd4d 3218
c19d1205
ZW
3219 /* New pools, and emptied pools, will have a NULL symbol. */
3220 if (pool->symbol == NULL)
a737bd4d 3221 {
c19d1205
ZW
3222 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3223 (valueT) 0, &zero_address_frag);
3224 pool->id = latest_pool_num ++;
a737bd4d
NC
3225 }
3226
c19d1205
ZW
3227 /* Done. */
3228 return pool;
a737bd4d
NC
3229}
3230
c19d1205 3231/* Add the literal in the global 'inst'
5f4273c7 3232 structure to the relevant literal pool. */
b99bd4ef
NC
3233
3234static int
8335d6aa 3235add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3236{
8335d6aa
JW
3237#define PADDING_SLOT 0x1
3238#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3239 literal_pool * pool;
8335d6aa
JW
3240 unsigned int entry, pool_size = 0;
3241 bfd_boolean padding_slot_p = FALSE;
e56c722b 3242 unsigned imm1 = 0;
8335d6aa
JW
3243 unsigned imm2 = 0;
3244
3245 if (nbytes == 8)
3246 {
3247 imm1 = inst.operands[1].imm;
3248 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3249 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3250 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3251 if (target_big_endian)
3252 {
3253 imm1 = imm2;
3254 imm2 = inst.operands[1].imm;
3255 }
3256 }
b99bd4ef 3257
c19d1205
ZW
3258 pool = find_or_make_literal_pool ();
3259
3260 /* Check if this literal value is already in the pool. */
3261 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3262 {
8335d6aa
JW
3263 if (nbytes == 4)
3264 {
3265 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3266 && (inst.reloc.exp.X_op == O_constant)
3267 && (pool->literals[entry].X_add_number
3268 == inst.reloc.exp.X_add_number)
3269 && (pool->literals[entry].X_md == nbytes)
3270 && (pool->literals[entry].X_unsigned
3271 == inst.reloc.exp.X_unsigned))
3272 break;
3273
3274 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3275 && (inst.reloc.exp.X_op == O_symbol)
3276 && (pool->literals[entry].X_add_number
3277 == inst.reloc.exp.X_add_number)
3278 && (pool->literals[entry].X_add_symbol
3279 == inst.reloc.exp.X_add_symbol)
3280 && (pool->literals[entry].X_op_symbol
3281 == inst.reloc.exp.X_op_symbol)
3282 && (pool->literals[entry].X_md == nbytes))
3283 break;
3284 }
3285 else if ((nbytes == 8)
3286 && !(pool_size & 0x7)
3287 && ((entry + 1) != pool->next_free_entry)
3288 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3289 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3290 && (pool->literals[entry].X_unsigned
3291 == inst.reloc.exp.X_unsigned)
3292 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3293 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3294 && (pool->literals[entry + 1].X_unsigned
3295 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3296 break;
3297
8335d6aa
JW
3298 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3299 if (padding_slot_p && (nbytes == 4))
c19d1205 3300 break;
8335d6aa
JW
3301
3302 pool_size += 4;
b99bd4ef
NC
3303 }
3304
c19d1205
ZW
3305 /* Do we need to create a new entry? */
3306 if (entry == pool->next_free_entry)
3307 {
3308 if (entry >= MAX_LITERAL_POOL_SIZE)
3309 {
3310 inst.error = _("literal pool overflow");
3311 return FAIL;
3312 }
3313
8335d6aa
JW
3314 if (nbytes == 8)
3315 {
3316 /* For 8-byte entries, we align to an 8-byte boundary,
3317 and split it into two 4-byte entries, because on 32-bit
3318 host, 8-byte constants are treated as big num, thus
3319 saved in "generic_bignum" which will be overwritten
3320 by later assignments.
3321
3322 We also need to make sure there is enough space for
3323 the split.
3324
3325 We also check to make sure the literal operand is a
3326 constant number. */
19f2f6a9
JW
3327 if (!(inst.reloc.exp.X_op == O_constant
3328 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3329 {
3330 inst.error = _("invalid type for literal pool");
3331 return FAIL;
3332 }
3333 else if (pool_size & 0x7)
3334 {
3335 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3336 {
3337 inst.error = _("literal pool overflow");
3338 return FAIL;
3339 }
3340
3341 pool->literals[entry] = inst.reloc.exp;
a6684f0d 3342 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3343 pool->literals[entry].X_add_number = 0;
3344 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3345 pool->next_free_entry += 1;
3346 pool_size += 4;
3347 }
3348 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3349 {
3350 inst.error = _("literal pool overflow");
3351 return FAIL;
3352 }
3353
3354 pool->literals[entry] = inst.reloc.exp;
3355 pool->literals[entry].X_op = O_constant;
3356 pool->literals[entry].X_add_number = imm1;
3357 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3358 pool->literals[entry++].X_md = 4;
3359 pool->literals[entry] = inst.reloc.exp;
3360 pool->literals[entry].X_op = O_constant;
3361 pool->literals[entry].X_add_number = imm2;
3362 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3363 pool->literals[entry].X_md = 4;
3364 pool->alignment = 3;
3365 pool->next_free_entry += 1;
3366 }
3367 else
3368 {
3369 pool->literals[entry] = inst.reloc.exp;
3370 pool->literals[entry].X_md = 4;
3371 }
3372
a8040cf2
NC
3373#ifdef OBJ_ELF
3374 /* PR ld/12974: Record the location of the first source line to reference
3375 this entry in the literal pool. If it turns out during linking that the
3376 symbol does not exist we will be able to give an accurate line number for
3377 the (first use of the) missing reference. */
3378 if (debug_type == DEBUG_DWARF2)
3379 dwarf2_where (pool->locs + entry);
3380#endif
c19d1205
ZW
3381 pool->next_free_entry += 1;
3382 }
8335d6aa
JW
3383 else if (padding_slot_p)
3384 {
3385 pool->literals[entry] = inst.reloc.exp;
3386 pool->literals[entry].X_md = nbytes;
3387 }
b99bd4ef 3388
c19d1205 3389 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3390 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3391 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3392
c19d1205 3393 return SUCCESS;
b99bd4ef
NC
3394}
3395
2e6976a8 3396bfd_boolean
2e57ce7b 3397tc_start_label_without_colon (void)
2e6976a8
DG
3398{
3399 bfd_boolean ret = TRUE;
3400
3401 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3402 {
2e57ce7b 3403 const char *label = input_line_pointer;
2e6976a8
DG
3404
3405 while (!is_end_of_line[(int) label[-1]])
3406 --label;
3407
3408 if (*label == '.')
3409 {
3410 as_bad (_("Invalid label '%s'"), label);
3411 ret = FALSE;
3412 }
3413
3414 asmfunc_debug (label);
3415
3416 asmfunc_state = WAITING_ENDASMFUNC;
3417 }
3418
3419 return ret;
3420}
3421
c19d1205 3422/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3423 a later date assign it a value. That's what these functions do. */
e16bb312 3424
c19d1205
ZW
3425static void
3426symbol_locate (symbolS * symbolP,
3427 const char * name, /* It is copied, the caller can modify. */
3428 segT segment, /* Segment identifier (SEG_<something>). */
3429 valueT valu, /* Symbol value. */
3430 fragS * frag) /* Associated fragment. */
3431{
e57e6ddc 3432 size_t name_length;
c19d1205 3433 char * preserved_copy_of_name;
e16bb312 3434
c19d1205
ZW
3435 name_length = strlen (name) + 1; /* +1 for \0. */
3436 obstack_grow (&notes, name, name_length);
21d799b5 3437 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3438
c19d1205
ZW
3439#ifdef tc_canonicalize_symbol_name
3440 preserved_copy_of_name =
3441 tc_canonicalize_symbol_name (preserved_copy_of_name);
3442#endif
b99bd4ef 3443
c19d1205 3444 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3445
c19d1205
ZW
3446 S_SET_SEGMENT (symbolP, segment);
3447 S_SET_VALUE (symbolP, valu);
3448 symbol_clear_list_pointers (symbolP);
b99bd4ef 3449
c19d1205 3450 symbol_set_frag (symbolP, frag);
b99bd4ef 3451
c19d1205
ZW
3452 /* Link to end of symbol chain. */
3453 {
3454 extern int symbol_table_frozen;
b99bd4ef 3455
c19d1205
ZW
3456 if (symbol_table_frozen)
3457 abort ();
3458 }
b99bd4ef 3459
c19d1205 3460 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3461
c19d1205 3462 obj_symbol_new_hook (symbolP);
b99bd4ef 3463
c19d1205
ZW
3464#ifdef tc_symbol_new_hook
3465 tc_symbol_new_hook (symbolP);
3466#endif
3467
3468#ifdef DEBUG_SYMS
3469 verify_symbol_chain (symbol_rootP, symbol_lastP);
3470#endif /* DEBUG_SYMS */
b99bd4ef
NC
3471}
3472
c19d1205
ZW
3473static void
3474s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3475{
c19d1205
ZW
3476 unsigned int entry;
3477 literal_pool * pool;
3478 char sym_name[20];
b99bd4ef 3479
c19d1205
ZW
3480 pool = find_literal_pool ();
3481 if (pool == NULL
3482 || pool->symbol == NULL
3483 || pool->next_free_entry == 0)
3484 return;
b99bd4ef 3485
c19d1205
ZW
3486 /* Align pool as you have word accesses.
3487 Only make a frag if we have to. */
3488 if (!need_pass_2)
8335d6aa 3489 frag_align (pool->alignment, 0, 0);
b99bd4ef 3490
c19d1205 3491 record_alignment (now_seg, 2);
b99bd4ef 3492
aaca88ef 3493#ifdef OBJ_ELF
47fc6e36
WN
3494 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3495 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3496#endif
c19d1205 3497 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3498
c19d1205
ZW
3499 symbol_locate (pool->symbol, sym_name, now_seg,
3500 (valueT) frag_now_fix (), frag_now);
3501 symbol_table_insert (pool->symbol);
b99bd4ef 3502
c19d1205 3503 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3504
c19d1205
ZW
3505#if defined OBJ_COFF || defined OBJ_ELF
3506 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3507#endif
6c43fab6 3508
c19d1205 3509 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3510 {
3511#ifdef OBJ_ELF
3512 if (debug_type == DEBUG_DWARF2)
3513 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3514#endif
3515 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3516 emit_expr (&(pool->literals[entry]),
3517 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3518 }
b99bd4ef 3519
c19d1205
ZW
3520 /* Mark the pool as empty. */
3521 pool->next_free_entry = 0;
3522 pool->symbol = NULL;
b99bd4ef
NC
3523}
3524
c19d1205
ZW
3525#ifdef OBJ_ELF
3526/* Forward declarations for functions below, in the MD interface
3527 section. */
3528static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3529static valueT create_unwind_entry (int);
3530static void start_unwind_section (const segT, int);
3531static void add_unwind_opcode (valueT, int);
3532static void flush_pending_unwind (void);
b99bd4ef 3533
c19d1205 3534/* Directives: Data. */
b99bd4ef 3535
c19d1205
ZW
3536static void
3537s_arm_elf_cons (int nbytes)
3538{
3539 expressionS exp;
b99bd4ef 3540
c19d1205
ZW
3541#ifdef md_flush_pending_output
3542 md_flush_pending_output ();
3543#endif
b99bd4ef 3544
c19d1205 3545 if (is_it_end_of_statement ())
b99bd4ef 3546 {
c19d1205
ZW
3547 demand_empty_rest_of_line ();
3548 return;
b99bd4ef
NC
3549 }
3550
c19d1205
ZW
3551#ifdef md_cons_align
3552 md_cons_align (nbytes);
3553#endif
b99bd4ef 3554
c19d1205
ZW
3555 mapping_state (MAP_DATA);
3556 do
b99bd4ef 3557 {
c19d1205
ZW
3558 int reloc;
3559 char *base = input_line_pointer;
b99bd4ef 3560
c19d1205 3561 expression (& exp);
b99bd4ef 3562
c19d1205
ZW
3563 if (exp.X_op != O_symbol)
3564 emit_expr (&exp, (unsigned int) nbytes);
3565 else
3566 {
3567 char *before_reloc = input_line_pointer;
3568 reloc = parse_reloc (&input_line_pointer);
3569 if (reloc == -1)
3570 {
3571 as_bad (_("unrecognized relocation suffix"));
3572 ignore_rest_of_line ();
3573 return;
3574 }
3575 else if (reloc == BFD_RELOC_UNUSED)
3576 emit_expr (&exp, (unsigned int) nbytes);
3577 else
3578 {
21d799b5 3579 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3580 bfd_reloc_type_lookup (stdoutput,
3581 (bfd_reloc_code_real_type) reloc);
c19d1205 3582 int size = bfd_get_reloc_size (howto);
b99bd4ef 3583
2fc8bdac
ZW
3584 if (reloc == BFD_RELOC_ARM_PLT32)
3585 {
3586 as_bad (_("(plt) is only valid on branch targets"));
3587 reloc = BFD_RELOC_UNUSED;
3588 size = 0;
3589 }
3590
c19d1205 3591 if (size > nbytes)
992a06ee
AM
3592 as_bad (ngettext ("%s relocations do not fit in %d byte",
3593 "%s relocations do not fit in %d bytes",
3594 nbytes),
c19d1205
ZW
3595 howto->name, nbytes);
3596 else
3597 {
3598 /* We've parsed an expression stopping at O_symbol.
3599 But there may be more expression left now that we
3600 have parsed the relocation marker. Parse it again.
3601 XXX Surely there is a cleaner way to do this. */
3602 char *p = input_line_pointer;
3603 int offset;
325801bd 3604 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3605
c19d1205
ZW
3606 memcpy (save_buf, base, input_line_pointer - base);
3607 memmove (base + (input_line_pointer - before_reloc),
3608 base, before_reloc - base);
3609
3610 input_line_pointer = base + (input_line_pointer-before_reloc);
3611 expression (&exp);
3612 memcpy (base, save_buf, p - base);
3613
3614 offset = nbytes - size;
4b1a927e
AM
3615 p = frag_more (nbytes);
3616 memset (p, 0, nbytes);
c19d1205 3617 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3618 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3619 free (save_buf);
c19d1205
ZW
3620 }
3621 }
3622 }
b99bd4ef 3623 }
c19d1205 3624 while (*input_line_pointer++ == ',');
b99bd4ef 3625
c19d1205
ZW
3626 /* Put terminator back into stream. */
3627 input_line_pointer --;
3628 demand_empty_rest_of_line ();
b99bd4ef
NC
3629}
3630
c921be7d
NC
3631/* Emit an expression containing a 32-bit thumb instruction.
3632 Implementation based on put_thumb32_insn. */
3633
3634static void
3635emit_thumb32_expr (expressionS * exp)
3636{
3637 expressionS exp_high = *exp;
3638
3639 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3640 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3641 exp->X_add_number &= 0xffff;
3642 emit_expr (exp, (unsigned int) THUMB_SIZE);
3643}
3644
3645/* Guess the instruction size based on the opcode. */
3646
3647static int
3648thumb_insn_size (int opcode)
3649{
3650 if ((unsigned int) opcode < 0xe800u)
3651 return 2;
3652 else if ((unsigned int) opcode >= 0xe8000000u)
3653 return 4;
3654 else
3655 return 0;
3656}
3657
3658static bfd_boolean
3659emit_insn (expressionS *exp, int nbytes)
3660{
3661 int size = 0;
3662
3663 if (exp->X_op == O_constant)
3664 {
3665 size = nbytes;
3666
3667 if (size == 0)
3668 size = thumb_insn_size (exp->X_add_number);
3669
3670 if (size != 0)
3671 {
3672 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3673 {
3674 as_bad (_(".inst.n operand too big. "\
3675 "Use .inst.w instead"));
3676 size = 0;
3677 }
3678 else
3679 {
3680 if (now_it.state == AUTOMATIC_IT_BLOCK)
3681 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3682 else
3683 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3684
3685 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3686 emit_thumb32_expr (exp);
3687 else
3688 emit_expr (exp, (unsigned int) size);
3689
3690 it_fsm_post_encode ();
3691 }
3692 }
3693 else
3694 as_bad (_("cannot determine Thumb instruction size. " \
3695 "Use .inst.n/.inst.w instead"));
3696 }
3697 else
3698 as_bad (_("constant expression required"));
3699
3700 return (size != 0);
3701}
3702
3703/* Like s_arm_elf_cons but do not use md_cons_align and
3704 set the mapping state to MAP_ARM/MAP_THUMB. */
3705
3706static void
3707s_arm_elf_inst (int nbytes)
3708{
3709 if (is_it_end_of_statement ())
3710 {
3711 demand_empty_rest_of_line ();
3712 return;
3713 }
3714
3715 /* Calling mapping_state () here will not change ARM/THUMB,
3716 but will ensure not to be in DATA state. */
3717
3718 if (thumb_mode)
3719 mapping_state (MAP_THUMB);
3720 else
3721 {
3722 if (nbytes != 0)
3723 {
3724 as_bad (_("width suffixes are invalid in ARM mode"));
3725 ignore_rest_of_line ();
3726 return;
3727 }
3728
3729 nbytes = 4;
3730
3731 mapping_state (MAP_ARM);
3732 }
3733
3734 do
3735 {
3736 expressionS exp;
3737
3738 expression (& exp);
3739
3740 if (! emit_insn (& exp, nbytes))
3741 {
3742 ignore_rest_of_line ();
3743 return;
3744 }
3745 }
3746 while (*input_line_pointer++ == ',');
3747
3748 /* Put terminator back into stream. */
3749 input_line_pointer --;
3750 demand_empty_rest_of_line ();
3751}
b99bd4ef 3752
c19d1205 3753/* Parse a .rel31 directive. */
b99bd4ef 3754
c19d1205
ZW
3755static void
3756s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3757{
3758 expressionS exp;
3759 char *p;
3760 valueT highbit;
b99bd4ef 3761
c19d1205
ZW
3762 highbit = 0;
3763 if (*input_line_pointer == '1')
3764 highbit = 0x80000000;
3765 else if (*input_line_pointer != '0')
3766 as_bad (_("expected 0 or 1"));
b99bd4ef 3767
c19d1205
ZW
3768 input_line_pointer++;
3769 if (*input_line_pointer != ',')
3770 as_bad (_("missing comma"));
3771 input_line_pointer++;
b99bd4ef 3772
c19d1205
ZW
3773#ifdef md_flush_pending_output
3774 md_flush_pending_output ();
3775#endif
b99bd4ef 3776
c19d1205
ZW
3777#ifdef md_cons_align
3778 md_cons_align (4);
3779#endif
b99bd4ef 3780
c19d1205 3781 mapping_state (MAP_DATA);
b99bd4ef 3782
c19d1205 3783 expression (&exp);
b99bd4ef 3784
c19d1205
ZW
3785 p = frag_more (4);
3786 md_number_to_chars (p, highbit, 4);
3787 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3788 BFD_RELOC_ARM_PREL31);
b99bd4ef 3789
c19d1205 3790 demand_empty_rest_of_line ();
b99bd4ef
NC
3791}
3792
c19d1205 3793/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3794
c19d1205 3795/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3796
c19d1205
ZW
3797static void
3798s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3799{
3800 demand_empty_rest_of_line ();
921e5f0a
PB
3801 if (unwind.proc_start)
3802 {
c921be7d 3803 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3804 return;
3805 }
3806
c19d1205
ZW
3807 /* Mark the start of the function. */
3808 unwind.proc_start = expr_build_dot ();
b99bd4ef 3809
c19d1205
ZW
3810 /* Reset the rest of the unwind info. */
3811 unwind.opcode_count = 0;
3812 unwind.table_entry = NULL;
3813 unwind.personality_routine = NULL;
3814 unwind.personality_index = -1;
3815 unwind.frame_size = 0;
3816 unwind.fp_offset = 0;
fdfde340 3817 unwind.fp_reg = REG_SP;
c19d1205
ZW
3818 unwind.fp_used = 0;
3819 unwind.sp_restored = 0;
3820}
b99bd4ef 3821
b99bd4ef 3822
c19d1205
ZW
3823/* Parse a handlerdata directive. Creates the exception handling table entry
3824 for the function. */
b99bd4ef 3825
c19d1205
ZW
3826static void
3827s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3828{
3829 demand_empty_rest_of_line ();
921e5f0a 3830 if (!unwind.proc_start)
c921be7d 3831 as_bad (MISSING_FNSTART);
921e5f0a 3832
c19d1205 3833 if (unwind.table_entry)
6decc662 3834 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3835
c19d1205
ZW
3836 create_unwind_entry (1);
3837}
a737bd4d 3838
c19d1205 3839/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3840
c19d1205
ZW
3841static void
3842s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3843{
3844 long where;
3845 char *ptr;
3846 valueT val;
940b5ce0 3847 unsigned int marked_pr_dependency;
f02232aa 3848
c19d1205 3849 demand_empty_rest_of_line ();
f02232aa 3850
921e5f0a
PB
3851 if (!unwind.proc_start)
3852 {
c921be7d 3853 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3854 return;
3855 }
3856
c19d1205
ZW
3857 /* Add eh table entry. */
3858 if (unwind.table_entry == NULL)
3859 val = create_unwind_entry (0);
3860 else
3861 val = 0;
f02232aa 3862
c19d1205
ZW
3863 /* Add index table entry. This is two words. */
3864 start_unwind_section (unwind.saved_seg, 1);
3865 frag_align (2, 0, 0);
3866 record_alignment (now_seg, 2);
b99bd4ef 3867
c19d1205 3868 ptr = frag_more (8);
5011093d 3869 memset (ptr, 0, 8);
c19d1205 3870 where = frag_now_fix () - 8;
f02232aa 3871
c19d1205
ZW
3872 /* Self relative offset of the function start. */
3873 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3874 BFD_RELOC_ARM_PREL31);
f02232aa 3875
c19d1205
ZW
3876 /* Indicate dependency on EHABI-defined personality routines to the
3877 linker, if it hasn't been done already. */
940b5ce0
DJ
3878 marked_pr_dependency
3879 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3880 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3881 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3882 {
5f4273c7
NC
3883 static const char *const name[] =
3884 {
3885 "__aeabi_unwind_cpp_pr0",
3886 "__aeabi_unwind_cpp_pr1",
3887 "__aeabi_unwind_cpp_pr2"
3888 };
c19d1205
ZW
3889 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3890 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3891 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3892 |= 1 << unwind.personality_index;
c19d1205 3893 }
f02232aa 3894
c19d1205
ZW
3895 if (val)
3896 /* Inline exception table entry. */
3897 md_number_to_chars (ptr + 4, val, 4);
3898 else
3899 /* Self relative offset of the table entry. */
3900 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3901 BFD_RELOC_ARM_PREL31);
f02232aa 3902
c19d1205
ZW
3903 /* Restore the original section. */
3904 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3905
3906 unwind.proc_start = NULL;
c19d1205 3907}
f02232aa 3908
f02232aa 3909
c19d1205 3910/* Parse an unwind_cantunwind directive. */
b99bd4ef 3911
c19d1205
ZW
3912static void
3913s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3914{
3915 demand_empty_rest_of_line ();
921e5f0a 3916 if (!unwind.proc_start)
c921be7d 3917 as_bad (MISSING_FNSTART);
921e5f0a 3918
c19d1205
ZW
3919 if (unwind.personality_routine || unwind.personality_index != -1)
3920 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3921
c19d1205
ZW
3922 unwind.personality_index = -2;
3923}
b99bd4ef 3924
b99bd4ef 3925
c19d1205 3926/* Parse a personalityindex directive. */
b99bd4ef 3927
c19d1205
ZW
3928static void
3929s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3930{
3931 expressionS exp;
b99bd4ef 3932
921e5f0a 3933 if (!unwind.proc_start)
c921be7d 3934 as_bad (MISSING_FNSTART);
921e5f0a 3935
c19d1205
ZW
3936 if (unwind.personality_routine || unwind.personality_index != -1)
3937 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3938
c19d1205 3939 expression (&exp);
b99bd4ef 3940
c19d1205
ZW
3941 if (exp.X_op != O_constant
3942 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3943 {
c19d1205
ZW
3944 as_bad (_("bad personality routine number"));
3945 ignore_rest_of_line ();
3946 return;
b99bd4ef
NC
3947 }
3948
c19d1205 3949 unwind.personality_index = exp.X_add_number;
b99bd4ef 3950
c19d1205
ZW
3951 demand_empty_rest_of_line ();
3952}
e16bb312 3953
e16bb312 3954
c19d1205 3955/* Parse a personality directive. */
e16bb312 3956
c19d1205
ZW
3957static void
3958s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3959{
3960 char *name, *p, c;
a737bd4d 3961
921e5f0a 3962 if (!unwind.proc_start)
c921be7d 3963 as_bad (MISSING_FNSTART);
921e5f0a 3964
c19d1205
ZW
3965 if (unwind.personality_routine || unwind.personality_index != -1)
3966 as_bad (_("duplicate .personality directive"));
a737bd4d 3967
d02603dc 3968 c = get_symbol_name (& name);
c19d1205 3969 p = input_line_pointer;
d02603dc
NC
3970 if (c == '"')
3971 ++ input_line_pointer;
c19d1205
ZW
3972 unwind.personality_routine = symbol_find_or_make (name);
3973 *p = c;
3974 demand_empty_rest_of_line ();
3975}
e16bb312 3976
e16bb312 3977
c19d1205 3978/* Parse a directive saving core registers. */
e16bb312 3979
c19d1205
ZW
3980static void
3981s_arm_unwind_save_core (void)
e16bb312 3982{
c19d1205
ZW
3983 valueT op;
3984 long range;
3985 int n;
e16bb312 3986
c19d1205
ZW
3987 range = parse_reg_list (&input_line_pointer);
3988 if (range == FAIL)
e16bb312 3989 {
c19d1205
ZW
3990 as_bad (_("expected register list"));
3991 ignore_rest_of_line ();
3992 return;
3993 }
e16bb312 3994
c19d1205 3995 demand_empty_rest_of_line ();
e16bb312 3996
c19d1205
ZW
3997 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3998 into .unwind_save {..., sp...}. We aren't bothered about the value of
3999 ip because it is clobbered by calls. */
4000 if (unwind.sp_restored && unwind.fp_reg == 12
4001 && (range & 0x3000) == 0x1000)
4002 {
4003 unwind.opcode_count--;
4004 unwind.sp_restored = 0;
4005 range = (range | 0x2000) & ~0x1000;
4006 unwind.pending_offset = 0;
4007 }
e16bb312 4008
01ae4198
DJ
4009 /* Pop r4-r15. */
4010 if (range & 0xfff0)
c19d1205 4011 {
01ae4198
DJ
4012 /* See if we can use the short opcodes. These pop a block of up to 8
4013 registers starting with r4, plus maybe r14. */
4014 for (n = 0; n < 8; n++)
4015 {
4016 /* Break at the first non-saved register. */
4017 if ((range & (1 << (n + 4))) == 0)
4018 break;
4019 }
4020 /* See if there are any other bits set. */
4021 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4022 {
4023 /* Use the long form. */
4024 op = 0x8000 | ((range >> 4) & 0xfff);
4025 add_unwind_opcode (op, 2);
4026 }
0dd132b6 4027 else
01ae4198
DJ
4028 {
4029 /* Use the short form. */
4030 if (range & 0x4000)
4031 op = 0xa8; /* Pop r14. */
4032 else
4033 op = 0xa0; /* Do not pop r14. */
4034 op |= (n - 1);
4035 add_unwind_opcode (op, 1);
4036 }
c19d1205 4037 }
0dd132b6 4038
c19d1205
ZW
4039 /* Pop r0-r3. */
4040 if (range & 0xf)
4041 {
4042 op = 0xb100 | (range & 0xf);
4043 add_unwind_opcode (op, 2);
0dd132b6
NC
4044 }
4045
c19d1205
ZW
4046 /* Record the number of bytes pushed. */
4047 for (n = 0; n < 16; n++)
4048 {
4049 if (range & (1 << n))
4050 unwind.frame_size += 4;
4051 }
0dd132b6
NC
4052}
4053
c19d1205
ZW
4054
4055/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4056
4057static void
c19d1205 4058s_arm_unwind_save_fpa (int reg)
b99bd4ef 4059{
c19d1205
ZW
4060 expressionS exp;
4061 int num_regs;
4062 valueT op;
b99bd4ef 4063
c19d1205
ZW
4064 /* Get Number of registers to transfer. */
4065 if (skip_past_comma (&input_line_pointer) != FAIL)
4066 expression (&exp);
4067 else
4068 exp.X_op = O_illegal;
b99bd4ef 4069
c19d1205 4070 if (exp.X_op != O_constant)
b99bd4ef 4071 {
c19d1205
ZW
4072 as_bad (_("expected , <constant>"));
4073 ignore_rest_of_line ();
b99bd4ef
NC
4074 return;
4075 }
4076
c19d1205
ZW
4077 num_regs = exp.X_add_number;
4078
4079 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4080 {
c19d1205
ZW
4081 as_bad (_("number of registers must be in the range [1:4]"));
4082 ignore_rest_of_line ();
b99bd4ef
NC
4083 return;
4084 }
4085
c19d1205 4086 demand_empty_rest_of_line ();
b99bd4ef 4087
c19d1205
ZW
4088 if (reg == 4)
4089 {
4090 /* Short form. */
4091 op = 0xb4 | (num_regs - 1);
4092 add_unwind_opcode (op, 1);
4093 }
b99bd4ef
NC
4094 else
4095 {
c19d1205
ZW
4096 /* Long form. */
4097 op = 0xc800 | (reg << 4) | (num_regs - 1);
4098 add_unwind_opcode (op, 2);
b99bd4ef 4099 }
c19d1205 4100 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4101}
4102
c19d1205 4103
fa073d69
MS
4104/* Parse a directive saving VFP registers for ARMv6 and above. */
4105
4106static void
4107s_arm_unwind_save_vfp_armv6 (void)
4108{
4109 int count;
4110 unsigned int start;
4111 valueT op;
4112 int num_vfpv3_regs = 0;
4113 int num_regs_below_16;
4114
4115 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4116 if (count == FAIL)
4117 {
4118 as_bad (_("expected register list"));
4119 ignore_rest_of_line ();
4120 return;
4121 }
4122
4123 demand_empty_rest_of_line ();
4124
4125 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4126 than FSTMX/FLDMX-style ones). */
4127
4128 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4129 if (start >= 16)
4130 num_vfpv3_regs = count;
4131 else if (start + count > 16)
4132 num_vfpv3_regs = start + count - 16;
4133
4134 if (num_vfpv3_regs > 0)
4135 {
4136 int start_offset = start > 16 ? start - 16 : 0;
4137 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4138 add_unwind_opcode (op, 2);
4139 }
4140
4141 /* Generate opcode for registers numbered in the range 0 .. 15. */
4142 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4143 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4144 if (num_regs_below_16 > 0)
4145 {
4146 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4147 add_unwind_opcode (op, 2);
4148 }
4149
4150 unwind.frame_size += count * 8;
4151}
4152
4153
4154/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4155
4156static void
c19d1205 4157s_arm_unwind_save_vfp (void)
b99bd4ef 4158{
c19d1205 4159 int count;
ca3f61f7 4160 unsigned int reg;
c19d1205 4161 valueT op;
b99bd4ef 4162
5287ad62 4163 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4164 if (count == FAIL)
b99bd4ef 4165 {
c19d1205
ZW
4166 as_bad (_("expected register list"));
4167 ignore_rest_of_line ();
b99bd4ef
NC
4168 return;
4169 }
4170
c19d1205 4171 demand_empty_rest_of_line ();
b99bd4ef 4172
c19d1205 4173 if (reg == 8)
b99bd4ef 4174 {
c19d1205
ZW
4175 /* Short form. */
4176 op = 0xb8 | (count - 1);
4177 add_unwind_opcode (op, 1);
b99bd4ef 4178 }
c19d1205 4179 else
b99bd4ef 4180 {
c19d1205
ZW
4181 /* Long form. */
4182 op = 0xb300 | (reg << 4) | (count - 1);
4183 add_unwind_opcode (op, 2);
b99bd4ef 4184 }
c19d1205
ZW
4185 unwind.frame_size += count * 8 + 4;
4186}
b99bd4ef 4187
b99bd4ef 4188
c19d1205
ZW
4189/* Parse a directive saving iWMMXt data registers. */
4190
4191static void
4192s_arm_unwind_save_mmxwr (void)
4193{
4194 int reg;
4195 int hi_reg;
4196 int i;
4197 unsigned mask = 0;
4198 valueT op;
b99bd4ef 4199
c19d1205
ZW
4200 if (*input_line_pointer == '{')
4201 input_line_pointer++;
b99bd4ef 4202
c19d1205 4203 do
b99bd4ef 4204 {
dcbf9037 4205 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4206
c19d1205 4207 if (reg == FAIL)
b99bd4ef 4208 {
9b7132d3 4209 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4210 goto error;
b99bd4ef
NC
4211 }
4212
c19d1205
ZW
4213 if (mask >> reg)
4214 as_tsktsk (_("register list not in ascending order"));
4215 mask |= 1 << reg;
b99bd4ef 4216
c19d1205
ZW
4217 if (*input_line_pointer == '-')
4218 {
4219 input_line_pointer++;
dcbf9037 4220 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4221 if (hi_reg == FAIL)
4222 {
9b7132d3 4223 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4224 goto error;
4225 }
4226 else if (reg >= hi_reg)
4227 {
4228 as_bad (_("bad register range"));
4229 goto error;
4230 }
4231 for (; reg < hi_reg; reg++)
4232 mask |= 1 << reg;
4233 }
4234 }
4235 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4236
d996d970 4237 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4238
c19d1205 4239 demand_empty_rest_of_line ();
b99bd4ef 4240
708587a4 4241 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4242 the list. */
4243 flush_pending_unwind ();
b99bd4ef 4244
c19d1205 4245 for (i = 0; i < 16; i++)
b99bd4ef 4246 {
c19d1205
ZW
4247 if (mask & (1 << i))
4248 unwind.frame_size += 8;
b99bd4ef
NC
4249 }
4250
c19d1205
ZW
4251 /* Attempt to combine with a previous opcode. We do this because gcc
4252 likes to output separate unwind directives for a single block of
4253 registers. */
4254 if (unwind.opcode_count > 0)
b99bd4ef 4255 {
c19d1205
ZW
4256 i = unwind.opcodes[unwind.opcode_count - 1];
4257 if ((i & 0xf8) == 0xc0)
4258 {
4259 i &= 7;
4260 /* Only merge if the blocks are contiguous. */
4261 if (i < 6)
4262 {
4263 if ((mask & 0xfe00) == (1 << 9))
4264 {
4265 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4266 unwind.opcode_count--;
4267 }
4268 }
4269 else if (i == 6 && unwind.opcode_count >= 2)
4270 {
4271 i = unwind.opcodes[unwind.opcode_count - 2];
4272 reg = i >> 4;
4273 i &= 0xf;
b99bd4ef 4274
c19d1205
ZW
4275 op = 0xffff << (reg - 1);
4276 if (reg > 0
87a1fd79 4277 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4278 {
4279 op = (1 << (reg + i + 1)) - 1;
4280 op &= ~((1 << reg) - 1);
4281 mask |= op;
4282 unwind.opcode_count -= 2;
4283 }
4284 }
4285 }
b99bd4ef
NC
4286 }
4287
c19d1205
ZW
4288 hi_reg = 15;
4289 /* We want to generate opcodes in the order the registers have been
4290 saved, ie. descending order. */
4291 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4292 {
c19d1205
ZW
4293 /* Save registers in blocks. */
4294 if (reg < 0
4295 || !(mask & (1 << reg)))
4296 {
4297 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4298 preceding block. */
c19d1205
ZW
4299 if (reg != hi_reg)
4300 {
4301 if (reg == 9)
4302 {
4303 /* Short form. */
4304 op = 0xc0 | (hi_reg - 10);
4305 add_unwind_opcode (op, 1);
4306 }
4307 else
4308 {
4309 /* Long form. */
4310 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4311 add_unwind_opcode (op, 2);
4312 }
4313 }
4314 hi_reg = reg - 1;
4315 }
b99bd4ef
NC
4316 }
4317
c19d1205
ZW
4318 return;
4319error:
4320 ignore_rest_of_line ();
b99bd4ef
NC
4321}
4322
4323static void
c19d1205 4324s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4325{
c19d1205
ZW
4326 int reg;
4327 int hi_reg;
4328 unsigned mask = 0;
4329 valueT op;
b99bd4ef 4330
c19d1205
ZW
4331 if (*input_line_pointer == '{')
4332 input_line_pointer++;
b99bd4ef 4333
477330fc
RM
4334 skip_whitespace (input_line_pointer);
4335
c19d1205 4336 do
b99bd4ef 4337 {
dcbf9037 4338 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4339
c19d1205
ZW
4340 if (reg == FAIL)
4341 {
9b7132d3 4342 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4343 goto error;
4344 }
b99bd4ef 4345
c19d1205
ZW
4346 reg -= 8;
4347 if (mask >> reg)
4348 as_tsktsk (_("register list not in ascending order"));
4349 mask |= 1 << reg;
b99bd4ef 4350
c19d1205
ZW
4351 if (*input_line_pointer == '-')
4352 {
4353 input_line_pointer++;
dcbf9037 4354 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4355 if (hi_reg == FAIL)
4356 {
9b7132d3 4357 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4358 goto error;
4359 }
4360 else if (reg >= hi_reg)
4361 {
4362 as_bad (_("bad register range"));
4363 goto error;
4364 }
4365 for (; reg < hi_reg; reg++)
4366 mask |= 1 << reg;
4367 }
b99bd4ef 4368 }
c19d1205 4369 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4370
d996d970 4371 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4372
c19d1205
ZW
4373 demand_empty_rest_of_line ();
4374
708587a4 4375 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4376 the list. */
4377 flush_pending_unwind ();
b99bd4ef 4378
c19d1205 4379 for (reg = 0; reg < 16; reg++)
b99bd4ef 4380 {
c19d1205
ZW
4381 if (mask & (1 << reg))
4382 unwind.frame_size += 4;
b99bd4ef 4383 }
c19d1205
ZW
4384 op = 0xc700 | mask;
4385 add_unwind_opcode (op, 2);
4386 return;
4387error:
4388 ignore_rest_of_line ();
b99bd4ef
NC
4389}
4390
c19d1205 4391
fa073d69
MS
4392/* Parse an unwind_save directive.
4393 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4394
b99bd4ef 4395static void
fa073d69 4396s_arm_unwind_save (int arch_v6)
b99bd4ef 4397{
c19d1205
ZW
4398 char *peek;
4399 struct reg_entry *reg;
4400 bfd_boolean had_brace = FALSE;
b99bd4ef 4401
921e5f0a 4402 if (!unwind.proc_start)
c921be7d 4403 as_bad (MISSING_FNSTART);
921e5f0a 4404
c19d1205
ZW
4405 /* Figure out what sort of save we have. */
4406 peek = input_line_pointer;
b99bd4ef 4407
c19d1205 4408 if (*peek == '{')
b99bd4ef 4409 {
c19d1205
ZW
4410 had_brace = TRUE;
4411 peek++;
b99bd4ef
NC
4412 }
4413
c19d1205 4414 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4415
c19d1205 4416 if (!reg)
b99bd4ef 4417 {
c19d1205
ZW
4418 as_bad (_("register expected"));
4419 ignore_rest_of_line ();
b99bd4ef
NC
4420 return;
4421 }
4422
c19d1205 4423 switch (reg->type)
b99bd4ef 4424 {
c19d1205
ZW
4425 case REG_TYPE_FN:
4426 if (had_brace)
4427 {
4428 as_bad (_("FPA .unwind_save does not take a register list"));
4429 ignore_rest_of_line ();
4430 return;
4431 }
93ac2687 4432 input_line_pointer = peek;
c19d1205 4433 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4434 return;
c19d1205 4435
1f5afe1c
NC
4436 case REG_TYPE_RN:
4437 s_arm_unwind_save_core ();
4438 return;
4439
fa073d69
MS
4440 case REG_TYPE_VFD:
4441 if (arch_v6)
477330fc 4442 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4443 else
477330fc 4444 s_arm_unwind_save_vfp ();
fa073d69 4445 return;
1f5afe1c
NC
4446
4447 case REG_TYPE_MMXWR:
4448 s_arm_unwind_save_mmxwr ();
4449 return;
4450
4451 case REG_TYPE_MMXWCG:
4452 s_arm_unwind_save_mmxwcg ();
4453 return;
c19d1205
ZW
4454
4455 default:
4456 as_bad (_(".unwind_save does not support this kind of register"));
4457 ignore_rest_of_line ();
b99bd4ef 4458 }
c19d1205 4459}
b99bd4ef 4460
b99bd4ef 4461
c19d1205
ZW
4462/* Parse an unwind_movsp directive. */
4463
4464static void
4465s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4466{
4467 int reg;
4468 valueT op;
4fa3602b 4469 int offset;
c19d1205 4470
921e5f0a 4471 if (!unwind.proc_start)
c921be7d 4472 as_bad (MISSING_FNSTART);
921e5f0a 4473
dcbf9037 4474 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4475 if (reg == FAIL)
b99bd4ef 4476 {
9b7132d3 4477 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4478 ignore_rest_of_line ();
b99bd4ef
NC
4479 return;
4480 }
4fa3602b
PB
4481
4482 /* Optional constant. */
4483 if (skip_past_comma (&input_line_pointer) != FAIL)
4484 {
4485 if (immediate_for_directive (&offset) == FAIL)
4486 return;
4487 }
4488 else
4489 offset = 0;
4490
c19d1205 4491 demand_empty_rest_of_line ();
b99bd4ef 4492
c19d1205 4493 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4494 {
c19d1205 4495 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4496 return;
4497 }
4498
c19d1205
ZW
4499 if (unwind.fp_reg != REG_SP)
4500 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4501
c19d1205
ZW
4502 /* Generate opcode to restore the value. */
4503 op = 0x90 | reg;
4504 add_unwind_opcode (op, 1);
4505
4506 /* Record the information for later. */
4507 unwind.fp_reg = reg;
4fa3602b 4508 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4509 unwind.sp_restored = 1;
b05fe5cf
ZW
4510}
4511
c19d1205
ZW
4512/* Parse an unwind_pad directive. */
4513
b05fe5cf 4514static void
c19d1205 4515s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4516{
c19d1205 4517 int offset;
b05fe5cf 4518
921e5f0a 4519 if (!unwind.proc_start)
c921be7d 4520 as_bad (MISSING_FNSTART);
921e5f0a 4521
c19d1205
ZW
4522 if (immediate_for_directive (&offset) == FAIL)
4523 return;
b99bd4ef 4524
c19d1205
ZW
4525 if (offset & 3)
4526 {
4527 as_bad (_("stack increment must be multiple of 4"));
4528 ignore_rest_of_line ();
4529 return;
4530 }
b99bd4ef 4531
c19d1205
ZW
4532 /* Don't generate any opcodes, just record the details for later. */
4533 unwind.frame_size += offset;
4534 unwind.pending_offset += offset;
4535
4536 demand_empty_rest_of_line ();
4537}
4538
4539/* Parse an unwind_setfp directive. */
4540
4541static void
4542s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4543{
c19d1205
ZW
4544 int sp_reg;
4545 int fp_reg;
4546 int offset;
4547
921e5f0a 4548 if (!unwind.proc_start)
c921be7d 4549 as_bad (MISSING_FNSTART);
921e5f0a 4550
dcbf9037 4551 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4552 if (skip_past_comma (&input_line_pointer) == FAIL)
4553 sp_reg = FAIL;
4554 else
dcbf9037 4555 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4556
c19d1205
ZW
4557 if (fp_reg == FAIL || sp_reg == FAIL)
4558 {
4559 as_bad (_("expected <reg>, <reg>"));
4560 ignore_rest_of_line ();
4561 return;
4562 }
b99bd4ef 4563
c19d1205
ZW
4564 /* Optional constant. */
4565 if (skip_past_comma (&input_line_pointer) != FAIL)
4566 {
4567 if (immediate_for_directive (&offset) == FAIL)
4568 return;
4569 }
4570 else
4571 offset = 0;
a737bd4d 4572
c19d1205 4573 demand_empty_rest_of_line ();
a737bd4d 4574
fdfde340 4575 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4576 {
c19d1205
ZW
4577 as_bad (_("register must be either sp or set by a previous"
4578 "unwind_movsp directive"));
4579 return;
a737bd4d
NC
4580 }
4581
c19d1205
ZW
4582 /* Don't generate any opcodes, just record the information for later. */
4583 unwind.fp_reg = fp_reg;
4584 unwind.fp_used = 1;
fdfde340 4585 if (sp_reg == REG_SP)
c19d1205
ZW
4586 unwind.fp_offset = unwind.frame_size - offset;
4587 else
4588 unwind.fp_offset -= offset;
a737bd4d
NC
4589}
4590
c19d1205
ZW
4591/* Parse an unwind_raw directive. */
4592
4593static void
4594s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4595{
c19d1205 4596 expressionS exp;
708587a4 4597 /* This is an arbitrary limit. */
c19d1205
ZW
4598 unsigned char op[16];
4599 int count;
a737bd4d 4600
921e5f0a 4601 if (!unwind.proc_start)
c921be7d 4602 as_bad (MISSING_FNSTART);
921e5f0a 4603
c19d1205
ZW
4604 expression (&exp);
4605 if (exp.X_op == O_constant
4606 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4607 {
c19d1205
ZW
4608 unwind.frame_size += exp.X_add_number;
4609 expression (&exp);
4610 }
4611 else
4612 exp.X_op = O_illegal;
a737bd4d 4613
c19d1205
ZW
4614 if (exp.X_op != O_constant)
4615 {
4616 as_bad (_("expected <offset>, <opcode>"));
4617 ignore_rest_of_line ();
4618 return;
4619 }
a737bd4d 4620
c19d1205 4621 count = 0;
a737bd4d 4622
c19d1205
ZW
4623 /* Parse the opcode. */
4624 for (;;)
4625 {
4626 if (count >= 16)
4627 {
4628 as_bad (_("unwind opcode too long"));
4629 ignore_rest_of_line ();
a737bd4d 4630 }
c19d1205 4631 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4632 {
c19d1205
ZW
4633 as_bad (_("invalid unwind opcode"));
4634 ignore_rest_of_line ();
4635 return;
a737bd4d 4636 }
c19d1205 4637 op[count++] = exp.X_add_number;
a737bd4d 4638
c19d1205
ZW
4639 /* Parse the next byte. */
4640 if (skip_past_comma (&input_line_pointer) == FAIL)
4641 break;
a737bd4d 4642
c19d1205
ZW
4643 expression (&exp);
4644 }
b99bd4ef 4645
c19d1205
ZW
4646 /* Add the opcode bytes in reverse order. */
4647 while (count--)
4648 add_unwind_opcode (op[count], 1);
b99bd4ef 4649
c19d1205 4650 demand_empty_rest_of_line ();
b99bd4ef 4651}
ee065d83
PB
4652
4653
4654/* Parse a .eabi_attribute directive. */
4655
4656static void
4657s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4658{
0420f52b 4659 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4660
4661 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4662 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4663}
4664
0855e32b
NS
4665/* Emit a tls fix for the symbol. */
4666
4667static void
4668s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4669{
4670 char *p;
4671 expressionS exp;
4672#ifdef md_flush_pending_output
4673 md_flush_pending_output ();
4674#endif
4675
4676#ifdef md_cons_align
4677 md_cons_align (4);
4678#endif
4679
4680 /* Since we're just labelling the code, there's no need to define a
4681 mapping symbol. */
4682 expression (&exp);
4683 p = obstack_next_free (&frchain_now->frch_obstack);
4684 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4685 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4686 : BFD_RELOC_ARM_TLS_DESCSEQ);
4687}
cdf9ccec 4688#endif /* OBJ_ELF */
0855e32b 4689
ee065d83 4690static void s_arm_arch (int);
7a1d4c38 4691static void s_arm_object_arch (int);
ee065d83
PB
4692static void s_arm_cpu (int);
4693static void s_arm_fpu (int);
69133863 4694static void s_arm_arch_extension (int);
b99bd4ef 4695
f0927246
NC
4696#ifdef TE_PE
4697
4698static void
5f4273c7 4699pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4700{
4701 expressionS exp;
4702
4703 do
4704 {
4705 expression (&exp);
4706 if (exp.X_op == O_symbol)
4707 exp.X_op = O_secrel;
4708
4709 emit_expr (&exp, 4);
4710 }
4711 while (*input_line_pointer++ == ',');
4712
4713 input_line_pointer--;
4714 demand_empty_rest_of_line ();
4715}
4716#endif /* TE_PE */
4717
c19d1205
ZW
4718/* This table describes all the machine specific pseudo-ops the assembler
4719 has to support. The fields are:
4720 pseudo-op name without dot
4721 function to call to execute this pseudo-op
4722 Integer arg to pass to the function. */
b99bd4ef 4723
c19d1205 4724const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4725{
c19d1205
ZW
4726 /* Never called because '.req' does not start a line. */
4727 { "req", s_req, 0 },
dcbf9037
JB
4728 /* Following two are likewise never called. */
4729 { "dn", s_dn, 0 },
4730 { "qn", s_qn, 0 },
c19d1205
ZW
4731 { "unreq", s_unreq, 0 },
4732 { "bss", s_bss, 0 },
db2ed2e0 4733 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4734 { "arm", s_arm, 0 },
4735 { "thumb", s_thumb, 0 },
4736 { "code", s_code, 0 },
4737 { "force_thumb", s_force_thumb, 0 },
4738 { "thumb_func", s_thumb_func, 0 },
4739 { "thumb_set", s_thumb_set, 0 },
4740 { "even", s_even, 0 },
4741 { "ltorg", s_ltorg, 0 },
4742 { "pool", s_ltorg, 0 },
4743 { "syntax", s_syntax, 0 },
8463be01
PB
4744 { "cpu", s_arm_cpu, 0 },
4745 { "arch", s_arm_arch, 0 },
7a1d4c38 4746 { "object_arch", s_arm_object_arch, 0 },
8463be01 4747 { "fpu", s_arm_fpu, 0 },
69133863 4748 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4749#ifdef OBJ_ELF
c921be7d
NC
4750 { "word", s_arm_elf_cons, 4 },
4751 { "long", s_arm_elf_cons, 4 },
4752 { "inst.n", s_arm_elf_inst, 2 },
4753 { "inst.w", s_arm_elf_inst, 4 },
4754 { "inst", s_arm_elf_inst, 0 },
4755 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4756 { "fnstart", s_arm_unwind_fnstart, 0 },
4757 { "fnend", s_arm_unwind_fnend, 0 },
4758 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4759 { "personality", s_arm_unwind_personality, 0 },
4760 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4761 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4762 { "save", s_arm_unwind_save, 0 },
fa073d69 4763 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4764 { "movsp", s_arm_unwind_movsp, 0 },
4765 { "pad", s_arm_unwind_pad, 0 },
4766 { "setfp", s_arm_unwind_setfp, 0 },
4767 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4768 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4769 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4770#else
4771 { "word", cons, 4},
f0927246
NC
4772
4773 /* These are used for dwarf. */
4774 {"2byte", cons, 2},
4775 {"4byte", cons, 4},
4776 {"8byte", cons, 8},
4777 /* These are used for dwarf2. */
68d20676 4778 { "file", dwarf2_directive_file, 0 },
f0927246
NC
4779 { "loc", dwarf2_directive_loc, 0 },
4780 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4781#endif
4782 { "extend", float_cons, 'x' },
4783 { "ldouble", float_cons, 'x' },
4784 { "packed", float_cons, 'p' },
f0927246
NC
4785#ifdef TE_PE
4786 {"secrel32", pe_directive_secrel, 0},
4787#endif
2e6976a8
DG
4788
4789 /* These are for compatibility with CodeComposer Studio. */
4790 {"ref", s_ccs_ref, 0},
4791 {"def", s_ccs_def, 0},
4792 {"asmfunc", s_ccs_asmfunc, 0},
4793 {"endasmfunc", s_ccs_endasmfunc, 0},
4794
c19d1205
ZW
4795 { 0, 0, 0 }
4796};
4797\f
4798/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4799
c19d1205
ZW
4800/* Generic immediate-value read function for use in insn parsing.
4801 STR points to the beginning of the immediate (the leading #);
4802 VAL receives the value; if the value is outside [MIN, MAX]
4803 issue an error. PREFIX_OPT is true if the immediate prefix is
4804 optional. */
b99bd4ef 4805
c19d1205
ZW
4806static int
4807parse_immediate (char **str, int *val, int min, int max,
4808 bfd_boolean prefix_opt)
4809{
4810 expressionS exp;
0198d5e6 4811
c19d1205
ZW
4812 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4813 if (exp.X_op != O_constant)
b99bd4ef 4814 {
c19d1205
ZW
4815 inst.error = _("constant expression required");
4816 return FAIL;
4817 }
b99bd4ef 4818
c19d1205
ZW
4819 if (exp.X_add_number < min || exp.X_add_number > max)
4820 {
4821 inst.error = _("immediate value out of range");
4822 return FAIL;
4823 }
b99bd4ef 4824
c19d1205
ZW
4825 *val = exp.X_add_number;
4826 return SUCCESS;
4827}
b99bd4ef 4828
5287ad62 4829/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4830 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4831 instructions. Puts the result directly in inst.operands[i]. */
4832
4833static int
8335d6aa
JW
4834parse_big_immediate (char **str, int i, expressionS *in_exp,
4835 bfd_boolean allow_symbol_p)
5287ad62
JB
4836{
4837 expressionS exp;
8335d6aa 4838 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4839 char *ptr = *str;
4840
8335d6aa 4841 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4842
8335d6aa 4843 if (exp_p->X_op == O_constant)
036dc3f7 4844 {
8335d6aa 4845 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4846 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4847 O_constant. We have to be careful not to break compilation for
4848 32-bit X_add_number, though. */
8335d6aa 4849 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4850 {
8335d6aa
JW
4851 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4852 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4853 & 0xffffffff);
036dc3f7
PB
4854 inst.operands[i].regisimm = 1;
4855 }
4856 }
8335d6aa
JW
4857 else if (exp_p->X_op == O_big
4858 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4859 {
4860 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4861
5287ad62 4862 /* Bignums have their least significant bits in
477330fc
RM
4863 generic_bignum[0]. Make sure we put 32 bits in imm and
4864 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4865 gas_assert (parts != 0);
95b75c01
NC
4866
4867 /* Make sure that the number is not too big.
4868 PR 11972: Bignums can now be sign-extended to the
4869 size of a .octa so check that the out of range bits
4870 are all zero or all one. */
8335d6aa 4871 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4872 {
4873 LITTLENUM_TYPE m = -1;
4874
4875 if (generic_bignum[parts * 2] != 0
4876 && generic_bignum[parts * 2] != m)
4877 return FAIL;
4878
8335d6aa 4879 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4880 if (generic_bignum[j] != generic_bignum[j-1])
4881 return FAIL;
4882 }
4883
5287ad62
JB
4884 inst.operands[i].imm = 0;
4885 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4886 inst.operands[i].imm |= generic_bignum[idx]
4887 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4888 inst.operands[i].reg = 0;
4889 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4890 inst.operands[i].reg |= generic_bignum[idx]
4891 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4892 inst.operands[i].regisimm = 1;
4893 }
8335d6aa 4894 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4895 return FAIL;
5f4273c7 4896
5287ad62
JB
4897 *str = ptr;
4898
4899 return SUCCESS;
4900}
4901
c19d1205
ZW
4902/* Returns the pseudo-register number of an FPA immediate constant,
4903 or FAIL if there isn't a valid constant here. */
b99bd4ef 4904
c19d1205
ZW
4905static int
4906parse_fpa_immediate (char ** str)
4907{
4908 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4909 char * save_in;
4910 expressionS exp;
4911 int i;
4912 int j;
b99bd4ef 4913
c19d1205
ZW
4914 /* First try and match exact strings, this is to guarantee
4915 that some formats will work even for cross assembly. */
b99bd4ef 4916
c19d1205
ZW
4917 for (i = 0; fp_const[i]; i++)
4918 {
4919 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4920 {
c19d1205 4921 char *start = *str;
b99bd4ef 4922
c19d1205
ZW
4923 *str += strlen (fp_const[i]);
4924 if (is_end_of_line[(unsigned char) **str])
4925 return i + 8;
4926 *str = start;
4927 }
4928 }
b99bd4ef 4929
c19d1205
ZW
4930 /* Just because we didn't get a match doesn't mean that the constant
4931 isn't valid, just that it is in a format that we don't
4932 automatically recognize. Try parsing it with the standard
4933 expression routines. */
b99bd4ef 4934
c19d1205 4935 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4936
c19d1205
ZW
4937 /* Look for a raw floating point number. */
4938 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4939 && is_end_of_line[(unsigned char) *save_in])
4940 {
4941 for (i = 0; i < NUM_FLOAT_VALS; i++)
4942 {
4943 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4944 {
c19d1205
ZW
4945 if (words[j] != fp_values[i][j])
4946 break;
b99bd4ef
NC
4947 }
4948
c19d1205 4949 if (j == MAX_LITTLENUMS)
b99bd4ef 4950 {
c19d1205
ZW
4951 *str = save_in;
4952 return i + 8;
b99bd4ef
NC
4953 }
4954 }
4955 }
b99bd4ef 4956
c19d1205
ZW
4957 /* Try and parse a more complex expression, this will probably fail
4958 unless the code uses a floating point prefix (eg "0f"). */
4959 save_in = input_line_pointer;
4960 input_line_pointer = *str;
4961 if (expression (&exp) == absolute_section
4962 && exp.X_op == O_big
4963 && exp.X_add_number < 0)
4964 {
4965 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4966 Ditto for 15. */
ba592044
AM
4967#define X_PRECISION 5
4968#define E_PRECISION 15L
4969 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4970 {
4971 for (i = 0; i < NUM_FLOAT_VALS; i++)
4972 {
4973 for (j = 0; j < MAX_LITTLENUMS; j++)
4974 {
4975 if (words[j] != fp_values[i][j])
4976 break;
4977 }
b99bd4ef 4978
c19d1205
ZW
4979 if (j == MAX_LITTLENUMS)
4980 {
4981 *str = input_line_pointer;
4982 input_line_pointer = save_in;
4983 return i + 8;
4984 }
4985 }
4986 }
b99bd4ef
NC
4987 }
4988
c19d1205
ZW
4989 *str = input_line_pointer;
4990 input_line_pointer = save_in;
4991 inst.error = _("invalid FPA immediate expression");
4992 return FAIL;
b99bd4ef
NC
4993}
4994
136da414
JB
4995/* Returns 1 if a number has "quarter-precision" float format
4996 0baBbbbbbc defgh000 00000000 00000000. */
4997
4998static int
4999is_quarter_float (unsigned imm)
5000{
5001 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5002 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5003}
5004
aacf0b33
KT
5005
5006/* Detect the presence of a floating point or integer zero constant,
5007 i.e. #0.0 or #0. */
5008
5009static bfd_boolean
5010parse_ifimm_zero (char **in)
5011{
5012 int error_code;
5013
5014 if (!is_immediate_prefix (**in))
3c6452ae
TP
5015 {
5016 /* In unified syntax, all prefixes are optional. */
5017 if (!unified_syntax)
5018 return FALSE;
5019 }
5020 else
5021 ++*in;
0900a05b
JW
5022
5023 /* Accept #0x0 as a synonym for #0. */
5024 if (strncmp (*in, "0x", 2) == 0)
5025 {
5026 int val;
5027 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5028 return FALSE;
5029 return TRUE;
5030 }
5031
aacf0b33
KT
5032 error_code = atof_generic (in, ".", EXP_CHARS,
5033 &generic_floating_point_number);
5034
5035 if (!error_code
5036 && generic_floating_point_number.sign == '+'
5037 && (generic_floating_point_number.low
5038 > generic_floating_point_number.leader))
5039 return TRUE;
5040
5041 return FALSE;
5042}
5043
136da414
JB
5044/* Parse an 8-bit "quarter-precision" floating point number of the form:
5045 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5046 The zero and minus-zero cases need special handling, since they can't be
5047 encoded in the "quarter-precision" float format, but can nonetheless be
5048 loaded as integer constants. */
136da414
JB
5049
5050static unsigned
5051parse_qfloat_immediate (char **ccp, int *immed)
5052{
5053 char *str = *ccp;
c96612cc 5054 char *fpnum;
136da414 5055 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5056 int found_fpchar = 0;
5f4273c7 5057
136da414 5058 skip_past_char (&str, '#');
5f4273c7 5059
c96612cc
JB
5060 /* We must not accidentally parse an integer as a floating-point number. Make
5061 sure that the value we parse is not an integer by checking for special
5062 characters '.' or 'e'.
5063 FIXME: This is a horrible hack, but doing better is tricky because type
5064 information isn't in a very usable state at parse time. */
5065 fpnum = str;
5066 skip_whitespace (fpnum);
5067
5068 if (strncmp (fpnum, "0x", 2) == 0)
5069 return FAIL;
5070 else
5071 {
5072 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5073 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5074 {
5075 found_fpchar = 1;
5076 break;
5077 }
c96612cc
JB
5078
5079 if (!found_fpchar)
477330fc 5080 return FAIL;
c96612cc 5081 }
5f4273c7 5082
136da414
JB
5083 if ((str = atof_ieee (str, 's', words)) != NULL)
5084 {
5085 unsigned fpword = 0;
5086 int i;
5f4273c7 5087
136da414
JB
5088 /* Our FP word must be 32 bits (single-precision FP). */
5089 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5090 {
5091 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5092 fpword |= words[i];
5093 }
5f4273c7 5094
c96612cc 5095 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5096 *immed = fpword;
136da414 5097 else
477330fc 5098 return FAIL;
136da414
JB
5099
5100 *ccp = str;
5f4273c7 5101
136da414
JB
5102 return SUCCESS;
5103 }
5f4273c7 5104
136da414
JB
5105 return FAIL;
5106}
5107
c19d1205
ZW
5108/* Shift operands. */
5109enum shift_kind
b99bd4ef 5110{
c19d1205
ZW
5111 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5112};
b99bd4ef 5113
c19d1205
ZW
5114struct asm_shift_name
5115{
5116 const char *name;
5117 enum shift_kind kind;
5118};
b99bd4ef 5119
c19d1205
ZW
5120/* Third argument to parse_shift. */
5121enum parse_shift_mode
5122{
5123 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5124 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5125 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5126 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5127 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5128};
b99bd4ef 5129
c19d1205
ZW
5130/* Parse a <shift> specifier on an ARM data processing instruction.
5131 This has three forms:
b99bd4ef 5132
c19d1205
ZW
5133 (LSL|LSR|ASL|ASR|ROR) Rs
5134 (LSL|LSR|ASL|ASR|ROR) #imm
5135 RRX
b99bd4ef 5136
c19d1205
ZW
5137 Note that ASL is assimilated to LSL in the instruction encoding, and
5138 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5139
c19d1205
ZW
5140static int
5141parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5142{
c19d1205
ZW
5143 const struct asm_shift_name *shift_name;
5144 enum shift_kind shift;
5145 char *s = *str;
5146 char *p = s;
5147 int reg;
b99bd4ef 5148
c19d1205
ZW
5149 for (p = *str; ISALPHA (*p); p++)
5150 ;
b99bd4ef 5151
c19d1205 5152 if (p == *str)
b99bd4ef 5153 {
c19d1205
ZW
5154 inst.error = _("shift expression expected");
5155 return FAIL;
b99bd4ef
NC
5156 }
5157
21d799b5 5158 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5159 p - *str);
c19d1205
ZW
5160
5161 if (shift_name == NULL)
b99bd4ef 5162 {
c19d1205
ZW
5163 inst.error = _("shift expression expected");
5164 return FAIL;
b99bd4ef
NC
5165 }
5166
c19d1205 5167 shift = shift_name->kind;
b99bd4ef 5168
c19d1205
ZW
5169 switch (mode)
5170 {
5171 case NO_SHIFT_RESTRICT:
5172 case SHIFT_IMMEDIATE: break;
b99bd4ef 5173
c19d1205
ZW
5174 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5175 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5176 {
5177 inst.error = _("'LSL' or 'ASR' required");
5178 return FAIL;
5179 }
5180 break;
b99bd4ef 5181
c19d1205
ZW
5182 case SHIFT_LSL_IMMEDIATE:
5183 if (shift != SHIFT_LSL)
5184 {
5185 inst.error = _("'LSL' required");
5186 return FAIL;
5187 }
5188 break;
b99bd4ef 5189
c19d1205
ZW
5190 case SHIFT_ASR_IMMEDIATE:
5191 if (shift != SHIFT_ASR)
5192 {
5193 inst.error = _("'ASR' required");
5194 return FAIL;
5195 }
5196 break;
b99bd4ef 5197
c19d1205
ZW
5198 default: abort ();
5199 }
b99bd4ef 5200
c19d1205
ZW
5201 if (shift != SHIFT_RRX)
5202 {
5203 /* Whitespace can appear here if the next thing is a bare digit. */
5204 skip_whitespace (p);
b99bd4ef 5205
c19d1205 5206 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5207 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5208 {
5209 inst.operands[i].imm = reg;
5210 inst.operands[i].immisreg = 1;
5211 }
5212 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5213 return FAIL;
5214 }
5215 inst.operands[i].shift_kind = shift;
5216 inst.operands[i].shifted = 1;
5217 *str = p;
5218 return SUCCESS;
b99bd4ef
NC
5219}
5220
c19d1205 5221/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5222
c19d1205
ZW
5223 #<immediate>
5224 #<immediate>, <rotate>
5225 <Rm>
5226 <Rm>, <shift>
b99bd4ef 5227
c19d1205
ZW
5228 where <shift> is defined by parse_shift above, and <rotate> is a
5229 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5230 is deferred to md_apply_fix. */
b99bd4ef 5231
c19d1205
ZW
5232static int
5233parse_shifter_operand (char **str, int i)
5234{
5235 int value;
91d6fa6a 5236 expressionS exp;
b99bd4ef 5237
dcbf9037 5238 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5239 {
5240 inst.operands[i].reg = value;
5241 inst.operands[i].isreg = 1;
b99bd4ef 5242
c19d1205
ZW
5243 /* parse_shift will override this if appropriate */
5244 inst.reloc.exp.X_op = O_constant;
5245 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5246
c19d1205
ZW
5247 if (skip_past_comma (str) == FAIL)
5248 return SUCCESS;
b99bd4ef 5249
c19d1205
ZW
5250 /* Shift operation on register. */
5251 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5252 }
5253
c19d1205
ZW
5254 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5255 return FAIL;
b99bd4ef 5256
c19d1205 5257 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5258 {
c19d1205 5259 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5260 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5261 return FAIL;
b99bd4ef 5262
91d6fa6a 5263 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5264 {
5265 inst.error = _("constant expression expected");
5266 return FAIL;
5267 }
b99bd4ef 5268
91d6fa6a 5269 value = exp.X_add_number;
c19d1205
ZW
5270 if (value < 0 || value > 30 || value % 2 != 0)
5271 {
5272 inst.error = _("invalid rotation");
5273 return FAIL;
5274 }
5275 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5276 {
5277 inst.error = _("invalid constant");
5278 return FAIL;
5279 }
09d92015 5280
a415b1cd
JB
5281 /* Encode as specified. */
5282 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5283 return SUCCESS;
09d92015
MM
5284 }
5285
c19d1205
ZW
5286 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5287 inst.reloc.pc_rel = 0;
5288 return SUCCESS;
09d92015
MM
5289}
5290
4962c51a
MS
5291/* Group relocation information. Each entry in the table contains the
5292 textual name of the relocation as may appear in assembler source
5293 and must end with a colon.
5294 Along with this textual name are the relocation codes to be used if
5295 the corresponding instruction is an ALU instruction (ADD or SUB only),
5296 an LDR, an LDRS, or an LDC. */
5297
5298struct group_reloc_table_entry
5299{
5300 const char *name;
5301 int alu_code;
5302 int ldr_code;
5303 int ldrs_code;
5304 int ldc_code;
5305};
5306
5307typedef enum
5308{
5309 /* Varieties of non-ALU group relocation. */
5310
5311 GROUP_LDR,
5312 GROUP_LDRS,
5313 GROUP_LDC
5314} group_reloc_type;
5315
5316static struct group_reloc_table_entry group_reloc_table[] =
5317 { /* Program counter relative: */
5318 { "pc_g0_nc",
5319 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5320 0, /* LDR */
5321 0, /* LDRS */
5322 0 }, /* LDC */
5323 { "pc_g0",
5324 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5325 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5326 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5327 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5328 { "pc_g1_nc",
5329 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5330 0, /* LDR */
5331 0, /* LDRS */
5332 0 }, /* LDC */
5333 { "pc_g1",
5334 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5335 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5336 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5337 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5338 { "pc_g2",
5339 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5340 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5341 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5342 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5343 /* Section base relative */
5344 { "sb_g0_nc",
5345 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5346 0, /* LDR */
5347 0, /* LDRS */
5348 0 }, /* LDC */
5349 { "sb_g0",
5350 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5351 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5352 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5353 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5354 { "sb_g1_nc",
5355 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5356 0, /* LDR */
5357 0, /* LDRS */
5358 0 }, /* LDC */
5359 { "sb_g1",
5360 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5361 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5362 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5363 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5364 { "sb_g2",
5365 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5366 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5367 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5368 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5369 /* Absolute thumb alu relocations. */
5370 { "lower0_7",
5371 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5372 0, /* LDR. */
5373 0, /* LDRS. */
5374 0 }, /* LDC. */
5375 { "lower8_15",
5376 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5377 0, /* LDR. */
5378 0, /* LDRS. */
5379 0 }, /* LDC. */
5380 { "upper0_7",
5381 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5382 0, /* LDR. */
5383 0, /* LDRS. */
5384 0 }, /* LDC. */
5385 { "upper8_15",
5386 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5387 0, /* LDR. */
5388 0, /* LDRS. */
5389 0 } }; /* LDC. */
4962c51a
MS
5390
5391/* Given the address of a pointer pointing to the textual name of a group
5392 relocation as may appear in assembler source, attempt to find its details
5393 in group_reloc_table. The pointer will be updated to the character after
5394 the trailing colon. On failure, FAIL will be returned; SUCCESS
5395 otherwise. On success, *entry will be updated to point at the relevant
5396 group_reloc_table entry. */
5397
5398static int
5399find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5400{
5401 unsigned int i;
5402 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5403 {
5404 int length = strlen (group_reloc_table[i].name);
5405
5f4273c7
NC
5406 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5407 && (*str)[length] == ':')
477330fc
RM
5408 {
5409 *out = &group_reloc_table[i];
5410 *str += (length + 1);
5411 return SUCCESS;
5412 }
4962c51a
MS
5413 }
5414
5415 return FAIL;
5416}
5417
5418/* Parse a <shifter_operand> for an ARM data processing instruction
5419 (as for parse_shifter_operand) where group relocations are allowed:
5420
5421 #<immediate>
5422 #<immediate>, <rotate>
5423 #:<group_reloc>:<expression>
5424 <Rm>
5425 <Rm>, <shift>
5426
5427 where <group_reloc> is one of the strings defined in group_reloc_table.
5428 The hashes are optional.
5429
5430 Everything else is as for parse_shifter_operand. */
5431
5432static parse_operand_result
5433parse_shifter_operand_group_reloc (char **str, int i)
5434{
5435 /* Determine if we have the sequence of characters #: or just :
5436 coming next. If we do, then we check for a group relocation.
5437 If we don't, punt the whole lot to parse_shifter_operand. */
5438
5439 if (((*str)[0] == '#' && (*str)[1] == ':')
5440 || (*str)[0] == ':')
5441 {
5442 struct group_reloc_table_entry *entry;
5443
5444 if ((*str)[0] == '#')
477330fc 5445 (*str) += 2;
4962c51a 5446 else
477330fc 5447 (*str)++;
4962c51a
MS
5448
5449 /* Try to parse a group relocation. Anything else is an error. */
5450 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5451 {
5452 inst.error = _("unknown group relocation");
5453 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5454 }
4962c51a
MS
5455
5456 /* We now have the group relocation table entry corresponding to
477330fc 5457 the name in the assembler source. Next, we parse the expression. */
4962c51a 5458 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5459 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5460
5461 /* Record the relocation type (always the ALU variant here). */
21d799b5 5462 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5463 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5464
5465 return PARSE_OPERAND_SUCCESS;
5466 }
5467 else
5468 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5469 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5470
5471 /* Never reached. */
5472}
5473
8e560766
MGD
5474/* Parse a Neon alignment expression. Information is written to
5475 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5476
8e560766
MGD
5477 align .imm = align << 8, .immisalign=1, .preind=0 */
5478static parse_operand_result
5479parse_neon_alignment (char **str, int i)
5480{
5481 char *p = *str;
5482 expressionS exp;
5483
5484 my_get_expression (&exp, &p, GE_NO_PREFIX);
5485
5486 if (exp.X_op != O_constant)
5487 {
5488 inst.error = _("alignment must be constant");
5489 return PARSE_OPERAND_FAIL;
5490 }
5491
5492 inst.operands[i].imm = exp.X_add_number << 8;
5493 inst.operands[i].immisalign = 1;
5494 /* Alignments are not pre-indexes. */
5495 inst.operands[i].preind = 0;
5496
5497 *str = p;
5498 return PARSE_OPERAND_SUCCESS;
5499}
5500
c19d1205
ZW
5501/* Parse all forms of an ARM address expression. Information is written
5502 to inst.operands[i] and/or inst.reloc.
09d92015 5503
c19d1205 5504 Preindexed addressing (.preind=1):
09d92015 5505
c19d1205
ZW
5506 [Rn, #offset] .reg=Rn .reloc.exp=offset
5507 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5508 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5509 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5510
c19d1205 5511 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5512
c19d1205 5513 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5514
c19d1205
ZW
5515 [Rn], #offset .reg=Rn .reloc.exp=offset
5516 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5517 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5518 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5519
c19d1205 5520 Unindexed addressing (.preind=0, .postind=0):
09d92015 5521
c19d1205 5522 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5523
c19d1205 5524 Other:
09d92015 5525
c19d1205
ZW
5526 [Rn]{!} shorthand for [Rn,#0]{!}
5527 =immediate .isreg=0 .reloc.exp=immediate
5528 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5529
c19d1205
ZW
5530 It is the caller's responsibility to check for addressing modes not
5531 supported by the instruction, and to set inst.reloc.type. */
5532
4962c51a
MS
5533static parse_operand_result
5534parse_address_main (char **str, int i, int group_relocations,
477330fc 5535 group_reloc_type group_type)
09d92015 5536{
c19d1205
ZW
5537 char *p = *str;
5538 int reg;
09d92015 5539
c19d1205 5540 if (skip_past_char (&p, '[') == FAIL)
09d92015 5541 {
c19d1205
ZW
5542 if (skip_past_char (&p, '=') == FAIL)
5543 {
974da60d 5544 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5545 inst.reloc.pc_rel = 1;
5546 inst.operands[i].reg = REG_PC;
5547 inst.operands[i].isreg = 1;
5548 inst.operands[i].preind = 1;
09d92015 5549
8335d6aa
JW
5550 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5551 return PARSE_OPERAND_FAIL;
5552 }
5553 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5554 /*allow_symbol_p=*/TRUE))
4962c51a 5555 return PARSE_OPERAND_FAIL;
09d92015 5556
c19d1205 5557 *str = p;
4962c51a 5558 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5559 }
5560
8ab8155f
NC
5561 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5562 skip_whitespace (p);
5563
dcbf9037 5564 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5565 {
c19d1205 5566 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5567 return PARSE_OPERAND_FAIL;
09d92015 5568 }
c19d1205
ZW
5569 inst.operands[i].reg = reg;
5570 inst.operands[i].isreg = 1;
09d92015 5571
c19d1205 5572 if (skip_past_comma (&p) == SUCCESS)
09d92015 5573 {
c19d1205 5574 inst.operands[i].preind = 1;
09d92015 5575
c19d1205
ZW
5576 if (*p == '+') p++;
5577 else if (*p == '-') p++, inst.operands[i].negative = 1;
5578
dcbf9037 5579 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5580 {
c19d1205
ZW
5581 inst.operands[i].imm = reg;
5582 inst.operands[i].immisreg = 1;
5583
5584 if (skip_past_comma (&p) == SUCCESS)
5585 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5586 return PARSE_OPERAND_FAIL;
c19d1205 5587 }
5287ad62 5588 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5589 {
5590 /* FIXME: '@' should be used here, but it's filtered out by generic
5591 code before we get to see it here. This may be subject to
5592 change. */
5593 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5594
8e560766
MGD
5595 if (result != PARSE_OPERAND_SUCCESS)
5596 return result;
5597 }
c19d1205
ZW
5598 else
5599 {
5600 if (inst.operands[i].negative)
5601 {
5602 inst.operands[i].negative = 0;
5603 p--;
5604 }
4962c51a 5605
5f4273c7
NC
5606 if (group_relocations
5607 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5608 {
5609 struct group_reloc_table_entry *entry;
5610
477330fc
RM
5611 /* Skip over the #: or : sequence. */
5612 if (*p == '#')
5613 p += 2;
5614 else
5615 p++;
4962c51a
MS
5616
5617 /* Try to parse a group relocation. Anything else is an
477330fc 5618 error. */
4962c51a
MS
5619 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5620 {
5621 inst.error = _("unknown group relocation");
5622 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5623 }
5624
5625 /* We now have the group relocation table entry corresponding to
5626 the name in the assembler source. Next, we parse the
477330fc 5627 expression. */
4962c51a
MS
5628 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5629 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5630
5631 /* Record the relocation type. */
477330fc
RM
5632 switch (group_type)
5633 {
5634 case GROUP_LDR:
5635 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5636 break;
4962c51a 5637
477330fc
RM
5638 case GROUP_LDRS:
5639 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5640 break;
4962c51a 5641
477330fc
RM
5642 case GROUP_LDC:
5643 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5644 break;
4962c51a 5645
477330fc
RM
5646 default:
5647 gas_assert (0);
5648 }
4962c51a 5649
477330fc 5650 if (inst.reloc.type == 0)
4962c51a
MS
5651 {
5652 inst.error = _("this group relocation is not allowed on this instruction");
5653 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5654 }
477330fc
RM
5655 }
5656 else
26d97720
NS
5657 {
5658 char *q = p;
0198d5e6 5659
26d97720
NS
5660 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5661 return PARSE_OPERAND_FAIL;
5662 /* If the offset is 0, find out if it's a +0 or -0. */
5663 if (inst.reloc.exp.X_op == O_constant
5664 && inst.reloc.exp.X_add_number == 0)
5665 {
5666 skip_whitespace (q);
5667 if (*q == '#')
5668 {
5669 q++;
5670 skip_whitespace (q);
5671 }
5672 if (*q == '-')
5673 inst.operands[i].negative = 1;
5674 }
5675 }
09d92015
MM
5676 }
5677 }
8e560766
MGD
5678 else if (skip_past_char (&p, ':') == SUCCESS)
5679 {
5680 /* FIXME: '@' should be used here, but it's filtered out by generic code
5681 before we get to see it here. This may be subject to change. */
5682 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5683
8e560766
MGD
5684 if (result != PARSE_OPERAND_SUCCESS)
5685 return result;
5686 }
09d92015 5687
c19d1205 5688 if (skip_past_char (&p, ']') == FAIL)
09d92015 5689 {
c19d1205 5690 inst.error = _("']' expected");
4962c51a 5691 return PARSE_OPERAND_FAIL;
09d92015
MM
5692 }
5693
c19d1205
ZW
5694 if (skip_past_char (&p, '!') == SUCCESS)
5695 inst.operands[i].writeback = 1;
09d92015 5696
c19d1205 5697 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5698 {
c19d1205
ZW
5699 if (skip_past_char (&p, '{') == SUCCESS)
5700 {
5701 /* [Rn], {expr} - unindexed, with option */
5702 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5703 0, 255, TRUE) == FAIL)
4962c51a 5704 return PARSE_OPERAND_FAIL;
09d92015 5705
c19d1205
ZW
5706 if (skip_past_char (&p, '}') == FAIL)
5707 {
5708 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5709 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5710 }
5711 if (inst.operands[i].preind)
5712 {
5713 inst.error = _("cannot combine index with option");
4962c51a 5714 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5715 }
5716 *str = p;
4962c51a 5717 return PARSE_OPERAND_SUCCESS;
09d92015 5718 }
c19d1205
ZW
5719 else
5720 {
5721 inst.operands[i].postind = 1;
5722 inst.operands[i].writeback = 1;
09d92015 5723
c19d1205
ZW
5724 if (inst.operands[i].preind)
5725 {
5726 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5727 return PARSE_OPERAND_FAIL;
c19d1205 5728 }
09d92015 5729
c19d1205
ZW
5730 if (*p == '+') p++;
5731 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5732
dcbf9037 5733 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5734 {
477330fc
RM
5735 /* We might be using the immediate for alignment already. If we
5736 are, OR the register number into the low-order bits. */
5737 if (inst.operands[i].immisalign)
5738 inst.operands[i].imm |= reg;
5739 else
5740 inst.operands[i].imm = reg;
c19d1205 5741 inst.operands[i].immisreg = 1;
a737bd4d 5742
c19d1205
ZW
5743 if (skip_past_comma (&p) == SUCCESS)
5744 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5745 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5746 }
5747 else
5748 {
26d97720 5749 char *q = p;
0198d5e6 5750
c19d1205
ZW
5751 if (inst.operands[i].negative)
5752 {
5753 inst.operands[i].negative = 0;
5754 p--;
5755 }
5756 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5757 return PARSE_OPERAND_FAIL;
26d97720
NS
5758 /* If the offset is 0, find out if it's a +0 or -0. */
5759 if (inst.reloc.exp.X_op == O_constant
5760 && inst.reloc.exp.X_add_number == 0)
5761 {
5762 skip_whitespace (q);
5763 if (*q == '#')
5764 {
5765 q++;
5766 skip_whitespace (q);
5767 }
5768 if (*q == '-')
5769 inst.operands[i].negative = 1;
5770 }
c19d1205
ZW
5771 }
5772 }
a737bd4d
NC
5773 }
5774
c19d1205
ZW
5775 /* If at this point neither .preind nor .postind is set, we have a
5776 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5777 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5778 {
5779 inst.operands[i].preind = 1;
5780 inst.reloc.exp.X_op = O_constant;
5781 inst.reloc.exp.X_add_number = 0;
5782 }
5783 *str = p;
4962c51a
MS
5784 return PARSE_OPERAND_SUCCESS;
5785}
5786
5787static int
5788parse_address (char **str, int i)
5789{
21d799b5 5790 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5791 ? SUCCESS : FAIL;
4962c51a
MS
5792}
5793
5794static parse_operand_result
5795parse_address_group_reloc (char **str, int i, group_reloc_type type)
5796{
5797 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5798}
5799
b6895b4f
PB
5800/* Parse an operand for a MOVW or MOVT instruction. */
5801static int
5802parse_half (char **str)
5803{
5804 char * p;
5f4273c7 5805
b6895b4f
PB
5806 p = *str;
5807 skip_past_char (&p, '#');
5f4273c7 5808 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5809 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5810 else if (strncasecmp (p, ":upper16:", 9) == 0)
5811 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5812
5813 if (inst.reloc.type != BFD_RELOC_UNUSED)
5814 {
5815 p += 9;
5f4273c7 5816 skip_whitespace (p);
b6895b4f
PB
5817 }
5818
5819 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5820 return FAIL;
5821
5822 if (inst.reloc.type == BFD_RELOC_UNUSED)
5823 {
5824 if (inst.reloc.exp.X_op != O_constant)
5825 {
5826 inst.error = _("constant expression expected");
5827 return FAIL;
5828 }
5829 if (inst.reloc.exp.X_add_number < 0
5830 || inst.reloc.exp.X_add_number > 0xffff)
5831 {
5832 inst.error = _("immediate value out of range");
5833 return FAIL;
5834 }
5835 }
5836 *str = p;
5837 return SUCCESS;
5838}
5839
c19d1205 5840/* Miscellaneous. */
a737bd4d 5841
c19d1205
ZW
5842/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5843 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5844static int
d2cd1205 5845parse_psr (char **str, bfd_boolean lhs)
09d92015 5846{
c19d1205
ZW
5847 char *p;
5848 unsigned long psr_field;
62b3e311
PB
5849 const struct asm_psr *psr;
5850 char *start;
d2cd1205 5851 bfd_boolean is_apsr = FALSE;
ac7f631b 5852 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5853
a4482bb6
NC
5854 /* PR gas/12698: If the user has specified -march=all then m_profile will
5855 be TRUE, but we want to ignore it in this case as we are building for any
5856 CPU type, including non-m variants. */
823d2571 5857 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5858 m_profile = FALSE;
5859
c19d1205
ZW
5860 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5861 feature for ease of use and backwards compatibility. */
5862 p = *str;
62b3e311 5863 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5864 {
5865 if (m_profile)
5866 goto unsupported_psr;
fa94de6b 5867
d2cd1205
JB
5868 psr_field = SPSR_BIT;
5869 }
5870 else if (strncasecmp (p, "CPSR", 4) == 0)
5871 {
5872 if (m_profile)
5873 goto unsupported_psr;
5874
5875 psr_field = 0;
5876 }
5877 else if (strncasecmp (p, "APSR", 4) == 0)
5878 {
5879 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5880 and ARMv7-R architecture CPUs. */
5881 is_apsr = TRUE;
5882 psr_field = 0;
5883 }
5884 else if (m_profile)
62b3e311
PB
5885 {
5886 start = p;
5887 do
5888 p++;
5889 while (ISALNUM (*p) || *p == '_');
5890
d2cd1205
JB
5891 if (strncasecmp (start, "iapsr", 5) == 0
5892 || strncasecmp (start, "eapsr", 5) == 0
5893 || strncasecmp (start, "xpsr", 4) == 0
5894 || strncasecmp (start, "psr", 3) == 0)
5895 p = start + strcspn (start, "rR") + 1;
5896
21d799b5 5897 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5898 p - start);
d2cd1205 5899
62b3e311
PB
5900 if (!psr)
5901 return FAIL;
09d92015 5902
d2cd1205
JB
5903 /* If APSR is being written, a bitfield may be specified. Note that
5904 APSR itself is handled above. */
5905 if (psr->field <= 3)
5906 {
5907 psr_field = psr->field;
5908 is_apsr = TRUE;
5909 goto check_suffix;
5910 }
5911
62b3e311 5912 *str = p;
d2cd1205
JB
5913 /* M-profile MSR instructions have the mask field set to "10", except
5914 *PSR variants which modify APSR, which may use a different mask (and
5915 have been handled already). Do that by setting the PSR_f field
5916 here. */
5917 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5918 }
d2cd1205
JB
5919 else
5920 goto unsupported_psr;
09d92015 5921
62b3e311 5922 p += 4;
d2cd1205 5923check_suffix:
c19d1205
ZW
5924 if (*p == '_')
5925 {
5926 /* A suffix follows. */
c19d1205
ZW
5927 p++;
5928 start = p;
a737bd4d 5929
c19d1205
ZW
5930 do
5931 p++;
5932 while (ISALNUM (*p) || *p == '_');
a737bd4d 5933
d2cd1205
JB
5934 if (is_apsr)
5935 {
5936 /* APSR uses a notation for bits, rather than fields. */
5937 unsigned int nzcvq_bits = 0;
5938 unsigned int g_bit = 0;
5939 char *bit;
fa94de6b 5940
d2cd1205
JB
5941 for (bit = start; bit != p; bit++)
5942 {
5943 switch (TOLOWER (*bit))
477330fc 5944 {
d2cd1205
JB
5945 case 'n':
5946 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5947 break;
5948
5949 case 'z':
5950 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5951 break;
5952
5953 case 'c':
5954 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5955 break;
5956
5957 case 'v':
5958 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5959 break;
fa94de6b 5960
d2cd1205
JB
5961 case 'q':
5962 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5963 break;
fa94de6b 5964
d2cd1205
JB
5965 case 'g':
5966 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5967 break;
fa94de6b 5968
d2cd1205
JB
5969 default:
5970 inst.error = _("unexpected bit specified after APSR");
5971 return FAIL;
5972 }
5973 }
fa94de6b 5974
d2cd1205
JB
5975 if (nzcvq_bits == 0x1f)
5976 psr_field |= PSR_f;
fa94de6b 5977
d2cd1205
JB
5978 if (g_bit == 0x1)
5979 {
5980 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5981 {
d2cd1205
JB
5982 inst.error = _("selected processor does not "
5983 "support DSP extension");
5984 return FAIL;
5985 }
5986
5987 psr_field |= PSR_s;
5988 }
fa94de6b 5989
d2cd1205
JB
5990 if ((nzcvq_bits & 0x20) != 0
5991 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5992 || (g_bit & 0x2) != 0)
5993 {
5994 inst.error = _("bad bitmask specified after APSR");
5995 return FAIL;
5996 }
5997 }
5998 else
477330fc 5999 {
d2cd1205 6000 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 6001 p - start);
d2cd1205 6002 if (!psr)
477330fc 6003 goto error;
a737bd4d 6004
d2cd1205
JB
6005 psr_field |= psr->field;
6006 }
a737bd4d 6007 }
c19d1205 6008 else
a737bd4d 6009 {
c19d1205
ZW
6010 if (ISALNUM (*p))
6011 goto error; /* Garbage after "[CS]PSR". */
6012
d2cd1205 6013 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 6014 is deprecated, but allow it anyway. */
d2cd1205
JB
6015 if (is_apsr && lhs)
6016 {
6017 psr_field |= PSR_f;
6018 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6019 "deprecated"));
6020 }
6021 else if (!m_profile)
6022 /* These bits are never right for M-profile devices: don't set them
6023 (only code paths which read/write APSR reach here). */
6024 psr_field |= (PSR_c | PSR_f);
a737bd4d 6025 }
c19d1205
ZW
6026 *str = p;
6027 return psr_field;
a737bd4d 6028
d2cd1205
JB
6029 unsupported_psr:
6030 inst.error = _("selected processor does not support requested special "
6031 "purpose register");
6032 return FAIL;
6033
c19d1205
ZW
6034 error:
6035 inst.error = _("flag for {c}psr instruction expected");
6036 return FAIL;
a737bd4d
NC
6037}
6038
c19d1205
ZW
6039/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6040 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6041
c19d1205
ZW
6042static int
6043parse_cps_flags (char **str)
a737bd4d 6044{
c19d1205
ZW
6045 int val = 0;
6046 int saw_a_flag = 0;
6047 char *s = *str;
a737bd4d 6048
c19d1205
ZW
6049 for (;;)
6050 switch (*s++)
6051 {
6052 case '\0': case ',':
6053 goto done;
a737bd4d 6054
c19d1205
ZW
6055 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6056 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6057 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6058
c19d1205
ZW
6059 default:
6060 inst.error = _("unrecognized CPS flag");
6061 return FAIL;
6062 }
a737bd4d 6063
c19d1205
ZW
6064 done:
6065 if (saw_a_flag == 0)
a737bd4d 6066 {
c19d1205
ZW
6067 inst.error = _("missing CPS flags");
6068 return FAIL;
a737bd4d 6069 }
a737bd4d 6070
c19d1205
ZW
6071 *str = s - 1;
6072 return val;
a737bd4d
NC
6073}
6074
c19d1205
ZW
6075/* Parse an endian specifier ("BE" or "LE", case insensitive);
6076 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6077
6078static int
c19d1205 6079parse_endian_specifier (char **str)
a737bd4d 6080{
c19d1205
ZW
6081 int little_endian;
6082 char *s = *str;
a737bd4d 6083
c19d1205
ZW
6084 if (strncasecmp (s, "BE", 2))
6085 little_endian = 0;
6086 else if (strncasecmp (s, "LE", 2))
6087 little_endian = 1;
6088 else
a737bd4d 6089 {
c19d1205 6090 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6091 return FAIL;
6092 }
6093
c19d1205 6094 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6095 {
c19d1205 6096 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6097 return FAIL;
6098 }
6099
c19d1205
ZW
6100 *str = s + 2;
6101 return little_endian;
6102}
a737bd4d 6103
c19d1205
ZW
6104/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6105 value suitable for poking into the rotate field of an sxt or sxta
6106 instruction, or FAIL on error. */
6107
6108static int
6109parse_ror (char **str)
6110{
6111 int rot;
6112 char *s = *str;
6113
6114 if (strncasecmp (s, "ROR", 3) == 0)
6115 s += 3;
6116 else
a737bd4d 6117 {
c19d1205 6118 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6119 return FAIL;
6120 }
c19d1205
ZW
6121
6122 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6123 return FAIL;
6124
6125 switch (rot)
a737bd4d 6126 {
c19d1205
ZW
6127 case 0: *str = s; return 0x0;
6128 case 8: *str = s; return 0x1;
6129 case 16: *str = s; return 0x2;
6130 case 24: *str = s; return 0x3;
6131
6132 default:
6133 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6134 return FAIL;
6135 }
c19d1205 6136}
a737bd4d 6137
c19d1205
ZW
6138/* Parse a conditional code (from conds[] below). The value returned is in the
6139 range 0 .. 14, or FAIL. */
6140static int
6141parse_cond (char **str)
6142{
c462b453 6143 char *q;
c19d1205 6144 const struct asm_cond *c;
c462b453
PB
6145 int n;
6146 /* Condition codes are always 2 characters, so matching up to
6147 3 characters is sufficient. */
6148 char cond[3];
a737bd4d 6149
c462b453
PB
6150 q = *str;
6151 n = 0;
6152 while (ISALPHA (*q) && n < 3)
6153 {
e07e6e58 6154 cond[n] = TOLOWER (*q);
c462b453
PB
6155 q++;
6156 n++;
6157 }
a737bd4d 6158
21d799b5 6159 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6160 if (!c)
a737bd4d 6161 {
c19d1205 6162 inst.error = _("condition required");
a737bd4d
NC
6163 return FAIL;
6164 }
6165
c19d1205
ZW
6166 *str = q;
6167 return c->value;
6168}
6169
643afb90
MW
6170/* Record a use of the given feature. */
6171static void
6172record_feature_use (const arm_feature_set *feature)
6173{
6174 if (thumb_mode)
6175 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6176 else
6177 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6178}
6179
4d354d8b
TP
6180/* If the given feature is currently allowed, mark it as used and return TRUE.
6181 Return FALSE otherwise. */
e797f7e0
MGD
6182static bfd_boolean
6183mark_feature_used (const arm_feature_set *feature)
6184{
4d354d8b 6185 /* Ensure the option is currently allowed. */
e797f7e0
MGD
6186 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6187 return FALSE;
6188
4d354d8b 6189 /* Add the appropriate architecture feature for the barrier option used. */
643afb90 6190 record_feature_use (feature);
e797f7e0
MGD
6191
6192 return TRUE;
6193}
6194
62b3e311
PB
6195/* Parse an option for a barrier instruction. Returns the encoding for the
6196 option, or FAIL. */
6197static int
6198parse_barrier (char **str)
6199{
6200 char *p, *q;
6201 const struct asm_barrier_opt *o;
6202
6203 p = q = *str;
6204 while (ISALPHA (*q))
6205 q++;
6206
21d799b5 6207 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6208 q - p);
62b3e311
PB
6209 if (!o)
6210 return FAIL;
6211
e797f7e0
MGD
6212 if (!mark_feature_used (&o->arch))
6213 return FAIL;
6214
62b3e311
PB
6215 *str = q;
6216 return o->value;
6217}
6218
92e90b6e
PB
6219/* Parse the operands of a table branch instruction. Similar to a memory
6220 operand. */
6221static int
6222parse_tb (char **str)
6223{
6224 char * p = *str;
6225 int reg;
6226
6227 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6228 {
6229 inst.error = _("'[' expected");
6230 return FAIL;
6231 }
92e90b6e 6232
dcbf9037 6233 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6234 {
6235 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6236 return FAIL;
6237 }
6238 inst.operands[0].reg = reg;
6239
6240 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6241 {
6242 inst.error = _("',' expected");
6243 return FAIL;
6244 }
5f4273c7 6245
dcbf9037 6246 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6247 {
6248 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6249 return FAIL;
6250 }
6251 inst.operands[0].imm = reg;
6252
6253 if (skip_past_comma (&p) == SUCCESS)
6254 {
6255 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6256 return FAIL;
6257 if (inst.reloc.exp.X_add_number != 1)
6258 {
6259 inst.error = _("invalid shift");
6260 return FAIL;
6261 }
6262 inst.operands[0].shifted = 1;
6263 }
6264
6265 if (skip_past_char (&p, ']') == FAIL)
6266 {
6267 inst.error = _("']' expected");
6268 return FAIL;
6269 }
6270 *str = p;
6271 return SUCCESS;
6272}
6273
5287ad62
JB
6274/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6275 information on the types the operands can take and how they are encoded.
037e8744
JB
6276 Up to four operands may be read; this function handles setting the
6277 ".present" field for each read operand itself.
5287ad62
JB
6278 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6279 else returns FAIL. */
6280
6281static int
6282parse_neon_mov (char **str, int *which_operand)
6283{
6284 int i = *which_operand, val;
6285 enum arm_reg_type rtype;
6286 char *ptr = *str;
dcbf9037 6287 struct neon_type_el optype;
5f4273c7 6288
dcbf9037 6289 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6290 {
6291 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6292 inst.operands[i].reg = val;
6293 inst.operands[i].isscalar = 1;
dcbf9037 6294 inst.operands[i].vectype = optype;
5287ad62
JB
6295 inst.operands[i++].present = 1;
6296
6297 if (skip_past_comma (&ptr) == FAIL)
477330fc 6298 goto wanted_comma;
5f4273c7 6299
dcbf9037 6300 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6301 goto wanted_arm;
5f4273c7 6302
5287ad62
JB
6303 inst.operands[i].reg = val;
6304 inst.operands[i].isreg = 1;
6305 inst.operands[i].present = 1;
6306 }
037e8744 6307 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6308 != FAIL)
5287ad62
JB
6309 {
6310 /* Cases 0, 1, 2, 3, 5 (D only). */
6311 if (skip_past_comma (&ptr) == FAIL)
477330fc 6312 goto wanted_comma;
5f4273c7 6313
5287ad62
JB
6314 inst.operands[i].reg = val;
6315 inst.operands[i].isreg = 1;
6316 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6317 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6318 inst.operands[i].isvec = 1;
dcbf9037 6319 inst.operands[i].vectype = optype;
5287ad62
JB
6320 inst.operands[i++].present = 1;
6321
dcbf9037 6322 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6323 {
6324 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6325 Case 13: VMOV <Sd>, <Rm> */
6326 inst.operands[i].reg = val;
6327 inst.operands[i].isreg = 1;
6328 inst.operands[i].present = 1;
6329
6330 if (rtype == REG_TYPE_NQ)
6331 {
6332 first_error (_("can't use Neon quad register here"));
6333 return FAIL;
6334 }
6335 else if (rtype != REG_TYPE_VFS)
6336 {
6337 i++;
6338 if (skip_past_comma (&ptr) == FAIL)
6339 goto wanted_comma;
6340 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6341 goto wanted_arm;
6342 inst.operands[i].reg = val;
6343 inst.operands[i].isreg = 1;
6344 inst.operands[i].present = 1;
6345 }
6346 }
037e8744 6347 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6348 &optype)) != FAIL)
6349 {
6350 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6351 Case 1: VMOV<c><q> <Dd>, <Dm>
6352 Case 8: VMOV.F32 <Sd>, <Sm>
6353 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6354
6355 inst.operands[i].reg = val;
6356 inst.operands[i].isreg = 1;
6357 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6358 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6359 inst.operands[i].isvec = 1;
6360 inst.operands[i].vectype = optype;
6361 inst.operands[i].present = 1;
6362
6363 if (skip_past_comma (&ptr) == SUCCESS)
6364 {
6365 /* Case 15. */
6366 i++;
6367
6368 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6369 goto wanted_arm;
6370
6371 inst.operands[i].reg = val;
6372 inst.operands[i].isreg = 1;
6373 inst.operands[i++].present = 1;
6374
6375 if (skip_past_comma (&ptr) == FAIL)
6376 goto wanted_comma;
6377
6378 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6379 goto wanted_arm;
6380
6381 inst.operands[i].reg = val;
6382 inst.operands[i].isreg = 1;
6383 inst.operands[i].present = 1;
6384 }
6385 }
4641781c 6386 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6387 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6388 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6389 Case 10: VMOV.F32 <Sd>, #<imm>
6390 Case 11: VMOV.F64 <Dd>, #<imm> */
6391 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6392 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6393 == SUCCESS)
477330fc
RM
6394 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6395 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6396 ;
5287ad62 6397 else
477330fc
RM
6398 {
6399 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6400 return FAIL;
6401 }
5287ad62 6402 }
dcbf9037 6403 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6404 {
6405 /* Cases 6, 7. */
6406 inst.operands[i].reg = val;
6407 inst.operands[i].isreg = 1;
6408 inst.operands[i++].present = 1;
5f4273c7 6409
5287ad62 6410 if (skip_past_comma (&ptr) == FAIL)
477330fc 6411 goto wanted_comma;
5f4273c7 6412
dcbf9037 6413 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6414 {
6415 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6416 inst.operands[i].reg = val;
6417 inst.operands[i].isscalar = 1;
6418 inst.operands[i].present = 1;
6419 inst.operands[i].vectype = optype;
6420 }
dcbf9037 6421 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6422 {
6423 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6424 inst.operands[i].reg = val;
6425 inst.operands[i].isreg = 1;
6426 inst.operands[i++].present = 1;
6427
6428 if (skip_past_comma (&ptr) == FAIL)
6429 goto wanted_comma;
6430
6431 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6432 == FAIL)
6433 {
6434 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6435 return FAIL;
6436 }
6437
6438 inst.operands[i].reg = val;
6439 inst.operands[i].isreg = 1;
6440 inst.operands[i].isvec = 1;
6441 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6442 inst.operands[i].vectype = optype;
6443 inst.operands[i].present = 1;
6444
6445 if (rtype == REG_TYPE_VFS)
6446 {
6447 /* Case 14. */
6448 i++;
6449 if (skip_past_comma (&ptr) == FAIL)
6450 goto wanted_comma;
6451 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6452 &optype)) == FAIL)
6453 {
6454 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6455 return FAIL;
6456 }
6457 inst.operands[i].reg = val;
6458 inst.operands[i].isreg = 1;
6459 inst.operands[i].isvec = 1;
6460 inst.operands[i].issingle = 1;
6461 inst.operands[i].vectype = optype;
6462 inst.operands[i].present = 1;
6463 }
6464 }
037e8744 6465 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6466 != FAIL)
6467 {
6468 /* Case 13. */
6469 inst.operands[i].reg = val;
6470 inst.operands[i].isreg = 1;
6471 inst.operands[i].isvec = 1;
6472 inst.operands[i].issingle = 1;
6473 inst.operands[i].vectype = optype;
6474 inst.operands[i].present = 1;
6475 }
5287ad62
JB
6476 }
6477 else
6478 {
dcbf9037 6479 first_error (_("parse error"));
5287ad62
JB
6480 return FAIL;
6481 }
6482
6483 /* Successfully parsed the operands. Update args. */
6484 *which_operand = i;
6485 *str = ptr;
6486 return SUCCESS;
6487
5f4273c7 6488 wanted_comma:
dcbf9037 6489 first_error (_("expected comma"));
5287ad62 6490 return FAIL;
5f4273c7
NC
6491
6492 wanted_arm:
dcbf9037 6493 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6494 return FAIL;
5287ad62
JB
6495}
6496
5be8be5d
DG
6497/* Use this macro when the operand constraints are different
6498 for ARM and THUMB (e.g. ldrd). */
6499#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6500 ((arm_operand) | ((thumb_operand) << 16))
6501
c19d1205
ZW
6502/* Matcher codes for parse_operands. */
6503enum operand_parse_code
6504{
6505 OP_stop, /* end of line */
6506
6507 OP_RR, /* ARM register */
6508 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6509 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6510 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6511 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6512 optional trailing ! */
c19d1205
ZW
6513 OP_RRw, /* ARM register, not r15, optional trailing ! */
6514 OP_RCP, /* Coprocessor number */
6515 OP_RCN, /* Coprocessor register */
6516 OP_RF, /* FPA register */
6517 OP_RVS, /* VFP single precision register */
5287ad62
JB
6518 OP_RVD, /* VFP double precision register (0..15) */
6519 OP_RND, /* Neon double precision register (0..31) */
6520 OP_RNQ, /* Neon quad precision register */
037e8744 6521 OP_RVSD, /* VFP single or double precision register */
dec41383 6522 OP_RNSD, /* Neon single or double precision register */
5287ad62 6523 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6524 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6525 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6526 OP_RVC, /* VFP control register */
6527 OP_RMF, /* Maverick F register */
6528 OP_RMD, /* Maverick D register */
6529 OP_RMFX, /* Maverick FX register */
6530 OP_RMDX, /* Maverick DX register */
6531 OP_RMAX, /* Maverick AX register */
6532 OP_RMDS, /* Maverick DSPSC register */
6533 OP_RIWR, /* iWMMXt wR register */
6534 OP_RIWC, /* iWMMXt wC register */
6535 OP_RIWG, /* iWMMXt wCG register */
6536 OP_RXA, /* XScale accumulator register */
6537
6538 OP_REGLST, /* ARM register list */
6539 OP_VRSLST, /* VFP single-precision register list */
6540 OP_VRDLST, /* VFP double-precision register list */
037e8744 6541 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6542 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6543 OP_NSTRLST, /* Neon element/structure list */
6544
5287ad62 6545 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6546 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6547 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6548 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 6549 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 6550 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6551 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6552 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6553 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6554 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6555 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6556 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6557
6558 OP_I0, /* immediate zero */
c19d1205
ZW
6559 OP_I7, /* immediate value 0 .. 7 */
6560 OP_I15, /* 0 .. 15 */
6561 OP_I16, /* 1 .. 16 */
5287ad62 6562 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6563 OP_I31, /* 0 .. 31 */
6564 OP_I31w, /* 0 .. 31, optional trailing ! */
6565 OP_I32, /* 1 .. 32 */
5287ad62
JB
6566 OP_I32z, /* 0 .. 32 */
6567 OP_I63, /* 0 .. 63 */
c19d1205 6568 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6569 OP_I64, /* 1 .. 64 */
6570 OP_I64z, /* 0 .. 64 */
c19d1205 6571 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6572
6573 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6574 OP_I7b, /* 0 .. 7 */
6575 OP_I15b, /* 0 .. 15 */
6576 OP_I31b, /* 0 .. 31 */
6577
6578 OP_SH, /* shifter operand */
4962c51a 6579 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6580 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6581 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6582 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6583 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6584 OP_EXP, /* arbitrary expression */
6585 OP_EXPi, /* same, with optional immediate prefix */
6586 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6587 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
6588 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6589 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
6590
6591 OP_CPSF, /* CPS flags */
6592 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6593 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6594 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6595 OP_COND, /* conditional code */
92e90b6e 6596 OP_TB, /* Table branch. */
c19d1205 6597
037e8744
JB
6598 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6599
c19d1205 6600 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 6601 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
6602 OP_RR_EXi, /* ARM register or expression with imm prefix */
6603 OP_RF_IF, /* FPA register or immediate */
6604 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6605 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6606
6607 /* Optional operands. */
6608 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6609 OP_oI31b, /* 0 .. 31 */
5287ad62 6610 OP_oI32b, /* 1 .. 32 */
5f1af56b 6611 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6612 OP_oIffffb, /* 0 .. 65535 */
6613 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6614
6615 OP_oRR, /* ARM register */
6616 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6617 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6618 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6619 OP_oRND, /* Optional Neon double precision register */
6620 OP_oRNQ, /* Optional Neon quad precision register */
6621 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6622 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6623 OP_oSHll, /* LSL immediate */
6624 OP_oSHar, /* ASR immediate */
6625 OP_oSHllar, /* LSL or ASR immediate */
6626 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6627 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6628
5be8be5d
DG
6629 /* Some pre-defined mixed (ARM/THUMB) operands. */
6630 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6631 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6632 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6633
c19d1205
ZW
6634 OP_FIRST_OPTIONAL = OP_oI7b
6635};
a737bd4d 6636
c19d1205
ZW
6637/* Generic instruction operand parser. This does no encoding and no
6638 semantic validation; it merely squirrels values away in the inst
6639 structure. Returns SUCCESS or FAIL depending on whether the
6640 specified grammar matched. */
6641static int
5be8be5d 6642parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6643{
5be8be5d 6644 unsigned const int *upat = pattern;
c19d1205
ZW
6645 char *backtrack_pos = 0;
6646 const char *backtrack_error = 0;
99aad254 6647 int i, val = 0, backtrack_index = 0;
5287ad62 6648 enum arm_reg_type rtype;
4962c51a 6649 parse_operand_result result;
5be8be5d 6650 unsigned int op_parse_code;
c19d1205 6651
e07e6e58
NC
6652#define po_char_or_fail(chr) \
6653 do \
6654 { \
6655 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6656 goto bad_args; \
e07e6e58
NC
6657 } \
6658 while (0)
c19d1205 6659
e07e6e58
NC
6660#define po_reg_or_fail(regtype) \
6661 do \
dcbf9037 6662 { \
e07e6e58 6663 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6664 & inst.operands[i].vectype); \
e07e6e58 6665 if (val == FAIL) \
477330fc
RM
6666 { \
6667 first_error (_(reg_expected_msgs[regtype])); \
6668 goto failure; \
6669 } \
e07e6e58
NC
6670 inst.operands[i].reg = val; \
6671 inst.operands[i].isreg = 1; \
6672 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6673 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6674 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6675 || rtype == REG_TYPE_VFD \
6676 || rtype == REG_TYPE_NQ); \
dcbf9037 6677 } \
e07e6e58
NC
6678 while (0)
6679
6680#define po_reg_or_goto(regtype, label) \
6681 do \
6682 { \
6683 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6684 & inst.operands[i].vectype); \
6685 if (val == FAIL) \
6686 goto label; \
dcbf9037 6687 \
e07e6e58
NC
6688 inst.operands[i].reg = val; \
6689 inst.operands[i].isreg = 1; \
6690 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6691 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6692 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6693 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6694 || rtype == REG_TYPE_NQ); \
6695 } \
6696 while (0)
6697
6698#define po_imm_or_fail(min, max, popt) \
6699 do \
6700 { \
6701 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6702 goto failure; \
6703 inst.operands[i].imm = val; \
6704 } \
6705 while (0)
6706
6707#define po_scalar_or_goto(elsz, label) \
6708 do \
6709 { \
6710 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6711 if (val == FAIL) \
6712 goto label; \
6713 inst.operands[i].reg = val; \
6714 inst.operands[i].isscalar = 1; \
6715 } \
6716 while (0)
6717
6718#define po_misc_or_fail(expr) \
6719 do \
6720 { \
6721 if (expr) \
6722 goto failure; \
6723 } \
6724 while (0)
6725
6726#define po_misc_or_fail_no_backtrack(expr) \
6727 do \
6728 { \
6729 result = expr; \
6730 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6731 backtrack_pos = 0; \
6732 if (result != PARSE_OPERAND_SUCCESS) \
6733 goto failure; \
6734 } \
6735 while (0)
4962c51a 6736
52e7f43d
RE
6737#define po_barrier_or_imm(str) \
6738 do \
6739 { \
6740 val = parse_barrier (&str); \
ccb84d65
JB
6741 if (val == FAIL && ! ISALPHA (*str)) \
6742 goto immediate; \
6743 if (val == FAIL \
6744 /* ISB can only take SY as an option. */ \
6745 || ((inst.instruction & 0xf0) == 0x60 \
6746 && val != 0xf)) \
52e7f43d 6747 { \
ccb84d65
JB
6748 inst.error = _("invalid barrier type"); \
6749 backtrack_pos = 0; \
6750 goto failure; \
52e7f43d
RE
6751 } \
6752 } \
6753 while (0)
6754
c19d1205
ZW
6755 skip_whitespace (str);
6756
6757 for (i = 0; upat[i] != OP_stop; i++)
6758 {
5be8be5d
DG
6759 op_parse_code = upat[i];
6760 if (op_parse_code >= 1<<16)
6761 op_parse_code = thumb ? (op_parse_code >> 16)
6762 : (op_parse_code & ((1<<16)-1));
6763
6764 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6765 {
6766 /* Remember where we are in case we need to backtrack. */
9c2799c2 6767 gas_assert (!backtrack_pos);
c19d1205
ZW
6768 backtrack_pos = str;
6769 backtrack_error = inst.error;
6770 backtrack_index = i;
6771 }
6772
b6702015 6773 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6774 po_char_or_fail (',');
6775
5be8be5d 6776 switch (op_parse_code)
c19d1205
ZW
6777 {
6778 /* Registers */
6779 case OP_oRRnpc:
5be8be5d 6780 case OP_oRRnpcsp:
c19d1205 6781 case OP_RRnpc:
5be8be5d 6782 case OP_RRnpcsp:
c19d1205
ZW
6783 case OP_oRR:
6784 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6785 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6786 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6787 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6788 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6789 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6790 case OP_oRND:
5287ad62 6791 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6792 case OP_RVC:
6793 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6794 break;
6795 /* Also accept generic coprocessor regs for unknown registers. */
6796 coproc_reg:
6797 po_reg_or_fail (REG_TYPE_CN);
6798 break;
c19d1205
ZW
6799 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6800 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6801 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6802 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6803 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6804 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6805 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6806 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6807 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6808 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6809 case OP_oRNQ:
5287ad62 6810 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 6811 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
477330fc 6812 case OP_oRNDQ:
5287ad62 6813 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6814 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6815 case OP_oRNSDQ:
6816 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6817
6818 /* Neon scalar. Using an element size of 8 means that some invalid
6819 scalars are accepted here, so deal with those in later code. */
6820 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6821
6822 case OP_RNDQ_I0:
6823 {
6824 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6825 break;
6826 try_imm0:
6827 po_imm_or_fail (0, 0, TRUE);
6828 }
6829 break;
6830
6831 case OP_RVSD_I0:
6832 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6833 break;
6834
aacf0b33
KT
6835 case OP_RSVD_FI0:
6836 {
6837 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6838 break;
6839 try_ifimm0:
6840 if (parse_ifimm_zero (&str))
6841 inst.operands[i].imm = 0;
6842 else
6843 {
6844 inst.error
6845 = _("only floating point zero is allowed as immediate value");
6846 goto failure;
6847 }
6848 }
6849 break;
6850
477330fc
RM
6851 case OP_RR_RNSC:
6852 {
6853 po_scalar_or_goto (8, try_rr);
6854 break;
6855 try_rr:
6856 po_reg_or_fail (REG_TYPE_RN);
6857 }
6858 break;
6859
6860 case OP_RNSDQ_RNSC:
6861 {
6862 po_scalar_or_goto (8, try_nsdq);
6863 break;
6864 try_nsdq:
6865 po_reg_or_fail (REG_TYPE_NSDQ);
6866 }
6867 break;
6868
dec41383
JW
6869 case OP_RNSD_RNSC:
6870 {
6871 po_scalar_or_goto (8, try_s_scalar);
6872 break;
6873 try_s_scalar:
6874 po_scalar_or_goto (4, try_nsd);
6875 break;
6876 try_nsd:
6877 po_reg_or_fail (REG_TYPE_NSD);
6878 }
6879 break;
6880
477330fc
RM
6881 case OP_RNDQ_RNSC:
6882 {
6883 po_scalar_or_goto (8, try_ndq);
6884 break;
6885 try_ndq:
6886 po_reg_or_fail (REG_TYPE_NDQ);
6887 }
6888 break;
6889
6890 case OP_RND_RNSC:
6891 {
6892 po_scalar_or_goto (8, try_vfd);
6893 break;
6894 try_vfd:
6895 po_reg_or_fail (REG_TYPE_VFD);
6896 }
6897 break;
6898
6899 case OP_VMOV:
6900 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6901 not careful then bad things might happen. */
6902 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6903 break;
6904
6905 case OP_RNDQ_Ibig:
6906 {
6907 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6908 break;
6909 try_immbig:
6910 /* There's a possibility of getting a 64-bit immediate here, so
6911 we need special handling. */
8335d6aa
JW
6912 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6913 == FAIL)
477330fc
RM
6914 {
6915 inst.error = _("immediate value is out of range");
6916 goto failure;
6917 }
6918 }
6919 break;
6920
6921 case OP_RNDQ_I63b:
6922 {
6923 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6924 break;
6925 try_shimm:
6926 po_imm_or_fail (0, 63, TRUE);
6927 }
6928 break;
c19d1205
ZW
6929
6930 case OP_RRnpcb:
6931 po_char_or_fail ('[');
6932 po_reg_or_fail (REG_TYPE_RN);
6933 po_char_or_fail (']');
6934 break;
a737bd4d 6935
55881a11 6936 case OP_RRnpctw:
c19d1205 6937 case OP_RRw:
b6702015 6938 case OP_oRRw:
c19d1205
ZW
6939 po_reg_or_fail (REG_TYPE_RN);
6940 if (skip_past_char (&str, '!') == SUCCESS)
6941 inst.operands[i].writeback = 1;
6942 break;
6943
6944 /* Immediates */
6945 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6946 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6947 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6948 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6949 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6950 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6951 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6952 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6953 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6954 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6955 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6956 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6957
6958 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6959 case OP_oI7b:
6960 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6961 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6962 case OP_oI31b:
6963 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6964 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6965 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6966 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6967
6968 /* Immediate variants */
6969 case OP_oI255c:
6970 po_char_or_fail ('{');
6971 po_imm_or_fail (0, 255, TRUE);
6972 po_char_or_fail ('}');
6973 break;
6974
6975 case OP_I31w:
6976 /* The expression parser chokes on a trailing !, so we have
6977 to find it first and zap it. */
6978 {
6979 char *s = str;
6980 while (*s && *s != ',')
6981 s++;
6982 if (s[-1] == '!')
6983 {
6984 s[-1] = '\0';
6985 inst.operands[i].writeback = 1;
6986 }
6987 po_imm_or_fail (0, 31, TRUE);
6988 if (str == s - 1)
6989 str = s;
6990 }
6991 break;
6992
6993 /* Expressions */
6994 case OP_EXPi: EXPi:
6995 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6996 GE_OPT_PREFIX));
6997 break;
6998
6999 case OP_EXP:
7000 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
7001 GE_NO_PREFIX));
7002 break;
7003
7004 case OP_EXPr: EXPr:
7005 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
7006 GE_NO_PREFIX));
7007 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 7008 {
c19d1205
ZW
7009 val = parse_reloc (&str);
7010 if (val == -1)
7011 {
7012 inst.error = _("unrecognized relocation suffix");
7013 goto failure;
7014 }
7015 else if (val != BFD_RELOC_UNUSED)
7016 {
7017 inst.operands[i].imm = val;
7018 inst.operands[i].hasreloc = 1;
7019 }
a737bd4d 7020 }
c19d1205 7021 break;
a737bd4d 7022
b6895b4f
PB
7023 /* Operand for MOVW or MOVT. */
7024 case OP_HALF:
7025 po_misc_or_fail (parse_half (&str));
7026 break;
7027
e07e6e58 7028 /* Register or expression. */
c19d1205
ZW
7029 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7030 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7031
e07e6e58 7032 /* Register or immediate. */
c19d1205
ZW
7033 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7034 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7035
c19d1205
ZW
7036 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7037 IF:
7038 if (!is_immediate_prefix (*str))
7039 goto bad_args;
7040 str++;
7041 val = parse_fpa_immediate (&str);
7042 if (val == FAIL)
7043 goto failure;
7044 /* FPA immediates are encoded as registers 8-15.
7045 parse_fpa_immediate has already applied the offset. */
7046 inst.operands[i].reg = val;
7047 inst.operands[i].isreg = 1;
7048 break;
09d92015 7049
2d447fca
JM
7050 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7051 I32z: po_imm_or_fail (0, 32, FALSE); break;
7052
e07e6e58 7053 /* Two kinds of register. */
c19d1205
ZW
7054 case OP_RIWR_RIWC:
7055 {
7056 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7057 if (!rege
7058 || (rege->type != REG_TYPE_MMXWR
7059 && rege->type != REG_TYPE_MMXWC
7060 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7061 {
7062 inst.error = _("iWMMXt data or control register expected");
7063 goto failure;
7064 }
7065 inst.operands[i].reg = rege->number;
7066 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7067 }
7068 break;
09d92015 7069
41adaa5c
JM
7070 case OP_RIWC_RIWG:
7071 {
7072 struct reg_entry *rege = arm_reg_parse_multi (&str);
7073 if (!rege
7074 || (rege->type != REG_TYPE_MMXWC
7075 && rege->type != REG_TYPE_MMXWCG))
7076 {
7077 inst.error = _("iWMMXt control register expected");
7078 goto failure;
7079 }
7080 inst.operands[i].reg = rege->number;
7081 inst.operands[i].isreg = 1;
7082 }
7083 break;
7084
c19d1205
ZW
7085 /* Misc */
7086 case OP_CPSF: val = parse_cps_flags (&str); break;
7087 case OP_ENDI: val = parse_endian_specifier (&str); break;
7088 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7089 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7090 case OP_oBARRIER_I15:
7091 po_barrier_or_imm (str); break;
7092 immediate:
7093 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7094 goto failure;
52e7f43d 7095 break;
c19d1205 7096
fa94de6b 7097 case OP_wPSR:
d2cd1205 7098 case OP_rPSR:
90ec0d68
MGD
7099 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7100 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7101 {
7102 inst.error = _("Banked registers are not available with this "
7103 "architecture.");
7104 goto failure;
7105 }
7106 break;
d2cd1205
JB
7107 try_psr:
7108 val = parse_psr (&str, op_parse_code == OP_wPSR);
7109 break;
037e8744 7110
477330fc
RM
7111 case OP_APSR_RR:
7112 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7113 break;
7114 try_apsr:
7115 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7116 instruction). */
7117 if (strncasecmp (str, "APSR_", 5) == 0)
7118 {
7119 unsigned found = 0;
7120 str += 5;
7121 while (found < 15)
7122 switch (*str++)
7123 {
7124 case 'c': found = (found & 1) ? 16 : found | 1; break;
7125 case 'n': found = (found & 2) ? 16 : found | 2; break;
7126 case 'z': found = (found & 4) ? 16 : found | 4; break;
7127 case 'v': found = (found & 8) ? 16 : found | 8; break;
7128 default: found = 16;
7129 }
7130 if (found != 15)
7131 goto failure;
7132 inst.operands[i].isvec = 1;
f7c21dc7
NC
7133 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7134 inst.operands[i].reg = REG_PC;
477330fc
RM
7135 }
7136 else
7137 goto failure;
7138 break;
037e8744 7139
92e90b6e
PB
7140 case OP_TB:
7141 po_misc_or_fail (parse_tb (&str));
7142 break;
7143
e07e6e58 7144 /* Register lists. */
c19d1205
ZW
7145 case OP_REGLST:
7146 val = parse_reg_list (&str);
7147 if (*str == '^')
7148 {
5e0d7f77 7149 inst.operands[i].writeback = 1;
c19d1205
ZW
7150 str++;
7151 }
7152 break;
09d92015 7153
c19d1205 7154 case OP_VRSLST:
5287ad62 7155 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7156 break;
09d92015 7157
c19d1205 7158 case OP_VRDLST:
5287ad62 7159 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7160 break;
a737bd4d 7161
477330fc
RM
7162 case OP_VRSDLST:
7163 /* Allow Q registers too. */
7164 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7165 REGLIST_NEON_D);
7166 if (val == FAIL)
7167 {
7168 inst.error = NULL;
7169 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7170 REGLIST_VFP_S);
7171 inst.operands[i].issingle = 1;
7172 }
7173 break;
7174
7175 case OP_NRDLST:
7176 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7177 REGLIST_NEON_D);
7178 break;
5287ad62
JB
7179
7180 case OP_NSTRLST:
477330fc
RM
7181 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7182 &inst.operands[i].vectype);
7183 break;
5287ad62 7184
c19d1205
ZW
7185 /* Addressing modes */
7186 case OP_ADDR:
7187 po_misc_or_fail (parse_address (&str, i));
7188 break;
09d92015 7189
4962c51a
MS
7190 case OP_ADDRGLDR:
7191 po_misc_or_fail_no_backtrack (
477330fc 7192 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7193 break;
7194
7195 case OP_ADDRGLDRS:
7196 po_misc_or_fail_no_backtrack (
477330fc 7197 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7198 break;
7199
7200 case OP_ADDRGLDC:
7201 po_misc_or_fail_no_backtrack (
477330fc 7202 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7203 break;
7204
c19d1205
ZW
7205 case OP_SH:
7206 po_misc_or_fail (parse_shifter_operand (&str, i));
7207 break;
09d92015 7208
4962c51a
MS
7209 case OP_SHG:
7210 po_misc_or_fail_no_backtrack (
477330fc 7211 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7212 break;
7213
c19d1205
ZW
7214 case OP_oSHll:
7215 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7216 break;
09d92015 7217
c19d1205
ZW
7218 case OP_oSHar:
7219 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7220 break;
09d92015 7221
c19d1205
ZW
7222 case OP_oSHllar:
7223 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7224 break;
09d92015 7225
c19d1205 7226 default:
5be8be5d 7227 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7228 }
09d92015 7229
c19d1205
ZW
7230 /* Various value-based sanity checks and shared operations. We
7231 do not signal immediate failures for the register constraints;
7232 this allows a syntax error to take precedence. */
5be8be5d 7233 switch (op_parse_code)
c19d1205
ZW
7234 {
7235 case OP_oRRnpc:
7236 case OP_RRnpc:
7237 case OP_RRnpcb:
7238 case OP_RRw:
b6702015 7239 case OP_oRRw:
c19d1205
ZW
7240 case OP_RRnpc_I0:
7241 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7242 inst.error = BAD_PC;
7243 break;
09d92015 7244
5be8be5d
DG
7245 case OP_oRRnpcsp:
7246 case OP_RRnpcsp:
7247 if (inst.operands[i].isreg)
7248 {
7249 if (inst.operands[i].reg == REG_PC)
7250 inst.error = BAD_PC;
5c8ed6a4
JW
7251 else if (inst.operands[i].reg == REG_SP
7252 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7253 relaxed since ARMv8-A. */
7254 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7255 {
7256 gas_assert (thumb);
7257 inst.error = BAD_SP;
7258 }
5be8be5d
DG
7259 }
7260 break;
7261
55881a11 7262 case OP_RRnpctw:
fa94de6b
RM
7263 if (inst.operands[i].isreg
7264 && inst.operands[i].reg == REG_PC
55881a11
MGD
7265 && (inst.operands[i].writeback || thumb))
7266 inst.error = BAD_PC;
7267 break;
7268
c19d1205
ZW
7269 case OP_CPSF:
7270 case OP_ENDI:
7271 case OP_oROR:
d2cd1205
JB
7272 case OP_wPSR:
7273 case OP_rPSR:
c19d1205 7274 case OP_COND:
52e7f43d 7275 case OP_oBARRIER_I15:
c19d1205
ZW
7276 case OP_REGLST:
7277 case OP_VRSLST:
7278 case OP_VRDLST:
477330fc
RM
7279 case OP_VRSDLST:
7280 case OP_NRDLST:
7281 case OP_NSTRLST:
c19d1205
ZW
7282 if (val == FAIL)
7283 goto failure;
7284 inst.operands[i].imm = val;
7285 break;
a737bd4d 7286
c19d1205
ZW
7287 default:
7288 break;
7289 }
09d92015 7290
c19d1205
ZW
7291 /* If we get here, this operand was successfully parsed. */
7292 inst.operands[i].present = 1;
7293 continue;
09d92015 7294
c19d1205 7295 bad_args:
09d92015 7296 inst.error = BAD_ARGS;
c19d1205
ZW
7297
7298 failure:
7299 if (!backtrack_pos)
d252fdde
PB
7300 {
7301 /* The parse routine should already have set inst.error, but set a
5f4273c7 7302 default here just in case. */
d252fdde
PB
7303 if (!inst.error)
7304 inst.error = _("syntax error");
7305 return FAIL;
7306 }
c19d1205
ZW
7307
7308 /* Do not backtrack over a trailing optional argument that
7309 absorbed some text. We will only fail again, with the
7310 'garbage following instruction' error message, which is
7311 probably less helpful than the current one. */
7312 if (backtrack_index == i && backtrack_pos != str
7313 && upat[i+1] == OP_stop)
d252fdde
PB
7314 {
7315 if (!inst.error)
7316 inst.error = _("syntax error");
7317 return FAIL;
7318 }
c19d1205
ZW
7319
7320 /* Try again, skipping the optional argument at backtrack_pos. */
7321 str = backtrack_pos;
7322 inst.error = backtrack_error;
7323 inst.operands[backtrack_index].present = 0;
7324 i = backtrack_index;
7325 backtrack_pos = 0;
09d92015 7326 }
09d92015 7327
c19d1205
ZW
7328 /* Check that we have parsed all the arguments. */
7329 if (*str != '\0' && !inst.error)
7330 inst.error = _("garbage following instruction");
09d92015 7331
c19d1205 7332 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7333}
7334
c19d1205
ZW
7335#undef po_char_or_fail
7336#undef po_reg_or_fail
7337#undef po_reg_or_goto
7338#undef po_imm_or_fail
5287ad62 7339#undef po_scalar_or_fail
52e7f43d 7340#undef po_barrier_or_imm
e07e6e58 7341
c19d1205 7342/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7343#define constraint(expr, err) \
7344 do \
c19d1205 7345 { \
e07e6e58
NC
7346 if (expr) \
7347 { \
7348 inst.error = err; \
7349 return; \
7350 } \
c19d1205 7351 } \
e07e6e58 7352 while (0)
c19d1205 7353
fdfde340
JM
7354/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7355 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
7356 is the BadReg predicate in ARM's Thumb-2 documentation.
7357
7358 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7359 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7360#define reject_bad_reg(reg) \
7361 do \
7362 if (reg == REG_PC) \
7363 { \
7364 inst.error = BAD_PC; \
7365 return; \
7366 } \
7367 else if (reg == REG_SP \
7368 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7369 { \
7370 inst.error = BAD_SP; \
7371 return; \
7372 } \
fdfde340
JM
7373 while (0)
7374
94206790
MM
7375/* If REG is R13 (the stack pointer), warn that its use is
7376 deprecated. */
7377#define warn_deprecated_sp(reg) \
7378 do \
7379 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7380 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7381 while (0)
7382
c19d1205
ZW
7383/* Functions for operand encoding. ARM, then Thumb. */
7384
d840c081 7385#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7386
9db2f6b4
RL
7387/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7388
7389 The only binary encoding difference is the Coprocessor number. Coprocessor
7390 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 7391 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
7392 exists for Single-Precision operation. */
7393
7394static void
7395do_scalar_fp16_v82_encode (void)
7396{
7397 if (inst.cond != COND_ALWAYS)
7398 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7399 " the behaviour is UNPREDICTABLE"));
7400 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7401 _(BAD_FP16));
7402
7403 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7404 mark_feature_used (&arm_ext_fp16);
7405}
7406
c19d1205
ZW
7407/* If VAL can be encoded in the immediate field of an ARM instruction,
7408 return the encoded form. Otherwise, return FAIL. */
7409
7410static unsigned int
7411encode_arm_immediate (unsigned int val)
09d92015 7412{
c19d1205
ZW
7413 unsigned int a, i;
7414
4f1d6205
L
7415 if (val <= 0xff)
7416 return val;
7417
7418 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7419 if ((a = rotate_left (val, i)) <= 0xff)
7420 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7421
7422 return FAIL;
09d92015
MM
7423}
7424
c19d1205
ZW
7425/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7426 return the encoded form. Otherwise, return FAIL. */
7427static unsigned int
7428encode_thumb32_immediate (unsigned int val)
09d92015 7429{
c19d1205 7430 unsigned int a, i;
09d92015 7431
9c3c69f2 7432 if (val <= 0xff)
c19d1205 7433 return val;
a737bd4d 7434
9c3c69f2 7435 for (i = 1; i <= 24; i++)
09d92015 7436 {
9c3c69f2
PB
7437 a = val >> i;
7438 if ((val & ~(0xff << i)) == 0)
7439 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7440 }
a737bd4d 7441
c19d1205
ZW
7442 a = val & 0xff;
7443 if (val == ((a << 16) | a))
7444 return 0x100 | a;
7445 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7446 return 0x300 | a;
09d92015 7447
c19d1205
ZW
7448 a = val & 0xff00;
7449 if (val == ((a << 16) | a))
7450 return 0x200 | (a >> 8);
a737bd4d 7451
c19d1205 7452 return FAIL;
09d92015 7453}
5287ad62 7454/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7455
7456static void
5287ad62
JB
7457encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7458{
7459 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7460 && reg > 15)
7461 {
b1cc4aeb 7462 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7463 {
7464 if (thumb_mode)
7465 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7466 fpu_vfp_ext_d32);
7467 else
7468 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7469 fpu_vfp_ext_d32);
7470 }
5287ad62 7471 else
477330fc
RM
7472 {
7473 first_error (_("D register out of range for selected VFP version"));
7474 return;
7475 }
5287ad62
JB
7476 }
7477
c19d1205 7478 switch (pos)
09d92015 7479 {
c19d1205
ZW
7480 case VFP_REG_Sd:
7481 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7482 break;
7483
7484 case VFP_REG_Sn:
7485 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7486 break;
7487
7488 case VFP_REG_Sm:
7489 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7490 break;
7491
5287ad62
JB
7492 case VFP_REG_Dd:
7493 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7494 break;
5f4273c7 7495
5287ad62
JB
7496 case VFP_REG_Dn:
7497 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7498 break;
5f4273c7 7499
5287ad62
JB
7500 case VFP_REG_Dm:
7501 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7502 break;
7503
c19d1205
ZW
7504 default:
7505 abort ();
09d92015 7506 }
09d92015
MM
7507}
7508
c19d1205 7509/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7510 if any, is handled by md_apply_fix. */
09d92015 7511static void
c19d1205 7512encode_arm_shift (int i)
09d92015 7513{
008a97ef
RL
7514 /* register-shifted register. */
7515 if (inst.operands[i].immisreg)
7516 {
bf355b69
MR
7517 int op_index;
7518 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 7519 {
5689c942
RL
7520 /* Check the operand only when it's presented. In pre-UAL syntax,
7521 if the destination register is the same as the first operand, two
7522 register form of the instruction can be used. */
bf355b69
MR
7523 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7524 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
7525 as_warn (UNPRED_REG ("r15"));
7526 }
7527
7528 if (inst.operands[i].imm == REG_PC)
7529 as_warn (UNPRED_REG ("r15"));
7530 }
7531
c19d1205
ZW
7532 if (inst.operands[i].shift_kind == SHIFT_RRX)
7533 inst.instruction |= SHIFT_ROR << 5;
7534 else
09d92015 7535 {
c19d1205
ZW
7536 inst.instruction |= inst.operands[i].shift_kind << 5;
7537 if (inst.operands[i].immisreg)
7538 {
7539 inst.instruction |= SHIFT_BY_REG;
7540 inst.instruction |= inst.operands[i].imm << 8;
7541 }
7542 else
7543 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7544 }
c19d1205 7545}
09d92015 7546
c19d1205
ZW
7547static void
7548encode_arm_shifter_operand (int i)
7549{
7550 if (inst.operands[i].isreg)
09d92015 7551 {
c19d1205
ZW
7552 inst.instruction |= inst.operands[i].reg;
7553 encode_arm_shift (i);
09d92015 7554 }
c19d1205 7555 else
a415b1cd
JB
7556 {
7557 inst.instruction |= INST_IMMEDIATE;
7558 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7559 inst.instruction |= inst.operands[i].imm;
7560 }
09d92015
MM
7561}
7562
c19d1205 7563/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7564static void
c19d1205 7565encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7566{
2b2f5df9
NC
7567 /* PR 14260:
7568 Generate an error if the operand is not a register. */
7569 constraint (!inst.operands[i].isreg,
7570 _("Instruction does not support =N addresses"));
7571
c19d1205 7572 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7573
c19d1205 7574 if (inst.operands[i].preind)
09d92015 7575 {
c19d1205
ZW
7576 if (is_t)
7577 {
7578 inst.error = _("instruction does not accept preindexed addressing");
7579 return;
7580 }
7581 inst.instruction |= PRE_INDEX;
7582 if (inst.operands[i].writeback)
7583 inst.instruction |= WRITE_BACK;
09d92015 7584
c19d1205
ZW
7585 }
7586 else if (inst.operands[i].postind)
7587 {
9c2799c2 7588 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7589 if (is_t)
7590 inst.instruction |= WRITE_BACK;
7591 }
7592 else /* unindexed - only for coprocessor */
09d92015 7593 {
c19d1205 7594 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7595 return;
7596 }
7597
c19d1205
ZW
7598 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7599 && (((inst.instruction & 0x000f0000) >> 16)
7600 == ((inst.instruction & 0x0000f000) >> 12)))
7601 as_warn ((inst.instruction & LOAD_BIT)
7602 ? _("destination register same as write-back base")
7603 : _("source register same as write-back base"));
09d92015
MM
7604}
7605
c19d1205
ZW
7606/* inst.operands[i] was set up by parse_address. Encode it into an
7607 ARM-format mode 2 load or store instruction. If is_t is true,
7608 reject forms that cannot be used with a T instruction (i.e. not
7609 post-indexed). */
a737bd4d 7610static void
c19d1205 7611encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7612{
5be8be5d
DG
7613 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7614
c19d1205 7615 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7616
c19d1205 7617 if (inst.operands[i].immisreg)
09d92015 7618 {
5be8be5d
DG
7619 constraint ((inst.operands[i].imm == REG_PC
7620 || (is_pc && inst.operands[i].writeback)),
7621 BAD_PC_ADDRESSING);
c19d1205
ZW
7622 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7623 inst.instruction |= inst.operands[i].imm;
7624 if (!inst.operands[i].negative)
7625 inst.instruction |= INDEX_UP;
7626 if (inst.operands[i].shifted)
7627 {
7628 if (inst.operands[i].shift_kind == SHIFT_RRX)
7629 inst.instruction |= SHIFT_ROR << 5;
7630 else
7631 {
7632 inst.instruction |= inst.operands[i].shift_kind << 5;
7633 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7634 }
7635 }
09d92015 7636 }
c19d1205 7637 else /* immediate offset in inst.reloc */
09d92015 7638 {
5be8be5d
DG
7639 if (is_pc && !inst.reloc.pc_rel)
7640 {
7641 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7642
7643 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7644 cannot use PC in addressing.
7645 PC cannot be used in writeback addressing, either. */
7646 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7647 BAD_PC_ADDRESSING);
23a10334 7648
dc5ec521 7649 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7650 if (warn_on_deprecated
7651 && !is_load
7652 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7653 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7654 }
7655
c19d1205 7656 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7657 {
7658 /* Prefer + for zero encoded value. */
7659 if (!inst.operands[i].negative)
7660 inst.instruction |= INDEX_UP;
7661 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7662 }
09d92015 7663 }
09d92015
MM
7664}
7665
c19d1205
ZW
7666/* inst.operands[i] was set up by parse_address. Encode it into an
7667 ARM-format mode 3 load or store instruction. Reject forms that
7668 cannot be used with such instructions. If is_t is true, reject
7669 forms that cannot be used with a T instruction (i.e. not
7670 post-indexed). */
7671static void
7672encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7673{
c19d1205 7674 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7675 {
c19d1205
ZW
7676 inst.error = _("instruction does not accept scaled register index");
7677 return;
09d92015 7678 }
a737bd4d 7679
c19d1205 7680 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7681
c19d1205
ZW
7682 if (inst.operands[i].immisreg)
7683 {
5be8be5d 7684 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7685 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7686 BAD_PC_ADDRESSING);
eb9f3f00
JB
7687 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7688 BAD_PC_WRITEBACK);
c19d1205
ZW
7689 inst.instruction |= inst.operands[i].imm;
7690 if (!inst.operands[i].negative)
7691 inst.instruction |= INDEX_UP;
7692 }
7693 else /* immediate offset in inst.reloc */
7694 {
5be8be5d
DG
7695 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7696 && inst.operands[i].writeback),
7697 BAD_PC_WRITEBACK);
c19d1205
ZW
7698 inst.instruction |= HWOFFSET_IMM;
7699 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7700 {
7701 /* Prefer + for zero encoded value. */
7702 if (!inst.operands[i].negative)
7703 inst.instruction |= INDEX_UP;
7704
7705 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7706 }
c19d1205 7707 }
a737bd4d
NC
7708}
7709
8335d6aa
JW
7710/* Write immediate bits [7:0] to the following locations:
7711
7712 |28/24|23 19|18 16|15 4|3 0|
7713 | 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|
7714
7715 This function is used by VMOV/VMVN/VORR/VBIC. */
7716
7717static void
7718neon_write_immbits (unsigned immbits)
7719{
7720 inst.instruction |= immbits & 0xf;
7721 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7722 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7723}
7724
7725/* Invert low-order SIZE bits of XHI:XLO. */
7726
7727static void
7728neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7729{
7730 unsigned immlo = xlo ? *xlo : 0;
7731 unsigned immhi = xhi ? *xhi : 0;
7732
7733 switch (size)
7734 {
7735 case 8:
7736 immlo = (~immlo) & 0xff;
7737 break;
7738
7739 case 16:
7740 immlo = (~immlo) & 0xffff;
7741 break;
7742
7743 case 64:
7744 immhi = (~immhi) & 0xffffffff;
7745 /* fall through. */
7746
7747 case 32:
7748 immlo = (~immlo) & 0xffffffff;
7749 break;
7750
7751 default:
7752 abort ();
7753 }
7754
7755 if (xlo)
7756 *xlo = immlo;
7757
7758 if (xhi)
7759 *xhi = immhi;
7760}
7761
7762/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7763 A, B, C, D. */
09d92015 7764
c19d1205 7765static int
8335d6aa 7766neon_bits_same_in_bytes (unsigned imm)
09d92015 7767{
8335d6aa
JW
7768 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7769 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7770 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7771 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7772}
a737bd4d 7773
8335d6aa 7774/* For immediate of above form, return 0bABCD. */
09d92015 7775
8335d6aa
JW
7776static unsigned
7777neon_squash_bits (unsigned imm)
7778{
7779 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7780 | ((imm & 0x01000000) >> 21);
7781}
7782
7783/* Compress quarter-float representation to 0b...000 abcdefgh. */
7784
7785static unsigned
7786neon_qfloat_bits (unsigned imm)
7787{
7788 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7789}
7790
7791/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7792 the instruction. *OP is passed as the initial value of the op field, and
7793 may be set to a different value depending on the constant (i.e.
7794 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7795 MVN). If the immediate looks like a repeated pattern then also
7796 try smaller element sizes. */
7797
7798static int
7799neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7800 unsigned *immbits, int *op, int size,
7801 enum neon_el_type type)
7802{
7803 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7804 float. */
7805 if (type == NT_float && !float_p)
7806 return FAIL;
7807
7808 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7809 {
8335d6aa
JW
7810 if (size != 32 || *op == 1)
7811 return FAIL;
7812 *immbits = neon_qfloat_bits (immlo);
7813 return 0xf;
7814 }
7815
7816 if (size == 64)
7817 {
7818 if (neon_bits_same_in_bytes (immhi)
7819 && neon_bits_same_in_bytes (immlo))
c19d1205 7820 {
8335d6aa
JW
7821 if (*op == 1)
7822 return FAIL;
7823 *immbits = (neon_squash_bits (immhi) << 4)
7824 | neon_squash_bits (immlo);
7825 *op = 1;
7826 return 0xe;
c19d1205 7827 }
a737bd4d 7828
8335d6aa
JW
7829 if (immhi != immlo)
7830 return FAIL;
7831 }
a737bd4d 7832
8335d6aa 7833 if (size >= 32)
09d92015 7834 {
8335d6aa 7835 if (immlo == (immlo & 0x000000ff))
c19d1205 7836 {
8335d6aa
JW
7837 *immbits = immlo;
7838 return 0x0;
c19d1205 7839 }
8335d6aa 7840 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7841 {
8335d6aa
JW
7842 *immbits = immlo >> 8;
7843 return 0x2;
c19d1205 7844 }
8335d6aa
JW
7845 else if (immlo == (immlo & 0x00ff0000))
7846 {
7847 *immbits = immlo >> 16;
7848 return 0x4;
7849 }
7850 else if (immlo == (immlo & 0xff000000))
7851 {
7852 *immbits = immlo >> 24;
7853 return 0x6;
7854 }
7855 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7856 {
7857 *immbits = (immlo >> 8) & 0xff;
7858 return 0xc;
7859 }
7860 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7861 {
7862 *immbits = (immlo >> 16) & 0xff;
7863 return 0xd;
7864 }
7865
7866 if ((immlo & 0xffff) != (immlo >> 16))
7867 return FAIL;
7868 immlo &= 0xffff;
09d92015 7869 }
a737bd4d 7870
8335d6aa 7871 if (size >= 16)
4962c51a 7872 {
8335d6aa
JW
7873 if (immlo == (immlo & 0x000000ff))
7874 {
7875 *immbits = immlo;
7876 return 0x8;
7877 }
7878 else if (immlo == (immlo & 0x0000ff00))
7879 {
7880 *immbits = immlo >> 8;
7881 return 0xa;
7882 }
7883
7884 if ((immlo & 0xff) != (immlo >> 8))
7885 return FAIL;
7886 immlo &= 0xff;
4962c51a
MS
7887 }
7888
8335d6aa
JW
7889 if (immlo == (immlo & 0x000000ff))
7890 {
7891 /* Don't allow MVN with 8-bit immediate. */
7892 if (*op == 1)
7893 return FAIL;
7894 *immbits = immlo;
7895 return 0xe;
7896 }
26d97720 7897
8335d6aa 7898 return FAIL;
c19d1205 7899}
a737bd4d 7900
5fc177c8 7901#if defined BFD_HOST_64_BIT
ba592044
AM
7902/* Returns TRUE if double precision value V may be cast
7903 to single precision without loss of accuracy. */
7904
7905static bfd_boolean
5fc177c8 7906is_double_a_single (bfd_int64_t v)
ba592044 7907{
5fc177c8 7908 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7909 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7910
7911 return (exp == 0 || exp == 0x7FF
7912 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7913 && (mantissa & 0x1FFFFFFFl) == 0;
7914}
7915
3739860c 7916/* Returns a double precision value casted to single precision
ba592044
AM
7917 (ignoring the least significant bits in exponent and mantissa). */
7918
7919static int
5fc177c8 7920double_to_single (bfd_int64_t v)
ba592044
AM
7921{
7922 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7923 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7924 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7925
7926 if (exp == 0x7FF)
7927 exp = 0xFF;
7928 else
7929 {
7930 exp = exp - 1023 + 127;
7931 if (exp >= 0xFF)
7932 {
7933 /* Infinity. */
7934 exp = 0x7F;
7935 mantissa = 0;
7936 }
7937 else if (exp < 0)
7938 {
7939 /* No denormalized numbers. */
7940 exp = 0;
7941 mantissa = 0;
7942 }
7943 }
7944 mantissa >>= 29;
7945 return (sign << 31) | (exp << 23) | mantissa;
7946}
5fc177c8 7947#endif /* BFD_HOST_64_BIT */
ba592044 7948
8335d6aa
JW
7949enum lit_type
7950{
7951 CONST_THUMB,
7952 CONST_ARM,
7953 CONST_VEC
7954};
7955
ba592044
AM
7956static void do_vfp_nsyn_opcode (const char *);
7957
c19d1205
ZW
7958/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7959 Determine whether it can be performed with a move instruction; if
7960 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7961 return TRUE; if it can't, convert inst.instruction to a literal-pool
7962 load and return FALSE. If this is not a valid thing to do in the
7963 current context, set inst.error and return TRUE.
a737bd4d 7964
c19d1205
ZW
7965 inst.operands[i] describes the destination register. */
7966
c921be7d 7967static bfd_boolean
8335d6aa 7968move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7969{
53365c0d 7970 unsigned long tbit;
8335d6aa
JW
7971 bfd_boolean thumb_p = (t == CONST_THUMB);
7972 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7973
7974 if (thumb_p)
7975 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7976 else
7977 tbit = LOAD_BIT;
7978
7979 if ((inst.instruction & tbit) == 0)
09d92015 7980 {
c19d1205 7981 inst.error = _("invalid pseudo operation");
c921be7d 7982 return TRUE;
09d92015 7983 }
ba592044 7984
8335d6aa
JW
7985 if (inst.reloc.exp.X_op != O_constant
7986 && inst.reloc.exp.X_op != O_symbol
7987 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7988 {
7989 inst.error = _("constant expression expected");
c921be7d 7990 return TRUE;
09d92015 7991 }
ba592044
AM
7992
7993 if (inst.reloc.exp.X_op == O_constant
7994 || inst.reloc.exp.X_op == O_big)
8335d6aa 7995 {
5fc177c8
NC
7996#if defined BFD_HOST_64_BIT
7997 bfd_int64_t v;
7998#else
ba592044 7999 offsetT v;
5fc177c8 8000#endif
ba592044 8001 if (inst.reloc.exp.X_op == O_big)
8335d6aa 8002 {
ba592044
AM
8003 LITTLENUM_TYPE w[X_PRECISION];
8004 LITTLENUM_TYPE * l;
8005
8006 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 8007 {
ba592044
AM
8008 gen_to_words (w, X_PRECISION, E_PRECISION);
8009 l = w;
8010 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 8011 }
ba592044
AM
8012 else
8013 l = generic_bignum;
3739860c 8014
5fc177c8
NC
8015#if defined BFD_HOST_64_BIT
8016 v =
8017 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8018 << LITTLENUM_NUMBER_OF_BITS)
8019 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8020 << LITTLENUM_NUMBER_OF_BITS)
8021 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8022 << LITTLENUM_NUMBER_OF_BITS)
8023 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8024#else
ba592044
AM
8025 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8026 | (l[0] & LITTLENUM_MASK);
5fc177c8 8027#endif
8335d6aa 8028 }
ba592044
AM
8029 else
8030 v = inst.reloc.exp.X_add_number;
8031
8032 if (!inst.operands[i].issingle)
8335d6aa 8033 {
12569877 8034 if (thumb_p)
8335d6aa 8035 {
53445554
TP
8036 /* LDR should not use lead in a flag-setting instruction being
8037 chosen so we do not check whether movs can be used. */
12569877 8038
53445554 8039 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8040 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8041 && inst.operands[i].reg != 13
8042 && inst.operands[i].reg != 15)
12569877 8043 {
fc289b0a
TP
8044 /* Check if on thumb2 it can be done with a mov.w, mvn or
8045 movw instruction. */
12569877
AM
8046 unsigned int newimm;
8047 bfd_boolean isNegated;
8048
8049 newimm = encode_thumb32_immediate (v);
8050 if (newimm != (unsigned int) FAIL)
8051 isNegated = FALSE;
8052 else
8053 {
582cfe03 8054 newimm = encode_thumb32_immediate (~v);
12569877
AM
8055 if (newimm != (unsigned int) FAIL)
8056 isNegated = TRUE;
8057 }
8058
fc289b0a
TP
8059 /* The number can be loaded with a mov.w or mvn
8060 instruction. */
ff8646ee
TP
8061 if (newimm != (unsigned int) FAIL
8062 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8063 {
fc289b0a 8064 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8065 | (inst.operands[i].reg << 8));
fc289b0a 8066 /* Change to MOVN. */
582cfe03 8067 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8068 inst.instruction |= (newimm & 0x800) << 15;
8069 inst.instruction |= (newimm & 0x700) << 4;
8070 inst.instruction |= (newimm & 0x0ff);
8071 return TRUE;
8072 }
fc289b0a 8073 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8074 else if ((v & ~0xFFFF) == 0
8075 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8076 {
582cfe03 8077 int imm = v & 0xFFFF;
12569877 8078
582cfe03 8079 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8080 inst.instruction |= (inst.operands[i].reg << 8);
8081 inst.instruction |= (imm & 0xf000) << 4;
8082 inst.instruction |= (imm & 0x0800) << 15;
8083 inst.instruction |= (imm & 0x0700) << 4;
8084 inst.instruction |= (imm & 0x00ff);
8085 return TRUE;
8086 }
8087 }
8335d6aa 8088 }
12569877 8089 else if (arm_p)
ba592044
AM
8090 {
8091 int value = encode_arm_immediate (v);
12569877 8092
ba592044
AM
8093 if (value != FAIL)
8094 {
8095 /* This can be done with a mov instruction. */
8096 inst.instruction &= LITERAL_MASK;
8097 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8098 inst.instruction |= value & 0xfff;
8099 return TRUE;
8100 }
8335d6aa 8101
ba592044
AM
8102 value = encode_arm_immediate (~ v);
8103 if (value != FAIL)
8104 {
8105 /* This can be done with a mvn instruction. */
8106 inst.instruction &= LITERAL_MASK;
8107 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8108 inst.instruction |= value & 0xfff;
8109 return TRUE;
8110 }
8111 }
934c2632 8112 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8113 {
ba592044
AM
8114 int op = 0;
8115 unsigned immbits = 0;
8116 unsigned immlo = inst.operands[1].imm;
8117 unsigned immhi = inst.operands[1].regisimm
8118 ? inst.operands[1].reg
8119 : inst.reloc.exp.X_unsigned
8120 ? 0
8121 : ((bfd_int64_t)((int) immlo)) >> 32;
8122 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8123 &op, 64, NT_invtype);
8124
8125 if (cmode == FAIL)
8126 {
8127 neon_invert_size (&immlo, &immhi, 64);
8128 op = !op;
8129 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8130 &op, 64, NT_invtype);
8131 }
8132
8133 if (cmode != FAIL)
8134 {
8135 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8136 | (1 << 23)
8137 | (cmode << 8)
8138 | (op << 5)
8139 | (1 << 4);
8140
8141 /* Fill other bits in vmov encoding for both thumb and arm. */
8142 if (thumb_mode)
eff0bc54 8143 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8144 else
eff0bc54 8145 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8146 neon_write_immbits (immbits);
8147 return TRUE;
8148 }
8335d6aa
JW
8149 }
8150 }
8335d6aa 8151
ba592044
AM
8152 if (t == CONST_VEC)
8153 {
8154 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8155 if (inst.operands[i].issingle
8156 && is_quarter_float (inst.operands[1].imm)
8157 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8158 {
ba592044
AM
8159 inst.operands[1].imm =
8160 neon_qfloat_bits (v);
8161 do_vfp_nsyn_opcode ("fconsts");
8162 return TRUE;
8335d6aa 8163 }
5fc177c8
NC
8164
8165 /* If our host does not support a 64-bit type then we cannot perform
8166 the following optimization. This mean that there will be a
8167 discrepancy between the output produced by an assembler built for
8168 a 32-bit-only host and the output produced from a 64-bit host, but
8169 this cannot be helped. */
8170#if defined BFD_HOST_64_BIT
ba592044
AM
8171 else if (!inst.operands[1].issingle
8172 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8173 {
ba592044
AM
8174 if (is_double_a_single (v)
8175 && is_quarter_float (double_to_single (v)))
8176 {
8177 inst.operands[1].imm =
8178 neon_qfloat_bits (double_to_single (v));
8179 do_vfp_nsyn_opcode ("fconstd");
8180 return TRUE;
8181 }
8335d6aa 8182 }
5fc177c8 8183#endif
8335d6aa
JW
8184 }
8185 }
8186
8187 if (add_to_lit_pool ((!inst.operands[i].isvec
8188 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8189 return TRUE;
8190
8191 inst.operands[1].reg = REG_PC;
8192 inst.operands[1].isreg = 1;
8193 inst.operands[1].preind = 1;
8194 inst.reloc.pc_rel = 1;
8195 inst.reloc.type = (thumb_p
8196 ? BFD_RELOC_ARM_THUMB_OFFSET
8197 : (mode_3
8198 ? BFD_RELOC_ARM_HWLITERAL
8199 : BFD_RELOC_ARM_LITERAL));
8200 return FALSE;
8201}
8202
8203/* inst.operands[i] was set up by parse_address. Encode it into an
8204 ARM-format instruction. Reject all forms which cannot be encoded
8205 into a coprocessor load/store instruction. If wb_ok is false,
8206 reject use of writeback; if unind_ok is false, reject use of
8207 unindexed addressing. If reloc_override is not 0, use it instead
8208 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8209 (in which case it is preserved). */
8210
8211static int
8212encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8213{
8214 if (!inst.operands[i].isreg)
8215 {
99b2a2dd
NC
8216 /* PR 18256 */
8217 if (! inst.operands[0].isvec)
8218 {
8219 inst.error = _("invalid co-processor operand");
8220 return FAIL;
8221 }
8335d6aa
JW
8222 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8223 return SUCCESS;
8224 }
8225
8226 inst.instruction |= inst.operands[i].reg << 16;
8227
8228 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8229
8230 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8231 {
8232 gas_assert (!inst.operands[i].writeback);
8233 if (!unind_ok)
8234 {
8235 inst.error = _("instruction does not support unindexed addressing");
8236 return FAIL;
8237 }
8238 inst.instruction |= inst.operands[i].imm;
8239 inst.instruction |= INDEX_UP;
8240 return SUCCESS;
8241 }
8242
8243 if (inst.operands[i].preind)
8244 inst.instruction |= PRE_INDEX;
8245
8246 if (inst.operands[i].writeback)
09d92015 8247 {
8335d6aa 8248 if (inst.operands[i].reg == REG_PC)
c19d1205 8249 {
8335d6aa
JW
8250 inst.error = _("pc may not be used with write-back");
8251 return FAIL;
c19d1205 8252 }
8335d6aa 8253 if (!wb_ok)
c19d1205 8254 {
8335d6aa
JW
8255 inst.error = _("instruction does not support writeback");
8256 return FAIL;
c19d1205 8257 }
8335d6aa 8258 inst.instruction |= WRITE_BACK;
09d92015
MM
8259 }
8260
8335d6aa
JW
8261 if (reloc_override)
8262 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8263 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8264 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8265 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8266 {
8335d6aa
JW
8267 if (thumb_mode)
8268 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8269 else
8270 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8271 }
8335d6aa
JW
8272
8273 /* Prefer + for zero encoded value. */
8274 if (!inst.operands[i].negative)
8275 inst.instruction |= INDEX_UP;
8276
8277 return SUCCESS;
09d92015
MM
8278}
8279
5f4273c7 8280/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8281 First some generics; their names are taken from the conventional
8282 bit positions for register arguments in ARM format instructions. */
09d92015 8283
a737bd4d 8284static void
c19d1205 8285do_noargs (void)
09d92015 8286{
c19d1205 8287}
a737bd4d 8288
c19d1205
ZW
8289static void
8290do_rd (void)
8291{
8292 inst.instruction |= inst.operands[0].reg << 12;
8293}
a737bd4d 8294
16a1fa25
TP
8295static void
8296do_rn (void)
8297{
8298 inst.instruction |= inst.operands[0].reg << 16;
8299}
8300
c19d1205
ZW
8301static void
8302do_rd_rm (void)
8303{
8304 inst.instruction |= inst.operands[0].reg << 12;
8305 inst.instruction |= inst.operands[1].reg;
8306}
09d92015 8307
9eb6c0f1
MGD
8308static void
8309do_rm_rn (void)
8310{
8311 inst.instruction |= inst.operands[0].reg;
8312 inst.instruction |= inst.operands[1].reg << 16;
8313}
8314
c19d1205
ZW
8315static void
8316do_rd_rn (void)
8317{
8318 inst.instruction |= inst.operands[0].reg << 12;
8319 inst.instruction |= inst.operands[1].reg << 16;
8320}
a737bd4d 8321
c19d1205
ZW
8322static void
8323do_rn_rd (void)
8324{
8325 inst.instruction |= inst.operands[0].reg << 16;
8326 inst.instruction |= inst.operands[1].reg << 12;
8327}
09d92015 8328
4ed7ed8d
TP
8329static void
8330do_tt (void)
8331{
8332 inst.instruction |= inst.operands[0].reg << 8;
8333 inst.instruction |= inst.operands[1].reg << 16;
8334}
8335
59d09be6
MGD
8336static bfd_boolean
8337check_obsolete (const arm_feature_set *feature, const char *msg)
8338{
8339 if (ARM_CPU_IS_ANY (cpu_variant))
8340 {
5c3696f8 8341 as_tsktsk ("%s", msg);
59d09be6
MGD
8342 return TRUE;
8343 }
8344 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8345 {
8346 as_bad ("%s", msg);
8347 return TRUE;
8348 }
8349
8350 return FALSE;
8351}
8352
c19d1205
ZW
8353static void
8354do_rd_rm_rn (void)
8355{
9a64e435 8356 unsigned Rn = inst.operands[2].reg;
708587a4 8357 /* Enforce restrictions on SWP instruction. */
9a64e435 8358 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8359 {
8360 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8361 _("Rn must not overlap other operands"));
8362
59d09be6
MGD
8363 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8364 */
8365 if (!check_obsolete (&arm_ext_v8,
8366 _("swp{b} use is obsoleted for ARMv8 and later"))
8367 && warn_on_deprecated
8368 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8369 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8370 }
59d09be6 8371
c19d1205
ZW
8372 inst.instruction |= inst.operands[0].reg << 12;
8373 inst.instruction |= inst.operands[1].reg;
9a64e435 8374 inst.instruction |= Rn << 16;
c19d1205 8375}
09d92015 8376
c19d1205
ZW
8377static void
8378do_rd_rn_rm (void)
8379{
8380 inst.instruction |= inst.operands[0].reg << 12;
8381 inst.instruction |= inst.operands[1].reg << 16;
8382 inst.instruction |= inst.operands[2].reg;
8383}
a737bd4d 8384
c19d1205
ZW
8385static void
8386do_rm_rd_rn (void)
8387{
5be8be5d
DG
8388 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8389 constraint (((inst.reloc.exp.X_op != O_constant
8390 && inst.reloc.exp.X_op != O_illegal)
8391 || inst.reloc.exp.X_add_number != 0),
8392 BAD_ADDR_MODE);
c19d1205
ZW
8393 inst.instruction |= inst.operands[0].reg;
8394 inst.instruction |= inst.operands[1].reg << 12;
8395 inst.instruction |= inst.operands[2].reg << 16;
8396}
09d92015 8397
c19d1205
ZW
8398static void
8399do_imm0 (void)
8400{
8401 inst.instruction |= inst.operands[0].imm;
8402}
09d92015 8403
c19d1205
ZW
8404static void
8405do_rd_cpaddr (void)
8406{
8407 inst.instruction |= inst.operands[0].reg << 12;
8408 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8409}
a737bd4d 8410
c19d1205
ZW
8411/* ARM instructions, in alphabetical order by function name (except
8412 that wrapper functions appear immediately after the function they
8413 wrap). */
09d92015 8414
c19d1205
ZW
8415/* This is a pseudo-op of the form "adr rd, label" to be converted
8416 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8417
8418static void
c19d1205 8419do_adr (void)
09d92015 8420{
c19d1205 8421 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8422
c19d1205
ZW
8423 /* Frag hacking will turn this into a sub instruction if the offset turns
8424 out to be negative. */
8425 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8426 inst.reloc.pc_rel = 1;
2fc8bdac 8427 inst.reloc.exp.X_add_number -= 8;
52a86f84 8428
fc6141f0
NC
8429 if (support_interwork
8430 && inst.reloc.exp.X_op == O_symbol
52a86f84
NC
8431 && inst.reloc.exp.X_add_symbol != NULL
8432 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8433 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
fc6141f0 8434 inst.reloc.exp.X_add_number |= 1;
c19d1205 8435}
b99bd4ef 8436
c19d1205
ZW
8437/* This is a pseudo-op of the form "adrl rd, label" to be converted
8438 into a relative address of the form:
8439 add rd, pc, #low(label-.-8)"
8440 add rd, rd, #high(label-.-8)" */
b99bd4ef 8441
c19d1205
ZW
8442static void
8443do_adrl (void)
8444{
8445 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8446
c19d1205
ZW
8447 /* Frag hacking will turn this into a sub instruction if the offset turns
8448 out to be negative. */
8449 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8450 inst.reloc.pc_rel = 1;
8451 inst.size = INSN_SIZE * 2;
2fc8bdac 8452 inst.reloc.exp.X_add_number -= 8;
52a86f84 8453
fc6141f0
NC
8454 if (support_interwork
8455 && inst.reloc.exp.X_op == O_symbol
52a86f84
NC
8456 && inst.reloc.exp.X_add_symbol != NULL
8457 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8458 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
fc6141f0 8459 inst.reloc.exp.X_add_number |= 1;
b99bd4ef
NC
8460}
8461
b99bd4ef 8462static void
c19d1205 8463do_arit (void)
b99bd4ef 8464{
a9f02af8
MG
8465 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8466 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8467 THUMB1_RELOC_ONLY);
c19d1205
ZW
8468 if (!inst.operands[1].present)
8469 inst.operands[1].reg = inst.operands[0].reg;
8470 inst.instruction |= inst.operands[0].reg << 12;
8471 inst.instruction |= inst.operands[1].reg << 16;
8472 encode_arm_shifter_operand (2);
8473}
b99bd4ef 8474
62b3e311
PB
8475static void
8476do_barrier (void)
8477{
8478 if (inst.operands[0].present)
ccb84d65 8479 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8480 else
8481 inst.instruction |= 0xf;
8482}
8483
c19d1205
ZW
8484static void
8485do_bfc (void)
8486{
8487 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8488 constraint (msb > 32, _("bit-field extends past end of register"));
8489 /* The instruction encoding stores the LSB and MSB,
8490 not the LSB and width. */
8491 inst.instruction |= inst.operands[0].reg << 12;
8492 inst.instruction |= inst.operands[1].imm << 7;
8493 inst.instruction |= (msb - 1) << 16;
8494}
b99bd4ef 8495
c19d1205
ZW
8496static void
8497do_bfi (void)
8498{
8499 unsigned int msb;
b99bd4ef 8500
c19d1205
ZW
8501 /* #0 in second position is alternative syntax for bfc, which is
8502 the same instruction but with REG_PC in the Rm field. */
8503 if (!inst.operands[1].isreg)
8504 inst.operands[1].reg = REG_PC;
b99bd4ef 8505
c19d1205
ZW
8506 msb = inst.operands[2].imm + inst.operands[3].imm;
8507 constraint (msb > 32, _("bit-field extends past end of register"));
8508 /* The instruction encoding stores the LSB and MSB,
8509 not the LSB and width. */
8510 inst.instruction |= inst.operands[0].reg << 12;
8511 inst.instruction |= inst.operands[1].reg;
8512 inst.instruction |= inst.operands[2].imm << 7;
8513 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8514}
8515
b99bd4ef 8516static void
c19d1205 8517do_bfx (void)
b99bd4ef 8518{
c19d1205
ZW
8519 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8520 _("bit-field extends past end of register"));
8521 inst.instruction |= inst.operands[0].reg << 12;
8522 inst.instruction |= inst.operands[1].reg;
8523 inst.instruction |= inst.operands[2].imm << 7;
8524 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8525}
09d92015 8526
c19d1205
ZW
8527/* ARM V5 breakpoint instruction (argument parse)
8528 BKPT <16 bit unsigned immediate>
8529 Instruction is not conditional.
8530 The bit pattern given in insns[] has the COND_ALWAYS condition,
8531 and it is an error if the caller tried to override that. */
b99bd4ef 8532
c19d1205
ZW
8533static void
8534do_bkpt (void)
8535{
8536 /* Top 12 of 16 bits to bits 19:8. */
8537 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8538
c19d1205
ZW
8539 /* Bottom 4 of 16 bits to bits 3:0. */
8540 inst.instruction |= inst.operands[0].imm & 0xf;
8541}
09d92015 8542
c19d1205
ZW
8543static void
8544encode_branch (int default_reloc)
8545{
8546 if (inst.operands[0].hasreloc)
8547 {
0855e32b
NS
8548 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8549 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8550 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8551 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8552 ? BFD_RELOC_ARM_PLT32
8553 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8554 }
b99bd4ef 8555 else
9ae92b05 8556 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8557 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8558}
8559
b99bd4ef 8560static void
c19d1205 8561do_branch (void)
b99bd4ef 8562{
39b41c9c
PB
8563#ifdef OBJ_ELF
8564 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8565 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8566 else
8567#endif
8568 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8569}
8570
8571static void
8572do_bl (void)
8573{
8574#ifdef OBJ_ELF
8575 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8576 {
8577 if (inst.cond == COND_ALWAYS)
8578 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8579 else
8580 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8581 }
8582 else
8583#endif
8584 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8585}
b99bd4ef 8586
c19d1205
ZW
8587/* ARM V5 branch-link-exchange instruction (argument parse)
8588 BLX <target_addr> ie BLX(1)
8589 BLX{<condition>} <Rm> ie BLX(2)
8590 Unfortunately, there are two different opcodes for this mnemonic.
8591 So, the insns[].value is not used, and the code here zaps values
8592 into inst.instruction.
8593 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8594
c19d1205
ZW
8595static void
8596do_blx (void)
8597{
8598 if (inst.operands[0].isreg)
b99bd4ef 8599 {
c19d1205
ZW
8600 /* Arg is a register; the opcode provided by insns[] is correct.
8601 It is not illegal to do "blx pc", just useless. */
8602 if (inst.operands[0].reg == REG_PC)
8603 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8604
c19d1205
ZW
8605 inst.instruction |= inst.operands[0].reg;
8606 }
8607 else
b99bd4ef 8608 {
c19d1205 8609 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8610 conditionally, and the opcode must be adjusted.
8611 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8612 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8613 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8614 inst.instruction = 0xfa000000;
267bf995 8615 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8616 }
c19d1205
ZW
8617}
8618
8619static void
8620do_bx (void)
8621{
845b51d6
PB
8622 bfd_boolean want_reloc;
8623
c19d1205
ZW
8624 if (inst.operands[0].reg == REG_PC)
8625 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8626
c19d1205 8627 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8628 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8629 it is for ARMv4t or earlier. */
8630 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
4d354d8b
TP
8631 if (!ARM_FEATURE_ZERO (selected_object_arch)
8632 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
845b51d6
PB
8633 want_reloc = TRUE;
8634
5ad34203 8635#ifdef OBJ_ELF
845b51d6 8636 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8637#endif
584206db 8638 want_reloc = FALSE;
845b51d6
PB
8639
8640 if (want_reloc)
8641 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8642}
8643
c19d1205
ZW
8644
8645/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8646
8647static void
c19d1205 8648do_bxj (void)
a737bd4d 8649{
c19d1205
ZW
8650 if (inst.operands[0].reg == REG_PC)
8651 as_tsktsk (_("use of r15 in bxj is not really useful"));
8652
8653 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8654}
8655
c19d1205
ZW
8656/* Co-processor data operation:
8657 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8658 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8659static void
8660do_cdp (void)
8661{
8662 inst.instruction |= inst.operands[0].reg << 8;
8663 inst.instruction |= inst.operands[1].imm << 20;
8664 inst.instruction |= inst.operands[2].reg << 12;
8665 inst.instruction |= inst.operands[3].reg << 16;
8666 inst.instruction |= inst.operands[4].reg;
8667 inst.instruction |= inst.operands[5].imm << 5;
8668}
a737bd4d
NC
8669
8670static void
c19d1205 8671do_cmp (void)
a737bd4d 8672{
c19d1205
ZW
8673 inst.instruction |= inst.operands[0].reg << 16;
8674 encode_arm_shifter_operand (1);
a737bd4d
NC
8675}
8676
c19d1205
ZW
8677/* Transfer between coprocessor and ARM registers.
8678 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8679 MRC2
8680 MCR{cond}
8681 MCR2
8682
8683 No special properties. */
09d92015 8684
dcbd0d71
MGD
8685struct deprecated_coproc_regs_s
8686{
8687 unsigned cp;
8688 int opc1;
8689 unsigned crn;
8690 unsigned crm;
8691 int opc2;
8692 arm_feature_set deprecated;
8693 arm_feature_set obsoleted;
8694 const char *dep_msg;
8695 const char *obs_msg;
8696};
8697
8698#define DEPR_ACCESS_V8 \
8699 N_("This coprocessor register access is deprecated in ARMv8")
8700
8701/* Table of all deprecated coprocessor registers. */
8702static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8703{
8704 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8705 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8706 DEPR_ACCESS_V8, NULL},
8707 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8708 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8709 DEPR_ACCESS_V8, NULL},
8710 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8711 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8712 DEPR_ACCESS_V8, NULL},
8713 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8714 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8715 DEPR_ACCESS_V8, NULL},
8716 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8717 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8718 DEPR_ACCESS_V8, NULL},
8719};
8720
8721#undef DEPR_ACCESS_V8
8722
8723static const size_t deprecated_coproc_reg_count =
8724 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8725
09d92015 8726static void
c19d1205 8727do_co_reg (void)
09d92015 8728{
fdfde340 8729 unsigned Rd;
dcbd0d71 8730 size_t i;
fdfde340
JM
8731
8732 Rd = inst.operands[2].reg;
8733 if (thumb_mode)
8734 {
8735 if (inst.instruction == 0xee000010
8736 || inst.instruction == 0xfe000010)
8737 /* MCR, MCR2 */
8738 reject_bad_reg (Rd);
5c8ed6a4 8739 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
8740 /* MRC, MRC2 */
8741 constraint (Rd == REG_SP, BAD_SP);
8742 }
8743 else
8744 {
8745 /* MCR */
8746 if (inst.instruction == 0xe000010)
8747 constraint (Rd == REG_PC, BAD_PC);
8748 }
8749
dcbd0d71
MGD
8750 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8751 {
8752 const struct deprecated_coproc_regs_s *r =
8753 deprecated_coproc_regs + i;
8754
8755 if (inst.operands[0].reg == r->cp
8756 && inst.operands[1].imm == r->opc1
8757 && inst.operands[3].reg == r->crn
8758 && inst.operands[4].reg == r->crm
8759 && inst.operands[5].imm == r->opc2)
8760 {
b10bf8c5 8761 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8762 && warn_on_deprecated
dcbd0d71 8763 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8764 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8765 }
8766 }
fdfde340 8767
c19d1205
ZW
8768 inst.instruction |= inst.operands[0].reg << 8;
8769 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8770 inst.instruction |= Rd << 12;
c19d1205
ZW
8771 inst.instruction |= inst.operands[3].reg << 16;
8772 inst.instruction |= inst.operands[4].reg;
8773 inst.instruction |= inst.operands[5].imm << 5;
8774}
09d92015 8775
c19d1205
ZW
8776/* Transfer between coprocessor register and pair of ARM registers.
8777 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8778 MCRR2
8779 MRRC{cond}
8780 MRRC2
b99bd4ef 8781
c19d1205 8782 Two XScale instructions are special cases of these:
09d92015 8783
c19d1205
ZW
8784 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8785 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8786
5f4273c7 8787 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8788
c19d1205
ZW
8789static void
8790do_co_reg2c (void)
8791{
fdfde340
JM
8792 unsigned Rd, Rn;
8793
8794 Rd = inst.operands[2].reg;
8795 Rn = inst.operands[3].reg;
8796
8797 if (thumb_mode)
8798 {
8799 reject_bad_reg (Rd);
8800 reject_bad_reg (Rn);
8801 }
8802 else
8803 {
8804 constraint (Rd == REG_PC, BAD_PC);
8805 constraint (Rn == REG_PC, BAD_PC);
8806 }
8807
873f10f0
TC
8808 /* Only check the MRRC{2} variants. */
8809 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8810 {
8811 /* If Rd == Rn, error that the operation is
8812 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8813 constraint (Rd == Rn, BAD_OVERLAP);
8814 }
8815
c19d1205
ZW
8816 inst.instruction |= inst.operands[0].reg << 8;
8817 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8818 inst.instruction |= Rd << 12;
8819 inst.instruction |= Rn << 16;
c19d1205 8820 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8821}
8822
c19d1205
ZW
8823static void
8824do_cpsi (void)
8825{
8826 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8827 if (inst.operands[1].present)
8828 {
8829 inst.instruction |= CPSI_MMOD;
8830 inst.instruction |= inst.operands[1].imm;
8831 }
c19d1205 8832}
b99bd4ef 8833
62b3e311
PB
8834static void
8835do_dbg (void)
8836{
8837 inst.instruction |= inst.operands[0].imm;
8838}
8839
eea54501
MGD
8840static void
8841do_div (void)
8842{
8843 unsigned Rd, Rn, Rm;
8844
8845 Rd = inst.operands[0].reg;
8846 Rn = (inst.operands[1].present
8847 ? inst.operands[1].reg : Rd);
8848 Rm = inst.operands[2].reg;
8849
8850 constraint ((Rd == REG_PC), BAD_PC);
8851 constraint ((Rn == REG_PC), BAD_PC);
8852 constraint ((Rm == REG_PC), BAD_PC);
8853
8854 inst.instruction |= Rd << 16;
8855 inst.instruction |= Rn << 0;
8856 inst.instruction |= Rm << 8;
8857}
8858
b99bd4ef 8859static void
c19d1205 8860do_it (void)
b99bd4ef 8861{
c19d1205 8862 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8863 process it to do the validation as if in
8864 thumb mode, just in case the code gets
8865 assembled for thumb using the unified syntax. */
8866
c19d1205 8867 inst.size = 0;
e07e6e58
NC
8868 if (unified_syntax)
8869 {
8870 set_it_insn_type (IT_INSN);
8871 now_it.mask = (inst.instruction & 0xf) | 0x10;
8872 now_it.cc = inst.operands[0].imm;
8873 }
09d92015 8874}
b99bd4ef 8875
6530b175
NC
8876/* If there is only one register in the register list,
8877 then return its register number. Otherwise return -1. */
8878static int
8879only_one_reg_in_list (int range)
8880{
8881 int i = ffs (range) - 1;
8882 return (i > 15 || range != (1 << i)) ? -1 : i;
8883}
8884
09d92015 8885static void
6530b175 8886encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8887{
c19d1205
ZW
8888 int base_reg = inst.operands[0].reg;
8889 int range = inst.operands[1].imm;
6530b175 8890 int one_reg;
ea6ef066 8891
c19d1205
ZW
8892 inst.instruction |= base_reg << 16;
8893 inst.instruction |= range;
ea6ef066 8894
c19d1205
ZW
8895 if (inst.operands[1].writeback)
8896 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8897
c19d1205 8898 if (inst.operands[0].writeback)
ea6ef066 8899 {
c19d1205
ZW
8900 inst.instruction |= WRITE_BACK;
8901 /* Check for unpredictable uses of writeback. */
8902 if (inst.instruction & LOAD_BIT)
09d92015 8903 {
c19d1205
ZW
8904 /* Not allowed in LDM type 2. */
8905 if ((inst.instruction & LDM_TYPE_2_OR_3)
8906 && ((range & (1 << REG_PC)) == 0))
8907 as_warn (_("writeback of base register is UNPREDICTABLE"));
8908 /* Only allowed if base reg not in list for other types. */
8909 else if (range & (1 << base_reg))
8910 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8911 }
8912 else /* STM. */
8913 {
8914 /* Not allowed for type 2. */
8915 if (inst.instruction & LDM_TYPE_2_OR_3)
8916 as_warn (_("writeback of base register is UNPREDICTABLE"));
8917 /* Only allowed if base reg not in list, or first in list. */
8918 else if ((range & (1 << base_reg))
8919 && (range & ((1 << base_reg) - 1)))
8920 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8921 }
ea6ef066 8922 }
6530b175
NC
8923
8924 /* If PUSH/POP has only one register, then use the A2 encoding. */
8925 one_reg = only_one_reg_in_list (range);
8926 if (from_push_pop_mnem && one_reg >= 0)
8927 {
8928 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8929
4f588891
NC
8930 if (is_push && one_reg == 13 /* SP */)
8931 /* PR 22483: The A2 encoding cannot be used when
8932 pushing the stack pointer as this is UNPREDICTABLE. */
8933 return;
8934
6530b175
NC
8935 inst.instruction &= A_COND_MASK;
8936 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8937 inst.instruction |= one_reg << 12;
8938 }
8939}
8940
8941static void
8942do_ldmstm (void)
8943{
8944 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8945}
8946
c19d1205
ZW
8947/* ARMv5TE load-consecutive (argument parse)
8948 Mode is like LDRH.
8949
8950 LDRccD R, mode
8951 STRccD R, mode. */
8952
a737bd4d 8953static void
c19d1205 8954do_ldrd (void)
a737bd4d 8955{
c19d1205 8956 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8957 _("first transfer register must be even"));
c19d1205
ZW
8958 constraint (inst.operands[1].present
8959 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8960 _("can only transfer two consecutive registers"));
c19d1205
ZW
8961 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8962 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8963
c19d1205
ZW
8964 if (!inst.operands[1].present)
8965 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8966
c56791bb
RE
8967 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8968 register and the first register written; we have to diagnose
8969 overlap between the base and the second register written here. */
ea6ef066 8970
c56791bb
RE
8971 if (inst.operands[2].reg == inst.operands[1].reg
8972 && (inst.operands[2].writeback || inst.operands[2].postind))
8973 as_warn (_("base register written back, and overlaps "
8974 "second transfer register"));
b05fe5cf 8975
c56791bb
RE
8976 if (!(inst.instruction & V4_STR_BIT))
8977 {
c19d1205 8978 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8979 destination (even if not write-back). */
8980 if (inst.operands[2].immisreg
8981 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8982 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8983 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8984 }
c19d1205
ZW
8985 inst.instruction |= inst.operands[0].reg << 12;
8986 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8987}
8988
8989static void
c19d1205 8990do_ldrex (void)
b05fe5cf 8991{
c19d1205
ZW
8992 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8993 || inst.operands[1].postind || inst.operands[1].writeback
8994 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8995 || inst.operands[1].negative
8996 /* This can arise if the programmer has written
8997 strex rN, rM, foo
8998 or if they have mistakenly used a register name as the last
8999 operand, eg:
9000 strex rN, rM, rX
9001 It is very difficult to distinguish between these two cases
9002 because "rX" might actually be a label. ie the register
9003 name has been occluded by a symbol of the same name. So we
9004 just generate a general 'bad addressing mode' type error
9005 message and leave it up to the programmer to discover the
9006 true cause and fix their mistake. */
9007 || (inst.operands[1].reg == REG_PC),
9008 BAD_ADDR_MODE);
b05fe5cf 9009
c19d1205
ZW
9010 constraint (inst.reloc.exp.X_op != O_constant
9011 || inst.reloc.exp.X_add_number != 0,
9012 _("offset must be zero in ARM encoding"));
b05fe5cf 9013
5be8be5d
DG
9014 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9015
c19d1205
ZW
9016 inst.instruction |= inst.operands[0].reg << 12;
9017 inst.instruction |= inst.operands[1].reg << 16;
9018 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
9019}
9020
9021static void
c19d1205 9022do_ldrexd (void)
b05fe5cf 9023{
c19d1205
ZW
9024 constraint (inst.operands[0].reg % 2 != 0,
9025 _("even register required"));
9026 constraint (inst.operands[1].present
9027 && inst.operands[1].reg != inst.operands[0].reg + 1,
9028 _("can only load two consecutive registers"));
9029 /* If op 1 were present and equal to PC, this function wouldn't
9030 have been called in the first place. */
9031 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9032
c19d1205
ZW
9033 inst.instruction |= inst.operands[0].reg << 12;
9034 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9035}
9036
1be5fd2e
NC
9037/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9038 which is not a multiple of four is UNPREDICTABLE. */
9039static void
9040check_ldr_r15_aligned (void)
9041{
9042 constraint (!(inst.operands[1].immisreg)
9043 && (inst.operands[0].reg == REG_PC
9044 && inst.operands[1].reg == REG_PC
9045 && (inst.reloc.exp.X_add_number & 0x3)),
de194d85 9046 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9047}
9048
b05fe5cf 9049static void
c19d1205 9050do_ldst (void)
b05fe5cf 9051{
c19d1205
ZW
9052 inst.instruction |= inst.operands[0].reg << 12;
9053 if (!inst.operands[1].isreg)
8335d6aa 9054 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9055 return;
c19d1205 9056 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9057 check_ldr_r15_aligned ();
b05fe5cf
ZW
9058}
9059
9060static void
c19d1205 9061do_ldstt (void)
b05fe5cf 9062{
c19d1205
ZW
9063 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9064 reject [Rn,...]. */
9065 if (inst.operands[1].preind)
b05fe5cf 9066 {
bd3ba5d1
NC
9067 constraint (inst.reloc.exp.X_op != O_constant
9068 || inst.reloc.exp.X_add_number != 0,
c19d1205 9069 _("this instruction requires a post-indexed address"));
b05fe5cf 9070
c19d1205
ZW
9071 inst.operands[1].preind = 0;
9072 inst.operands[1].postind = 1;
9073 inst.operands[1].writeback = 1;
b05fe5cf 9074 }
c19d1205
ZW
9075 inst.instruction |= inst.operands[0].reg << 12;
9076 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9077}
b05fe5cf 9078
c19d1205 9079/* Halfword and signed-byte load/store operations. */
b05fe5cf 9080
c19d1205
ZW
9081static void
9082do_ldstv4 (void)
9083{
ff4a8d2b 9084 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9085 inst.instruction |= inst.operands[0].reg << 12;
9086 if (!inst.operands[1].isreg)
8335d6aa 9087 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9088 return;
c19d1205 9089 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9090}
9091
9092static void
c19d1205 9093do_ldsttv4 (void)
b05fe5cf 9094{
c19d1205
ZW
9095 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9096 reject [Rn,...]. */
9097 if (inst.operands[1].preind)
b05fe5cf 9098 {
bd3ba5d1
NC
9099 constraint (inst.reloc.exp.X_op != O_constant
9100 || inst.reloc.exp.X_add_number != 0,
c19d1205 9101 _("this instruction requires a post-indexed address"));
b05fe5cf 9102
c19d1205
ZW
9103 inst.operands[1].preind = 0;
9104 inst.operands[1].postind = 1;
9105 inst.operands[1].writeback = 1;
b05fe5cf 9106 }
c19d1205
ZW
9107 inst.instruction |= inst.operands[0].reg << 12;
9108 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9109}
b05fe5cf 9110
c19d1205
ZW
9111/* Co-processor register load/store.
9112 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9113static void
9114do_lstc (void)
9115{
9116 inst.instruction |= inst.operands[0].reg << 8;
9117 inst.instruction |= inst.operands[1].reg << 12;
9118 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9119}
9120
b05fe5cf 9121static void
c19d1205 9122do_mlas (void)
b05fe5cf 9123{
8fb9d7b9 9124 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9125 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9126 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9127 && !(inst.instruction & 0x00400000))
8fb9d7b9 9128 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9129
c19d1205
ZW
9130 inst.instruction |= inst.operands[0].reg << 16;
9131 inst.instruction |= inst.operands[1].reg;
9132 inst.instruction |= inst.operands[2].reg << 8;
9133 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9134}
b05fe5cf 9135
c19d1205
ZW
9136static void
9137do_mov (void)
9138{
a9f02af8
MG
9139 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9140 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9141 THUMB1_RELOC_ONLY);
c19d1205
ZW
9142 inst.instruction |= inst.operands[0].reg << 12;
9143 encode_arm_shifter_operand (1);
9144}
b05fe5cf 9145
c19d1205
ZW
9146/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9147static void
9148do_mov16 (void)
9149{
b6895b4f
PB
9150 bfd_vma imm;
9151 bfd_boolean top;
9152
9153 top = (inst.instruction & 0x00400000) != 0;
9154 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
33eaf5de 9155 _(":lower16: not allowed in this instruction"));
b6895b4f 9156 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
33eaf5de 9157 _(":upper16: not allowed in this instruction"));
c19d1205 9158 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9159 if (inst.reloc.type == BFD_RELOC_UNUSED)
9160 {
9161 imm = inst.reloc.exp.X_add_number;
9162 /* The value is in two pieces: 0:11, 16:19. */
9163 inst.instruction |= (imm & 0x00000fff);
9164 inst.instruction |= (imm & 0x0000f000) << 4;
9165 }
b05fe5cf 9166}
b99bd4ef 9167
037e8744
JB
9168static int
9169do_vfp_nsyn_mrs (void)
9170{
9171 if (inst.operands[0].isvec)
9172 {
9173 if (inst.operands[1].reg != 1)
477330fc 9174 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9175 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9176 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9177 do_vfp_nsyn_opcode ("fmstat");
9178 }
9179 else if (inst.operands[1].isvec)
9180 do_vfp_nsyn_opcode ("fmrx");
9181 else
9182 return FAIL;
5f4273c7 9183
037e8744
JB
9184 return SUCCESS;
9185}
9186
9187static int
9188do_vfp_nsyn_msr (void)
9189{
9190 if (inst.operands[0].isvec)
9191 do_vfp_nsyn_opcode ("fmxr");
9192 else
9193 return FAIL;
9194
9195 return SUCCESS;
9196}
9197
f7c21dc7
NC
9198static void
9199do_vmrs (void)
9200{
9201 unsigned Rt = inst.operands[0].reg;
fa94de6b 9202
16d02dc9 9203 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9204 {
9205 inst.error = BAD_SP;
9206 return;
9207 }
9208
40c7d507
RR
9209 /* MVFR2 is only valid at ARMv8-A. */
9210 if (inst.operands[1].reg == 5)
9211 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9212 _(BAD_FPU));
9213
f7c21dc7 9214 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9215 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9216 {
9217 inst.error = BAD_PC;
9218 return;
9219 }
9220
16d02dc9
JB
9221 /* If we get through parsing the register name, we just insert the number
9222 generated into the instruction without further validation. */
9223 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9224 inst.instruction |= (Rt << 12);
9225}
9226
9227static void
9228do_vmsr (void)
9229{
9230 unsigned Rt = inst.operands[1].reg;
fa94de6b 9231
f7c21dc7
NC
9232 if (thumb_mode)
9233 reject_bad_reg (Rt);
9234 else if (Rt == REG_PC)
9235 {
9236 inst.error = BAD_PC;
9237 return;
9238 }
9239
40c7d507
RR
9240 /* MVFR2 is only valid for ARMv8-A. */
9241 if (inst.operands[0].reg == 5)
9242 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9243 _(BAD_FPU));
9244
16d02dc9
JB
9245 /* If we get through parsing the register name, we just insert the number
9246 generated into the instruction without further validation. */
9247 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9248 inst.instruction |= (Rt << 12);
9249}
9250
b99bd4ef 9251static void
c19d1205 9252do_mrs (void)
b99bd4ef 9253{
90ec0d68
MGD
9254 unsigned br;
9255
037e8744
JB
9256 if (do_vfp_nsyn_mrs () == SUCCESS)
9257 return;
9258
ff4a8d2b 9259 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9260 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9261
9262 if (inst.operands[1].isreg)
9263 {
9264 br = inst.operands[1].reg;
806ab1c0 9265 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
90ec0d68
MGD
9266 as_bad (_("bad register for mrs"));
9267 }
9268 else
9269 {
9270 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9271 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9272 != (PSR_c|PSR_f),
d2cd1205 9273 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9274 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9275 }
9276
9277 inst.instruction |= br;
c19d1205 9278}
b99bd4ef 9279
c19d1205
ZW
9280/* Two possible forms:
9281 "{C|S}PSR_<field>, Rm",
9282 "{C|S}PSR_f, #expression". */
b99bd4ef 9283
c19d1205
ZW
9284static void
9285do_msr (void)
9286{
037e8744
JB
9287 if (do_vfp_nsyn_msr () == SUCCESS)
9288 return;
9289
c19d1205
ZW
9290 inst.instruction |= inst.operands[0].imm;
9291 if (inst.operands[1].isreg)
9292 inst.instruction |= inst.operands[1].reg;
9293 else
b99bd4ef 9294 {
c19d1205
ZW
9295 inst.instruction |= INST_IMMEDIATE;
9296 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9297 inst.reloc.pc_rel = 0;
b99bd4ef 9298 }
b99bd4ef
NC
9299}
9300
c19d1205
ZW
9301static void
9302do_mul (void)
a737bd4d 9303{
ff4a8d2b
NC
9304 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9305
c19d1205
ZW
9306 if (!inst.operands[2].present)
9307 inst.operands[2].reg = inst.operands[0].reg;
9308 inst.instruction |= inst.operands[0].reg << 16;
9309 inst.instruction |= inst.operands[1].reg;
9310 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9311
8fb9d7b9
MS
9312 if (inst.operands[0].reg == inst.operands[1].reg
9313 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9314 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9315}
9316
c19d1205
ZW
9317/* Long Multiply Parser
9318 UMULL RdLo, RdHi, Rm, Rs
9319 SMULL RdLo, RdHi, Rm, Rs
9320 UMLAL RdLo, RdHi, Rm, Rs
9321 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9322
9323static void
c19d1205 9324do_mull (void)
b99bd4ef 9325{
c19d1205
ZW
9326 inst.instruction |= inst.operands[0].reg << 12;
9327 inst.instruction |= inst.operands[1].reg << 16;
9328 inst.instruction |= inst.operands[2].reg;
9329 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9330
682b27ad
PB
9331 /* rdhi and rdlo must be different. */
9332 if (inst.operands[0].reg == inst.operands[1].reg)
9333 as_tsktsk (_("rdhi and rdlo must be different"));
9334
9335 /* rdhi, rdlo and rm must all be different before armv6. */
9336 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9337 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9338 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9339 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9340}
b99bd4ef 9341
c19d1205
ZW
9342static void
9343do_nop (void)
9344{
e7495e45
NS
9345 if (inst.operands[0].present
9346 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9347 {
9348 /* Architectural NOP hints are CPSR sets with no bits selected. */
9349 inst.instruction &= 0xf0000000;
e7495e45
NS
9350 inst.instruction |= 0x0320f000;
9351 if (inst.operands[0].present)
9352 inst.instruction |= inst.operands[0].imm;
c19d1205 9353 }
b99bd4ef
NC
9354}
9355
c19d1205
ZW
9356/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9357 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9358 Condition defaults to COND_ALWAYS.
9359 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9360
9361static void
c19d1205 9362do_pkhbt (void)
b99bd4ef 9363{
c19d1205
ZW
9364 inst.instruction |= inst.operands[0].reg << 12;
9365 inst.instruction |= inst.operands[1].reg << 16;
9366 inst.instruction |= inst.operands[2].reg;
9367 if (inst.operands[3].present)
9368 encode_arm_shift (3);
9369}
b99bd4ef 9370
c19d1205 9371/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9372
c19d1205
ZW
9373static void
9374do_pkhtb (void)
9375{
9376 if (!inst.operands[3].present)
b99bd4ef 9377 {
c19d1205
ZW
9378 /* If the shift specifier is omitted, turn the instruction
9379 into pkhbt rd, rm, rn. */
9380 inst.instruction &= 0xfff00010;
9381 inst.instruction |= inst.operands[0].reg << 12;
9382 inst.instruction |= inst.operands[1].reg;
9383 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9384 }
9385 else
9386 {
c19d1205
ZW
9387 inst.instruction |= inst.operands[0].reg << 12;
9388 inst.instruction |= inst.operands[1].reg << 16;
9389 inst.instruction |= inst.operands[2].reg;
9390 encode_arm_shift (3);
b99bd4ef
NC
9391 }
9392}
9393
c19d1205 9394/* ARMv5TE: Preload-Cache
60e5ef9f 9395 MP Extensions: Preload for write
c19d1205 9396
60e5ef9f 9397 PLD(W) <addr_mode>
c19d1205
ZW
9398
9399 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9400
9401static void
c19d1205 9402do_pld (void)
b99bd4ef 9403{
c19d1205
ZW
9404 constraint (!inst.operands[0].isreg,
9405 _("'[' expected after PLD mnemonic"));
9406 constraint (inst.operands[0].postind,
9407 _("post-indexed expression used in preload instruction"));
9408 constraint (inst.operands[0].writeback,
9409 _("writeback used in preload instruction"));
9410 constraint (!inst.operands[0].preind,
9411 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9412 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9413}
b99bd4ef 9414
62b3e311
PB
9415/* ARMv7: PLI <addr_mode> */
9416static void
9417do_pli (void)
9418{
9419 constraint (!inst.operands[0].isreg,
9420 _("'[' expected after PLI mnemonic"));
9421 constraint (inst.operands[0].postind,
9422 _("post-indexed expression used in preload instruction"));
9423 constraint (inst.operands[0].writeback,
9424 _("writeback used in preload instruction"));
9425 constraint (!inst.operands[0].preind,
9426 _("unindexed addressing used in preload instruction"));
9427 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9428 inst.instruction &= ~PRE_INDEX;
9429}
9430
c19d1205
ZW
9431static void
9432do_push_pop (void)
9433{
5e0d7f77
MP
9434 constraint (inst.operands[0].writeback,
9435 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9436 inst.operands[1] = inst.operands[0];
9437 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9438 inst.operands[0].isreg = 1;
9439 inst.operands[0].writeback = 1;
9440 inst.operands[0].reg = REG_SP;
6530b175 9441 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9442}
b99bd4ef 9443
c19d1205
ZW
9444/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9445 word at the specified address and the following word
9446 respectively.
9447 Unconditionally executed.
9448 Error if Rn is R15. */
b99bd4ef 9449
c19d1205
ZW
9450static void
9451do_rfe (void)
9452{
9453 inst.instruction |= inst.operands[0].reg << 16;
9454 if (inst.operands[0].writeback)
9455 inst.instruction |= WRITE_BACK;
9456}
b99bd4ef 9457
c19d1205 9458/* ARM V6 ssat (argument parse). */
b99bd4ef 9459
c19d1205
ZW
9460static void
9461do_ssat (void)
9462{
9463 inst.instruction |= inst.operands[0].reg << 12;
9464 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9465 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9466
c19d1205
ZW
9467 if (inst.operands[3].present)
9468 encode_arm_shift (3);
b99bd4ef
NC
9469}
9470
c19d1205 9471/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9472
9473static void
c19d1205 9474do_usat (void)
b99bd4ef 9475{
c19d1205
ZW
9476 inst.instruction |= inst.operands[0].reg << 12;
9477 inst.instruction |= inst.operands[1].imm << 16;
9478 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9479
c19d1205
ZW
9480 if (inst.operands[3].present)
9481 encode_arm_shift (3);
b99bd4ef
NC
9482}
9483
c19d1205 9484/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9485
9486static void
c19d1205 9487do_ssat16 (void)
09d92015 9488{
c19d1205
ZW
9489 inst.instruction |= inst.operands[0].reg << 12;
9490 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9491 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9492}
9493
c19d1205
ZW
9494static void
9495do_usat16 (void)
a737bd4d 9496{
c19d1205
ZW
9497 inst.instruction |= inst.operands[0].reg << 12;
9498 inst.instruction |= inst.operands[1].imm << 16;
9499 inst.instruction |= inst.operands[2].reg;
9500}
a737bd4d 9501
c19d1205
ZW
9502/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9503 preserving the other bits.
a737bd4d 9504
c19d1205
ZW
9505 setend <endian_specifier>, where <endian_specifier> is either
9506 BE or LE. */
a737bd4d 9507
c19d1205
ZW
9508static void
9509do_setend (void)
9510{
12e37cbc
MGD
9511 if (warn_on_deprecated
9512 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9513 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9514
c19d1205
ZW
9515 if (inst.operands[0].imm)
9516 inst.instruction |= 0x200;
a737bd4d
NC
9517}
9518
9519static void
c19d1205 9520do_shift (void)
a737bd4d 9521{
c19d1205
ZW
9522 unsigned int Rm = (inst.operands[1].present
9523 ? inst.operands[1].reg
9524 : inst.operands[0].reg);
a737bd4d 9525
c19d1205
ZW
9526 inst.instruction |= inst.operands[0].reg << 12;
9527 inst.instruction |= Rm;
9528 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9529 {
c19d1205
ZW
9530 inst.instruction |= inst.operands[2].reg << 8;
9531 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9532 /* PR 12854: Error on extraneous shifts. */
9533 constraint (inst.operands[2].shifted,
9534 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9535 }
9536 else
c19d1205 9537 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9538}
9539
09d92015 9540static void
3eb17e6b 9541do_smc (void)
09d92015 9542{
3eb17e6b 9543 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9544 inst.reloc.pc_rel = 0;
09d92015
MM
9545}
9546
90ec0d68
MGD
9547static void
9548do_hvc (void)
9549{
9550 inst.reloc.type = BFD_RELOC_ARM_HVC;
9551 inst.reloc.pc_rel = 0;
9552}
9553
09d92015 9554static void
c19d1205 9555do_swi (void)
09d92015 9556{
c19d1205
ZW
9557 inst.reloc.type = BFD_RELOC_ARM_SWI;
9558 inst.reloc.pc_rel = 0;
09d92015
MM
9559}
9560
ddfded2f
MW
9561static void
9562do_setpan (void)
9563{
9564 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9565 _("selected processor does not support SETPAN instruction"));
9566
9567 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9568}
9569
9570static void
9571do_t_setpan (void)
9572{
9573 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9574 _("selected processor does not support SETPAN instruction"));
9575
9576 inst.instruction |= (inst.operands[0].imm << 3);
9577}
9578
c19d1205
ZW
9579/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9580 SMLAxy{cond} Rd,Rm,Rs,Rn
9581 SMLAWy{cond} Rd,Rm,Rs,Rn
9582 Error if any register is R15. */
e16bb312 9583
c19d1205
ZW
9584static void
9585do_smla (void)
e16bb312 9586{
c19d1205
ZW
9587 inst.instruction |= inst.operands[0].reg << 16;
9588 inst.instruction |= inst.operands[1].reg;
9589 inst.instruction |= inst.operands[2].reg << 8;
9590 inst.instruction |= inst.operands[3].reg << 12;
9591}
a737bd4d 9592
c19d1205
ZW
9593/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9594 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9595 Error if any register is R15.
9596 Warning if Rdlo == Rdhi. */
a737bd4d 9597
c19d1205
ZW
9598static void
9599do_smlal (void)
9600{
9601 inst.instruction |= inst.operands[0].reg << 12;
9602 inst.instruction |= inst.operands[1].reg << 16;
9603 inst.instruction |= inst.operands[2].reg;
9604 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9605
c19d1205
ZW
9606 if (inst.operands[0].reg == inst.operands[1].reg)
9607 as_tsktsk (_("rdhi and rdlo must be different"));
9608}
a737bd4d 9609
c19d1205
ZW
9610/* ARM V5E (El Segundo) signed-multiply (argument parse)
9611 SMULxy{cond} Rd,Rm,Rs
9612 Error if any register is R15. */
a737bd4d 9613
c19d1205
ZW
9614static void
9615do_smul (void)
9616{
9617 inst.instruction |= inst.operands[0].reg << 16;
9618 inst.instruction |= inst.operands[1].reg;
9619 inst.instruction |= inst.operands[2].reg << 8;
9620}
a737bd4d 9621
b6702015
PB
9622/* ARM V6 srs (argument parse). The variable fields in the encoding are
9623 the same for both ARM and Thumb-2. */
a737bd4d 9624
c19d1205
ZW
9625static void
9626do_srs (void)
9627{
b6702015
PB
9628 int reg;
9629
9630 if (inst.operands[0].present)
9631 {
9632 reg = inst.operands[0].reg;
fdfde340 9633 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9634 }
9635 else
fdfde340 9636 reg = REG_SP;
b6702015
PB
9637
9638 inst.instruction |= reg << 16;
9639 inst.instruction |= inst.operands[1].imm;
9640 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9641 inst.instruction |= WRITE_BACK;
9642}
a737bd4d 9643
c19d1205 9644/* ARM V6 strex (argument parse). */
a737bd4d 9645
c19d1205
ZW
9646static void
9647do_strex (void)
9648{
9649 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9650 || inst.operands[2].postind || inst.operands[2].writeback
9651 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9652 || inst.operands[2].negative
9653 /* See comment in do_ldrex(). */
9654 || (inst.operands[2].reg == REG_PC),
9655 BAD_ADDR_MODE);
a737bd4d 9656
c19d1205
ZW
9657 constraint (inst.operands[0].reg == inst.operands[1].reg
9658 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9659
c19d1205
ZW
9660 constraint (inst.reloc.exp.X_op != O_constant
9661 || inst.reloc.exp.X_add_number != 0,
9662 _("offset must be zero in ARM encoding"));
a737bd4d 9663
c19d1205
ZW
9664 inst.instruction |= inst.operands[0].reg << 12;
9665 inst.instruction |= inst.operands[1].reg;
9666 inst.instruction |= inst.operands[2].reg << 16;
9667 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9668}
9669
877807f8
NC
9670static void
9671do_t_strexbh (void)
9672{
9673 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9674 || inst.operands[2].postind || inst.operands[2].writeback
9675 || inst.operands[2].immisreg || inst.operands[2].shifted
9676 || inst.operands[2].negative,
9677 BAD_ADDR_MODE);
9678
9679 constraint (inst.operands[0].reg == inst.operands[1].reg
9680 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9681
9682 do_rm_rd_rn ();
9683}
9684
e16bb312 9685static void
c19d1205 9686do_strexd (void)
e16bb312 9687{
c19d1205
ZW
9688 constraint (inst.operands[1].reg % 2 != 0,
9689 _("even register required"));
9690 constraint (inst.operands[2].present
9691 && inst.operands[2].reg != inst.operands[1].reg + 1,
9692 _("can only store two consecutive registers"));
9693 /* If op 2 were present and equal to PC, this function wouldn't
9694 have been called in the first place. */
9695 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9696
c19d1205
ZW
9697 constraint (inst.operands[0].reg == inst.operands[1].reg
9698 || inst.operands[0].reg == inst.operands[1].reg + 1
9699 || inst.operands[0].reg == inst.operands[3].reg,
9700 BAD_OVERLAP);
e16bb312 9701
c19d1205
ZW
9702 inst.instruction |= inst.operands[0].reg << 12;
9703 inst.instruction |= inst.operands[1].reg;
9704 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9705}
9706
9eb6c0f1
MGD
9707/* ARM V8 STRL. */
9708static void
4b8c8c02 9709do_stlex (void)
9eb6c0f1
MGD
9710{
9711 constraint (inst.operands[0].reg == inst.operands[1].reg
9712 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9713
9714 do_rd_rm_rn ();
9715}
9716
9717static void
4b8c8c02 9718do_t_stlex (void)
9eb6c0f1
MGD
9719{
9720 constraint (inst.operands[0].reg == inst.operands[1].reg
9721 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9722
9723 do_rm_rd_rn ();
9724}
9725
c19d1205
ZW
9726/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9727 extends it to 32-bits, and adds the result to a value in another
9728 register. You can specify a rotation by 0, 8, 16, or 24 bits
9729 before extracting the 16-bit value.
9730 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9731 Condition defaults to COND_ALWAYS.
9732 Error if any register uses R15. */
9733
e16bb312 9734static void
c19d1205 9735do_sxtah (void)
e16bb312 9736{
c19d1205
ZW
9737 inst.instruction |= inst.operands[0].reg << 12;
9738 inst.instruction |= inst.operands[1].reg << 16;
9739 inst.instruction |= inst.operands[2].reg;
9740 inst.instruction |= inst.operands[3].imm << 10;
9741}
e16bb312 9742
c19d1205 9743/* ARM V6 SXTH.
e16bb312 9744
c19d1205
ZW
9745 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9746 Condition defaults to COND_ALWAYS.
9747 Error if any register uses R15. */
e16bb312
NC
9748
9749static void
c19d1205 9750do_sxth (void)
e16bb312 9751{
c19d1205
ZW
9752 inst.instruction |= inst.operands[0].reg << 12;
9753 inst.instruction |= inst.operands[1].reg;
9754 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9755}
c19d1205
ZW
9756\f
9757/* VFP instructions. In a logical order: SP variant first, monad
9758 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9759
9760static void
c19d1205 9761do_vfp_sp_monadic (void)
e16bb312 9762{
5287ad62
JB
9763 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9764 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9765}
9766
9767static void
c19d1205 9768do_vfp_sp_dyadic (void)
e16bb312 9769{
5287ad62
JB
9770 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9771 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9772 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9773}
9774
9775static void
c19d1205 9776do_vfp_sp_compare_z (void)
e16bb312 9777{
5287ad62 9778 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9779}
9780
9781static void
c19d1205 9782do_vfp_dp_sp_cvt (void)
e16bb312 9783{
5287ad62
JB
9784 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9785 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9786}
9787
9788static void
c19d1205 9789do_vfp_sp_dp_cvt (void)
e16bb312 9790{
5287ad62
JB
9791 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9792 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9793}
9794
9795static void
c19d1205 9796do_vfp_reg_from_sp (void)
e16bb312 9797{
c19d1205 9798 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9799 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9800}
9801
9802static void
c19d1205 9803do_vfp_reg2_from_sp2 (void)
e16bb312 9804{
c19d1205
ZW
9805 constraint (inst.operands[2].imm != 2,
9806 _("only two consecutive VFP SP registers allowed here"));
9807 inst.instruction |= inst.operands[0].reg << 12;
9808 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9809 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9810}
9811
9812static void
c19d1205 9813do_vfp_sp_from_reg (void)
e16bb312 9814{
5287ad62 9815 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9816 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9817}
9818
9819static void
c19d1205 9820do_vfp_sp2_from_reg2 (void)
e16bb312 9821{
c19d1205
ZW
9822 constraint (inst.operands[0].imm != 2,
9823 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9824 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9825 inst.instruction |= inst.operands[1].reg << 12;
9826 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9827}
9828
9829static void
c19d1205 9830do_vfp_sp_ldst (void)
e16bb312 9831{
5287ad62 9832 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9833 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9834}
9835
9836static void
c19d1205 9837do_vfp_dp_ldst (void)
e16bb312 9838{
5287ad62 9839 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9840 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9841}
9842
c19d1205 9843
e16bb312 9844static void
c19d1205 9845vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9846{
c19d1205
ZW
9847 if (inst.operands[0].writeback)
9848 inst.instruction |= WRITE_BACK;
9849 else
9850 constraint (ldstm_type != VFP_LDSTMIA,
9851 _("this addressing mode requires base-register writeback"));
9852 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9853 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9854 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9855}
9856
9857static void
c19d1205 9858vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9859{
c19d1205 9860 int count;
e16bb312 9861
c19d1205
ZW
9862 if (inst.operands[0].writeback)
9863 inst.instruction |= WRITE_BACK;
9864 else
9865 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9866 _("this addressing mode requires base-register writeback"));
e16bb312 9867
c19d1205 9868 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9869 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9870
c19d1205
ZW
9871 count = inst.operands[1].imm << 1;
9872 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9873 count += 1;
e16bb312 9874
c19d1205 9875 inst.instruction |= count;
e16bb312
NC
9876}
9877
9878static void
c19d1205 9879do_vfp_sp_ldstmia (void)
e16bb312 9880{
c19d1205 9881 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9882}
9883
9884static void
c19d1205 9885do_vfp_sp_ldstmdb (void)
e16bb312 9886{
c19d1205 9887 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9888}
9889
9890static void
c19d1205 9891do_vfp_dp_ldstmia (void)
e16bb312 9892{
c19d1205 9893 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9894}
9895
9896static void
c19d1205 9897do_vfp_dp_ldstmdb (void)
e16bb312 9898{
c19d1205 9899 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9900}
9901
9902static void
c19d1205 9903do_vfp_xp_ldstmia (void)
e16bb312 9904{
c19d1205
ZW
9905 vfp_dp_ldstm (VFP_LDSTMIAX);
9906}
e16bb312 9907
c19d1205
ZW
9908static void
9909do_vfp_xp_ldstmdb (void)
9910{
9911 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9912}
5287ad62
JB
9913
9914static void
9915do_vfp_dp_rd_rm (void)
9916{
9917 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9918 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9919}
9920
9921static void
9922do_vfp_dp_rn_rd (void)
9923{
9924 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9925 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9926}
9927
9928static void
9929do_vfp_dp_rd_rn (void)
9930{
9931 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9932 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9933}
9934
9935static void
9936do_vfp_dp_rd_rn_rm (void)
9937{
9938 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9939 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9940 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9941}
9942
9943static void
9944do_vfp_dp_rd (void)
9945{
9946 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9947}
9948
9949static void
9950do_vfp_dp_rm_rd_rn (void)
9951{
9952 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9953 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9954 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9955}
9956
9957/* VFPv3 instructions. */
9958static void
9959do_vfp_sp_const (void)
9960{
9961 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9962 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9963 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9964}
9965
9966static void
9967do_vfp_dp_const (void)
9968{
9969 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9970 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9971 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9972}
9973
9974static void
9975vfp_conv (int srcsize)
9976{
5f1af56b
MGD
9977 int immbits = srcsize - inst.operands[1].imm;
9978
fa94de6b
RM
9979 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9980 {
5f1af56b 9981 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9982 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9983 inst.error = _("immediate value out of range, expected range [0, 16]");
9984 return;
9985 }
fa94de6b 9986 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9987 {
9988 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9989 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9990 inst.error = _("immediate value out of range, expected range [1, 32]");
9991 return;
9992 }
9993
5287ad62
JB
9994 inst.instruction |= (immbits & 1) << 5;
9995 inst.instruction |= (immbits >> 1);
9996}
9997
9998static void
9999do_vfp_sp_conv_16 (void)
10000{
10001 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10002 vfp_conv (16);
10003}
10004
10005static void
10006do_vfp_dp_conv_16 (void)
10007{
10008 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10009 vfp_conv (16);
10010}
10011
10012static void
10013do_vfp_sp_conv_32 (void)
10014{
10015 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10016 vfp_conv (32);
10017}
10018
10019static void
10020do_vfp_dp_conv_32 (void)
10021{
10022 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10023 vfp_conv (32);
10024}
c19d1205
ZW
10025\f
10026/* FPA instructions. Also in a logical order. */
e16bb312 10027
c19d1205
ZW
10028static void
10029do_fpa_cmp (void)
10030{
10031 inst.instruction |= inst.operands[0].reg << 16;
10032 inst.instruction |= inst.operands[1].reg;
10033}
b99bd4ef
NC
10034
10035static void
c19d1205 10036do_fpa_ldmstm (void)
b99bd4ef 10037{
c19d1205
ZW
10038 inst.instruction |= inst.operands[0].reg << 12;
10039 switch (inst.operands[1].imm)
10040 {
10041 case 1: inst.instruction |= CP_T_X; break;
10042 case 2: inst.instruction |= CP_T_Y; break;
10043 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10044 case 4: break;
10045 default: abort ();
10046 }
b99bd4ef 10047
c19d1205
ZW
10048 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10049 {
10050 /* The instruction specified "ea" or "fd", so we can only accept
10051 [Rn]{!}. The instruction does not really support stacking or
10052 unstacking, so we have to emulate these by setting appropriate
10053 bits and offsets. */
10054 constraint (inst.reloc.exp.X_op != O_constant
10055 || inst.reloc.exp.X_add_number != 0,
10056 _("this instruction does not support indexing"));
b99bd4ef 10057
c19d1205
ZW
10058 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
10059 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 10060
c19d1205
ZW
10061 if (!(inst.instruction & INDEX_UP))
10062 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 10063
c19d1205
ZW
10064 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10065 {
10066 inst.operands[2].preind = 0;
10067 inst.operands[2].postind = 1;
10068 }
10069 }
b99bd4ef 10070
c19d1205 10071 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 10072}
c19d1205
ZW
10073\f
10074/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 10075
c19d1205
ZW
10076static void
10077do_iwmmxt_tandorc (void)
10078{
10079 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10080}
b99bd4ef 10081
c19d1205
ZW
10082static void
10083do_iwmmxt_textrc (void)
10084{
10085 inst.instruction |= inst.operands[0].reg << 12;
10086 inst.instruction |= inst.operands[1].imm;
10087}
b99bd4ef
NC
10088
10089static void
c19d1205 10090do_iwmmxt_textrm (void)
b99bd4ef 10091{
c19d1205
ZW
10092 inst.instruction |= inst.operands[0].reg << 12;
10093 inst.instruction |= inst.operands[1].reg << 16;
10094 inst.instruction |= inst.operands[2].imm;
10095}
b99bd4ef 10096
c19d1205
ZW
10097static void
10098do_iwmmxt_tinsr (void)
10099{
10100 inst.instruction |= inst.operands[0].reg << 16;
10101 inst.instruction |= inst.operands[1].reg << 12;
10102 inst.instruction |= inst.operands[2].imm;
10103}
b99bd4ef 10104
c19d1205
ZW
10105static void
10106do_iwmmxt_tmia (void)
10107{
10108 inst.instruction |= inst.operands[0].reg << 5;
10109 inst.instruction |= inst.operands[1].reg;
10110 inst.instruction |= inst.operands[2].reg << 12;
10111}
b99bd4ef 10112
c19d1205
ZW
10113static void
10114do_iwmmxt_waligni (void)
10115{
10116 inst.instruction |= inst.operands[0].reg << 12;
10117 inst.instruction |= inst.operands[1].reg << 16;
10118 inst.instruction |= inst.operands[2].reg;
10119 inst.instruction |= inst.operands[3].imm << 20;
10120}
b99bd4ef 10121
2d447fca
JM
10122static void
10123do_iwmmxt_wmerge (void)
10124{
10125 inst.instruction |= inst.operands[0].reg << 12;
10126 inst.instruction |= inst.operands[1].reg << 16;
10127 inst.instruction |= inst.operands[2].reg;
10128 inst.instruction |= inst.operands[3].imm << 21;
10129}
10130
c19d1205
ZW
10131static void
10132do_iwmmxt_wmov (void)
10133{
10134 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10135 inst.instruction |= inst.operands[0].reg << 12;
10136 inst.instruction |= inst.operands[1].reg << 16;
10137 inst.instruction |= inst.operands[1].reg;
10138}
b99bd4ef 10139
c19d1205
ZW
10140static void
10141do_iwmmxt_wldstbh (void)
10142{
8f06b2d8 10143 int reloc;
c19d1205 10144 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10145 if (thumb_mode)
10146 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10147 else
10148 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10149 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10150}
10151
c19d1205
ZW
10152static void
10153do_iwmmxt_wldstw (void)
10154{
10155 /* RIWR_RIWC clears .isreg for a control register. */
10156 if (!inst.operands[0].isreg)
10157 {
10158 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10159 inst.instruction |= 0xf0000000;
10160 }
b99bd4ef 10161
c19d1205
ZW
10162 inst.instruction |= inst.operands[0].reg << 12;
10163 encode_arm_cp_address (1, TRUE, TRUE, 0);
10164}
b99bd4ef
NC
10165
10166static void
c19d1205 10167do_iwmmxt_wldstd (void)
b99bd4ef 10168{
c19d1205 10169 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10170 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10171 && inst.operands[1].immisreg)
10172 {
10173 inst.instruction &= ~0x1a000ff;
eff0bc54 10174 inst.instruction |= (0xfU << 28);
2d447fca
JM
10175 if (inst.operands[1].preind)
10176 inst.instruction |= PRE_INDEX;
10177 if (!inst.operands[1].negative)
10178 inst.instruction |= INDEX_UP;
10179 if (inst.operands[1].writeback)
10180 inst.instruction |= WRITE_BACK;
10181 inst.instruction |= inst.operands[1].reg << 16;
10182 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10183 inst.instruction |= inst.operands[1].imm;
10184 }
10185 else
10186 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10187}
b99bd4ef 10188
c19d1205
ZW
10189static void
10190do_iwmmxt_wshufh (void)
10191{
10192 inst.instruction |= inst.operands[0].reg << 12;
10193 inst.instruction |= inst.operands[1].reg << 16;
10194 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10195 inst.instruction |= (inst.operands[2].imm & 0x0f);
10196}
b99bd4ef 10197
c19d1205
ZW
10198static void
10199do_iwmmxt_wzero (void)
10200{
10201 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10202 inst.instruction |= inst.operands[0].reg;
10203 inst.instruction |= inst.operands[0].reg << 12;
10204 inst.instruction |= inst.operands[0].reg << 16;
10205}
2d447fca
JM
10206
10207static void
10208do_iwmmxt_wrwrwr_or_imm5 (void)
10209{
10210 if (inst.operands[2].isreg)
10211 do_rd_rn_rm ();
10212 else {
10213 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10214 _("immediate operand requires iWMMXt2"));
10215 do_rd_rn ();
10216 if (inst.operands[2].imm == 0)
10217 {
10218 switch ((inst.instruction >> 20) & 0xf)
10219 {
10220 case 4:
10221 case 5:
10222 case 6:
5f4273c7 10223 case 7:
2d447fca
JM
10224 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10225 inst.operands[2].imm = 16;
10226 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10227 break;
10228 case 8:
10229 case 9:
10230 case 10:
10231 case 11:
10232 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10233 inst.operands[2].imm = 32;
10234 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10235 break;
10236 case 12:
10237 case 13:
10238 case 14:
10239 case 15:
10240 {
10241 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10242 unsigned long wrn;
10243 wrn = (inst.instruction >> 16) & 0xf;
10244 inst.instruction &= 0xff0fff0f;
10245 inst.instruction |= wrn;
10246 /* Bail out here; the instruction is now assembled. */
10247 return;
10248 }
10249 }
10250 }
10251 /* Map 32 -> 0, etc. */
10252 inst.operands[2].imm &= 0x1f;
eff0bc54 10253 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10254 }
10255}
c19d1205
ZW
10256\f
10257/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10258 operations first, then control, shift, and load/store. */
b99bd4ef 10259
c19d1205 10260/* Insns like "foo X,Y,Z". */
b99bd4ef 10261
c19d1205
ZW
10262static void
10263do_mav_triple (void)
10264{
10265 inst.instruction |= inst.operands[0].reg << 16;
10266 inst.instruction |= inst.operands[1].reg;
10267 inst.instruction |= inst.operands[2].reg << 12;
10268}
b99bd4ef 10269
c19d1205
ZW
10270/* Insns like "foo W,X,Y,Z".
10271 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10272
c19d1205
ZW
10273static void
10274do_mav_quad (void)
10275{
10276 inst.instruction |= inst.operands[0].reg << 5;
10277 inst.instruction |= inst.operands[1].reg << 12;
10278 inst.instruction |= inst.operands[2].reg << 16;
10279 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10280}
10281
c19d1205
ZW
10282/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10283static void
10284do_mav_dspsc (void)
a737bd4d 10285{
c19d1205
ZW
10286 inst.instruction |= inst.operands[1].reg << 12;
10287}
a737bd4d 10288
c19d1205
ZW
10289/* Maverick shift immediate instructions.
10290 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10291 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10292
c19d1205
ZW
10293static void
10294do_mav_shift (void)
10295{
10296 int imm = inst.operands[2].imm;
a737bd4d 10297
c19d1205
ZW
10298 inst.instruction |= inst.operands[0].reg << 12;
10299 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10300
c19d1205
ZW
10301 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10302 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10303 Bit 4 should be 0. */
10304 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10305
c19d1205
ZW
10306 inst.instruction |= imm;
10307}
10308\f
10309/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10310
c19d1205
ZW
10311/* Xscale multiply-accumulate (argument parse)
10312 MIAcc acc0,Rm,Rs
10313 MIAPHcc acc0,Rm,Rs
10314 MIAxycc acc0,Rm,Rs. */
a737bd4d 10315
c19d1205
ZW
10316static void
10317do_xsc_mia (void)
10318{
10319 inst.instruction |= inst.operands[1].reg;
10320 inst.instruction |= inst.operands[2].reg << 12;
10321}
a737bd4d 10322
c19d1205 10323/* Xscale move-accumulator-register (argument parse)
a737bd4d 10324
c19d1205 10325 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10326
c19d1205
ZW
10327static void
10328do_xsc_mar (void)
10329{
10330 inst.instruction |= inst.operands[1].reg << 12;
10331 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10332}
10333
c19d1205 10334/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10335
c19d1205 10336 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10337
10338static void
c19d1205 10339do_xsc_mra (void)
b99bd4ef 10340{
c19d1205
ZW
10341 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10342 inst.instruction |= inst.operands[0].reg << 12;
10343 inst.instruction |= inst.operands[1].reg << 16;
10344}
10345\f
10346/* Encoding functions relevant only to Thumb. */
b99bd4ef 10347
c19d1205
ZW
10348/* inst.operands[i] is a shifted-register operand; encode
10349 it into inst.instruction in the format used by Thumb32. */
10350
10351static void
10352encode_thumb32_shifted_operand (int i)
10353{
10354 unsigned int value = inst.reloc.exp.X_add_number;
10355 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10356
9c3c69f2
PB
10357 constraint (inst.operands[i].immisreg,
10358 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10359 inst.instruction |= inst.operands[i].reg;
10360 if (shift == SHIFT_RRX)
10361 inst.instruction |= SHIFT_ROR << 4;
10362 else
b99bd4ef 10363 {
c19d1205
ZW
10364 constraint (inst.reloc.exp.X_op != O_constant,
10365 _("expression too complex"));
10366
10367 constraint (value > 32
10368 || (value == 32 && (shift == SHIFT_LSL
10369 || shift == SHIFT_ROR)),
10370 _("shift expression is too large"));
10371
10372 if (value == 0)
10373 shift = SHIFT_LSL;
10374 else if (value == 32)
10375 value = 0;
10376
10377 inst.instruction |= shift << 4;
10378 inst.instruction |= (value & 0x1c) << 10;
10379 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10380 }
c19d1205 10381}
b99bd4ef 10382
b99bd4ef 10383
c19d1205
ZW
10384/* inst.operands[i] was set up by parse_address. Encode it into a
10385 Thumb32 format load or store instruction. Reject forms that cannot
10386 be used with such instructions. If is_t is true, reject forms that
10387 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10388 that cannot be used with a D instruction. If it is a store insn,
10389 reject PC in Rn. */
b99bd4ef 10390
c19d1205
ZW
10391static void
10392encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10393{
5be8be5d 10394 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10395
10396 constraint (!inst.operands[i].isreg,
53365c0d 10397 _("Instruction does not support =N addresses"));
b99bd4ef 10398
c19d1205
ZW
10399 inst.instruction |= inst.operands[i].reg << 16;
10400 if (inst.operands[i].immisreg)
b99bd4ef 10401 {
5be8be5d 10402 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10403 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10404 constraint (inst.operands[i].negative,
10405 _("Thumb does not support negative register indexing"));
10406 constraint (inst.operands[i].postind,
10407 _("Thumb does not support register post-indexing"));
10408 constraint (inst.operands[i].writeback,
10409 _("Thumb does not support register indexing with writeback"));
10410 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10411 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10412
f40d1643 10413 inst.instruction |= inst.operands[i].imm;
c19d1205 10414 if (inst.operands[i].shifted)
b99bd4ef 10415 {
c19d1205
ZW
10416 constraint (inst.reloc.exp.X_op != O_constant,
10417 _("expression too complex"));
9c3c69f2
PB
10418 constraint (inst.reloc.exp.X_add_number < 0
10419 || inst.reloc.exp.X_add_number > 3,
c19d1205 10420 _("shift out of range"));
9c3c69f2 10421 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10422 }
10423 inst.reloc.type = BFD_RELOC_UNUSED;
10424 }
10425 else if (inst.operands[i].preind)
10426 {
5be8be5d 10427 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10428 constraint (is_t && inst.operands[i].writeback,
c19d1205 10429 _("cannot use writeback with this instruction"));
4755303e
WN
10430 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10431 BAD_PC_ADDRESSING);
c19d1205
ZW
10432
10433 if (is_d)
10434 {
10435 inst.instruction |= 0x01000000;
10436 if (inst.operands[i].writeback)
10437 inst.instruction |= 0x00200000;
b99bd4ef 10438 }
c19d1205 10439 else
b99bd4ef 10440 {
c19d1205
ZW
10441 inst.instruction |= 0x00000c00;
10442 if (inst.operands[i].writeback)
10443 inst.instruction |= 0x00000100;
b99bd4ef 10444 }
c19d1205 10445 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10446 }
c19d1205 10447 else if (inst.operands[i].postind)
b99bd4ef 10448 {
9c2799c2 10449 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10450 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10451 constraint (is_t, _("cannot use post-indexing with this instruction"));
10452
10453 if (is_d)
10454 inst.instruction |= 0x00200000;
10455 else
10456 inst.instruction |= 0x00000900;
10457 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10458 }
10459 else /* unindexed - only for coprocessor */
10460 inst.error = _("instruction does not accept unindexed addressing");
10461}
10462
10463/* Table of Thumb instructions which exist in both 16- and 32-bit
10464 encodings (the latter only in post-V6T2 cores). The index is the
10465 value used in the insns table below. When there is more than one
10466 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10467 holds variant (1).
10468 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10469#define T16_32_TAB \
21d799b5
NC
10470 X(_adc, 4140, eb400000), \
10471 X(_adcs, 4140, eb500000), \
10472 X(_add, 1c00, eb000000), \
10473 X(_adds, 1c00, eb100000), \
10474 X(_addi, 0000, f1000000), \
10475 X(_addis, 0000, f1100000), \
10476 X(_add_pc,000f, f20f0000), \
10477 X(_add_sp,000d, f10d0000), \
10478 X(_adr, 000f, f20f0000), \
10479 X(_and, 4000, ea000000), \
10480 X(_ands, 4000, ea100000), \
10481 X(_asr, 1000, fa40f000), \
10482 X(_asrs, 1000, fa50f000), \
10483 X(_b, e000, f000b000), \
10484 X(_bcond, d000, f0008000), \
10485 X(_bic, 4380, ea200000), \
10486 X(_bics, 4380, ea300000), \
10487 X(_cmn, 42c0, eb100f00), \
10488 X(_cmp, 2800, ebb00f00), \
10489 X(_cpsie, b660, f3af8400), \
10490 X(_cpsid, b670, f3af8600), \
10491 X(_cpy, 4600, ea4f0000), \
10492 X(_dec_sp,80dd, f1ad0d00), \
10493 X(_eor, 4040, ea800000), \
10494 X(_eors, 4040, ea900000), \
10495 X(_inc_sp,00dd, f10d0d00), \
10496 X(_ldmia, c800, e8900000), \
10497 X(_ldr, 6800, f8500000), \
10498 X(_ldrb, 7800, f8100000), \
10499 X(_ldrh, 8800, f8300000), \
10500 X(_ldrsb, 5600, f9100000), \
10501 X(_ldrsh, 5e00, f9300000), \
10502 X(_ldr_pc,4800, f85f0000), \
10503 X(_ldr_pc2,4800, f85f0000), \
10504 X(_ldr_sp,9800, f85d0000), \
10505 X(_lsl, 0000, fa00f000), \
10506 X(_lsls, 0000, fa10f000), \
10507 X(_lsr, 0800, fa20f000), \
10508 X(_lsrs, 0800, fa30f000), \
10509 X(_mov, 2000, ea4f0000), \
10510 X(_movs, 2000, ea5f0000), \
10511 X(_mul, 4340, fb00f000), \
10512 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10513 X(_mvn, 43c0, ea6f0000), \
10514 X(_mvns, 43c0, ea7f0000), \
10515 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10516 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10517 X(_orr, 4300, ea400000), \
10518 X(_orrs, 4300, ea500000), \
10519 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10520 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10521 X(_rev, ba00, fa90f080), \
10522 X(_rev16, ba40, fa90f090), \
10523 X(_revsh, bac0, fa90f0b0), \
10524 X(_ror, 41c0, fa60f000), \
10525 X(_rors, 41c0, fa70f000), \
10526 X(_sbc, 4180, eb600000), \
10527 X(_sbcs, 4180, eb700000), \
10528 X(_stmia, c000, e8800000), \
10529 X(_str, 6000, f8400000), \
10530 X(_strb, 7000, f8000000), \
10531 X(_strh, 8000, f8200000), \
10532 X(_str_sp,9000, f84d0000), \
10533 X(_sub, 1e00, eba00000), \
10534 X(_subs, 1e00, ebb00000), \
10535 X(_subi, 8000, f1a00000), \
10536 X(_subis, 8000, f1b00000), \
10537 X(_sxtb, b240, fa4ff080), \
10538 X(_sxth, b200, fa0ff080), \
10539 X(_tst, 4200, ea100f00), \
10540 X(_uxtb, b2c0, fa5ff080), \
10541 X(_uxth, b280, fa1ff080), \
10542 X(_nop, bf00, f3af8000), \
10543 X(_yield, bf10, f3af8001), \
10544 X(_wfe, bf20, f3af8002), \
10545 X(_wfi, bf30, f3af8003), \
53c4b28b 10546 X(_sev, bf40, f3af8004), \
74db7efb
NC
10547 X(_sevl, bf50, f3af8005), \
10548 X(_udf, de00, f7f0a000)
c19d1205
ZW
10549
10550/* To catch errors in encoding functions, the codes are all offset by
10551 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10552 as 16-bit instructions. */
21d799b5 10553#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10554enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10555#undef X
10556
10557#define X(a,b,c) 0x##b
10558static const unsigned short thumb_op16[] = { T16_32_TAB };
10559#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10560#undef X
10561
10562#define X(a,b,c) 0x##c
10563static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10564#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10565#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10566#undef X
10567#undef T16_32_TAB
10568
10569/* Thumb instruction encoders, in alphabetical order. */
10570
92e90b6e 10571/* ADDW or SUBW. */
c921be7d 10572
92e90b6e
PB
10573static void
10574do_t_add_sub_w (void)
10575{
10576 int Rd, Rn;
10577
10578 Rd = inst.operands[0].reg;
10579 Rn = inst.operands[1].reg;
10580
539d4391
NC
10581 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10582 is the SP-{plus,minus}-immediate form of the instruction. */
10583 if (Rn == REG_SP)
10584 constraint (Rd == REG_PC, BAD_PC);
10585 else
10586 reject_bad_reg (Rd);
fdfde340 10587
92e90b6e
PB
10588 inst.instruction |= (Rn << 16) | (Rd << 8);
10589 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10590}
10591
c19d1205 10592/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 10593 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
10594
10595static void
10596do_t_add_sub (void)
10597{
10598 int Rd, Rs, Rn;
10599
10600 Rd = inst.operands[0].reg;
10601 Rs = (inst.operands[1].present
10602 ? inst.operands[1].reg /* Rd, Rs, foo */
10603 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10604
e07e6e58
NC
10605 if (Rd == REG_PC)
10606 set_it_insn_type_last ();
10607
c19d1205
ZW
10608 if (unified_syntax)
10609 {
0110f2b8
PB
10610 bfd_boolean flags;
10611 bfd_boolean narrow;
10612 int opcode;
10613
10614 flags = (inst.instruction == T_MNEM_adds
10615 || inst.instruction == T_MNEM_subs);
10616 if (flags)
e07e6e58 10617 narrow = !in_it_block ();
0110f2b8 10618 else
e07e6e58 10619 narrow = in_it_block ();
c19d1205 10620 if (!inst.operands[2].isreg)
b99bd4ef 10621 {
16805f35
PB
10622 int add;
10623
5c8ed6a4
JW
10624 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10625 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 10626
16805f35
PB
10627 add = (inst.instruction == T_MNEM_add
10628 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10629 opcode = 0;
10630 if (inst.size_req != 4)
10631 {
0110f2b8 10632 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10633 appropriate. */
0110f2b8
PB
10634 if (Rd == REG_SP && Rs == REG_SP && !flags)
10635 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10636 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10637 opcode = T_MNEM_add_sp;
10638 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10639 opcode = T_MNEM_add_pc;
10640 else if (Rd <= 7 && Rs <= 7 && narrow)
10641 {
10642 if (flags)
10643 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10644 else
10645 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10646 }
10647 if (opcode)
10648 {
10649 inst.instruction = THUMB_OP16(opcode);
10650 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10651 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10652 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10653 {
10654 if (inst.size_req == 2)
10655 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10656 else
10657 inst.relax = opcode;
10658 }
0110f2b8
PB
10659 }
10660 else
10661 constraint (inst.size_req == 2, BAD_HIREG);
10662 }
10663 if (inst.size_req == 4
10664 || (inst.size_req != 2 && !opcode))
10665 {
a9f02af8
MG
10666 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10667 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10668 THUMB1_RELOC_ONLY);
efd81785
PB
10669 if (Rd == REG_PC)
10670 {
fdfde340 10671 constraint (add, BAD_PC);
efd81785
PB
10672 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10673 _("only SUBS PC, LR, #const allowed"));
10674 constraint (inst.reloc.exp.X_op != O_constant,
10675 _("expression too complex"));
10676 constraint (inst.reloc.exp.X_add_number < 0
10677 || inst.reloc.exp.X_add_number > 0xff,
10678 _("immediate value out of range"));
10679 inst.instruction = T2_SUBS_PC_LR
10680 | inst.reloc.exp.X_add_number;
10681 inst.reloc.type = BFD_RELOC_UNUSED;
10682 return;
10683 }
10684 else if (Rs == REG_PC)
16805f35
PB
10685 {
10686 /* Always use addw/subw. */
10687 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10688 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10689 }
10690 else
10691 {
10692 inst.instruction = THUMB_OP32 (inst.instruction);
10693 inst.instruction = (inst.instruction & 0xe1ffffff)
10694 | 0x10000000;
10695 if (flags)
10696 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10697 else
10698 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10699 }
dc4503c6
PB
10700 inst.instruction |= Rd << 8;
10701 inst.instruction |= Rs << 16;
0110f2b8 10702 }
b99bd4ef 10703 }
c19d1205
ZW
10704 else
10705 {
5f4cb198
NC
10706 unsigned int value = inst.reloc.exp.X_add_number;
10707 unsigned int shift = inst.operands[2].shift_kind;
10708
c19d1205
ZW
10709 Rn = inst.operands[2].reg;
10710 /* See if we can do this with a 16-bit instruction. */
10711 if (!inst.operands[2].shifted && inst.size_req != 4)
10712 {
e27ec89e
PB
10713 if (Rd > 7 || Rs > 7 || Rn > 7)
10714 narrow = FALSE;
10715
10716 if (narrow)
c19d1205 10717 {
e27ec89e
PB
10718 inst.instruction = ((inst.instruction == T_MNEM_adds
10719 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10720 ? T_OPCODE_ADD_R3
10721 : T_OPCODE_SUB_R3);
10722 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10723 return;
10724 }
b99bd4ef 10725
7e806470 10726 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10727 {
7e806470
PB
10728 /* Thumb-1 cores (except v6-M) require at least one high
10729 register in a narrow non flag setting add. */
10730 if (Rd > 7 || Rn > 7
10731 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10732 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10733 {
7e806470
PB
10734 if (Rd == Rn)
10735 {
10736 Rn = Rs;
10737 Rs = Rd;
10738 }
c19d1205
ZW
10739 inst.instruction = T_OPCODE_ADD_HI;
10740 inst.instruction |= (Rd & 8) << 4;
10741 inst.instruction |= (Rd & 7);
10742 inst.instruction |= Rn << 3;
10743 return;
10744 }
c19d1205
ZW
10745 }
10746 }
c921be7d 10747
fdfde340 10748 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
10749 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10750 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
10751 constraint (Rs == REG_PC, BAD_PC);
10752 reject_bad_reg (Rn);
10753
c19d1205
ZW
10754 /* If we get here, it can't be done in 16 bits. */
10755 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10756 _("shift must be constant"));
10757 inst.instruction = THUMB_OP32 (inst.instruction);
10758 inst.instruction |= Rd << 8;
10759 inst.instruction |= Rs << 16;
5f4cb198
NC
10760 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10761 _("shift value over 3 not allowed in thumb mode"));
10762 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10763 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10764 encode_thumb32_shifted_operand (2);
10765 }
10766 }
10767 else
10768 {
10769 constraint (inst.instruction == T_MNEM_adds
10770 || inst.instruction == T_MNEM_subs,
10771 BAD_THUMB32);
b99bd4ef 10772
c19d1205 10773 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10774 {
c19d1205
ZW
10775 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10776 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10777 BAD_HIREG);
10778
10779 inst.instruction = (inst.instruction == T_MNEM_add
10780 ? 0x0000 : 0x8000);
10781 inst.instruction |= (Rd << 4) | Rs;
10782 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10783 return;
10784 }
10785
c19d1205
ZW
10786 Rn = inst.operands[2].reg;
10787 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10788
c19d1205
ZW
10789 /* We now have Rd, Rs, and Rn set to registers. */
10790 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10791 {
c19d1205
ZW
10792 /* Can't do this for SUB. */
10793 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10794 inst.instruction = T_OPCODE_ADD_HI;
10795 inst.instruction |= (Rd & 8) << 4;
10796 inst.instruction |= (Rd & 7);
10797 if (Rs == Rd)
10798 inst.instruction |= Rn << 3;
10799 else if (Rn == Rd)
10800 inst.instruction |= Rs << 3;
10801 else
10802 constraint (1, _("dest must overlap one source register"));
10803 }
10804 else
10805 {
10806 inst.instruction = (inst.instruction == T_MNEM_add
10807 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10808 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10809 }
b99bd4ef 10810 }
b99bd4ef
NC
10811}
10812
c19d1205
ZW
10813static void
10814do_t_adr (void)
10815{
fdfde340
JM
10816 unsigned Rd;
10817
10818 Rd = inst.operands[0].reg;
10819 reject_bad_reg (Rd);
10820
10821 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10822 {
10823 /* Defer to section relaxation. */
10824 inst.relax = inst.instruction;
10825 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10826 inst.instruction |= Rd << 4;
0110f2b8
PB
10827 }
10828 else if (unified_syntax && inst.size_req != 2)
e9f89963 10829 {
0110f2b8 10830 /* Generate a 32-bit opcode. */
e9f89963 10831 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10832 inst.instruction |= Rd << 8;
e9f89963
PB
10833 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10834 inst.reloc.pc_rel = 1;
10835 }
10836 else
10837 {
0110f2b8 10838 /* Generate a 16-bit opcode. */
e9f89963
PB
10839 inst.instruction = THUMB_OP16 (inst.instruction);
10840 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10841 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10842 inst.reloc.pc_rel = 1;
fdfde340 10843 inst.instruction |= Rd << 4;
e9f89963 10844 }
52a86f84
NC
10845
10846 if (inst.reloc.exp.X_op == O_symbol
10847 && inst.reloc.exp.X_add_symbol != NULL
10848 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10849 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10850 inst.reloc.exp.X_add_number += 1;
c19d1205 10851}
b99bd4ef 10852
c19d1205
ZW
10853/* Arithmetic instructions for which there is just one 16-bit
10854 instruction encoding, and it allows only two low registers.
10855 For maximal compatibility with ARM syntax, we allow three register
10856 operands even when Thumb-32 instructions are not available, as long
10857 as the first two are identical. For instance, both "sbc r0,r1" and
10858 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10859static void
c19d1205 10860do_t_arit3 (void)
b99bd4ef 10861{
c19d1205 10862 int Rd, Rs, Rn;
b99bd4ef 10863
c19d1205
ZW
10864 Rd = inst.operands[0].reg;
10865 Rs = (inst.operands[1].present
10866 ? inst.operands[1].reg /* Rd, Rs, foo */
10867 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10868 Rn = inst.operands[2].reg;
b99bd4ef 10869
fdfde340
JM
10870 reject_bad_reg (Rd);
10871 reject_bad_reg (Rs);
10872 if (inst.operands[2].isreg)
10873 reject_bad_reg (Rn);
10874
c19d1205 10875 if (unified_syntax)
b99bd4ef 10876 {
c19d1205
ZW
10877 if (!inst.operands[2].isreg)
10878 {
10879 /* For an immediate, we always generate a 32-bit opcode;
10880 section relaxation will shrink it later if possible. */
10881 inst.instruction = THUMB_OP32 (inst.instruction);
10882 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10883 inst.instruction |= Rd << 8;
10884 inst.instruction |= Rs << 16;
10885 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10886 }
10887 else
10888 {
e27ec89e
PB
10889 bfd_boolean narrow;
10890
c19d1205 10891 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10892 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10893 narrow = !in_it_block ();
e27ec89e 10894 else
e07e6e58 10895 narrow = in_it_block ();
e27ec89e
PB
10896
10897 if (Rd > 7 || Rn > 7 || Rs > 7)
10898 narrow = FALSE;
10899 if (inst.operands[2].shifted)
10900 narrow = FALSE;
10901 if (inst.size_req == 4)
10902 narrow = FALSE;
10903
10904 if (narrow
c19d1205
ZW
10905 && Rd == Rs)
10906 {
10907 inst.instruction = THUMB_OP16 (inst.instruction);
10908 inst.instruction |= Rd;
10909 inst.instruction |= Rn << 3;
10910 return;
10911 }
b99bd4ef 10912
c19d1205
ZW
10913 /* If we get here, it can't be done in 16 bits. */
10914 constraint (inst.operands[2].shifted
10915 && inst.operands[2].immisreg,
10916 _("shift must be constant"));
10917 inst.instruction = THUMB_OP32 (inst.instruction);
10918 inst.instruction |= Rd << 8;
10919 inst.instruction |= Rs << 16;
10920 encode_thumb32_shifted_operand (2);
10921 }
a737bd4d 10922 }
c19d1205 10923 else
b99bd4ef 10924 {
c19d1205
ZW
10925 /* On its face this is a lie - the instruction does set the
10926 flags. However, the only supported mnemonic in this mode
10927 says it doesn't. */
10928 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10929
c19d1205
ZW
10930 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10931 _("unshifted register required"));
10932 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10933 constraint (Rd != Rs,
10934 _("dest and source1 must be the same register"));
a737bd4d 10935
c19d1205
ZW
10936 inst.instruction = THUMB_OP16 (inst.instruction);
10937 inst.instruction |= Rd;
10938 inst.instruction |= Rn << 3;
b99bd4ef 10939 }
a737bd4d 10940}
b99bd4ef 10941
c19d1205
ZW
10942/* Similarly, but for instructions where the arithmetic operation is
10943 commutative, so we can allow either of them to be different from
10944 the destination operand in a 16-bit instruction. For instance, all
10945 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10946 accepted. */
10947static void
10948do_t_arit3c (void)
a737bd4d 10949{
c19d1205 10950 int Rd, Rs, Rn;
b99bd4ef 10951
c19d1205
ZW
10952 Rd = inst.operands[0].reg;
10953 Rs = (inst.operands[1].present
10954 ? inst.operands[1].reg /* Rd, Rs, foo */
10955 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10956 Rn = inst.operands[2].reg;
c921be7d 10957
fdfde340
JM
10958 reject_bad_reg (Rd);
10959 reject_bad_reg (Rs);
10960 if (inst.operands[2].isreg)
10961 reject_bad_reg (Rn);
a737bd4d 10962
c19d1205 10963 if (unified_syntax)
a737bd4d 10964 {
c19d1205 10965 if (!inst.operands[2].isreg)
b99bd4ef 10966 {
c19d1205
ZW
10967 /* For an immediate, we always generate a 32-bit opcode;
10968 section relaxation will shrink it later if possible. */
10969 inst.instruction = THUMB_OP32 (inst.instruction);
10970 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10971 inst.instruction |= Rd << 8;
10972 inst.instruction |= Rs << 16;
10973 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10974 }
c19d1205 10975 else
a737bd4d 10976 {
e27ec89e
PB
10977 bfd_boolean narrow;
10978
c19d1205 10979 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10980 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10981 narrow = !in_it_block ();
e27ec89e 10982 else
e07e6e58 10983 narrow = in_it_block ();
e27ec89e
PB
10984
10985 if (Rd > 7 || Rn > 7 || Rs > 7)
10986 narrow = FALSE;
10987 if (inst.operands[2].shifted)
10988 narrow = FALSE;
10989 if (inst.size_req == 4)
10990 narrow = FALSE;
10991
10992 if (narrow)
a737bd4d 10993 {
c19d1205 10994 if (Rd == Rs)
a737bd4d 10995 {
c19d1205
ZW
10996 inst.instruction = THUMB_OP16 (inst.instruction);
10997 inst.instruction |= Rd;
10998 inst.instruction |= Rn << 3;
10999 return;
a737bd4d 11000 }
c19d1205 11001 if (Rd == Rn)
a737bd4d 11002 {
c19d1205
ZW
11003 inst.instruction = THUMB_OP16 (inst.instruction);
11004 inst.instruction |= Rd;
11005 inst.instruction |= Rs << 3;
11006 return;
a737bd4d
NC
11007 }
11008 }
c19d1205
ZW
11009
11010 /* If we get here, it can't be done in 16 bits. */
11011 constraint (inst.operands[2].shifted
11012 && inst.operands[2].immisreg,
11013 _("shift must be constant"));
11014 inst.instruction = THUMB_OP32 (inst.instruction);
11015 inst.instruction |= Rd << 8;
11016 inst.instruction |= Rs << 16;
11017 encode_thumb32_shifted_operand (2);
a737bd4d 11018 }
b99bd4ef 11019 }
c19d1205
ZW
11020 else
11021 {
11022 /* On its face this is a lie - the instruction does set the
11023 flags. However, the only supported mnemonic in this mode
11024 says it doesn't. */
11025 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11026
c19d1205
ZW
11027 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11028 _("unshifted register required"));
11029 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11030
11031 inst.instruction = THUMB_OP16 (inst.instruction);
11032 inst.instruction |= Rd;
11033
11034 if (Rd == Rs)
11035 inst.instruction |= Rn << 3;
11036 else if (Rd == Rn)
11037 inst.instruction |= Rs << 3;
11038 else
11039 constraint (1, _("dest must overlap one source register"));
11040 }
a737bd4d
NC
11041}
11042
c19d1205
ZW
11043static void
11044do_t_bfc (void)
a737bd4d 11045{
fdfde340 11046 unsigned Rd;
c19d1205
ZW
11047 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11048 constraint (msb > 32, _("bit-field extends past end of register"));
11049 /* The instruction encoding stores the LSB and MSB,
11050 not the LSB and width. */
fdfde340
JM
11051 Rd = inst.operands[0].reg;
11052 reject_bad_reg (Rd);
11053 inst.instruction |= Rd << 8;
c19d1205
ZW
11054 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11055 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11056 inst.instruction |= msb - 1;
b99bd4ef
NC
11057}
11058
c19d1205
ZW
11059static void
11060do_t_bfi (void)
b99bd4ef 11061{
fdfde340 11062 int Rd, Rn;
c19d1205 11063 unsigned int msb;
b99bd4ef 11064
fdfde340
JM
11065 Rd = inst.operands[0].reg;
11066 reject_bad_reg (Rd);
11067
c19d1205
ZW
11068 /* #0 in second position is alternative syntax for bfc, which is
11069 the same instruction but with REG_PC in the Rm field. */
11070 if (!inst.operands[1].isreg)
fdfde340
JM
11071 Rn = REG_PC;
11072 else
11073 {
11074 Rn = inst.operands[1].reg;
11075 reject_bad_reg (Rn);
11076 }
b99bd4ef 11077
c19d1205
ZW
11078 msb = inst.operands[2].imm + inst.operands[3].imm;
11079 constraint (msb > 32, _("bit-field extends past end of register"));
11080 /* The instruction encoding stores the LSB and MSB,
11081 not the LSB and width. */
fdfde340
JM
11082 inst.instruction |= Rd << 8;
11083 inst.instruction |= Rn << 16;
c19d1205
ZW
11084 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11085 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11086 inst.instruction |= msb - 1;
b99bd4ef
NC
11087}
11088
c19d1205
ZW
11089static void
11090do_t_bfx (void)
b99bd4ef 11091{
fdfde340
JM
11092 unsigned Rd, Rn;
11093
11094 Rd = inst.operands[0].reg;
11095 Rn = inst.operands[1].reg;
11096
11097 reject_bad_reg (Rd);
11098 reject_bad_reg (Rn);
11099
c19d1205
ZW
11100 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11101 _("bit-field extends past end of register"));
fdfde340
JM
11102 inst.instruction |= Rd << 8;
11103 inst.instruction |= Rn << 16;
c19d1205
ZW
11104 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11105 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11106 inst.instruction |= inst.operands[3].imm - 1;
11107}
b99bd4ef 11108
c19d1205
ZW
11109/* ARM V5 Thumb BLX (argument parse)
11110 BLX <target_addr> which is BLX(1)
11111 BLX <Rm> which is BLX(2)
11112 Unfortunately, there are two different opcodes for this mnemonic.
11113 So, the insns[].value is not used, and the code here zaps values
11114 into inst.instruction.
b99bd4ef 11115
c19d1205
ZW
11116 ??? How to take advantage of the additional two bits of displacement
11117 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11118
c19d1205
ZW
11119static void
11120do_t_blx (void)
11121{
e07e6e58
NC
11122 set_it_insn_type_last ();
11123
c19d1205 11124 if (inst.operands[0].isreg)
fdfde340
JM
11125 {
11126 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11127 /* We have a register, so this is BLX(2). */
11128 inst.instruction |= inst.operands[0].reg << 3;
11129 }
b99bd4ef
NC
11130 else
11131 {
c19d1205 11132 /* No register. This must be BLX(1). */
2fc8bdac 11133 inst.instruction = 0xf000e800;
0855e32b 11134 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11135 }
11136}
11137
c19d1205
ZW
11138static void
11139do_t_branch (void)
b99bd4ef 11140{
0110f2b8 11141 int opcode;
dfa9f0d5 11142 int cond;
2fe88214 11143 bfd_reloc_code_real_type reloc;
dfa9f0d5 11144
e07e6e58
NC
11145 cond = inst.cond;
11146 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11147
11148 if (in_it_block ())
dfa9f0d5
PB
11149 {
11150 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11151 branches. */
dfa9f0d5 11152 cond = COND_ALWAYS;
dfa9f0d5
PB
11153 }
11154 else
11155 cond = inst.cond;
11156
11157 if (cond != COND_ALWAYS)
0110f2b8
PB
11158 opcode = T_MNEM_bcond;
11159 else
11160 opcode = inst.instruction;
11161
12d6b0b7
RS
11162 if (unified_syntax
11163 && (inst.size_req == 4
10960bfb
PB
11164 || (inst.size_req != 2
11165 && (inst.operands[0].hasreloc
11166 || inst.reloc.exp.X_op == O_constant))))
c19d1205 11167 {
0110f2b8 11168 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11169 if (cond == COND_ALWAYS)
9ae92b05 11170 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11171 else
11172 {
ff8646ee
TP
11173 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11174 _("selected architecture does not support "
11175 "wide conditional branch instruction"));
11176
9c2799c2 11177 gas_assert (cond != 0xF);
dfa9f0d5 11178 inst.instruction |= cond << 22;
9ae92b05 11179 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11180 }
11181 }
b99bd4ef
NC
11182 else
11183 {
0110f2b8 11184 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11185 if (cond == COND_ALWAYS)
9ae92b05 11186 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11187 else
b99bd4ef 11188 {
dfa9f0d5 11189 inst.instruction |= cond << 8;
9ae92b05 11190 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11191 }
0110f2b8
PB
11192 /* Allow section relaxation. */
11193 if (unified_syntax && inst.size_req != 2)
11194 inst.relax = opcode;
b99bd4ef 11195 }
9ae92b05 11196 inst.reloc.type = reloc;
c19d1205 11197 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11198}
11199
8884b720 11200/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11201 between the two is the maximum immediate allowed - which is passed in
8884b720 11202 RANGE. */
b99bd4ef 11203static void
8884b720 11204do_t_bkpt_hlt1 (int range)
b99bd4ef 11205{
dfa9f0d5
PB
11206 constraint (inst.cond != COND_ALWAYS,
11207 _("instruction is always unconditional"));
c19d1205 11208 if (inst.operands[0].present)
b99bd4ef 11209 {
8884b720 11210 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11211 _("immediate value out of range"));
11212 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11213 }
8884b720
MGD
11214
11215 set_it_insn_type (NEUTRAL_IT_INSN);
11216}
11217
11218static void
11219do_t_hlt (void)
11220{
11221 do_t_bkpt_hlt1 (63);
11222}
11223
11224static void
11225do_t_bkpt (void)
11226{
11227 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11228}
11229
11230static void
c19d1205 11231do_t_branch23 (void)
b99bd4ef 11232{
e07e6e58 11233 set_it_insn_type_last ();
0855e32b 11234 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11235
0855e32b
NS
11236 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11237 this file. We used to simply ignore the PLT reloc type here --
11238 the branch encoding is now needed to deal with TLSCALL relocs.
11239 So if we see a PLT reloc now, put it back to how it used to be to
11240 keep the preexisting behaviour. */
11241 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11242 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11243
4343666d 11244#if defined(OBJ_COFF)
c19d1205
ZW
11245 /* If the destination of the branch is a defined symbol which does not have
11246 the THUMB_FUNC attribute, then we must be calling a function which has
11247 the (interfacearm) attribute. We look for the Thumb entry point to that
11248 function and change the branch to refer to that function instead. */
11249 if ( inst.reloc.exp.X_op == O_symbol
11250 && inst.reloc.exp.X_add_symbol != NULL
11251 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11252 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11253 inst.reloc.exp.X_add_symbol =
11254 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11255#endif
90e4755a
RE
11256}
11257
11258static void
c19d1205 11259do_t_bx (void)
90e4755a 11260{
e07e6e58 11261 set_it_insn_type_last ();
c19d1205
ZW
11262 inst.instruction |= inst.operands[0].reg << 3;
11263 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11264 should cause the alignment to be checked once it is known. This is
11265 because BX PC only works if the instruction is word aligned. */
11266}
90e4755a 11267
c19d1205
ZW
11268static void
11269do_t_bxj (void)
11270{
fdfde340 11271 int Rm;
90e4755a 11272
e07e6e58 11273 set_it_insn_type_last ();
fdfde340
JM
11274 Rm = inst.operands[0].reg;
11275 reject_bad_reg (Rm);
11276 inst.instruction |= Rm << 16;
90e4755a
RE
11277}
11278
11279static void
c19d1205 11280do_t_clz (void)
90e4755a 11281{
fdfde340
JM
11282 unsigned Rd;
11283 unsigned Rm;
11284
11285 Rd = inst.operands[0].reg;
11286 Rm = inst.operands[1].reg;
11287
11288 reject_bad_reg (Rd);
11289 reject_bad_reg (Rm);
11290
11291 inst.instruction |= Rd << 8;
11292 inst.instruction |= Rm << 16;
11293 inst.instruction |= Rm;
c19d1205 11294}
90e4755a 11295
91d8b670
JG
11296static void
11297do_t_csdb (void)
11298{
11299 set_it_insn_type (OUTSIDE_IT_INSN);
11300}
11301
dfa9f0d5
PB
11302static void
11303do_t_cps (void)
11304{
e07e6e58 11305 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11306 inst.instruction |= inst.operands[0].imm;
11307}
11308
c19d1205
ZW
11309static void
11310do_t_cpsi (void)
11311{
e07e6e58 11312 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11313 if (unified_syntax
62b3e311
PB
11314 && (inst.operands[1].present || inst.size_req == 4)
11315 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11316 {
c19d1205
ZW
11317 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11318 inst.instruction = 0xf3af8000;
11319 inst.instruction |= imod << 9;
11320 inst.instruction |= inst.operands[0].imm << 5;
11321 if (inst.operands[1].present)
11322 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11323 }
c19d1205 11324 else
90e4755a 11325 {
62b3e311
PB
11326 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11327 && (inst.operands[0].imm & 4),
11328 _("selected processor does not support 'A' form "
11329 "of this instruction"));
11330 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11331 _("Thumb does not support the 2-argument "
11332 "form of this instruction"));
11333 inst.instruction |= inst.operands[0].imm;
90e4755a 11334 }
90e4755a
RE
11335}
11336
c19d1205
ZW
11337/* THUMB CPY instruction (argument parse). */
11338
90e4755a 11339static void
c19d1205 11340do_t_cpy (void)
90e4755a 11341{
c19d1205 11342 if (inst.size_req == 4)
90e4755a 11343 {
c19d1205
ZW
11344 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11345 inst.instruction |= inst.operands[0].reg << 8;
11346 inst.instruction |= inst.operands[1].reg;
90e4755a 11347 }
c19d1205 11348 else
90e4755a 11349 {
c19d1205
ZW
11350 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11351 inst.instruction |= (inst.operands[0].reg & 0x7);
11352 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11353 }
90e4755a
RE
11354}
11355
90e4755a 11356static void
25fe350b 11357do_t_cbz (void)
90e4755a 11358{
e07e6e58 11359 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11360 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11361 inst.instruction |= inst.operands[0].reg;
11362 inst.reloc.pc_rel = 1;
11363 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11364}
90e4755a 11365
62b3e311
PB
11366static void
11367do_t_dbg (void)
11368{
11369 inst.instruction |= inst.operands[0].imm;
11370}
11371
11372static void
11373do_t_div (void)
11374{
fdfde340
JM
11375 unsigned Rd, Rn, Rm;
11376
11377 Rd = inst.operands[0].reg;
11378 Rn = (inst.operands[1].present
11379 ? inst.operands[1].reg : Rd);
11380 Rm = inst.operands[2].reg;
11381
11382 reject_bad_reg (Rd);
11383 reject_bad_reg (Rn);
11384 reject_bad_reg (Rm);
11385
11386 inst.instruction |= Rd << 8;
11387 inst.instruction |= Rn << 16;
11388 inst.instruction |= Rm;
62b3e311
PB
11389}
11390
c19d1205
ZW
11391static void
11392do_t_hint (void)
11393{
11394 if (unified_syntax && inst.size_req == 4)
11395 inst.instruction = THUMB_OP32 (inst.instruction);
11396 else
11397 inst.instruction = THUMB_OP16 (inst.instruction);
11398}
90e4755a 11399
c19d1205
ZW
11400static void
11401do_t_it (void)
11402{
11403 unsigned int cond = inst.operands[0].imm;
e27ec89e 11404
e07e6e58
NC
11405 set_it_insn_type (IT_INSN);
11406 now_it.mask = (inst.instruction & 0xf) | 0x10;
11407 now_it.cc = cond;
5a01bb1d 11408 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11409
11410 /* If the condition is a negative condition, invert the mask. */
c19d1205 11411 if ((cond & 0x1) == 0x0)
90e4755a 11412 {
c19d1205 11413 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11414
c19d1205 11415 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11416 {
11417 /* No conversion needed. */
11418 now_it.block_length = 1;
11419 }
c19d1205 11420 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11421 {
11422 mask ^= 0x8;
11423 now_it.block_length = 2;
11424 }
e27ec89e 11425 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11426 {
11427 mask ^= 0xC;
11428 now_it.block_length = 3;
11429 }
c19d1205 11430 else
5a01bb1d
MGD
11431 {
11432 mask ^= 0xE;
11433 now_it.block_length = 4;
11434 }
90e4755a 11435
e27ec89e
PB
11436 inst.instruction &= 0xfff0;
11437 inst.instruction |= mask;
c19d1205 11438 }
90e4755a 11439
c19d1205
ZW
11440 inst.instruction |= cond << 4;
11441}
90e4755a 11442
3c707909
PB
11443/* Helper function used for both push/pop and ldm/stm. */
11444static void
11445encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11446{
11447 bfd_boolean load;
11448
11449 load = (inst.instruction & (1 << 20)) != 0;
11450
11451 if (mask & (1 << 13))
11452 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11453
11454 if ((mask & (1 << base)) != 0
11455 && writeback)
11456 inst.error = _("having the base register in the register list when "
11457 "using write back is UNPREDICTABLE");
11458
3c707909
PB
11459 if (load)
11460 {
e07e6e58 11461 if (mask & (1 << 15))
477330fc
RM
11462 {
11463 if (mask & (1 << 14))
11464 inst.error = _("LR and PC should not both be in register list");
11465 else
11466 set_it_insn_type_last ();
11467 }
3c707909
PB
11468 }
11469 else
11470 {
11471 if (mask & (1 << 15))
11472 inst.error = _("PC not allowed in register list");
3c707909
PB
11473 }
11474
11475 if ((mask & (mask - 1)) == 0)
11476 {
11477 /* Single register transfers implemented as str/ldr. */
11478 if (writeback)
11479 {
11480 if (inst.instruction & (1 << 23))
11481 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11482 else
11483 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11484 }
11485 else
11486 {
11487 if (inst.instruction & (1 << 23))
11488 inst.instruction = 0x00800000; /* ia -> [base] */
11489 else
11490 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11491 }
11492
11493 inst.instruction |= 0xf8400000;
11494 if (load)
11495 inst.instruction |= 0x00100000;
11496
5f4273c7 11497 mask = ffs (mask) - 1;
3c707909
PB
11498 mask <<= 12;
11499 }
11500 else if (writeback)
11501 inst.instruction |= WRITE_BACK;
11502
11503 inst.instruction |= mask;
11504 inst.instruction |= base << 16;
11505}
11506
c19d1205
ZW
11507static void
11508do_t_ldmstm (void)
11509{
11510 /* This really doesn't seem worth it. */
11511 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11512 _("expression too complex"));
11513 constraint (inst.operands[1].writeback,
11514 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11515
c19d1205
ZW
11516 if (unified_syntax)
11517 {
3c707909
PB
11518 bfd_boolean narrow;
11519 unsigned mask;
11520
11521 narrow = FALSE;
c19d1205
ZW
11522 /* See if we can use a 16-bit instruction. */
11523 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11524 && inst.size_req != 4
3c707909 11525 && !(inst.operands[1].imm & ~0xff))
90e4755a 11526 {
3c707909 11527 mask = 1 << inst.operands[0].reg;
90e4755a 11528
eab4f823 11529 if (inst.operands[0].reg <= 7)
90e4755a 11530 {
3c707909 11531 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11532 ? inst.operands[0].writeback
11533 : (inst.operands[0].writeback
11534 == !(inst.operands[1].imm & mask)))
477330fc 11535 {
eab4f823
MGD
11536 if (inst.instruction == T_MNEM_stmia
11537 && (inst.operands[1].imm & mask)
11538 && (inst.operands[1].imm & (mask - 1)))
11539 as_warn (_("value stored for r%d is UNKNOWN"),
11540 inst.operands[0].reg);
3c707909 11541
eab4f823
MGD
11542 inst.instruction = THUMB_OP16 (inst.instruction);
11543 inst.instruction |= inst.operands[0].reg << 8;
11544 inst.instruction |= inst.operands[1].imm;
11545 narrow = TRUE;
11546 }
11547 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11548 {
11549 /* This means 1 register in reg list one of 3 situations:
11550 1. Instruction is stmia, but without writeback.
11551 2. lmdia without writeback, but with Rn not in
477330fc 11552 reglist.
eab4f823
MGD
11553 3. ldmia with writeback, but with Rn in reglist.
11554 Case 3 is UNPREDICTABLE behaviour, so we handle
11555 case 1 and 2 which can be converted into a 16-bit
11556 str or ldr. The SP cases are handled below. */
11557 unsigned long opcode;
11558 /* First, record an error for Case 3. */
11559 if (inst.operands[1].imm & mask
11560 && inst.operands[0].writeback)
fa94de6b 11561 inst.error =
eab4f823
MGD
11562 _("having the base register in the register list when "
11563 "using write back is UNPREDICTABLE");
fa94de6b
RM
11564
11565 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11566 : T_MNEM_ldr);
11567 inst.instruction = THUMB_OP16 (opcode);
11568 inst.instruction |= inst.operands[0].reg << 3;
11569 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11570 narrow = TRUE;
11571 }
90e4755a 11572 }
eab4f823 11573 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11574 {
eab4f823
MGD
11575 if (inst.operands[0].writeback)
11576 {
fa94de6b 11577 inst.instruction =
eab4f823 11578 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11579 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11580 inst.instruction |= inst.operands[1].imm;
477330fc 11581 narrow = TRUE;
eab4f823
MGD
11582 }
11583 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11584 {
fa94de6b 11585 inst.instruction =
eab4f823 11586 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11587 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11588 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11589 narrow = TRUE;
eab4f823 11590 }
90e4755a 11591 }
3c707909
PB
11592 }
11593
11594 if (!narrow)
11595 {
c19d1205
ZW
11596 if (inst.instruction < 0xffff)
11597 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11598
5f4273c7
NC
11599 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11600 inst.operands[0].writeback);
90e4755a
RE
11601 }
11602 }
c19d1205 11603 else
90e4755a 11604 {
c19d1205
ZW
11605 constraint (inst.operands[0].reg > 7
11606 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11607 constraint (inst.instruction != T_MNEM_ldmia
11608 && inst.instruction != T_MNEM_stmia,
11609 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11610 if (inst.instruction == T_MNEM_stmia)
f03698e6 11611 {
c19d1205
ZW
11612 if (!inst.operands[0].writeback)
11613 as_warn (_("this instruction will write back the base register"));
11614 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11615 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11616 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11617 inst.operands[0].reg);
f03698e6 11618 }
c19d1205 11619 else
90e4755a 11620 {
c19d1205
ZW
11621 if (!inst.operands[0].writeback
11622 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11623 as_warn (_("this instruction will write back the base register"));
11624 else if (inst.operands[0].writeback
11625 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11626 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11627 }
11628
c19d1205
ZW
11629 inst.instruction = THUMB_OP16 (inst.instruction);
11630 inst.instruction |= inst.operands[0].reg << 8;
11631 inst.instruction |= inst.operands[1].imm;
11632 }
11633}
e28cd48c 11634
c19d1205
ZW
11635static void
11636do_t_ldrex (void)
11637{
11638 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11639 || inst.operands[1].postind || inst.operands[1].writeback
11640 || inst.operands[1].immisreg || inst.operands[1].shifted
11641 || inst.operands[1].negative,
01cfc07f 11642 BAD_ADDR_MODE);
e28cd48c 11643
5be8be5d
DG
11644 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11645
c19d1205
ZW
11646 inst.instruction |= inst.operands[0].reg << 12;
11647 inst.instruction |= inst.operands[1].reg << 16;
11648 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11649}
e28cd48c 11650
c19d1205
ZW
11651static void
11652do_t_ldrexd (void)
11653{
11654 if (!inst.operands[1].present)
1cac9012 11655 {
c19d1205
ZW
11656 constraint (inst.operands[0].reg == REG_LR,
11657 _("r14 not allowed as first register "
11658 "when second register is omitted"));
11659 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11660 }
c19d1205
ZW
11661 constraint (inst.operands[0].reg == inst.operands[1].reg,
11662 BAD_OVERLAP);
b99bd4ef 11663
c19d1205
ZW
11664 inst.instruction |= inst.operands[0].reg << 12;
11665 inst.instruction |= inst.operands[1].reg << 8;
11666 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11667}
11668
11669static void
c19d1205 11670do_t_ldst (void)
b99bd4ef 11671{
0110f2b8
PB
11672 unsigned long opcode;
11673 int Rn;
11674
e07e6e58
NC
11675 if (inst.operands[0].isreg
11676 && !inst.operands[0].preind
11677 && inst.operands[0].reg == REG_PC)
11678 set_it_insn_type_last ();
11679
0110f2b8 11680 opcode = inst.instruction;
c19d1205 11681 if (unified_syntax)
b99bd4ef 11682 {
53365c0d
PB
11683 if (!inst.operands[1].isreg)
11684 {
11685 if (opcode <= 0xffff)
11686 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11687 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11688 return;
11689 }
0110f2b8
PB
11690 if (inst.operands[1].isreg
11691 && !inst.operands[1].writeback
c19d1205
ZW
11692 && !inst.operands[1].shifted && !inst.operands[1].postind
11693 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11694 && opcode <= 0xffff
11695 && inst.size_req != 4)
c19d1205 11696 {
0110f2b8
PB
11697 /* Insn may have a 16-bit form. */
11698 Rn = inst.operands[1].reg;
11699 if (inst.operands[1].immisreg)
11700 {
11701 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11702 /* [Rn, Rik] */
0110f2b8
PB
11703 if (Rn <= 7 && inst.operands[1].imm <= 7)
11704 goto op16;
5be8be5d
DG
11705 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11706 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11707 }
11708 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11709 && opcode != T_MNEM_ldrsb)
11710 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11711 || (Rn == REG_SP && opcode == T_MNEM_str))
11712 {
11713 /* [Rn, #const] */
11714 if (Rn > 7)
11715 {
11716 if (Rn == REG_PC)
11717 {
11718 if (inst.reloc.pc_rel)
11719 opcode = T_MNEM_ldr_pc2;
11720 else
11721 opcode = T_MNEM_ldr_pc;
11722 }
11723 else
11724 {
11725 if (opcode == T_MNEM_ldr)
11726 opcode = T_MNEM_ldr_sp;
11727 else
11728 opcode = T_MNEM_str_sp;
11729 }
11730 inst.instruction = inst.operands[0].reg << 8;
11731 }
11732 else
11733 {
11734 inst.instruction = inst.operands[0].reg;
11735 inst.instruction |= inst.operands[1].reg << 3;
11736 }
11737 inst.instruction |= THUMB_OP16 (opcode);
11738 if (inst.size_req == 2)
11739 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11740 else
11741 inst.relax = opcode;
11742 return;
11743 }
c19d1205 11744 }
0110f2b8 11745 /* Definitely a 32-bit variant. */
5be8be5d 11746
8d67f500
NC
11747 /* Warning for Erratum 752419. */
11748 if (opcode == T_MNEM_ldr
11749 && inst.operands[0].reg == REG_SP
11750 && inst.operands[1].writeback == 1
11751 && !inst.operands[1].immisreg)
11752 {
11753 if (no_cpu_selected ()
11754 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11755 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11756 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11757 as_warn (_("This instruction may be unpredictable "
11758 "if executed on M-profile cores "
11759 "with interrupts enabled."));
11760 }
11761
5be8be5d 11762 /* Do some validations regarding addressing modes. */
1be5fd2e 11763 if (inst.operands[1].immisreg)
5be8be5d
DG
11764 reject_bad_reg (inst.operands[1].imm);
11765
1be5fd2e
NC
11766 constraint (inst.operands[1].writeback == 1
11767 && inst.operands[0].reg == inst.operands[1].reg,
11768 BAD_OVERLAP);
11769
0110f2b8 11770 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11771 inst.instruction |= inst.operands[0].reg << 12;
11772 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11773 check_ldr_r15_aligned ();
b99bd4ef
NC
11774 return;
11775 }
11776
c19d1205
ZW
11777 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11778
11779 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11780 {
c19d1205
ZW
11781 /* Only [Rn,Rm] is acceptable. */
11782 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11783 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11784 || inst.operands[1].postind || inst.operands[1].shifted
11785 || inst.operands[1].negative,
11786 _("Thumb does not support this addressing mode"));
11787 inst.instruction = THUMB_OP16 (inst.instruction);
11788 goto op16;
b99bd4ef 11789 }
5f4273c7 11790
c19d1205
ZW
11791 inst.instruction = THUMB_OP16 (inst.instruction);
11792 if (!inst.operands[1].isreg)
8335d6aa 11793 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11794 return;
b99bd4ef 11795
c19d1205
ZW
11796 constraint (!inst.operands[1].preind
11797 || inst.operands[1].shifted
11798 || inst.operands[1].writeback,
11799 _("Thumb does not support this addressing mode"));
11800 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11801 {
c19d1205
ZW
11802 constraint (inst.instruction & 0x0600,
11803 _("byte or halfword not valid for base register"));
11804 constraint (inst.operands[1].reg == REG_PC
11805 && !(inst.instruction & THUMB_LOAD_BIT),
11806 _("r15 based store not allowed"));
11807 constraint (inst.operands[1].immisreg,
11808 _("invalid base register for register offset"));
b99bd4ef 11809
c19d1205
ZW
11810 if (inst.operands[1].reg == REG_PC)
11811 inst.instruction = T_OPCODE_LDR_PC;
11812 else if (inst.instruction & THUMB_LOAD_BIT)
11813 inst.instruction = T_OPCODE_LDR_SP;
11814 else
11815 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11816
c19d1205
ZW
11817 inst.instruction |= inst.operands[0].reg << 8;
11818 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11819 return;
11820 }
90e4755a 11821
c19d1205
ZW
11822 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11823 if (!inst.operands[1].immisreg)
11824 {
11825 /* Immediate offset. */
11826 inst.instruction |= inst.operands[0].reg;
11827 inst.instruction |= inst.operands[1].reg << 3;
11828 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11829 return;
11830 }
90e4755a 11831
c19d1205
ZW
11832 /* Register offset. */
11833 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11834 constraint (inst.operands[1].negative,
11835 _("Thumb does not support this addressing mode"));
90e4755a 11836
c19d1205
ZW
11837 op16:
11838 switch (inst.instruction)
11839 {
11840 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11841 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11842 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11843 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11844 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11845 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11846 case 0x5600 /* ldrsb */:
11847 case 0x5e00 /* ldrsh */: break;
11848 default: abort ();
11849 }
90e4755a 11850
c19d1205
ZW
11851 inst.instruction |= inst.operands[0].reg;
11852 inst.instruction |= inst.operands[1].reg << 3;
11853 inst.instruction |= inst.operands[1].imm << 6;
11854}
90e4755a 11855
c19d1205
ZW
11856static void
11857do_t_ldstd (void)
11858{
11859 if (!inst.operands[1].present)
b99bd4ef 11860 {
c19d1205
ZW
11861 inst.operands[1].reg = inst.operands[0].reg + 1;
11862 constraint (inst.operands[0].reg == REG_LR,
11863 _("r14 not allowed here"));
bd340a04 11864 constraint (inst.operands[0].reg == REG_R12,
477330fc 11865 _("r12 not allowed here"));
b99bd4ef 11866 }
bd340a04
MGD
11867
11868 if (inst.operands[2].writeback
11869 && (inst.operands[0].reg == inst.operands[2].reg
11870 || inst.operands[1].reg == inst.operands[2].reg))
11871 as_warn (_("base register written back, and overlaps "
477330fc 11872 "one of transfer registers"));
bd340a04 11873
c19d1205
ZW
11874 inst.instruction |= inst.operands[0].reg << 12;
11875 inst.instruction |= inst.operands[1].reg << 8;
11876 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11877}
11878
c19d1205
ZW
11879static void
11880do_t_ldstt (void)
11881{
11882 inst.instruction |= inst.operands[0].reg << 12;
11883 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11884}
a737bd4d 11885
b99bd4ef 11886static void
c19d1205 11887do_t_mla (void)
b99bd4ef 11888{
fdfde340 11889 unsigned Rd, Rn, Rm, Ra;
c921be7d 11890
fdfde340
JM
11891 Rd = inst.operands[0].reg;
11892 Rn = inst.operands[1].reg;
11893 Rm = inst.operands[2].reg;
11894 Ra = inst.operands[3].reg;
11895
11896 reject_bad_reg (Rd);
11897 reject_bad_reg (Rn);
11898 reject_bad_reg (Rm);
11899 reject_bad_reg (Ra);
11900
11901 inst.instruction |= Rd << 8;
11902 inst.instruction |= Rn << 16;
11903 inst.instruction |= Rm;
11904 inst.instruction |= Ra << 12;
c19d1205 11905}
b99bd4ef 11906
c19d1205
ZW
11907static void
11908do_t_mlal (void)
11909{
fdfde340
JM
11910 unsigned RdLo, RdHi, Rn, Rm;
11911
11912 RdLo = inst.operands[0].reg;
11913 RdHi = inst.operands[1].reg;
11914 Rn = inst.operands[2].reg;
11915 Rm = inst.operands[3].reg;
11916
11917 reject_bad_reg (RdLo);
11918 reject_bad_reg (RdHi);
11919 reject_bad_reg (Rn);
11920 reject_bad_reg (Rm);
11921
11922 inst.instruction |= RdLo << 12;
11923 inst.instruction |= RdHi << 8;
11924 inst.instruction |= Rn << 16;
11925 inst.instruction |= Rm;
c19d1205 11926}
b99bd4ef 11927
c19d1205
ZW
11928static void
11929do_t_mov_cmp (void)
11930{
fdfde340
JM
11931 unsigned Rn, Rm;
11932
11933 Rn = inst.operands[0].reg;
11934 Rm = inst.operands[1].reg;
11935
e07e6e58
NC
11936 if (Rn == REG_PC)
11937 set_it_insn_type_last ();
11938
c19d1205 11939 if (unified_syntax)
b99bd4ef 11940 {
c19d1205
ZW
11941 int r0off = (inst.instruction == T_MNEM_mov
11942 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11943 unsigned long opcode;
3d388997
PB
11944 bfd_boolean narrow;
11945 bfd_boolean low_regs;
11946
fdfde340 11947 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11948 opcode = inst.instruction;
e07e6e58 11949 if (in_it_block ())
0110f2b8 11950 narrow = opcode != T_MNEM_movs;
3d388997 11951 else
0110f2b8 11952 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11953 if (inst.size_req == 4
11954 || inst.operands[1].shifted)
11955 narrow = FALSE;
11956
efd81785
PB
11957 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11958 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11959 && !inst.operands[1].shifted
fdfde340
JM
11960 && Rn == REG_PC
11961 && Rm == REG_LR)
efd81785
PB
11962 {
11963 inst.instruction = T2_SUBS_PC_LR;
11964 return;
11965 }
11966
fdfde340
JM
11967 if (opcode == T_MNEM_cmp)
11968 {
11969 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11970 if (narrow)
11971 {
11972 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11973 but valid. */
11974 warn_deprecated_sp (Rm);
11975 /* R15 was documented as a valid choice for Rm in ARMv6,
11976 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11977 tools reject R15, so we do too. */
11978 constraint (Rm == REG_PC, BAD_PC);
11979 }
11980 else
11981 reject_bad_reg (Rm);
fdfde340
JM
11982 }
11983 else if (opcode == T_MNEM_mov
11984 || opcode == T_MNEM_movs)
11985 {
11986 if (inst.operands[1].isreg)
11987 {
11988 if (opcode == T_MNEM_movs)
11989 {
11990 reject_bad_reg (Rn);
11991 reject_bad_reg (Rm);
11992 }
76fa04a4
MGD
11993 else if (narrow)
11994 {
11995 /* This is mov.n. */
11996 if ((Rn == REG_SP || Rn == REG_PC)
11997 && (Rm == REG_SP || Rm == REG_PC))
11998 {
5c3696f8 11999 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
12000 "deprecated when r%u is the destination "
12001 "register."), Rm, Rn);
12002 }
12003 }
12004 else
12005 {
12006 /* This is mov.w. */
12007 constraint (Rn == REG_PC, BAD_PC);
12008 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
12009 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12010 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 12011 }
fdfde340
JM
12012 }
12013 else
12014 reject_bad_reg (Rn);
12015 }
12016
c19d1205
ZW
12017 if (!inst.operands[1].isreg)
12018 {
0110f2b8 12019 /* Immediate operand. */
e07e6e58 12020 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
12021 narrow = 0;
12022 if (low_regs && narrow)
12023 {
12024 inst.instruction = THUMB_OP16 (opcode);
fdfde340 12025 inst.instruction |= Rn << 8;
a9f02af8
MG
12026 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12027 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 12028 {
a9f02af8 12029 if (inst.size_req == 2)
72d98d16 12030 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
12031 else
12032 inst.relax = opcode;
72d98d16 12033 }
0110f2b8
PB
12034 }
12035 else
12036 {
a9f02af8
MG
12037 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12038 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
12039 THUMB1_RELOC_ONLY);
12040
0110f2b8
PB
12041 inst.instruction = THUMB_OP32 (inst.instruction);
12042 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12043 inst.instruction |= Rn << r0off;
0110f2b8
PB
12044 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12045 }
c19d1205 12046 }
728ca7c9
PB
12047 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12048 && (inst.instruction == T_MNEM_mov
12049 || inst.instruction == T_MNEM_movs))
12050 {
12051 /* Register shifts are encoded as separate shift instructions. */
12052 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
12053
e07e6e58 12054 if (in_it_block ())
728ca7c9
PB
12055 narrow = !flags;
12056 else
12057 narrow = flags;
12058
12059 if (inst.size_req == 4)
12060 narrow = FALSE;
12061
12062 if (!low_regs || inst.operands[1].imm > 7)
12063 narrow = FALSE;
12064
fdfde340 12065 if (Rn != Rm)
728ca7c9
PB
12066 narrow = FALSE;
12067
12068 switch (inst.operands[1].shift_kind)
12069 {
12070 case SHIFT_LSL:
12071 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12072 break;
12073 case SHIFT_ASR:
12074 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12075 break;
12076 case SHIFT_LSR:
12077 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12078 break;
12079 case SHIFT_ROR:
12080 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12081 break;
12082 default:
5f4273c7 12083 abort ();
728ca7c9
PB
12084 }
12085
12086 inst.instruction = opcode;
12087 if (narrow)
12088 {
fdfde340 12089 inst.instruction |= Rn;
728ca7c9
PB
12090 inst.instruction |= inst.operands[1].imm << 3;
12091 }
12092 else
12093 {
12094 if (flags)
12095 inst.instruction |= CONDS_BIT;
12096
fdfde340
JM
12097 inst.instruction |= Rn << 8;
12098 inst.instruction |= Rm << 16;
728ca7c9
PB
12099 inst.instruction |= inst.operands[1].imm;
12100 }
12101 }
3d388997 12102 else if (!narrow)
c19d1205 12103 {
728ca7c9
PB
12104 /* Some mov with immediate shift have narrow variants.
12105 Register shifts are handled above. */
12106 if (low_regs && inst.operands[1].shifted
12107 && (inst.instruction == T_MNEM_mov
12108 || inst.instruction == T_MNEM_movs))
12109 {
e07e6e58 12110 if (in_it_block ())
728ca7c9
PB
12111 narrow = (inst.instruction == T_MNEM_mov);
12112 else
12113 narrow = (inst.instruction == T_MNEM_movs);
12114 }
12115
12116 if (narrow)
12117 {
12118 switch (inst.operands[1].shift_kind)
12119 {
12120 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12121 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12122 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12123 default: narrow = FALSE; break;
12124 }
12125 }
12126
12127 if (narrow)
12128 {
fdfde340
JM
12129 inst.instruction |= Rn;
12130 inst.instruction |= Rm << 3;
728ca7c9
PB
12131 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12132 }
12133 else
12134 {
12135 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12136 inst.instruction |= Rn << r0off;
728ca7c9
PB
12137 encode_thumb32_shifted_operand (1);
12138 }
c19d1205
ZW
12139 }
12140 else
12141 switch (inst.instruction)
12142 {
12143 case T_MNEM_mov:
837b3435 12144 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12145 results. Don't allow this. */
12146 if (low_regs)
12147 {
12148 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12149 "MOV Rd, Rs with two low registers is not "
12150 "permitted on this architecture");
fa94de6b 12151 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12152 arm_ext_v6);
12153 }
12154
c19d1205 12155 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12156 inst.instruction |= (Rn & 0x8) << 4;
12157 inst.instruction |= (Rn & 0x7);
12158 inst.instruction |= Rm << 3;
c19d1205 12159 break;
b99bd4ef 12160
c19d1205
ZW
12161 case T_MNEM_movs:
12162 /* We know we have low registers at this point.
941a8a52
MGD
12163 Generate LSLS Rd, Rs, #0. */
12164 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12165 inst.instruction |= Rn;
12166 inst.instruction |= Rm << 3;
c19d1205
ZW
12167 break;
12168
12169 case T_MNEM_cmp:
3d388997 12170 if (low_regs)
c19d1205
ZW
12171 {
12172 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12173 inst.instruction |= Rn;
12174 inst.instruction |= Rm << 3;
c19d1205
ZW
12175 }
12176 else
12177 {
12178 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12179 inst.instruction |= (Rn & 0x8) << 4;
12180 inst.instruction |= (Rn & 0x7);
12181 inst.instruction |= Rm << 3;
c19d1205
ZW
12182 }
12183 break;
12184 }
b99bd4ef
NC
12185 return;
12186 }
12187
c19d1205 12188 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12189
12190 /* PR 10443: Do not silently ignore shifted operands. */
12191 constraint (inst.operands[1].shifted,
12192 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12193
c19d1205 12194 if (inst.operands[1].isreg)
b99bd4ef 12195 {
fdfde340 12196 if (Rn < 8 && Rm < 8)
b99bd4ef 12197 {
c19d1205
ZW
12198 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12199 since a MOV instruction produces unpredictable results. */
12200 if (inst.instruction == T_OPCODE_MOV_I8)
12201 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12202 else
c19d1205 12203 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12204
fdfde340
JM
12205 inst.instruction |= Rn;
12206 inst.instruction |= Rm << 3;
b99bd4ef
NC
12207 }
12208 else
12209 {
c19d1205
ZW
12210 if (inst.instruction == T_OPCODE_MOV_I8)
12211 inst.instruction = T_OPCODE_MOV_HR;
12212 else
12213 inst.instruction = T_OPCODE_CMP_HR;
12214 do_t_cpy ();
b99bd4ef
NC
12215 }
12216 }
c19d1205 12217 else
b99bd4ef 12218 {
fdfde340 12219 constraint (Rn > 7,
c19d1205 12220 _("only lo regs allowed with immediate"));
fdfde340 12221 inst.instruction |= Rn << 8;
c19d1205
ZW
12222 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12223 }
12224}
b99bd4ef 12225
c19d1205
ZW
12226static void
12227do_t_mov16 (void)
12228{
fdfde340 12229 unsigned Rd;
b6895b4f
PB
12230 bfd_vma imm;
12231 bfd_boolean top;
12232
12233 top = (inst.instruction & 0x00800000) != 0;
12234 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12235 {
33eaf5de 12236 constraint (top, _(":lower16: not allowed in this instruction"));
b6895b4f
PB
12237 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12238 }
12239 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12240 {
33eaf5de 12241 constraint (!top, _(":upper16: not allowed in this instruction"));
b6895b4f
PB
12242 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12243 }
12244
fdfde340
JM
12245 Rd = inst.operands[0].reg;
12246 reject_bad_reg (Rd);
12247
12248 inst.instruction |= Rd << 8;
b6895b4f
PB
12249 if (inst.reloc.type == BFD_RELOC_UNUSED)
12250 {
12251 imm = inst.reloc.exp.X_add_number;
12252 inst.instruction |= (imm & 0xf000) << 4;
12253 inst.instruction |= (imm & 0x0800) << 15;
12254 inst.instruction |= (imm & 0x0700) << 4;
12255 inst.instruction |= (imm & 0x00ff);
12256 }
c19d1205 12257}
b99bd4ef 12258
c19d1205
ZW
12259static void
12260do_t_mvn_tst (void)
12261{
fdfde340 12262 unsigned Rn, Rm;
c921be7d 12263
fdfde340
JM
12264 Rn = inst.operands[0].reg;
12265 Rm = inst.operands[1].reg;
12266
12267 if (inst.instruction == T_MNEM_cmp
12268 || inst.instruction == T_MNEM_cmn)
12269 constraint (Rn == REG_PC, BAD_PC);
12270 else
12271 reject_bad_reg (Rn);
12272 reject_bad_reg (Rm);
12273
c19d1205
ZW
12274 if (unified_syntax)
12275 {
12276 int r0off = (inst.instruction == T_MNEM_mvn
12277 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12278 bfd_boolean narrow;
12279
12280 if (inst.size_req == 4
12281 || inst.instruction > 0xffff
12282 || inst.operands[1].shifted
fdfde340 12283 || Rn > 7 || Rm > 7)
3d388997 12284 narrow = FALSE;
fe8b4cc3
KT
12285 else if (inst.instruction == T_MNEM_cmn
12286 || inst.instruction == T_MNEM_tst)
3d388997
PB
12287 narrow = TRUE;
12288 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12289 narrow = !in_it_block ();
3d388997 12290 else
e07e6e58 12291 narrow = in_it_block ();
3d388997 12292
c19d1205 12293 if (!inst.operands[1].isreg)
b99bd4ef 12294 {
c19d1205
ZW
12295 /* For an immediate, we always generate a 32-bit opcode;
12296 section relaxation will shrink it later if possible. */
12297 if (inst.instruction < 0xffff)
12298 inst.instruction = THUMB_OP32 (inst.instruction);
12299 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12300 inst.instruction |= Rn << r0off;
c19d1205 12301 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12302 }
c19d1205 12303 else
b99bd4ef 12304 {
c19d1205 12305 /* See if we can do this with a 16-bit instruction. */
3d388997 12306 if (narrow)
b99bd4ef 12307 {
c19d1205 12308 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12309 inst.instruction |= Rn;
12310 inst.instruction |= Rm << 3;
b99bd4ef 12311 }
c19d1205 12312 else
b99bd4ef 12313 {
c19d1205
ZW
12314 constraint (inst.operands[1].shifted
12315 && inst.operands[1].immisreg,
12316 _("shift must be constant"));
12317 if (inst.instruction < 0xffff)
12318 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12319 inst.instruction |= Rn << r0off;
c19d1205 12320 encode_thumb32_shifted_operand (1);
b99bd4ef 12321 }
b99bd4ef
NC
12322 }
12323 }
12324 else
12325 {
c19d1205
ZW
12326 constraint (inst.instruction > 0xffff
12327 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12328 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12329 _("unshifted register required"));
fdfde340 12330 constraint (Rn > 7 || Rm > 7,
c19d1205 12331 BAD_HIREG);
b99bd4ef 12332
c19d1205 12333 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12334 inst.instruction |= Rn;
12335 inst.instruction |= Rm << 3;
b99bd4ef 12336 }
b99bd4ef
NC
12337}
12338
b05fe5cf 12339static void
c19d1205 12340do_t_mrs (void)
b05fe5cf 12341{
fdfde340 12342 unsigned Rd;
037e8744
JB
12343
12344 if (do_vfp_nsyn_mrs () == SUCCESS)
12345 return;
12346
90ec0d68
MGD
12347 Rd = inst.operands[0].reg;
12348 reject_bad_reg (Rd);
12349 inst.instruction |= Rd << 8;
12350
12351 if (inst.operands[1].isreg)
62b3e311 12352 {
90ec0d68
MGD
12353 unsigned br = inst.operands[1].reg;
12354 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12355 as_bad (_("bad register for mrs"));
12356
12357 inst.instruction |= br & (0xf << 16);
12358 inst.instruction |= (br & 0x300) >> 4;
12359 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12360 }
12361 else
12362 {
90ec0d68 12363 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12364
d2cd1205 12365 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12366 {
12367 /* PR gas/12698: The constraint is only applied for m_profile.
12368 If the user has specified -march=all, we want to ignore it as
12369 we are building for any CPU type, including non-m variants. */
823d2571
TG
12370 bfd_boolean m_profile =
12371 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12372 constraint ((flags != 0) && m_profile, _("selected processor does "
12373 "not support requested special purpose register"));
12374 }
90ec0d68 12375 else
d2cd1205
JB
12376 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12377 devices). */
12378 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12379 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12380
90ec0d68
MGD
12381 inst.instruction |= (flags & SPSR_BIT) >> 2;
12382 inst.instruction |= inst.operands[1].imm & 0xff;
12383 inst.instruction |= 0xf0000;
12384 }
c19d1205 12385}
b05fe5cf 12386
c19d1205
ZW
12387static void
12388do_t_msr (void)
12389{
62b3e311 12390 int flags;
fdfde340 12391 unsigned Rn;
62b3e311 12392
037e8744
JB
12393 if (do_vfp_nsyn_msr () == SUCCESS)
12394 return;
12395
c19d1205
ZW
12396 constraint (!inst.operands[1].isreg,
12397 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12398
12399 if (inst.operands[0].isreg)
12400 flags = (int)(inst.operands[0].reg);
12401 else
12402 flags = inst.operands[0].imm;
12403
d2cd1205 12404 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12405 {
d2cd1205
JB
12406 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12407
1a43faaf 12408 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12409 If the user has specified -march=all, we want to ignore it as
12410 we are building for any CPU type, including non-m variants. */
823d2571
TG
12411 bfd_boolean m_profile =
12412 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12413 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12414 && (bits & ~(PSR_s | PSR_f)) != 0)
12415 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12416 && bits != PSR_f)) && m_profile,
12417 _("selected processor does not support requested special "
12418 "purpose register"));
62b3e311
PB
12419 }
12420 else
d2cd1205
JB
12421 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12422 "requested special purpose register"));
c921be7d 12423
fdfde340
JM
12424 Rn = inst.operands[1].reg;
12425 reject_bad_reg (Rn);
12426
62b3e311 12427 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12428 inst.instruction |= (flags & 0xf0000) >> 8;
12429 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12430 inst.instruction |= (flags & 0xff);
fdfde340 12431 inst.instruction |= Rn << 16;
c19d1205 12432}
b05fe5cf 12433
c19d1205
ZW
12434static void
12435do_t_mul (void)
12436{
17828f45 12437 bfd_boolean narrow;
fdfde340 12438 unsigned Rd, Rn, Rm;
17828f45 12439
c19d1205
ZW
12440 if (!inst.operands[2].present)
12441 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12442
fdfde340
JM
12443 Rd = inst.operands[0].reg;
12444 Rn = inst.operands[1].reg;
12445 Rm = inst.operands[2].reg;
12446
17828f45 12447 if (unified_syntax)
b05fe5cf 12448 {
17828f45 12449 if (inst.size_req == 4
fdfde340
JM
12450 || (Rd != Rn
12451 && Rd != Rm)
12452 || Rn > 7
12453 || Rm > 7)
17828f45
JM
12454 narrow = FALSE;
12455 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12456 narrow = !in_it_block ();
17828f45 12457 else
e07e6e58 12458 narrow = in_it_block ();
b05fe5cf 12459 }
c19d1205 12460 else
b05fe5cf 12461 {
17828f45 12462 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12463 constraint (Rn > 7 || Rm > 7,
c19d1205 12464 BAD_HIREG);
17828f45
JM
12465 narrow = TRUE;
12466 }
b05fe5cf 12467
17828f45
JM
12468 if (narrow)
12469 {
12470 /* 16-bit MULS/Conditional MUL. */
c19d1205 12471 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12472 inst.instruction |= Rd;
b05fe5cf 12473
fdfde340
JM
12474 if (Rd == Rn)
12475 inst.instruction |= Rm << 3;
12476 else if (Rd == Rm)
12477 inst.instruction |= Rn << 3;
c19d1205
ZW
12478 else
12479 constraint (1, _("dest must overlap one source register"));
12480 }
17828f45
JM
12481 else
12482 {
e07e6e58
NC
12483 constraint (inst.instruction != T_MNEM_mul,
12484 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12485 /* 32-bit MUL. */
12486 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12487 inst.instruction |= Rd << 8;
12488 inst.instruction |= Rn << 16;
12489 inst.instruction |= Rm << 0;
12490
12491 reject_bad_reg (Rd);
12492 reject_bad_reg (Rn);
12493 reject_bad_reg (Rm);
17828f45 12494 }
c19d1205 12495}
b05fe5cf 12496
c19d1205
ZW
12497static void
12498do_t_mull (void)
12499{
fdfde340 12500 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12501
fdfde340
JM
12502 RdLo = inst.operands[0].reg;
12503 RdHi = inst.operands[1].reg;
12504 Rn = inst.operands[2].reg;
12505 Rm = inst.operands[3].reg;
12506
12507 reject_bad_reg (RdLo);
12508 reject_bad_reg (RdHi);
12509 reject_bad_reg (Rn);
12510 reject_bad_reg (Rm);
12511
12512 inst.instruction |= RdLo << 12;
12513 inst.instruction |= RdHi << 8;
12514 inst.instruction |= Rn << 16;
12515 inst.instruction |= Rm;
12516
12517 if (RdLo == RdHi)
c19d1205
ZW
12518 as_tsktsk (_("rdhi and rdlo must be different"));
12519}
b05fe5cf 12520
c19d1205
ZW
12521static void
12522do_t_nop (void)
12523{
e07e6e58
NC
12524 set_it_insn_type (NEUTRAL_IT_INSN);
12525
c19d1205
ZW
12526 if (unified_syntax)
12527 {
12528 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12529 {
c19d1205
ZW
12530 inst.instruction = THUMB_OP32 (inst.instruction);
12531 inst.instruction |= inst.operands[0].imm;
12532 }
12533 else
12534 {
bc2d1808
NC
12535 /* PR9722: Check for Thumb2 availability before
12536 generating a thumb2 nop instruction. */
afa62d5e 12537 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12538 {
12539 inst.instruction = THUMB_OP16 (inst.instruction);
12540 inst.instruction |= inst.operands[0].imm << 4;
12541 }
12542 else
12543 inst.instruction = 0x46c0;
c19d1205
ZW
12544 }
12545 }
12546 else
12547 {
12548 constraint (inst.operands[0].present,
12549 _("Thumb does not support NOP with hints"));
12550 inst.instruction = 0x46c0;
12551 }
12552}
b05fe5cf 12553
c19d1205
ZW
12554static void
12555do_t_neg (void)
12556{
12557 if (unified_syntax)
12558 {
3d388997
PB
12559 bfd_boolean narrow;
12560
12561 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12562 narrow = !in_it_block ();
3d388997 12563 else
e07e6e58 12564 narrow = in_it_block ();
3d388997
PB
12565 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12566 narrow = FALSE;
12567 if (inst.size_req == 4)
12568 narrow = FALSE;
12569
12570 if (!narrow)
c19d1205
ZW
12571 {
12572 inst.instruction = THUMB_OP32 (inst.instruction);
12573 inst.instruction |= inst.operands[0].reg << 8;
12574 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12575 }
12576 else
12577 {
c19d1205
ZW
12578 inst.instruction = THUMB_OP16 (inst.instruction);
12579 inst.instruction |= inst.operands[0].reg;
12580 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12581 }
12582 }
12583 else
12584 {
c19d1205
ZW
12585 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12586 BAD_HIREG);
12587 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12588
12589 inst.instruction = THUMB_OP16 (inst.instruction);
12590 inst.instruction |= inst.operands[0].reg;
12591 inst.instruction |= inst.operands[1].reg << 3;
12592 }
12593}
12594
1c444d06
JM
12595static void
12596do_t_orn (void)
12597{
12598 unsigned Rd, Rn;
12599
12600 Rd = inst.operands[0].reg;
12601 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12602
fdfde340
JM
12603 reject_bad_reg (Rd);
12604 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12605 reject_bad_reg (Rn);
12606
1c444d06
JM
12607 inst.instruction |= Rd << 8;
12608 inst.instruction |= Rn << 16;
12609
12610 if (!inst.operands[2].isreg)
12611 {
12612 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12613 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12614 }
12615 else
12616 {
12617 unsigned Rm;
12618
12619 Rm = inst.operands[2].reg;
fdfde340 12620 reject_bad_reg (Rm);
1c444d06
JM
12621
12622 constraint (inst.operands[2].shifted
12623 && inst.operands[2].immisreg,
12624 _("shift must be constant"));
12625 encode_thumb32_shifted_operand (2);
12626 }
12627}
12628
c19d1205
ZW
12629static void
12630do_t_pkhbt (void)
12631{
fdfde340
JM
12632 unsigned Rd, Rn, Rm;
12633
12634 Rd = inst.operands[0].reg;
12635 Rn = inst.operands[1].reg;
12636 Rm = inst.operands[2].reg;
12637
12638 reject_bad_reg (Rd);
12639 reject_bad_reg (Rn);
12640 reject_bad_reg (Rm);
12641
12642 inst.instruction |= Rd << 8;
12643 inst.instruction |= Rn << 16;
12644 inst.instruction |= Rm;
c19d1205
ZW
12645 if (inst.operands[3].present)
12646 {
12647 unsigned int val = inst.reloc.exp.X_add_number;
12648 constraint (inst.reloc.exp.X_op != O_constant,
12649 _("expression too complex"));
12650 inst.instruction |= (val & 0x1c) << 10;
12651 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12652 }
c19d1205 12653}
b05fe5cf 12654
c19d1205
ZW
12655static void
12656do_t_pkhtb (void)
12657{
12658 if (!inst.operands[3].present)
1ef52f49
NC
12659 {
12660 unsigned Rtmp;
12661
12662 inst.instruction &= ~0x00000020;
12663
12664 /* PR 10168. Swap the Rm and Rn registers. */
12665 Rtmp = inst.operands[1].reg;
12666 inst.operands[1].reg = inst.operands[2].reg;
12667 inst.operands[2].reg = Rtmp;
12668 }
c19d1205 12669 do_t_pkhbt ();
b05fe5cf
ZW
12670}
12671
c19d1205
ZW
12672static void
12673do_t_pld (void)
12674{
fdfde340
JM
12675 if (inst.operands[0].immisreg)
12676 reject_bad_reg (inst.operands[0].imm);
12677
c19d1205
ZW
12678 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12679}
b05fe5cf 12680
c19d1205
ZW
12681static void
12682do_t_push_pop (void)
b99bd4ef 12683{
e9f89963 12684 unsigned mask;
5f4273c7 12685
c19d1205
ZW
12686 constraint (inst.operands[0].writeback,
12687 _("push/pop do not support {reglist}^"));
12688 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12689 _("expression too complex"));
b99bd4ef 12690
e9f89963 12691 mask = inst.operands[0].imm;
d3bfe16e 12692 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12693 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12694 else if (inst.size_req != 4
c6025a80 12695 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12696 ? REG_LR : REG_PC)))
b99bd4ef 12697 {
c19d1205
ZW
12698 inst.instruction = THUMB_OP16 (inst.instruction);
12699 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12700 inst.instruction |= mask & 0xff;
c19d1205
ZW
12701 }
12702 else if (unified_syntax)
12703 {
3c707909 12704 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12705 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12706 }
12707 else
12708 {
12709 inst.error = _("invalid register list to push/pop instruction");
12710 return;
12711 }
c19d1205 12712}
b99bd4ef 12713
c19d1205
ZW
12714static void
12715do_t_rbit (void)
12716{
fdfde340
JM
12717 unsigned Rd, Rm;
12718
12719 Rd = inst.operands[0].reg;
12720 Rm = inst.operands[1].reg;
12721
12722 reject_bad_reg (Rd);
12723 reject_bad_reg (Rm);
12724
12725 inst.instruction |= Rd << 8;
12726 inst.instruction |= Rm << 16;
12727 inst.instruction |= Rm;
c19d1205 12728}
b99bd4ef 12729
c19d1205
ZW
12730static void
12731do_t_rev (void)
12732{
fdfde340
JM
12733 unsigned Rd, Rm;
12734
12735 Rd = inst.operands[0].reg;
12736 Rm = inst.operands[1].reg;
12737
12738 reject_bad_reg (Rd);
12739 reject_bad_reg (Rm);
12740
12741 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12742 && inst.size_req != 4)
12743 {
12744 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12745 inst.instruction |= Rd;
12746 inst.instruction |= Rm << 3;
c19d1205
ZW
12747 }
12748 else if (unified_syntax)
12749 {
12750 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12751 inst.instruction |= Rd << 8;
12752 inst.instruction |= Rm << 16;
12753 inst.instruction |= Rm;
c19d1205
ZW
12754 }
12755 else
12756 inst.error = BAD_HIREG;
12757}
b99bd4ef 12758
1c444d06
JM
12759static void
12760do_t_rrx (void)
12761{
12762 unsigned Rd, Rm;
12763
12764 Rd = inst.operands[0].reg;
12765 Rm = inst.operands[1].reg;
12766
fdfde340
JM
12767 reject_bad_reg (Rd);
12768 reject_bad_reg (Rm);
c921be7d 12769
1c444d06
JM
12770 inst.instruction |= Rd << 8;
12771 inst.instruction |= Rm;
12772}
12773
c19d1205
ZW
12774static void
12775do_t_rsb (void)
12776{
fdfde340 12777 unsigned Rd, Rs;
b99bd4ef 12778
c19d1205
ZW
12779 Rd = inst.operands[0].reg;
12780 Rs = (inst.operands[1].present
12781 ? inst.operands[1].reg /* Rd, Rs, foo */
12782 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12783
fdfde340
JM
12784 reject_bad_reg (Rd);
12785 reject_bad_reg (Rs);
12786 if (inst.operands[2].isreg)
12787 reject_bad_reg (inst.operands[2].reg);
12788
c19d1205
ZW
12789 inst.instruction |= Rd << 8;
12790 inst.instruction |= Rs << 16;
12791 if (!inst.operands[2].isreg)
12792 {
026d3abb
PB
12793 bfd_boolean narrow;
12794
12795 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12796 narrow = !in_it_block ();
026d3abb 12797 else
e07e6e58 12798 narrow = in_it_block ();
026d3abb
PB
12799
12800 if (Rd > 7 || Rs > 7)
12801 narrow = FALSE;
12802
12803 if (inst.size_req == 4 || !unified_syntax)
12804 narrow = FALSE;
12805
12806 if (inst.reloc.exp.X_op != O_constant
12807 || inst.reloc.exp.X_add_number != 0)
12808 narrow = FALSE;
12809
12810 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12811 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12812 if (narrow)
12813 {
12814 inst.reloc.type = BFD_RELOC_UNUSED;
12815 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12816 inst.instruction |= Rs << 3;
12817 inst.instruction |= Rd;
12818 }
12819 else
12820 {
12821 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12822 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12823 }
c19d1205
ZW
12824 }
12825 else
12826 encode_thumb32_shifted_operand (2);
12827}
b99bd4ef 12828
c19d1205
ZW
12829static void
12830do_t_setend (void)
12831{
12e37cbc
MGD
12832 if (warn_on_deprecated
12833 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12834 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12835
e07e6e58 12836 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12837 if (inst.operands[0].imm)
12838 inst.instruction |= 0x8;
12839}
b99bd4ef 12840
c19d1205
ZW
12841static void
12842do_t_shift (void)
12843{
12844 if (!inst.operands[1].present)
12845 inst.operands[1].reg = inst.operands[0].reg;
12846
12847 if (unified_syntax)
12848 {
3d388997
PB
12849 bfd_boolean narrow;
12850 int shift_kind;
12851
12852 switch (inst.instruction)
12853 {
12854 case T_MNEM_asr:
12855 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12856 case T_MNEM_lsl:
12857 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12858 case T_MNEM_lsr:
12859 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12860 case T_MNEM_ror:
12861 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12862 default: abort ();
12863 }
12864
12865 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12866 narrow = !in_it_block ();
3d388997 12867 else
e07e6e58 12868 narrow = in_it_block ();
3d388997
PB
12869 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12870 narrow = FALSE;
12871 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12872 narrow = FALSE;
12873 if (inst.operands[2].isreg
12874 && (inst.operands[1].reg != inst.operands[0].reg
12875 || inst.operands[2].reg > 7))
12876 narrow = FALSE;
12877 if (inst.size_req == 4)
12878 narrow = FALSE;
12879
fdfde340
JM
12880 reject_bad_reg (inst.operands[0].reg);
12881 reject_bad_reg (inst.operands[1].reg);
c921be7d 12882
3d388997 12883 if (!narrow)
c19d1205
ZW
12884 {
12885 if (inst.operands[2].isreg)
b99bd4ef 12886 {
fdfde340 12887 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12888 inst.instruction = THUMB_OP32 (inst.instruction);
12889 inst.instruction |= inst.operands[0].reg << 8;
12890 inst.instruction |= inst.operands[1].reg << 16;
12891 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12892
12893 /* PR 12854: Error on extraneous shifts. */
12894 constraint (inst.operands[2].shifted,
12895 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12896 }
12897 else
12898 {
12899 inst.operands[1].shifted = 1;
3d388997 12900 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12901 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12902 ? T_MNEM_movs : T_MNEM_mov);
12903 inst.instruction |= inst.operands[0].reg << 8;
12904 encode_thumb32_shifted_operand (1);
12905 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12906 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12907 }
12908 }
12909 else
12910 {
c19d1205 12911 if (inst.operands[2].isreg)
b99bd4ef 12912 {
3d388997 12913 switch (shift_kind)
b99bd4ef 12914 {
3d388997
PB
12915 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12916 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12917 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12918 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12919 default: abort ();
b99bd4ef 12920 }
5f4273c7 12921
c19d1205
ZW
12922 inst.instruction |= inst.operands[0].reg;
12923 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12924
12925 /* PR 12854: Error on extraneous shifts. */
12926 constraint (inst.operands[2].shifted,
12927 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12928 }
12929 else
12930 {
3d388997 12931 switch (shift_kind)
b99bd4ef 12932 {
3d388997
PB
12933 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12934 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12935 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12936 default: abort ();
b99bd4ef 12937 }
c19d1205
ZW
12938 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12939 inst.instruction |= inst.operands[0].reg;
12940 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12941 }
12942 }
c19d1205
ZW
12943 }
12944 else
12945 {
12946 constraint (inst.operands[0].reg > 7
12947 || inst.operands[1].reg > 7, BAD_HIREG);
12948 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12949
c19d1205
ZW
12950 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12951 {
12952 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12953 constraint (inst.operands[0].reg != inst.operands[1].reg,
12954 _("source1 and dest must be same register"));
b99bd4ef 12955
c19d1205
ZW
12956 switch (inst.instruction)
12957 {
12958 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12959 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12960 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12961 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12962 default: abort ();
12963 }
5f4273c7 12964
c19d1205
ZW
12965 inst.instruction |= inst.operands[0].reg;
12966 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12967
12968 /* PR 12854: Error on extraneous shifts. */
12969 constraint (inst.operands[2].shifted,
12970 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12971 }
12972 else
b99bd4ef 12973 {
c19d1205
ZW
12974 switch (inst.instruction)
12975 {
12976 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12977 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12978 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12979 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12980 default: abort ();
12981 }
12982 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12983 inst.instruction |= inst.operands[0].reg;
12984 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12985 }
12986 }
b99bd4ef
NC
12987}
12988
12989static void
c19d1205 12990do_t_simd (void)
b99bd4ef 12991{
fdfde340
JM
12992 unsigned Rd, Rn, Rm;
12993
12994 Rd = inst.operands[0].reg;
12995 Rn = inst.operands[1].reg;
12996 Rm = inst.operands[2].reg;
12997
12998 reject_bad_reg (Rd);
12999 reject_bad_reg (Rn);
13000 reject_bad_reg (Rm);
13001
13002 inst.instruction |= Rd << 8;
13003 inst.instruction |= Rn << 16;
13004 inst.instruction |= Rm;
c19d1205 13005}
b99bd4ef 13006
03ee1b7f
NC
13007static void
13008do_t_simd2 (void)
13009{
13010 unsigned Rd, Rn, Rm;
13011
13012 Rd = inst.operands[0].reg;
13013 Rm = inst.operands[1].reg;
13014 Rn = inst.operands[2].reg;
13015
13016 reject_bad_reg (Rd);
13017 reject_bad_reg (Rn);
13018 reject_bad_reg (Rm);
13019
13020 inst.instruction |= Rd << 8;
13021 inst.instruction |= Rn << 16;
13022 inst.instruction |= Rm;
13023}
13024
c19d1205 13025static void
3eb17e6b 13026do_t_smc (void)
c19d1205
ZW
13027{
13028 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
13029 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
13030 _("SMC is not permitted on this architecture"));
c19d1205
ZW
13031 constraint (inst.reloc.exp.X_op != O_constant,
13032 _("expression too complex"));
13033 inst.reloc.type = BFD_RELOC_UNUSED;
13034 inst.instruction |= (value & 0xf000) >> 12;
13035 inst.instruction |= (value & 0x0ff0);
13036 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
13037 /* PR gas/15623: SMC instructions must be last in an IT block. */
13038 set_it_insn_type_last ();
c19d1205 13039}
b99bd4ef 13040
90ec0d68
MGD
13041static void
13042do_t_hvc (void)
13043{
13044 unsigned int value = inst.reloc.exp.X_add_number;
13045
13046 inst.reloc.type = BFD_RELOC_UNUSED;
13047 inst.instruction |= (value & 0x0fff);
13048 inst.instruction |= (value & 0xf000) << 4;
13049}
13050
c19d1205 13051static void
3a21c15a 13052do_t_ssat_usat (int bias)
c19d1205 13053{
fdfde340
JM
13054 unsigned Rd, Rn;
13055
13056 Rd = inst.operands[0].reg;
13057 Rn = inst.operands[2].reg;
13058
13059 reject_bad_reg (Rd);
13060 reject_bad_reg (Rn);
13061
13062 inst.instruction |= Rd << 8;
3a21c15a 13063 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 13064 inst.instruction |= Rn << 16;
b99bd4ef 13065
c19d1205 13066 if (inst.operands[3].present)
b99bd4ef 13067 {
3a21c15a
NC
13068 offsetT shift_amount = inst.reloc.exp.X_add_number;
13069
13070 inst.reloc.type = BFD_RELOC_UNUSED;
13071
c19d1205
ZW
13072 constraint (inst.reloc.exp.X_op != O_constant,
13073 _("expression too complex"));
b99bd4ef 13074
3a21c15a 13075 if (shift_amount != 0)
6189168b 13076 {
3a21c15a
NC
13077 constraint (shift_amount > 31,
13078 _("shift expression is too large"));
13079
c19d1205 13080 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
13081 inst.instruction |= 0x00200000; /* sh bit. */
13082
13083 inst.instruction |= (shift_amount & 0x1c) << 10;
13084 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
13085 }
13086 }
b99bd4ef 13087}
c921be7d 13088
3a21c15a
NC
13089static void
13090do_t_ssat (void)
13091{
13092 do_t_ssat_usat (1);
13093}
b99bd4ef 13094
0dd132b6 13095static void
c19d1205 13096do_t_ssat16 (void)
0dd132b6 13097{
fdfde340
JM
13098 unsigned Rd, Rn;
13099
13100 Rd = inst.operands[0].reg;
13101 Rn = inst.operands[2].reg;
13102
13103 reject_bad_reg (Rd);
13104 reject_bad_reg (Rn);
13105
13106 inst.instruction |= Rd << 8;
c19d1205 13107 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 13108 inst.instruction |= Rn << 16;
c19d1205 13109}
0dd132b6 13110
c19d1205
ZW
13111static void
13112do_t_strex (void)
13113{
13114 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13115 || inst.operands[2].postind || inst.operands[2].writeback
13116 || inst.operands[2].immisreg || inst.operands[2].shifted
13117 || inst.operands[2].negative,
01cfc07f 13118 BAD_ADDR_MODE);
0dd132b6 13119
5be8be5d
DG
13120 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13121
c19d1205
ZW
13122 inst.instruction |= inst.operands[0].reg << 8;
13123 inst.instruction |= inst.operands[1].reg << 12;
13124 inst.instruction |= inst.operands[2].reg << 16;
13125 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13126}
13127
b99bd4ef 13128static void
c19d1205 13129do_t_strexd (void)
b99bd4ef 13130{
c19d1205
ZW
13131 if (!inst.operands[2].present)
13132 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13133
c19d1205
ZW
13134 constraint (inst.operands[0].reg == inst.operands[1].reg
13135 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13136 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13137 BAD_OVERLAP);
b99bd4ef 13138
c19d1205
ZW
13139 inst.instruction |= inst.operands[0].reg;
13140 inst.instruction |= inst.operands[1].reg << 12;
13141 inst.instruction |= inst.operands[2].reg << 8;
13142 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13143}
13144
13145static void
c19d1205 13146do_t_sxtah (void)
b99bd4ef 13147{
fdfde340
JM
13148 unsigned Rd, Rn, Rm;
13149
13150 Rd = inst.operands[0].reg;
13151 Rn = inst.operands[1].reg;
13152 Rm = inst.operands[2].reg;
13153
13154 reject_bad_reg (Rd);
13155 reject_bad_reg (Rn);
13156 reject_bad_reg (Rm);
13157
13158 inst.instruction |= Rd << 8;
13159 inst.instruction |= Rn << 16;
13160 inst.instruction |= Rm;
c19d1205
ZW
13161 inst.instruction |= inst.operands[3].imm << 4;
13162}
b99bd4ef 13163
c19d1205
ZW
13164static void
13165do_t_sxth (void)
13166{
fdfde340
JM
13167 unsigned Rd, Rm;
13168
13169 Rd = inst.operands[0].reg;
13170 Rm = inst.operands[1].reg;
13171
13172 reject_bad_reg (Rd);
13173 reject_bad_reg (Rm);
c921be7d
NC
13174
13175 if (inst.instruction <= 0xffff
13176 && inst.size_req != 4
fdfde340 13177 && Rd <= 7 && Rm <= 7
c19d1205 13178 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13179 {
c19d1205 13180 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13181 inst.instruction |= Rd;
13182 inst.instruction |= Rm << 3;
b99bd4ef 13183 }
c19d1205 13184 else if (unified_syntax)
b99bd4ef 13185 {
c19d1205
ZW
13186 if (inst.instruction <= 0xffff)
13187 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13188 inst.instruction |= Rd << 8;
13189 inst.instruction |= Rm;
c19d1205 13190 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13191 }
c19d1205 13192 else
b99bd4ef 13193 {
c19d1205
ZW
13194 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13195 _("Thumb encoding does not support rotation"));
13196 constraint (1, BAD_HIREG);
b99bd4ef 13197 }
c19d1205 13198}
b99bd4ef 13199
c19d1205
ZW
13200static void
13201do_t_swi (void)
13202{
13203 inst.reloc.type = BFD_RELOC_ARM_SWI;
13204}
b99bd4ef 13205
92e90b6e
PB
13206static void
13207do_t_tb (void)
13208{
fdfde340 13209 unsigned Rn, Rm;
92e90b6e
PB
13210 int half;
13211
13212 half = (inst.instruction & 0x10) != 0;
e07e6e58 13213 set_it_insn_type_last ();
dfa9f0d5
PB
13214 constraint (inst.operands[0].immisreg,
13215 _("instruction requires register index"));
fdfde340
JM
13216
13217 Rn = inst.operands[0].reg;
13218 Rm = inst.operands[0].imm;
c921be7d 13219
5c8ed6a4
JW
13220 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13221 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
13222 reject_bad_reg (Rm);
13223
92e90b6e
PB
13224 constraint (!half && inst.operands[0].shifted,
13225 _("instruction does not allow shifted index"));
fdfde340 13226 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13227}
13228
74db7efb
NC
13229static void
13230do_t_udf (void)
13231{
13232 if (!inst.operands[0].present)
13233 inst.operands[0].imm = 0;
13234
13235 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13236 {
13237 constraint (inst.size_req == 2,
13238 _("immediate value out of range"));
13239 inst.instruction = THUMB_OP32 (inst.instruction);
13240 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13241 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13242 }
13243 else
13244 {
13245 inst.instruction = THUMB_OP16 (inst.instruction);
13246 inst.instruction |= inst.operands[0].imm;
13247 }
13248
13249 set_it_insn_type (NEUTRAL_IT_INSN);
13250}
13251
13252
c19d1205
ZW
13253static void
13254do_t_usat (void)
13255{
3a21c15a 13256 do_t_ssat_usat (0);
b99bd4ef
NC
13257}
13258
13259static void
c19d1205 13260do_t_usat16 (void)
b99bd4ef 13261{
fdfde340
JM
13262 unsigned Rd, Rn;
13263
13264 Rd = inst.operands[0].reg;
13265 Rn = inst.operands[2].reg;
13266
13267 reject_bad_reg (Rd);
13268 reject_bad_reg (Rn);
13269
13270 inst.instruction |= Rd << 8;
c19d1205 13271 inst.instruction |= inst.operands[1].imm;
fdfde340 13272 inst.instruction |= Rn << 16;
b99bd4ef 13273}
c19d1205 13274
5287ad62 13275/* Neon instruction encoder helpers. */
5f4273c7 13276
5287ad62 13277/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13278
5287ad62
JB
13279/* An "invalid" code for the following tables. */
13280#define N_INV -1u
13281
13282struct neon_tab_entry
b99bd4ef 13283{
5287ad62
JB
13284 unsigned integer;
13285 unsigned float_or_poly;
13286 unsigned scalar_or_imm;
13287};
5f4273c7 13288
5287ad62
JB
13289/* Map overloaded Neon opcodes to their respective encodings. */
13290#define NEON_ENC_TAB \
13291 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13292 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13293 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13294 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13295 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13296 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13297 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13298 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13299 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13300 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13301 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13302 /* Register variants of the following two instructions are encoded as
e07e6e58 13303 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13304 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13305 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13306 X(vfma, N_INV, 0x0000c10, N_INV), \
13307 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13308 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13309 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13310 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13311 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13312 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13313 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13314 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13315 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13316 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13317 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13318 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13319 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13320 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13321 X(vshl, 0x0000400, N_INV, 0x0800510), \
13322 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13323 X(vand, 0x0000110, N_INV, 0x0800030), \
13324 X(vbic, 0x0100110, N_INV, 0x0800030), \
13325 X(veor, 0x1000110, N_INV, N_INV), \
13326 X(vorn, 0x0300110, N_INV, 0x0800010), \
13327 X(vorr, 0x0200110, N_INV, 0x0800010), \
13328 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13329 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13330 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13331 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13332 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13333 X(vst1, 0x0000000, 0x0800000, N_INV), \
13334 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13335 X(vst2, 0x0000100, 0x0800100, N_INV), \
13336 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13337 X(vst3, 0x0000200, 0x0800200, N_INV), \
13338 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13339 X(vst4, 0x0000300, 0x0800300, N_INV), \
13340 X(vmovn, 0x1b20200, N_INV, N_INV), \
13341 X(vtrn, 0x1b20080, N_INV, N_INV), \
13342 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13343 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13344 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13345 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13346 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13347 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13348 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13349 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13350 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13351 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13352 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13353 X(vseleq, 0xe000a00, N_INV, N_INV), \
13354 X(vselvs, 0xe100a00, N_INV, N_INV), \
13355 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13356 X(vselgt, 0xe300a00, N_INV, N_INV), \
13357 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13358 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13359 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13360 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13361 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13362 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13363 X(sha3op, 0x2000c00, N_INV, N_INV), \
13364 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13365 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13366
13367enum neon_opc
13368{
13369#define X(OPC,I,F,S) N_MNEM_##OPC
13370NEON_ENC_TAB
13371#undef X
13372};
b99bd4ef 13373
5287ad62
JB
13374static const struct neon_tab_entry neon_enc_tab[] =
13375{
13376#define X(OPC,I,F,S) { (I), (F), (S) }
13377NEON_ENC_TAB
13378#undef X
13379};
b99bd4ef 13380
88714cb8
DG
13381/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13382#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13383#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13384#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13385#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13386#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13387#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13388#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13389#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13390#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13391#define NEON_ENC_SINGLE_(X) \
037e8744 13392 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13393#define NEON_ENC_DOUBLE_(X) \
037e8744 13394 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13395#define NEON_ENC_FPV8_(X) \
13396 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13397
88714cb8
DG
13398#define NEON_ENCODE(type, inst) \
13399 do \
13400 { \
13401 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13402 inst.is_neon = 1; \
13403 } \
13404 while (0)
13405
13406#define check_neon_suffixes \
13407 do \
13408 { \
13409 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13410 { \
13411 as_bad (_("invalid neon suffix for non neon instruction")); \
13412 return; \
13413 } \
13414 } \
13415 while (0)
13416
037e8744
JB
13417/* Define shapes for instruction operands. The following mnemonic characters
13418 are used in this table:
5287ad62 13419
037e8744 13420 F - VFP S<n> register
5287ad62
JB
13421 D - Neon D<n> register
13422 Q - Neon Q<n> register
13423 I - Immediate
13424 S - Scalar
13425 R - ARM register
13426 L - D<n> register list
5f4273c7 13427
037e8744
JB
13428 This table is used to generate various data:
13429 - enumerations of the form NS_DDR to be used as arguments to
13430 neon_select_shape.
13431 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13432 - a table used to drive neon_select_shape. */
b99bd4ef 13433
037e8744
JB
13434#define NEON_SHAPE_DEF \
13435 X(3, (D, D, D), DOUBLE), \
13436 X(3, (Q, Q, Q), QUAD), \
13437 X(3, (D, D, I), DOUBLE), \
13438 X(3, (Q, Q, I), QUAD), \
13439 X(3, (D, D, S), DOUBLE), \
13440 X(3, (Q, Q, S), QUAD), \
13441 X(2, (D, D), DOUBLE), \
13442 X(2, (Q, Q), QUAD), \
13443 X(2, (D, S), DOUBLE), \
13444 X(2, (Q, S), QUAD), \
13445 X(2, (D, R), DOUBLE), \
13446 X(2, (Q, R), QUAD), \
13447 X(2, (D, I), DOUBLE), \
13448 X(2, (Q, I), QUAD), \
13449 X(3, (D, L, D), DOUBLE), \
13450 X(2, (D, Q), MIXED), \
13451 X(2, (Q, D), MIXED), \
13452 X(3, (D, Q, I), MIXED), \
13453 X(3, (Q, D, I), MIXED), \
13454 X(3, (Q, D, D), MIXED), \
13455 X(3, (D, Q, Q), MIXED), \
13456 X(3, (Q, Q, D), MIXED), \
13457 X(3, (Q, D, S), MIXED), \
13458 X(3, (D, Q, S), MIXED), \
13459 X(4, (D, D, D, I), DOUBLE), \
13460 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
13461 X(4, (D, D, S, I), DOUBLE), \
13462 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
13463 X(2, (F, F), SINGLE), \
13464 X(3, (F, F, F), SINGLE), \
13465 X(2, (F, I), SINGLE), \
13466 X(2, (F, D), MIXED), \
13467 X(2, (D, F), MIXED), \
13468 X(3, (F, F, I), MIXED), \
13469 X(4, (R, R, F, F), SINGLE), \
13470 X(4, (F, F, R, R), SINGLE), \
13471 X(3, (D, R, R), DOUBLE), \
13472 X(3, (R, R, D), DOUBLE), \
13473 X(2, (S, R), SINGLE), \
13474 X(2, (R, S), SINGLE), \
13475 X(2, (F, R), SINGLE), \
d54af2d0
RL
13476 X(2, (R, F), SINGLE), \
13477/* Half float shape supported so far. */\
13478 X (2, (H, D), MIXED), \
13479 X (2, (D, H), MIXED), \
13480 X (2, (H, F), MIXED), \
13481 X (2, (F, H), MIXED), \
13482 X (2, (H, H), HALF), \
13483 X (2, (H, R), HALF), \
13484 X (2, (R, H), HALF), \
13485 X (2, (H, I), HALF), \
13486 X (3, (H, H, H), HALF), \
13487 X (3, (H, F, I), MIXED), \
dec41383
JW
13488 X (3, (F, H, I), MIXED), \
13489 X (3, (D, H, H), MIXED), \
13490 X (3, (D, H, S), MIXED)
037e8744
JB
13491
13492#define S2(A,B) NS_##A##B
13493#define S3(A,B,C) NS_##A##B##C
13494#define S4(A,B,C,D) NS_##A##B##C##D
13495
13496#define X(N, L, C) S##N L
13497
5287ad62
JB
13498enum neon_shape
13499{
037e8744
JB
13500 NEON_SHAPE_DEF,
13501 NS_NULL
5287ad62 13502};
b99bd4ef 13503
037e8744
JB
13504#undef X
13505#undef S2
13506#undef S3
13507#undef S4
13508
13509enum neon_shape_class
13510{
d54af2d0 13511 SC_HALF,
037e8744
JB
13512 SC_SINGLE,
13513 SC_DOUBLE,
13514 SC_QUAD,
13515 SC_MIXED
13516};
13517
13518#define X(N, L, C) SC_##C
13519
13520static enum neon_shape_class neon_shape_class[] =
13521{
13522 NEON_SHAPE_DEF
13523};
13524
13525#undef X
13526
13527enum neon_shape_el
13528{
d54af2d0 13529 SE_H,
037e8744
JB
13530 SE_F,
13531 SE_D,
13532 SE_Q,
13533 SE_I,
13534 SE_S,
13535 SE_R,
13536 SE_L
13537};
13538
13539/* Register widths of above. */
13540static unsigned neon_shape_el_size[] =
13541{
d54af2d0 13542 16,
037e8744
JB
13543 32,
13544 64,
13545 128,
13546 0,
13547 32,
13548 32,
13549 0
13550};
13551
13552struct neon_shape_info
13553{
13554 unsigned els;
13555 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13556};
13557
13558#define S2(A,B) { SE_##A, SE_##B }
13559#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13560#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13561
13562#define X(N, L, C) { N, S##N L }
13563
13564static struct neon_shape_info neon_shape_tab[] =
13565{
13566 NEON_SHAPE_DEF
13567};
13568
13569#undef X
13570#undef S2
13571#undef S3
13572#undef S4
13573
5287ad62
JB
13574/* Bit masks used in type checking given instructions.
13575 'N_EQK' means the type must be the same as (or based on in some way) the key
13576 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13577 set, various other bits can be set as well in order to modify the meaning of
13578 the type constraint. */
13579
13580enum neon_type_mask
13581{
8e79c3df
CM
13582 N_S8 = 0x0000001,
13583 N_S16 = 0x0000002,
13584 N_S32 = 0x0000004,
13585 N_S64 = 0x0000008,
13586 N_U8 = 0x0000010,
13587 N_U16 = 0x0000020,
13588 N_U32 = 0x0000040,
13589 N_U64 = 0x0000080,
13590 N_I8 = 0x0000100,
13591 N_I16 = 0x0000200,
13592 N_I32 = 0x0000400,
13593 N_I64 = 0x0000800,
13594 N_8 = 0x0001000,
13595 N_16 = 0x0002000,
13596 N_32 = 0x0004000,
13597 N_64 = 0x0008000,
13598 N_P8 = 0x0010000,
13599 N_P16 = 0x0020000,
13600 N_F16 = 0x0040000,
13601 N_F32 = 0x0080000,
13602 N_F64 = 0x0100000,
4f51b4bd 13603 N_P64 = 0x0200000,
c921be7d
NC
13604 N_KEY = 0x1000000, /* Key element (main type specifier). */
13605 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13606 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13607 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13608 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13609 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13610 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13611 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13612 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13613 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13614 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13615 N_UTYP = 0,
4f51b4bd 13616 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13617};
13618
dcbf9037
JB
13619#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13620
5287ad62
JB
13621#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13622#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13623#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13624#define N_S_32 (N_S8 | N_S16 | N_S32)
13625#define N_F_16_32 (N_F16 | N_F32)
13626#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13627#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13628#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13629#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13630
13631/* Pass this as the first type argument to neon_check_type to ignore types
13632 altogether. */
13633#define N_IGNORE_TYPE (N_KEY | N_EQK)
13634
037e8744
JB
13635/* Select a "shape" for the current instruction (describing register types or
13636 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13637 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13638 function of operand parsing, so this function doesn't need to be called.
13639 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13640
13641static enum neon_shape
037e8744 13642neon_select_shape (enum neon_shape shape, ...)
5287ad62 13643{
037e8744
JB
13644 va_list ap;
13645 enum neon_shape first_shape = shape;
5287ad62
JB
13646
13647 /* Fix missing optional operands. FIXME: we don't know at this point how
13648 many arguments we should have, so this makes the assumption that we have
13649 > 1. This is true of all current Neon opcodes, I think, but may not be
13650 true in the future. */
13651 if (!inst.operands[1].present)
13652 inst.operands[1] = inst.operands[0];
13653
037e8744 13654 va_start (ap, shape);
5f4273c7 13655
21d799b5 13656 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13657 {
13658 unsigned j;
13659 int matches = 1;
13660
13661 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13662 {
13663 if (!inst.operands[j].present)
13664 {
13665 matches = 0;
13666 break;
13667 }
13668
13669 switch (neon_shape_tab[shape].el[j])
13670 {
d54af2d0
RL
13671 /* If a .f16, .16, .u16, .s16 type specifier is given over
13672 a VFP single precision register operand, it's essentially
13673 means only half of the register is used.
13674
13675 If the type specifier is given after the mnemonics, the
13676 information is stored in inst.vectype. If the type specifier
13677 is given after register operand, the information is stored
13678 in inst.operands[].vectype.
13679
13680 When there is only one type specifier, and all the register
13681 operands are the same type of hardware register, the type
13682 specifier applies to all register operands.
13683
13684 If no type specifier is given, the shape is inferred from
13685 operand information.
13686
13687 for example:
13688 vadd.f16 s0, s1, s2: NS_HHH
13689 vabs.f16 s0, s1: NS_HH
13690 vmov.f16 s0, r1: NS_HR
13691 vmov.f16 r0, s1: NS_RH
13692 vcvt.f16 r0, s1: NS_RH
13693 vcvt.f16.s32 s2, s2, #29: NS_HFI
13694 vcvt.f16.s32 s2, s2: NS_HF
13695 */
13696 case SE_H:
13697 if (!(inst.operands[j].isreg
13698 && inst.operands[j].isvec
13699 && inst.operands[j].issingle
13700 && !inst.operands[j].isquad
13701 && ((inst.vectype.elems == 1
13702 && inst.vectype.el[0].size == 16)
13703 || (inst.vectype.elems > 1
13704 && inst.vectype.el[j].size == 16)
13705 || (inst.vectype.elems == 0
13706 && inst.operands[j].vectype.type != NT_invtype
13707 && inst.operands[j].vectype.size == 16))))
13708 matches = 0;
13709 break;
13710
477330fc
RM
13711 case SE_F:
13712 if (!(inst.operands[j].isreg
13713 && inst.operands[j].isvec
13714 && inst.operands[j].issingle
d54af2d0
RL
13715 && !inst.operands[j].isquad
13716 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13717 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13718 || (inst.vectype.elems == 0
13719 && (inst.operands[j].vectype.size == 32
13720 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13721 matches = 0;
13722 break;
13723
13724 case SE_D:
13725 if (!(inst.operands[j].isreg
13726 && inst.operands[j].isvec
13727 && !inst.operands[j].isquad
13728 && !inst.operands[j].issingle))
13729 matches = 0;
13730 break;
13731
13732 case SE_R:
13733 if (!(inst.operands[j].isreg
13734 && !inst.operands[j].isvec))
13735 matches = 0;
13736 break;
13737
13738 case SE_Q:
13739 if (!(inst.operands[j].isreg
13740 && inst.operands[j].isvec
13741 && inst.operands[j].isquad
13742 && !inst.operands[j].issingle))
13743 matches = 0;
13744 break;
13745
13746 case SE_I:
13747 if (!(!inst.operands[j].isreg
13748 && !inst.operands[j].isscalar))
13749 matches = 0;
13750 break;
13751
13752 case SE_S:
13753 if (!(!inst.operands[j].isreg
13754 && inst.operands[j].isscalar))
13755 matches = 0;
13756 break;
13757
13758 case SE_L:
13759 break;
13760 }
3fde54a2
JZ
13761 if (!matches)
13762 break;
477330fc 13763 }
ad6cec43
MGD
13764 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13765 /* We've matched all the entries in the shape table, and we don't
13766 have any left over operands which have not been matched. */
477330fc 13767 break;
037e8744 13768 }
5f4273c7 13769
037e8744 13770 va_end (ap);
5287ad62 13771
037e8744
JB
13772 if (shape == NS_NULL && first_shape != NS_NULL)
13773 first_error (_("invalid instruction shape"));
5287ad62 13774
037e8744
JB
13775 return shape;
13776}
5287ad62 13777
037e8744
JB
13778/* True if SHAPE is predominantly a quadword operation (most of the time, this
13779 means the Q bit should be set). */
13780
13781static int
13782neon_quad (enum neon_shape shape)
13783{
13784 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13785}
037e8744 13786
5287ad62
JB
13787static void
13788neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13789 unsigned *g_size)
5287ad62
JB
13790{
13791 /* Allow modification to be made to types which are constrained to be
13792 based on the key element, based on bits set alongside N_EQK. */
13793 if ((typebits & N_EQK) != 0)
13794 {
13795 if ((typebits & N_HLF) != 0)
13796 *g_size /= 2;
13797 else if ((typebits & N_DBL) != 0)
13798 *g_size *= 2;
13799 if ((typebits & N_SGN) != 0)
13800 *g_type = NT_signed;
13801 else if ((typebits & N_UNS) != 0)
477330fc 13802 *g_type = NT_unsigned;
5287ad62 13803 else if ((typebits & N_INT) != 0)
477330fc 13804 *g_type = NT_integer;
5287ad62 13805 else if ((typebits & N_FLT) != 0)
477330fc 13806 *g_type = NT_float;
dcbf9037 13807 else if ((typebits & N_SIZ) != 0)
477330fc 13808 *g_type = NT_untyped;
5287ad62
JB
13809 }
13810}
5f4273c7 13811
5287ad62
JB
13812/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13813 operand type, i.e. the single type specified in a Neon instruction when it
13814 is the only one given. */
13815
13816static struct neon_type_el
13817neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13818{
13819 struct neon_type_el dest = *key;
5f4273c7 13820
9c2799c2 13821 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13822
5287ad62
JB
13823 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13824
13825 return dest;
13826}
13827
13828/* Convert Neon type and size into compact bitmask representation. */
13829
13830static enum neon_type_mask
13831type_chk_of_el_type (enum neon_el_type type, unsigned size)
13832{
13833 switch (type)
13834 {
13835 case NT_untyped:
13836 switch (size)
477330fc
RM
13837 {
13838 case 8: return N_8;
13839 case 16: return N_16;
13840 case 32: return N_32;
13841 case 64: return N_64;
13842 default: ;
13843 }
5287ad62
JB
13844 break;
13845
13846 case NT_integer:
13847 switch (size)
477330fc
RM
13848 {
13849 case 8: return N_I8;
13850 case 16: return N_I16;
13851 case 32: return N_I32;
13852 case 64: return N_I64;
13853 default: ;
13854 }
5287ad62
JB
13855 break;
13856
13857 case NT_float:
037e8744 13858 switch (size)
477330fc 13859 {
8e79c3df 13860 case 16: return N_F16;
477330fc
RM
13861 case 32: return N_F32;
13862 case 64: return N_F64;
13863 default: ;
13864 }
5287ad62
JB
13865 break;
13866
13867 case NT_poly:
13868 switch (size)
477330fc
RM
13869 {
13870 case 8: return N_P8;
13871 case 16: return N_P16;
4f51b4bd 13872 case 64: return N_P64;
477330fc
RM
13873 default: ;
13874 }
5287ad62
JB
13875 break;
13876
13877 case NT_signed:
13878 switch (size)
477330fc
RM
13879 {
13880 case 8: return N_S8;
13881 case 16: return N_S16;
13882 case 32: return N_S32;
13883 case 64: return N_S64;
13884 default: ;
13885 }
5287ad62
JB
13886 break;
13887
13888 case NT_unsigned:
13889 switch (size)
477330fc
RM
13890 {
13891 case 8: return N_U8;
13892 case 16: return N_U16;
13893 case 32: return N_U32;
13894 case 64: return N_U64;
13895 default: ;
13896 }
5287ad62
JB
13897 break;
13898
13899 default: ;
13900 }
5f4273c7 13901
5287ad62
JB
13902 return N_UTYP;
13903}
13904
13905/* Convert compact Neon bitmask type representation to a type and size. Only
13906 handles the case where a single bit is set in the mask. */
13907
dcbf9037 13908static int
5287ad62 13909el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13910 enum neon_type_mask mask)
5287ad62 13911{
dcbf9037
JB
13912 if ((mask & N_EQK) != 0)
13913 return FAIL;
13914
5287ad62
JB
13915 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13916 *size = 8;
c70a8987 13917 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13918 *size = 16;
dcbf9037 13919 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13920 *size = 32;
4f51b4bd 13921 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13922 *size = 64;
dcbf9037
JB
13923 else
13924 return FAIL;
13925
5287ad62
JB
13926 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13927 *type = NT_signed;
dcbf9037 13928 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13929 *type = NT_unsigned;
dcbf9037 13930 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13931 *type = NT_integer;
dcbf9037 13932 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13933 *type = NT_untyped;
4f51b4bd 13934 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13935 *type = NT_poly;
d54af2d0 13936 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13937 *type = NT_float;
dcbf9037
JB
13938 else
13939 return FAIL;
5f4273c7 13940
dcbf9037 13941 return SUCCESS;
5287ad62
JB
13942}
13943
13944/* Modify a bitmask of allowed types. This is only needed for type
13945 relaxation. */
13946
13947static unsigned
13948modify_types_allowed (unsigned allowed, unsigned mods)
13949{
13950 unsigned size;
13951 enum neon_el_type type;
13952 unsigned destmask;
13953 int i;
5f4273c7 13954
5287ad62 13955 destmask = 0;
5f4273c7 13956
5287ad62
JB
13957 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13958 {
21d799b5 13959 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13960 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13961 {
13962 neon_modify_type_size (mods, &type, &size);
13963 destmask |= type_chk_of_el_type (type, size);
13964 }
5287ad62 13965 }
5f4273c7 13966
5287ad62
JB
13967 return destmask;
13968}
13969
13970/* Check type and return type classification.
13971 The manual states (paraphrase): If one datatype is given, it indicates the
13972 type given in:
13973 - the second operand, if there is one
13974 - the operand, if there is no second operand
13975 - the result, if there are no operands.
13976 This isn't quite good enough though, so we use a concept of a "key" datatype
13977 which is set on a per-instruction basis, which is the one which matters when
13978 only one data type is written.
13979 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13980 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13981
13982static struct neon_type_el
13983neon_check_type (unsigned els, enum neon_shape ns, ...)
13984{
13985 va_list ap;
13986 unsigned i, pass, key_el = 0;
13987 unsigned types[NEON_MAX_TYPE_ELS];
13988 enum neon_el_type k_type = NT_invtype;
13989 unsigned k_size = -1u;
13990 struct neon_type_el badtype = {NT_invtype, -1};
13991 unsigned key_allowed = 0;
13992
13993 /* Optional registers in Neon instructions are always (not) in operand 1.
13994 Fill in the missing operand here, if it was omitted. */
13995 if (els > 1 && !inst.operands[1].present)
13996 inst.operands[1] = inst.operands[0];
13997
13998 /* Suck up all the varargs. */
13999 va_start (ap, ns);
14000 for (i = 0; i < els; i++)
14001 {
14002 unsigned thisarg = va_arg (ap, unsigned);
14003 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
14004 {
14005 va_end (ap);
14006 return badtype;
14007 }
5287ad62
JB
14008 types[i] = thisarg;
14009 if ((thisarg & N_KEY) != 0)
477330fc 14010 key_el = i;
5287ad62
JB
14011 }
14012 va_end (ap);
14013
dcbf9037
JB
14014 if (inst.vectype.elems > 0)
14015 for (i = 0; i < els; i++)
14016 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
14017 {
14018 first_error (_("types specified in both the mnemonic and operands"));
14019 return badtype;
14020 }
dcbf9037 14021
5287ad62
JB
14022 /* Duplicate inst.vectype elements here as necessary.
14023 FIXME: No idea if this is exactly the same as the ARM assembler,
14024 particularly when an insn takes one register and one non-register
14025 operand. */
14026 if (inst.vectype.elems == 1 && els > 1)
14027 {
14028 unsigned j;
14029 inst.vectype.elems = els;
14030 inst.vectype.el[key_el] = inst.vectype.el[0];
14031 for (j = 0; j < els; j++)
477330fc
RM
14032 if (j != key_el)
14033 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14034 types[j]);
dcbf9037
JB
14035 }
14036 else if (inst.vectype.elems == 0 && els > 0)
14037 {
14038 unsigned j;
14039 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
14040 after each operand. We allow some flexibility here; as long as the
14041 "key" operand has a type, we can infer the others. */
dcbf9037 14042 for (j = 0; j < els; j++)
477330fc
RM
14043 if (inst.operands[j].vectype.type != NT_invtype)
14044 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
14045
14046 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
14047 {
14048 for (j = 0; j < els; j++)
14049 if (inst.operands[j].vectype.type == NT_invtype)
14050 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14051 types[j]);
14052 }
dcbf9037 14053 else
477330fc
RM
14054 {
14055 first_error (_("operand types can't be inferred"));
14056 return badtype;
14057 }
5287ad62
JB
14058 }
14059 else if (inst.vectype.elems != els)
14060 {
dcbf9037 14061 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
14062 return badtype;
14063 }
14064
14065 for (pass = 0; pass < 2; pass++)
14066 {
14067 for (i = 0; i < els; i++)
477330fc
RM
14068 {
14069 unsigned thisarg = types[i];
14070 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
14071 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
14072 enum neon_el_type g_type = inst.vectype.el[i].type;
14073 unsigned g_size = inst.vectype.el[i].size;
14074
14075 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 14076 integer types if sign-specific variants are unavailable. */
477330fc 14077 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
14078 && (types_allowed & N_SU_ALL) == 0)
14079 g_type = NT_integer;
14080
477330fc 14081 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
14082 them. Some instructions only care about signs for some element
14083 sizes, so handle that properly. */
477330fc 14084 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
14085 && ((g_size == 8 && (types_allowed & N_8) != 0)
14086 || (g_size == 16 && (types_allowed & N_16) != 0)
14087 || (g_size == 32 && (types_allowed & N_32) != 0)
14088 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
14089 g_type = NT_untyped;
14090
477330fc
RM
14091 if (pass == 0)
14092 {
14093 if ((thisarg & N_KEY) != 0)
14094 {
14095 k_type = g_type;
14096 k_size = g_size;
14097 key_allowed = thisarg & ~N_KEY;
cc933301
JW
14098
14099 /* Check architecture constraint on FP16 extension. */
14100 if (k_size == 16
14101 && k_type == NT_float
14102 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14103 {
14104 inst.error = _(BAD_FP16);
14105 return badtype;
14106 }
477330fc
RM
14107 }
14108 }
14109 else
14110 {
14111 if ((thisarg & N_VFP) != 0)
14112 {
14113 enum neon_shape_el regshape;
14114 unsigned regwidth, match;
99b253c5
NC
14115
14116 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14117 if (ns == NS_NULL)
14118 {
14119 first_error (_("invalid instruction shape"));
14120 return badtype;
14121 }
477330fc
RM
14122 regshape = neon_shape_tab[ns].el[i];
14123 regwidth = neon_shape_el_size[regshape];
14124
14125 /* In VFP mode, operands must match register widths. If we
14126 have a key operand, use its width, else use the width of
14127 the current operand. */
14128 if (k_size != -1u)
14129 match = k_size;
14130 else
14131 match = g_size;
14132
9db2f6b4
RL
14133 /* FP16 will use a single precision register. */
14134 if (regwidth == 32 && match == 16)
14135 {
14136 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14137 match = regwidth;
14138 else
14139 {
14140 inst.error = _(BAD_FP16);
14141 return badtype;
14142 }
14143 }
14144
477330fc
RM
14145 if (regwidth != match)
14146 {
14147 first_error (_("operand size must match register width"));
14148 return badtype;
14149 }
14150 }
14151
14152 if ((thisarg & N_EQK) == 0)
14153 {
14154 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14155
14156 if ((given_type & types_allowed) == 0)
14157 {
14158 first_error (_("bad type in Neon instruction"));
14159 return badtype;
14160 }
14161 }
14162 else
14163 {
14164 enum neon_el_type mod_k_type = k_type;
14165 unsigned mod_k_size = k_size;
14166 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14167 if (g_type != mod_k_type || g_size != mod_k_size)
14168 {
14169 first_error (_("inconsistent types in Neon instruction"));
14170 return badtype;
14171 }
14172 }
14173 }
14174 }
5287ad62
JB
14175 }
14176
14177 return inst.vectype.el[key_el];
14178}
14179
037e8744 14180/* Neon-style VFP instruction forwarding. */
5287ad62 14181
037e8744
JB
14182/* Thumb VFP instructions have 0xE in the condition field. */
14183
14184static void
14185do_vfp_cond_or_thumb (void)
5287ad62 14186{
88714cb8
DG
14187 inst.is_neon = 1;
14188
5287ad62 14189 if (thumb_mode)
037e8744 14190 inst.instruction |= 0xe0000000;
5287ad62 14191 else
037e8744 14192 inst.instruction |= inst.cond << 28;
5287ad62
JB
14193}
14194
037e8744
JB
14195/* Look up and encode a simple mnemonic, for use as a helper function for the
14196 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14197 etc. It is assumed that operand parsing has already been done, and that the
14198 operands are in the form expected by the given opcode (this isn't necessarily
14199 the same as the form in which they were parsed, hence some massaging must
14200 take place before this function is called).
14201 Checks current arch version against that in the looked-up opcode. */
5287ad62 14202
037e8744
JB
14203static void
14204do_vfp_nsyn_opcode (const char *opname)
5287ad62 14205{
037e8744 14206 const struct asm_opcode *opcode;
5f4273c7 14207
21d799b5 14208 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14209
037e8744
JB
14210 if (!opcode)
14211 abort ();
5287ad62 14212
037e8744 14213 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14214 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14215 _(BAD_FPU));
5287ad62 14216
88714cb8
DG
14217 inst.is_neon = 1;
14218
037e8744
JB
14219 if (thumb_mode)
14220 {
14221 inst.instruction = opcode->tvalue;
14222 opcode->tencode ();
14223 }
14224 else
14225 {
14226 inst.instruction = (inst.cond << 28) | opcode->avalue;
14227 opcode->aencode ();
14228 }
14229}
5287ad62
JB
14230
14231static void
037e8744 14232do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14233{
037e8744
JB
14234 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14235
9db2f6b4 14236 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14237 {
14238 if (is_add)
477330fc 14239 do_vfp_nsyn_opcode ("fadds");
037e8744 14240 else
477330fc 14241 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14242
14243 /* ARMv8.2 fp16 instruction. */
14244 if (rs == NS_HHH)
14245 do_scalar_fp16_v82_encode ();
037e8744
JB
14246 }
14247 else
14248 {
14249 if (is_add)
477330fc 14250 do_vfp_nsyn_opcode ("faddd");
037e8744 14251 else
477330fc 14252 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14253 }
14254}
14255
14256/* Check operand types to see if this is a VFP instruction, and if so call
14257 PFN (). */
14258
14259static int
14260try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14261{
14262 enum neon_shape rs;
14263 struct neon_type_el et;
14264
14265 switch (args)
14266 {
14267 case 2:
9db2f6b4
RL
14268 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14269 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14270 break;
5f4273c7 14271
037e8744 14272 case 3:
9db2f6b4
RL
14273 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14274 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14275 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14276 break;
14277
14278 default:
14279 abort ();
14280 }
14281
14282 if (et.type != NT_invtype)
14283 {
14284 pfn (rs);
14285 return SUCCESS;
14286 }
037e8744 14287
99b253c5 14288 inst.error = NULL;
037e8744
JB
14289 return FAIL;
14290}
14291
14292static void
14293do_vfp_nsyn_mla_mls (enum neon_shape rs)
14294{
14295 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14296
9db2f6b4 14297 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14298 {
14299 if (is_mla)
477330fc 14300 do_vfp_nsyn_opcode ("fmacs");
037e8744 14301 else
477330fc 14302 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14303
14304 /* ARMv8.2 fp16 instruction. */
14305 if (rs == NS_HHH)
14306 do_scalar_fp16_v82_encode ();
037e8744
JB
14307 }
14308 else
14309 {
14310 if (is_mla)
477330fc 14311 do_vfp_nsyn_opcode ("fmacd");
037e8744 14312 else
477330fc 14313 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14314 }
14315}
14316
62f3b8c8
PB
14317static void
14318do_vfp_nsyn_fma_fms (enum neon_shape rs)
14319{
14320 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14321
9db2f6b4 14322 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14323 {
14324 if (is_fma)
477330fc 14325 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14326 else
477330fc 14327 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14328
14329 /* ARMv8.2 fp16 instruction. */
14330 if (rs == NS_HHH)
14331 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14332 }
14333 else
14334 {
14335 if (is_fma)
477330fc 14336 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14337 else
477330fc 14338 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14339 }
14340}
14341
037e8744
JB
14342static void
14343do_vfp_nsyn_mul (enum neon_shape rs)
14344{
9db2f6b4
RL
14345 if (rs == NS_FFF || rs == NS_HHH)
14346 {
14347 do_vfp_nsyn_opcode ("fmuls");
14348
14349 /* ARMv8.2 fp16 instruction. */
14350 if (rs == NS_HHH)
14351 do_scalar_fp16_v82_encode ();
14352 }
037e8744
JB
14353 else
14354 do_vfp_nsyn_opcode ("fmuld");
14355}
14356
14357static void
14358do_vfp_nsyn_abs_neg (enum neon_shape rs)
14359{
14360 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14361 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14362
9db2f6b4 14363 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14364 {
14365 if (is_neg)
477330fc 14366 do_vfp_nsyn_opcode ("fnegs");
037e8744 14367 else
477330fc 14368 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14369
14370 /* ARMv8.2 fp16 instruction. */
14371 if (rs == NS_HH)
14372 do_scalar_fp16_v82_encode ();
037e8744
JB
14373 }
14374 else
14375 {
14376 if (is_neg)
477330fc 14377 do_vfp_nsyn_opcode ("fnegd");
037e8744 14378 else
477330fc 14379 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14380 }
14381}
14382
14383/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14384 insns belong to Neon, and are handled elsewhere. */
14385
14386static void
14387do_vfp_nsyn_ldm_stm (int is_dbmode)
14388{
14389 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14390 if (is_ldm)
14391 {
14392 if (is_dbmode)
477330fc 14393 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14394 else
477330fc 14395 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14396 }
14397 else
14398 {
14399 if (is_dbmode)
477330fc 14400 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14401 else
477330fc 14402 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14403 }
14404}
14405
037e8744
JB
14406static void
14407do_vfp_nsyn_sqrt (void)
14408{
9db2f6b4
RL
14409 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14410 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14411
9db2f6b4
RL
14412 if (rs == NS_FF || rs == NS_HH)
14413 {
14414 do_vfp_nsyn_opcode ("fsqrts");
14415
14416 /* ARMv8.2 fp16 instruction. */
14417 if (rs == NS_HH)
14418 do_scalar_fp16_v82_encode ();
14419 }
037e8744
JB
14420 else
14421 do_vfp_nsyn_opcode ("fsqrtd");
14422}
14423
14424static void
14425do_vfp_nsyn_div (void)
14426{
9db2f6b4 14427 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14428 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14429 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14430
9db2f6b4
RL
14431 if (rs == NS_FFF || rs == NS_HHH)
14432 {
14433 do_vfp_nsyn_opcode ("fdivs");
14434
14435 /* ARMv8.2 fp16 instruction. */
14436 if (rs == NS_HHH)
14437 do_scalar_fp16_v82_encode ();
14438 }
037e8744
JB
14439 else
14440 do_vfp_nsyn_opcode ("fdivd");
14441}
14442
14443static void
14444do_vfp_nsyn_nmul (void)
14445{
9db2f6b4 14446 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14447 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14448 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14449
9db2f6b4 14450 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14451 {
88714cb8 14452 NEON_ENCODE (SINGLE, inst);
037e8744 14453 do_vfp_sp_dyadic ();
9db2f6b4
RL
14454
14455 /* ARMv8.2 fp16 instruction. */
14456 if (rs == NS_HHH)
14457 do_scalar_fp16_v82_encode ();
037e8744
JB
14458 }
14459 else
14460 {
88714cb8 14461 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14462 do_vfp_dp_rd_rn_rm ();
14463 }
14464 do_vfp_cond_or_thumb ();
9db2f6b4 14465
037e8744
JB
14466}
14467
14468static void
14469do_vfp_nsyn_cmp (void)
14470{
9db2f6b4 14471 enum neon_shape rs;
037e8744
JB
14472 if (inst.operands[1].isreg)
14473 {
9db2f6b4
RL
14474 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14475 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14476
9db2f6b4 14477 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14478 {
14479 NEON_ENCODE (SINGLE, inst);
14480 do_vfp_sp_monadic ();
14481 }
037e8744 14482 else
477330fc
RM
14483 {
14484 NEON_ENCODE (DOUBLE, inst);
14485 do_vfp_dp_rd_rm ();
14486 }
037e8744
JB
14487 }
14488 else
14489 {
9db2f6b4
RL
14490 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14491 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14492
14493 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14494 {
14495 case N_MNEM_vcmp:
14496 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14497 break;
14498 case N_MNEM_vcmpe:
14499 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14500 break;
14501 default:
14502 abort ();
14503 }
5f4273c7 14504
9db2f6b4 14505 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14506 {
14507 NEON_ENCODE (SINGLE, inst);
14508 do_vfp_sp_compare_z ();
14509 }
037e8744 14510 else
477330fc
RM
14511 {
14512 NEON_ENCODE (DOUBLE, inst);
14513 do_vfp_dp_rd ();
14514 }
037e8744
JB
14515 }
14516 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14517
14518 /* ARMv8.2 fp16 instruction. */
14519 if (rs == NS_HI || rs == NS_HH)
14520 do_scalar_fp16_v82_encode ();
037e8744
JB
14521}
14522
14523static void
14524nsyn_insert_sp (void)
14525{
14526 inst.operands[1] = inst.operands[0];
14527 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14528 inst.operands[0].reg = REG_SP;
037e8744
JB
14529 inst.operands[0].isreg = 1;
14530 inst.operands[0].writeback = 1;
14531 inst.operands[0].present = 1;
14532}
14533
14534static void
14535do_vfp_nsyn_push (void)
14536{
14537 nsyn_insert_sp ();
b126985e
NC
14538
14539 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14540 _("register list must contain at least 1 and at most 16 "
14541 "registers"));
14542
037e8744
JB
14543 if (inst.operands[1].issingle)
14544 do_vfp_nsyn_opcode ("fstmdbs");
14545 else
14546 do_vfp_nsyn_opcode ("fstmdbd");
14547}
14548
14549static void
14550do_vfp_nsyn_pop (void)
14551{
14552 nsyn_insert_sp ();
b126985e
NC
14553
14554 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14555 _("register list must contain at least 1 and at most 16 "
14556 "registers"));
14557
037e8744 14558 if (inst.operands[1].issingle)
22b5b651 14559 do_vfp_nsyn_opcode ("fldmias");
037e8744 14560 else
22b5b651 14561 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14562}
14563
14564/* Fix up Neon data-processing instructions, ORing in the correct bits for
14565 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14566
88714cb8
DG
14567static void
14568neon_dp_fixup (struct arm_it* insn)
037e8744 14569{
88714cb8
DG
14570 unsigned int i = insn->instruction;
14571 insn->is_neon = 1;
14572
037e8744
JB
14573 if (thumb_mode)
14574 {
14575 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14576 if (i & (1 << 24))
477330fc 14577 i |= 1 << 28;
5f4273c7 14578
037e8744 14579 i &= ~(1 << 24);
5f4273c7 14580
037e8744
JB
14581 i |= 0xef000000;
14582 }
14583 else
14584 i |= 0xf2000000;
5f4273c7 14585
88714cb8 14586 insn->instruction = i;
037e8744
JB
14587}
14588
14589/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14590 (0, 1, 2, 3). */
14591
14592static unsigned
14593neon_logbits (unsigned x)
14594{
14595 return ffs (x) - 4;
14596}
14597
14598#define LOW4(R) ((R) & 0xf)
14599#define HI1(R) (((R) >> 4) & 1)
14600
14601/* Encode insns with bit pattern:
14602
14603 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14604 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14605
037e8744
JB
14606 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14607 different meaning for some instruction. */
14608
14609static void
14610neon_three_same (int isquad, int ubit, int size)
14611{
14612 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14613 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14614 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14615 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14616 inst.instruction |= LOW4 (inst.operands[2].reg);
14617 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14618 inst.instruction |= (isquad != 0) << 6;
14619 inst.instruction |= (ubit != 0) << 24;
14620 if (size != -1)
14621 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14622
88714cb8 14623 neon_dp_fixup (&inst);
037e8744
JB
14624}
14625
14626/* Encode instructions of the form:
14627
14628 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14629 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14630
14631 Don't write size if SIZE == -1. */
14632
14633static void
14634neon_two_same (int qbit, int ubit, int size)
14635{
14636 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14637 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14638 inst.instruction |= LOW4 (inst.operands[1].reg);
14639 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14640 inst.instruction |= (qbit != 0) << 6;
14641 inst.instruction |= (ubit != 0) << 24;
14642
14643 if (size != -1)
14644 inst.instruction |= neon_logbits (size) << 18;
14645
88714cb8 14646 neon_dp_fixup (&inst);
5287ad62
JB
14647}
14648
14649/* Neon instruction encoders, in approximate order of appearance. */
14650
14651static void
14652do_neon_dyadic_i_su (void)
14653{
037e8744 14654 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14655 struct neon_type_el et = neon_check_type (3, rs,
14656 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14657 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14658}
14659
14660static void
14661do_neon_dyadic_i64_su (void)
14662{
037e8744 14663 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14664 struct neon_type_el et = neon_check_type (3, rs,
14665 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14666 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14667}
14668
14669static void
14670neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14671 unsigned immbits)
5287ad62
JB
14672{
14673 unsigned size = et.size >> 3;
14674 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14675 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14676 inst.instruction |= LOW4 (inst.operands[1].reg);
14677 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14678 inst.instruction |= (isquad != 0) << 6;
14679 inst.instruction |= immbits << 16;
14680 inst.instruction |= (size >> 3) << 7;
14681 inst.instruction |= (size & 0x7) << 19;
14682 if (write_ubit)
14683 inst.instruction |= (uval != 0) << 24;
14684
88714cb8 14685 neon_dp_fixup (&inst);
5287ad62
JB
14686}
14687
14688static void
14689do_neon_shl_imm (void)
14690{
14691 if (!inst.operands[2].isreg)
14692 {
037e8744 14693 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14694 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14695 int imm = inst.operands[2].imm;
14696
14697 constraint (imm < 0 || (unsigned)imm >= et.size,
14698 _("immediate out of range for shift"));
88714cb8 14699 NEON_ENCODE (IMMED, inst);
cb3b1e65 14700 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14701 }
14702 else
14703 {
037e8744 14704 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14705 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14706 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14707 unsigned int tmp;
14708
14709 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14710 vshl.xx Dd, Dm, Dn
14711 whereas other 3-register operations encoded by neon_three_same have
14712 syntax like:
14713 vadd.xx Dd, Dn, Dm
14714 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14715 here. */
627907b7
JB
14716 tmp = inst.operands[2].reg;
14717 inst.operands[2].reg = inst.operands[1].reg;
14718 inst.operands[1].reg = tmp;
88714cb8 14719 NEON_ENCODE (INTEGER, inst);
037e8744 14720 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14721 }
14722}
14723
14724static void
14725do_neon_qshl_imm (void)
14726{
14727 if (!inst.operands[2].isreg)
14728 {
037e8744 14729 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14730 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14731 int imm = inst.operands[2].imm;
627907b7 14732
cb3b1e65
JB
14733 constraint (imm < 0 || (unsigned)imm >= et.size,
14734 _("immediate out of range for shift"));
88714cb8 14735 NEON_ENCODE (IMMED, inst);
cb3b1e65 14736 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14737 }
14738 else
14739 {
037e8744 14740 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14741 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14742 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14743 unsigned int tmp;
14744
14745 /* See note in do_neon_shl_imm. */
14746 tmp = inst.operands[2].reg;
14747 inst.operands[2].reg = inst.operands[1].reg;
14748 inst.operands[1].reg = tmp;
88714cb8 14749 NEON_ENCODE (INTEGER, inst);
037e8744 14750 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14751 }
14752}
14753
627907b7
JB
14754static void
14755do_neon_rshl (void)
14756{
14757 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14758 struct neon_type_el et = neon_check_type (3, rs,
14759 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14760 unsigned int tmp;
14761
14762 tmp = inst.operands[2].reg;
14763 inst.operands[2].reg = inst.operands[1].reg;
14764 inst.operands[1].reg = tmp;
14765 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14766}
14767
5287ad62
JB
14768static int
14769neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14770{
036dc3f7
PB
14771 /* Handle .I8 pseudo-instructions. */
14772 if (size == 8)
5287ad62 14773 {
5287ad62 14774 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14775 FIXME is this the intended semantics? There doesn't seem much point in
14776 accepting .I8 if so. */
5287ad62
JB
14777 immediate |= immediate << 8;
14778 size = 16;
036dc3f7
PB
14779 }
14780
14781 if (size >= 32)
14782 {
14783 if (immediate == (immediate & 0x000000ff))
14784 {
14785 *immbits = immediate;
14786 return 0x1;
14787 }
14788 else if (immediate == (immediate & 0x0000ff00))
14789 {
14790 *immbits = immediate >> 8;
14791 return 0x3;
14792 }
14793 else if (immediate == (immediate & 0x00ff0000))
14794 {
14795 *immbits = immediate >> 16;
14796 return 0x5;
14797 }
14798 else if (immediate == (immediate & 0xff000000))
14799 {
14800 *immbits = immediate >> 24;
14801 return 0x7;
14802 }
14803 if ((immediate & 0xffff) != (immediate >> 16))
14804 goto bad_immediate;
14805 immediate &= 0xffff;
5287ad62
JB
14806 }
14807
14808 if (immediate == (immediate & 0x000000ff))
14809 {
14810 *immbits = immediate;
036dc3f7 14811 return 0x9;
5287ad62
JB
14812 }
14813 else if (immediate == (immediate & 0x0000ff00))
14814 {
14815 *immbits = immediate >> 8;
036dc3f7 14816 return 0xb;
5287ad62
JB
14817 }
14818
14819 bad_immediate:
dcbf9037 14820 first_error (_("immediate value out of range"));
5287ad62
JB
14821 return FAIL;
14822}
14823
5287ad62
JB
14824static void
14825do_neon_logic (void)
14826{
14827 if (inst.operands[2].present && inst.operands[2].isreg)
14828 {
037e8744 14829 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14830 neon_check_type (3, rs, N_IGNORE_TYPE);
14831 /* U bit and size field were set as part of the bitmask. */
88714cb8 14832 NEON_ENCODE (INTEGER, inst);
037e8744 14833 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14834 }
14835 else
14836 {
4316f0d2
DG
14837 const int three_ops_form = (inst.operands[2].present
14838 && !inst.operands[2].isreg);
14839 const int immoperand = (three_ops_form ? 2 : 1);
14840 enum neon_shape rs = (three_ops_form
14841 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14842 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14843 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14844 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14845 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14846 unsigned immbits;
14847 int cmode;
5f4273c7 14848
5287ad62 14849 if (et.type == NT_invtype)
477330fc 14850 return;
5f4273c7 14851
4316f0d2
DG
14852 if (three_ops_form)
14853 constraint (inst.operands[0].reg != inst.operands[1].reg,
14854 _("first and second operands shall be the same register"));
14855
88714cb8 14856 NEON_ENCODE (IMMED, inst);
5287ad62 14857
4316f0d2 14858 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14859 if (et.size == 64)
14860 {
14861 /* .i64 is a pseudo-op, so the immediate must be a repeating
14862 pattern. */
4316f0d2
DG
14863 if (immbits != (inst.operands[immoperand].regisimm ?
14864 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14865 {
14866 /* Set immbits to an invalid constant. */
14867 immbits = 0xdeadbeef;
14868 }
14869 }
14870
5287ad62 14871 switch (opcode)
477330fc
RM
14872 {
14873 case N_MNEM_vbic:
14874 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14875 break;
14876
14877 case N_MNEM_vorr:
14878 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14879 break;
14880
14881 case N_MNEM_vand:
14882 /* Pseudo-instruction for VBIC. */
14883 neon_invert_size (&immbits, 0, et.size);
14884 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14885 break;
14886
14887 case N_MNEM_vorn:
14888 /* Pseudo-instruction for VORR. */
14889 neon_invert_size (&immbits, 0, et.size);
14890 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14891 break;
14892
14893 default:
14894 abort ();
14895 }
5287ad62
JB
14896
14897 if (cmode == FAIL)
477330fc 14898 return;
5287ad62 14899
037e8744 14900 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14901 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14902 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14903 inst.instruction |= cmode << 8;
14904 neon_write_immbits (immbits);
5f4273c7 14905
88714cb8 14906 neon_dp_fixup (&inst);
5287ad62
JB
14907 }
14908}
14909
14910static void
14911do_neon_bitfield (void)
14912{
037e8744 14913 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14914 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14915 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14916}
14917
14918static void
dcbf9037 14919neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14920 unsigned destbits)
5287ad62 14921{
037e8744 14922 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14923 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14924 types | N_KEY);
5287ad62
JB
14925 if (et.type == NT_float)
14926 {
88714cb8 14927 NEON_ENCODE (FLOAT, inst);
cc933301 14928 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14929 }
14930 else
14931 {
88714cb8 14932 NEON_ENCODE (INTEGER, inst);
037e8744 14933 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14934 }
14935}
14936
14937static void
14938do_neon_dyadic_if_su (void)
14939{
dcbf9037 14940 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14941}
14942
14943static void
14944do_neon_dyadic_if_su_d (void)
14945{
14946 /* This version only allow D registers, but that constraint is enforced during
14947 operand parsing so we don't need to do anything extra here. */
dcbf9037 14948 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14949}
14950
5287ad62
JB
14951static void
14952do_neon_dyadic_if_i_d (void)
14953{
428e3f1f
PB
14954 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14955 affected if we specify unsigned args. */
14956 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14957}
14958
037e8744
JB
14959enum vfp_or_neon_is_neon_bits
14960{
14961 NEON_CHECK_CC = 1,
73924fbc
MGD
14962 NEON_CHECK_ARCH = 2,
14963 NEON_CHECK_ARCH8 = 4
037e8744
JB
14964};
14965
14966/* Call this function if an instruction which may have belonged to the VFP or
14967 Neon instruction sets, but turned out to be a Neon instruction (due to the
14968 operand types involved, etc.). We have to check and/or fix-up a couple of
14969 things:
14970
14971 - Make sure the user hasn't attempted to make a Neon instruction
14972 conditional.
14973 - Alter the value in the condition code field if necessary.
14974 - Make sure that the arch supports Neon instructions.
14975
14976 Which of these operations take place depends on bits from enum
14977 vfp_or_neon_is_neon_bits.
14978
14979 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14980 current instruction's condition is COND_ALWAYS, the condition field is
14981 changed to inst.uncond_value. This is necessary because instructions shared
14982 between VFP and Neon may be conditional for the VFP variants only, and the
14983 unconditional Neon version must have, e.g., 0xF in the condition field. */
14984
14985static int
14986vfp_or_neon_is_neon (unsigned check)
14987{
14988 /* Conditions are always legal in Thumb mode (IT blocks). */
14989 if (!thumb_mode && (check & NEON_CHECK_CC))
14990 {
14991 if (inst.cond != COND_ALWAYS)
477330fc
RM
14992 {
14993 first_error (_(BAD_COND));
14994 return FAIL;
14995 }
037e8744 14996 if (inst.uncond_value != -1)
477330fc 14997 inst.instruction |= inst.uncond_value << 28;
037e8744 14998 }
5f4273c7 14999
037e8744 15000 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
15001 && !mark_feature_used (&fpu_neon_ext_v1))
15002 {
15003 first_error (_(BAD_FPU));
15004 return FAIL;
15005 }
15006
15007 if ((check & NEON_CHECK_ARCH8)
15008 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
15009 {
15010 first_error (_(BAD_FPU));
15011 return FAIL;
15012 }
5f4273c7 15013
037e8744
JB
15014 return SUCCESS;
15015}
15016
5287ad62
JB
15017static void
15018do_neon_addsub_if_i (void)
15019{
037e8744
JB
15020 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
15021 return;
15022
15023 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15024 return;
15025
5287ad62
JB
15026 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15027 affected if we specify unsigned args. */
dcbf9037 15028 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
15029}
15030
15031/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
15032 result to be:
15033 V<op> A,B (A is operand 0, B is operand 2)
15034 to mean:
15035 V<op> A,B,A
15036 not:
15037 V<op> A,B,B
15038 so handle that case specially. */
15039
15040static void
15041neon_exchange_operands (void)
15042{
5287ad62
JB
15043 if (inst.operands[1].present)
15044 {
e1fa0163
NC
15045 void *scratch = xmalloc (sizeof (inst.operands[0]));
15046
5287ad62
JB
15047 /* Swap operands[1] and operands[2]. */
15048 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
15049 inst.operands[1] = inst.operands[2];
15050 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 15051 free (scratch);
5287ad62
JB
15052 }
15053 else
15054 {
15055 inst.operands[1] = inst.operands[2];
15056 inst.operands[2] = inst.operands[0];
15057 }
15058}
15059
15060static void
15061neon_compare (unsigned regtypes, unsigned immtypes, int invert)
15062{
15063 if (inst.operands[2].isreg)
15064 {
15065 if (invert)
477330fc 15066 neon_exchange_operands ();
dcbf9037 15067 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
15068 }
15069 else
15070 {
037e8744 15071 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 15072 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15073 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 15074
88714cb8 15075 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15076 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15077 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15078 inst.instruction |= LOW4 (inst.operands[1].reg);
15079 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15080 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15081 inst.instruction |= (et.type == NT_float) << 10;
15082 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15083
88714cb8 15084 neon_dp_fixup (&inst);
5287ad62
JB
15085 }
15086}
15087
15088static void
15089do_neon_cmp (void)
15090{
cc933301 15091 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
15092}
15093
15094static void
15095do_neon_cmp_inv (void)
15096{
cc933301 15097 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
15098}
15099
15100static void
15101do_neon_ceq (void)
15102{
15103 neon_compare (N_IF_32, N_IF_32, FALSE);
15104}
15105
15106/* For multiply instructions, we have the possibility of 16-bit or 32-bit
15107 scalars, which are encoded in 5 bits, M : Rm.
15108 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15109 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
15110 index in M.
15111
15112 Dot Product instructions are similar to multiply instructions except elsize
15113 should always be 32.
15114
15115 This function translates SCALAR, which is GAS's internal encoding of indexed
15116 scalar register, to raw encoding. There is also register and index range
15117 check based on ELSIZE. */
5287ad62
JB
15118
15119static unsigned
15120neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15121{
dcbf9037
JB
15122 unsigned regno = NEON_SCALAR_REG (scalar);
15123 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
15124
15125 switch (elsize)
15126 {
15127 case 16:
15128 if (regno > 7 || elno > 3)
477330fc 15129 goto bad_scalar;
5287ad62 15130 return regno | (elno << 3);
5f4273c7 15131
5287ad62
JB
15132 case 32:
15133 if (regno > 15 || elno > 1)
477330fc 15134 goto bad_scalar;
5287ad62
JB
15135 return regno | (elno << 4);
15136
15137 default:
15138 bad_scalar:
dcbf9037 15139 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15140 }
15141
15142 return 0;
15143}
15144
15145/* Encode multiply / multiply-accumulate scalar instructions. */
15146
15147static void
15148neon_mul_mac (struct neon_type_el et, int ubit)
15149{
dcbf9037
JB
15150 unsigned scalar;
15151
15152 /* Give a more helpful error message if we have an invalid type. */
15153 if (et.type == NT_invtype)
15154 return;
5f4273c7 15155
dcbf9037 15156 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15157 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15158 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15159 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15160 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15161 inst.instruction |= LOW4 (scalar);
15162 inst.instruction |= HI1 (scalar) << 5;
15163 inst.instruction |= (et.type == NT_float) << 8;
15164 inst.instruction |= neon_logbits (et.size) << 20;
15165 inst.instruction |= (ubit != 0) << 24;
15166
88714cb8 15167 neon_dp_fixup (&inst);
5287ad62
JB
15168}
15169
15170static void
15171do_neon_mac_maybe_scalar (void)
15172{
037e8744
JB
15173 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15174 return;
15175
15176 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15177 return;
15178
5287ad62
JB
15179 if (inst.operands[2].isscalar)
15180 {
037e8744 15181 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15182 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15183 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15184 NEON_ENCODE (SCALAR, inst);
037e8744 15185 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15186 }
15187 else
428e3f1f
PB
15188 {
15189 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15190 affected if we specify unsigned args. */
15191 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15192 }
5287ad62
JB
15193}
15194
62f3b8c8
PB
15195static void
15196do_neon_fmac (void)
15197{
15198 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15199 return;
15200
15201 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15202 return;
15203
15204 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15205}
15206
5287ad62
JB
15207static void
15208do_neon_tst (void)
15209{
037e8744 15210 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15211 struct neon_type_el et = neon_check_type (3, rs,
15212 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15213 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15214}
15215
15216/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15217 same types as the MAC equivalents. The polynomial type for this instruction
15218 is encoded the same as the integer type. */
15219
15220static void
15221do_neon_mul (void)
15222{
037e8744
JB
15223 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15224 return;
15225
15226 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15227 return;
15228
5287ad62
JB
15229 if (inst.operands[2].isscalar)
15230 do_neon_mac_maybe_scalar ();
15231 else
cc933301 15232 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15233}
15234
15235static void
15236do_neon_qdmulh (void)
15237{
15238 if (inst.operands[2].isscalar)
15239 {
037e8744 15240 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15241 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15242 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15243 NEON_ENCODE (SCALAR, inst);
037e8744 15244 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15245 }
15246 else
15247 {
037e8744 15248 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15249 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15250 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15251 NEON_ENCODE (INTEGER, inst);
5287ad62 15252 /* The U bit (rounding) comes from bit mask. */
037e8744 15253 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15254 }
15255}
15256
643afb90
MW
15257static void
15258do_neon_qrdmlah (void)
15259{
15260 /* Check we're on the correct architecture. */
15261 if (!mark_feature_used (&fpu_neon_ext_armv8))
15262 inst.error =
15263 _("instruction form not available on this architecture.");
15264 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15265 {
15266 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15267 record_feature_use (&fpu_neon_ext_v8_1);
15268 }
15269
15270 if (inst.operands[2].isscalar)
15271 {
15272 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15273 struct neon_type_el et = neon_check_type (3, rs,
15274 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15275 NEON_ENCODE (SCALAR, inst);
15276 neon_mul_mac (et, neon_quad (rs));
15277 }
15278 else
15279 {
15280 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15281 struct neon_type_el et = neon_check_type (3, rs,
15282 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15283 NEON_ENCODE (INTEGER, inst);
15284 /* The U bit (rounding) comes from bit mask. */
15285 neon_three_same (neon_quad (rs), 0, et.size);
15286 }
15287}
15288
5287ad62
JB
15289static void
15290do_neon_fcmp_absolute (void)
15291{
037e8744 15292 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15293 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15294 N_F_16_32 | N_KEY);
5287ad62 15295 /* Size field comes from bit mask. */
cc933301 15296 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15297}
15298
15299static void
15300do_neon_fcmp_absolute_inv (void)
15301{
15302 neon_exchange_operands ();
15303 do_neon_fcmp_absolute ();
15304}
15305
15306static void
15307do_neon_step (void)
15308{
037e8744 15309 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15310 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15311 N_F_16_32 | N_KEY);
15312 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15313}
15314
15315static void
15316do_neon_abs_neg (void)
15317{
037e8744
JB
15318 enum neon_shape rs;
15319 struct neon_type_el et;
5f4273c7 15320
037e8744
JB
15321 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15322 return;
15323
15324 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15325 return;
15326
15327 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15328 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15329
5287ad62
JB
15330 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15331 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15332 inst.instruction |= LOW4 (inst.operands[1].reg);
15333 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15334 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15335 inst.instruction |= (et.type == NT_float) << 10;
15336 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15337
88714cb8 15338 neon_dp_fixup (&inst);
5287ad62
JB
15339}
15340
15341static void
15342do_neon_sli (void)
15343{
037e8744 15344 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15345 struct neon_type_el et = neon_check_type (2, rs,
15346 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15347 int imm = inst.operands[2].imm;
15348 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15349 _("immediate out of range for insert"));
037e8744 15350 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15351}
15352
15353static void
15354do_neon_sri (void)
15355{
037e8744 15356 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15357 struct neon_type_el et = neon_check_type (2, rs,
15358 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15359 int imm = inst.operands[2].imm;
15360 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15361 _("immediate out of range for insert"));
037e8744 15362 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15363}
15364
15365static void
15366do_neon_qshlu_imm (void)
15367{
037e8744 15368 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15369 struct neon_type_el et = neon_check_type (2, rs,
15370 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15371 int imm = inst.operands[2].imm;
15372 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15373 _("immediate out of range for shift"));
5287ad62
JB
15374 /* Only encodes the 'U present' variant of the instruction.
15375 In this case, signed types have OP (bit 8) set to 0.
15376 Unsigned types have OP set to 1. */
15377 inst.instruction |= (et.type == NT_unsigned) << 8;
15378 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15379 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15380}
15381
15382static void
15383do_neon_qmovn (void)
15384{
15385 struct neon_type_el et = neon_check_type (2, NS_DQ,
15386 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15387 /* Saturating move where operands can be signed or unsigned, and the
15388 destination has the same signedness. */
88714cb8 15389 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15390 if (et.type == NT_unsigned)
15391 inst.instruction |= 0xc0;
15392 else
15393 inst.instruction |= 0x80;
15394 neon_two_same (0, 1, et.size / 2);
15395}
15396
15397static void
15398do_neon_qmovun (void)
15399{
15400 struct neon_type_el et = neon_check_type (2, NS_DQ,
15401 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15402 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15403 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15404 neon_two_same (0, 1, et.size / 2);
15405}
15406
15407static void
15408do_neon_rshift_sat_narrow (void)
15409{
15410 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15411 or unsigned. If operands are unsigned, results must also be unsigned. */
15412 struct neon_type_el et = neon_check_type (2, NS_DQI,
15413 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15414 int imm = inst.operands[2].imm;
15415 /* This gets the bounds check, size encoding and immediate bits calculation
15416 right. */
15417 et.size /= 2;
5f4273c7 15418
5287ad62
JB
15419 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15420 VQMOVN.I<size> <Dd>, <Qm>. */
15421 if (imm == 0)
15422 {
15423 inst.operands[2].present = 0;
15424 inst.instruction = N_MNEM_vqmovn;
15425 do_neon_qmovn ();
15426 return;
15427 }
5f4273c7 15428
5287ad62 15429 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15430 _("immediate out of range"));
5287ad62
JB
15431 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15432}
15433
15434static void
15435do_neon_rshift_sat_narrow_u (void)
15436{
15437 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15438 or unsigned. If operands are unsigned, results must also be unsigned. */
15439 struct neon_type_el et = neon_check_type (2, NS_DQI,
15440 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15441 int imm = inst.operands[2].imm;
15442 /* This gets the bounds check, size encoding and immediate bits calculation
15443 right. */
15444 et.size /= 2;
15445
15446 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15447 VQMOVUN.I<size> <Dd>, <Qm>. */
15448 if (imm == 0)
15449 {
15450 inst.operands[2].present = 0;
15451 inst.instruction = N_MNEM_vqmovun;
15452 do_neon_qmovun ();
15453 return;
15454 }
15455
15456 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15457 _("immediate out of range"));
5287ad62
JB
15458 /* FIXME: The manual is kind of unclear about what value U should have in
15459 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15460 must be 1. */
15461 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15462}
15463
15464static void
15465do_neon_movn (void)
15466{
15467 struct neon_type_el et = neon_check_type (2, NS_DQ,
15468 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15469 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15470 neon_two_same (0, 1, et.size / 2);
15471}
15472
15473static void
15474do_neon_rshift_narrow (void)
15475{
15476 struct neon_type_el et = neon_check_type (2, NS_DQI,
15477 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15478 int imm = inst.operands[2].imm;
15479 /* This gets the bounds check, size encoding and immediate bits calculation
15480 right. */
15481 et.size /= 2;
5f4273c7 15482
5287ad62
JB
15483 /* If immediate is zero then we are a pseudo-instruction for
15484 VMOVN.I<size> <Dd>, <Qm> */
15485 if (imm == 0)
15486 {
15487 inst.operands[2].present = 0;
15488 inst.instruction = N_MNEM_vmovn;
15489 do_neon_movn ();
15490 return;
15491 }
5f4273c7 15492
5287ad62 15493 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15494 _("immediate out of range for narrowing operation"));
5287ad62
JB
15495 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15496}
15497
15498static void
15499do_neon_shll (void)
15500{
15501 /* FIXME: Type checking when lengthening. */
15502 struct neon_type_el et = neon_check_type (2, NS_QDI,
15503 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15504 unsigned imm = inst.operands[2].imm;
15505
15506 if (imm == et.size)
15507 {
15508 /* Maximum shift variant. */
88714cb8 15509 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15510 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15511 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15512 inst.instruction |= LOW4 (inst.operands[1].reg);
15513 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15514 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15515
88714cb8 15516 neon_dp_fixup (&inst);
5287ad62
JB
15517 }
15518 else
15519 {
15520 /* A more-specific type check for non-max versions. */
15521 et = neon_check_type (2, NS_QDI,
477330fc 15522 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15523 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15524 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15525 }
15526}
15527
037e8744 15528/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15529 the current instruction is. */
15530
6b9a8b67
MGD
15531#define CVT_FLAVOUR_VAR \
15532 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15533 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15534 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15535 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15536 /* Half-precision conversions. */ \
cc933301
JW
15537 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15538 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15539 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15540 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15541 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15542 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15543 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15544 Compared with single/double precision variants, only the co-processor \
15545 field is different, so the encoding flow is reused here. */ \
15546 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15547 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15548 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15549 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15550 /* VFP instructions. */ \
15551 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15552 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15553 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15554 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15555 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15556 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15557 /* VFP instructions with bitshift. */ \
15558 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15559 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15560 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15561 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15562 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15563 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15564 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15565 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15566
15567#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15568 neon_cvt_flavour_##C,
15569
15570/* The different types of conversions we can do. */
15571enum neon_cvt_flavour
15572{
15573 CVT_FLAVOUR_VAR
15574 neon_cvt_flavour_invalid,
15575 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15576};
15577
15578#undef CVT_VAR
15579
15580static enum neon_cvt_flavour
15581get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15582{
6b9a8b67
MGD
15583#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15584 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15585 if (et.type != NT_invtype) \
15586 { \
15587 inst.error = NULL; \
15588 return (neon_cvt_flavour_##C); \
5287ad62 15589 }
6b9a8b67 15590
5287ad62 15591 struct neon_type_el et;
037e8744 15592 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15593 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15594 /* The instruction versions which take an immediate take one register
15595 argument, which is extended to the width of the full register. Thus the
15596 "source" and "destination" registers must have the same width. Hack that
15597 here by making the size equal to the key (wider, in this case) operand. */
15598 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15599
6b9a8b67
MGD
15600 CVT_FLAVOUR_VAR;
15601
15602 return neon_cvt_flavour_invalid;
5287ad62
JB
15603#undef CVT_VAR
15604}
15605
7e8e6784
MGD
15606enum neon_cvt_mode
15607{
15608 neon_cvt_mode_a,
15609 neon_cvt_mode_n,
15610 neon_cvt_mode_p,
15611 neon_cvt_mode_m,
15612 neon_cvt_mode_z,
30bdf752
MGD
15613 neon_cvt_mode_x,
15614 neon_cvt_mode_r
7e8e6784
MGD
15615};
15616
037e8744
JB
15617/* Neon-syntax VFP conversions. */
15618
5287ad62 15619static void
6b9a8b67 15620do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15621{
037e8744 15622 const char *opname = 0;
5f4273c7 15623
d54af2d0
RL
15624 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15625 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15626 {
037e8744
JB
15627 /* Conversions with immediate bitshift. */
15628 const char *enc[] =
477330fc 15629 {
6b9a8b67
MGD
15630#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15631 CVT_FLAVOUR_VAR
15632 NULL
15633#undef CVT_VAR
477330fc 15634 };
037e8744 15635
6b9a8b67 15636 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15637 {
15638 opname = enc[flavour];
15639 constraint (inst.operands[0].reg != inst.operands[1].reg,
15640 _("operands 0 and 1 must be the same register"));
15641 inst.operands[1] = inst.operands[2];
15642 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15643 }
5287ad62
JB
15644 }
15645 else
15646 {
037e8744
JB
15647 /* Conversions without bitshift. */
15648 const char *enc[] =
477330fc 15649 {
6b9a8b67
MGD
15650#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15651 CVT_FLAVOUR_VAR
15652 NULL
15653#undef CVT_VAR
477330fc 15654 };
037e8744 15655
6b9a8b67 15656 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15657 opname = enc[flavour];
037e8744
JB
15658 }
15659
15660 if (opname)
15661 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15662
15663 /* ARMv8.2 fp16 VCVT instruction. */
15664 if (flavour == neon_cvt_flavour_s32_f16
15665 || flavour == neon_cvt_flavour_u32_f16
15666 || flavour == neon_cvt_flavour_f16_u32
15667 || flavour == neon_cvt_flavour_f16_s32)
15668 do_scalar_fp16_v82_encode ();
037e8744
JB
15669}
15670
15671static void
15672do_vfp_nsyn_cvtz (void)
15673{
d54af2d0 15674 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15675 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15676 const char *enc[] =
15677 {
6b9a8b67
MGD
15678#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15679 CVT_FLAVOUR_VAR
15680 NULL
15681#undef CVT_VAR
037e8744
JB
15682 };
15683
6b9a8b67 15684 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15685 do_vfp_nsyn_opcode (enc[flavour]);
15686}
f31fef98 15687
037e8744 15688static void
bacebabc 15689do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15690 enum neon_cvt_mode mode)
15691{
15692 int sz, op;
15693 int rm;
15694
a715796b
TG
15695 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15696 D register operands. */
15697 if (flavour == neon_cvt_flavour_s32_f64
15698 || flavour == neon_cvt_flavour_u32_f64)
15699 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15700 _(BAD_FPU));
15701
9db2f6b4
RL
15702 if (flavour == neon_cvt_flavour_s32_f16
15703 || flavour == neon_cvt_flavour_u32_f16)
15704 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15705 _(BAD_FP16));
15706
7e8e6784
MGD
15707 set_it_insn_type (OUTSIDE_IT_INSN);
15708
15709 switch (flavour)
15710 {
15711 case neon_cvt_flavour_s32_f64:
15712 sz = 1;
827f64ff 15713 op = 1;
7e8e6784
MGD
15714 break;
15715 case neon_cvt_flavour_s32_f32:
15716 sz = 0;
15717 op = 1;
15718 break;
9db2f6b4
RL
15719 case neon_cvt_flavour_s32_f16:
15720 sz = 0;
15721 op = 1;
15722 break;
7e8e6784
MGD
15723 case neon_cvt_flavour_u32_f64:
15724 sz = 1;
15725 op = 0;
15726 break;
15727 case neon_cvt_flavour_u32_f32:
15728 sz = 0;
15729 op = 0;
15730 break;
9db2f6b4
RL
15731 case neon_cvt_flavour_u32_f16:
15732 sz = 0;
15733 op = 0;
15734 break;
7e8e6784
MGD
15735 default:
15736 first_error (_("invalid instruction shape"));
15737 return;
15738 }
15739
15740 switch (mode)
15741 {
15742 case neon_cvt_mode_a: rm = 0; break;
15743 case neon_cvt_mode_n: rm = 1; break;
15744 case neon_cvt_mode_p: rm = 2; break;
15745 case neon_cvt_mode_m: rm = 3; break;
15746 default: first_error (_("invalid rounding mode")); return;
15747 }
15748
15749 NEON_ENCODE (FPV8, inst);
15750 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15751 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15752 inst.instruction |= sz << 8;
9db2f6b4
RL
15753
15754 /* ARMv8.2 fp16 VCVT instruction. */
15755 if (flavour == neon_cvt_flavour_s32_f16
15756 ||flavour == neon_cvt_flavour_u32_f16)
15757 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15758 inst.instruction |= op << 7;
15759 inst.instruction |= rm << 16;
15760 inst.instruction |= 0xf0000000;
15761 inst.is_neon = TRUE;
15762}
15763
15764static void
15765do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15766{
15767 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15768 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15769 NS_FH, NS_HF, NS_FHI, NS_HFI,
15770 NS_NULL);
6b9a8b67 15771 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15772
cc933301
JW
15773 if (flavour == neon_cvt_flavour_invalid)
15774 return;
15775
e3e535bc 15776 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15777 if (mode == neon_cvt_mode_z
e3e535bc 15778 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15779 && (flavour == neon_cvt_flavour_s16_f16
15780 || flavour == neon_cvt_flavour_u16_f16
15781 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15782 || flavour == neon_cvt_flavour_u32_f32
15783 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15784 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15785 && (rs == NS_FD || rs == NS_FF))
15786 {
15787 do_vfp_nsyn_cvtz ();
15788 return;
15789 }
15790
9db2f6b4
RL
15791 /* ARMv8.2 fp16 VCVT conversions. */
15792 if (mode == neon_cvt_mode_z
15793 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15794 && (flavour == neon_cvt_flavour_s32_f16
15795 || flavour == neon_cvt_flavour_u32_f16)
15796 && (rs == NS_FH))
15797 {
15798 do_vfp_nsyn_cvtz ();
15799 do_scalar_fp16_v82_encode ();
15800 return;
15801 }
15802
037e8744 15803 /* VFP rather than Neon conversions. */
6b9a8b67 15804 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15805 {
7e8e6784
MGD
15806 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15807 do_vfp_nsyn_cvt (rs, flavour);
15808 else
15809 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15810
037e8744
JB
15811 return;
15812 }
15813
15814 switch (rs)
15815 {
15816 case NS_DDI:
15817 case NS_QQI:
15818 {
477330fc 15819 unsigned immbits;
cc933301
JW
15820 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15821 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15822
477330fc
RM
15823 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15824 return;
037e8744 15825
477330fc
RM
15826 /* Fixed-point conversion with #0 immediate is encoded as an
15827 integer conversion. */
15828 if (inst.operands[2].present && inst.operands[2].imm == 0)
15829 goto int_encode;
477330fc
RM
15830 NEON_ENCODE (IMMED, inst);
15831 if (flavour != neon_cvt_flavour_invalid)
15832 inst.instruction |= enctab[flavour];
15833 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15834 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15835 inst.instruction |= LOW4 (inst.operands[1].reg);
15836 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15837 inst.instruction |= neon_quad (rs) << 6;
15838 inst.instruction |= 1 << 21;
cc933301
JW
15839 if (flavour < neon_cvt_flavour_s16_f16)
15840 {
15841 inst.instruction |= 1 << 21;
15842 immbits = 32 - inst.operands[2].imm;
15843 inst.instruction |= immbits << 16;
15844 }
15845 else
15846 {
15847 inst.instruction |= 3 << 20;
15848 immbits = 16 - inst.operands[2].imm;
15849 inst.instruction |= immbits << 16;
15850 inst.instruction &= ~(1 << 9);
15851 }
477330fc
RM
15852
15853 neon_dp_fixup (&inst);
037e8744
JB
15854 }
15855 break;
15856
15857 case NS_DD:
15858 case NS_QQ:
7e8e6784
MGD
15859 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15860 {
15861 NEON_ENCODE (FLOAT, inst);
15862 set_it_insn_type (OUTSIDE_IT_INSN);
15863
15864 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15865 return;
15866
15867 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15868 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15869 inst.instruction |= LOW4 (inst.operands[1].reg);
15870 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15871 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15872 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15873 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15874 inst.instruction |= mode << 8;
cc933301
JW
15875 if (flavour == neon_cvt_flavour_u16_f16
15876 || flavour == neon_cvt_flavour_s16_f16)
15877 /* Mask off the original size bits and reencode them. */
15878 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15879
7e8e6784
MGD
15880 if (thumb_mode)
15881 inst.instruction |= 0xfc000000;
15882 else
15883 inst.instruction |= 0xf0000000;
15884 }
15885 else
15886 {
037e8744 15887 int_encode:
7e8e6784 15888 {
cc933301
JW
15889 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15890 0x100, 0x180, 0x0, 0x080};
037e8744 15891
7e8e6784 15892 NEON_ENCODE (INTEGER, inst);
037e8744 15893
7e8e6784
MGD
15894 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15895 return;
037e8744 15896
7e8e6784
MGD
15897 if (flavour != neon_cvt_flavour_invalid)
15898 inst.instruction |= enctab[flavour];
037e8744 15899
7e8e6784
MGD
15900 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15901 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15902 inst.instruction |= LOW4 (inst.operands[1].reg);
15903 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15904 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15905 if (flavour >= neon_cvt_flavour_s16_f16
15906 && flavour <= neon_cvt_flavour_f16_u16)
15907 /* Half precision. */
15908 inst.instruction |= 1 << 18;
15909 else
15910 inst.instruction |= 2 << 18;
037e8744 15911
7e8e6784
MGD
15912 neon_dp_fixup (&inst);
15913 }
15914 }
15915 break;
037e8744 15916
8e79c3df
CM
15917 /* Half-precision conversions for Advanced SIMD -- neon. */
15918 case NS_QD:
15919 case NS_DQ:
bc52d49c
MM
15920 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15921 return;
8e79c3df
CM
15922
15923 if ((rs == NS_DQ)
15924 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15925 {
15926 as_bad (_("operand size must match register width"));
15927 break;
15928 }
15929
15930 if ((rs == NS_QD)
15931 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15932 {
15933 as_bad (_("operand size must match register width"));
15934 break;
15935 }
15936
15937 if (rs == NS_DQ)
477330fc 15938 inst.instruction = 0x3b60600;
8e79c3df
CM
15939 else
15940 inst.instruction = 0x3b60700;
15941
15942 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15943 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15944 inst.instruction |= LOW4 (inst.operands[1].reg);
15945 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15946 neon_dp_fixup (&inst);
8e79c3df
CM
15947 break;
15948
037e8744
JB
15949 default:
15950 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15951 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15952 do_vfp_nsyn_cvt (rs, flavour);
15953 else
15954 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15955 }
5287ad62
JB
15956}
15957
e3e535bc
NC
15958static void
15959do_neon_cvtr (void)
15960{
7e8e6784 15961 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15962}
15963
15964static void
15965do_neon_cvt (void)
15966{
7e8e6784
MGD
15967 do_neon_cvt_1 (neon_cvt_mode_z);
15968}
15969
15970static void
15971do_neon_cvta (void)
15972{
15973 do_neon_cvt_1 (neon_cvt_mode_a);
15974}
15975
15976static void
15977do_neon_cvtn (void)
15978{
15979 do_neon_cvt_1 (neon_cvt_mode_n);
15980}
15981
15982static void
15983do_neon_cvtp (void)
15984{
15985 do_neon_cvt_1 (neon_cvt_mode_p);
15986}
15987
15988static void
15989do_neon_cvtm (void)
15990{
15991 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15992}
15993
8e79c3df 15994static void
c70a8987 15995do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15996{
c70a8987
MGD
15997 if (is_double)
15998 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15999
c70a8987
MGD
16000 encode_arm_vfp_reg (inst.operands[0].reg,
16001 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
16002 encode_arm_vfp_reg (inst.operands[1].reg,
16003 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
16004 inst.instruction |= to ? 0x10000 : 0;
16005 inst.instruction |= t ? 0x80 : 0;
16006 inst.instruction |= is_double ? 0x100 : 0;
16007 do_vfp_cond_or_thumb ();
16008}
8e79c3df 16009
c70a8987
MGD
16010static void
16011do_neon_cvttb_1 (bfd_boolean t)
16012{
d54af2d0
RL
16013 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
16014 NS_DF, NS_DH, NS_NULL);
8e79c3df 16015
c70a8987
MGD
16016 if (rs == NS_NULL)
16017 return;
16018 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
16019 {
16020 inst.error = NULL;
16021 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
16022 }
16023 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
16024 {
16025 inst.error = NULL;
16026 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
16027 }
16028 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
16029 {
a715796b
TG
16030 /* The VCVTB and VCVTT instructions with D-register operands
16031 don't work for SP only targets. */
16032 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16033 _(BAD_FPU));
16034
c70a8987
MGD
16035 inst.error = NULL;
16036 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
16037 }
16038 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
16039 {
a715796b
TG
16040 /* The VCVTB and VCVTT instructions with D-register operands
16041 don't work for SP only targets. */
16042 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16043 _(BAD_FPU));
16044
c70a8987
MGD
16045 inst.error = NULL;
16046 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
16047 }
16048 else
16049 return;
16050}
16051
16052static void
16053do_neon_cvtb (void)
16054{
16055 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
16056}
16057
16058
16059static void
16060do_neon_cvtt (void)
16061{
c70a8987 16062 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
16063}
16064
5287ad62
JB
16065static void
16066neon_move_immediate (void)
16067{
037e8744
JB
16068 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
16069 struct neon_type_el et = neon_check_type (2, rs,
16070 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 16071 unsigned immlo, immhi = 0, immbits;
c96612cc 16072 int op, cmode, float_p;
5287ad62 16073
037e8744 16074 constraint (et.type == NT_invtype,
477330fc 16075 _("operand size must be specified for immediate VMOV"));
037e8744 16076
5287ad62
JB
16077 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
16078 op = (inst.instruction & (1 << 5)) != 0;
16079
16080 immlo = inst.operands[1].imm;
16081 if (inst.operands[1].regisimm)
16082 immhi = inst.operands[1].reg;
16083
16084 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 16085 _("immediate has bits set outside the operand size"));
5287ad62 16086
c96612cc
JB
16087 float_p = inst.operands[1].immisfloat;
16088
16089 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 16090 et.size, et.type)) == FAIL)
5287ad62
JB
16091 {
16092 /* Invert relevant bits only. */
16093 neon_invert_size (&immlo, &immhi, et.size);
16094 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
16095 with one or the other; those cases are caught by
16096 neon_cmode_for_move_imm. */
5287ad62 16097 op = !op;
c96612cc
JB
16098 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16099 &op, et.size, et.type)) == FAIL)
477330fc
RM
16100 {
16101 first_error (_("immediate out of range"));
16102 return;
16103 }
5287ad62
JB
16104 }
16105
16106 inst.instruction &= ~(1 << 5);
16107 inst.instruction |= op << 5;
16108
16109 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16110 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 16111 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16112 inst.instruction |= cmode << 8;
16113
16114 neon_write_immbits (immbits);
16115}
16116
16117static void
16118do_neon_mvn (void)
16119{
16120 if (inst.operands[1].isreg)
16121 {
037e8744 16122 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16123
88714cb8 16124 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16125 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16126 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16127 inst.instruction |= LOW4 (inst.operands[1].reg);
16128 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16129 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16130 }
16131 else
16132 {
88714cb8 16133 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16134 neon_move_immediate ();
16135 }
16136
88714cb8 16137 neon_dp_fixup (&inst);
5287ad62
JB
16138}
16139
16140/* Encode instructions of form:
16141
16142 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16143 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16144
16145static void
16146neon_mixed_length (struct neon_type_el et, unsigned size)
16147{
16148 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16149 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16150 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16151 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16152 inst.instruction |= LOW4 (inst.operands[2].reg);
16153 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16154 inst.instruction |= (et.type == NT_unsigned) << 24;
16155 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16156
88714cb8 16157 neon_dp_fixup (&inst);
5287ad62
JB
16158}
16159
16160static void
16161do_neon_dyadic_long (void)
16162{
16163 /* FIXME: Type checking for lengthening op. */
16164 struct neon_type_el et = neon_check_type (3, NS_QDD,
16165 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16166 neon_mixed_length (et, et.size);
16167}
16168
16169static void
16170do_neon_abal (void)
16171{
16172 struct neon_type_el et = neon_check_type (3, NS_QDD,
16173 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16174 neon_mixed_length (et, et.size);
16175}
16176
16177static void
16178neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16179{
16180 if (inst.operands[2].isscalar)
16181 {
dcbf9037 16182 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16183 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16184 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16185 neon_mul_mac (et, et.type == NT_unsigned);
16186 }
16187 else
16188 {
16189 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16190 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16191 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16192 neon_mixed_length (et, et.size);
16193 }
16194}
16195
16196static void
16197do_neon_mac_maybe_scalar_long (void)
16198{
16199 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16200}
16201
dec41383
JW
16202/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
16203 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
16204
16205static unsigned
16206neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
16207{
16208 unsigned regno = NEON_SCALAR_REG (scalar);
16209 unsigned elno = NEON_SCALAR_INDEX (scalar);
16210
16211 if (quad_p)
16212 {
16213 if (regno > 7 || elno > 3)
16214 goto bad_scalar;
16215
16216 return ((regno & 0x7)
16217 | ((elno & 0x1) << 3)
16218 | (((elno >> 1) & 0x1) << 5));
16219 }
16220 else
16221 {
16222 if (regno > 15 || elno > 1)
16223 goto bad_scalar;
16224
16225 return (((regno & 0x1) << 5)
16226 | ((regno >> 1) & 0x7)
16227 | ((elno & 0x1) << 3));
16228 }
16229
16230bad_scalar:
16231 first_error (_("scalar out of range for multiply instruction"));
16232 return 0;
16233}
16234
16235static void
16236do_neon_fmac_maybe_scalar_long (int subtype)
16237{
16238 enum neon_shape rs;
16239 int high8;
16240 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
16241 field (bits[21:20]) has different meaning. For scalar index variant, it's
16242 used to differentiate add and subtract, otherwise it's with fixed value
16243 0x2. */
16244 int size = -1;
16245
16246 if (inst.cond != COND_ALWAYS)
16247 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
16248 "behaviour is UNPREDICTABLE"));
16249
01f48020 16250 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
dec41383
JW
16251 _(BAD_FP16));
16252
16253 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
16254 _(BAD_FPU));
16255
16256 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
16257 be a scalar index register. */
16258 if (inst.operands[2].isscalar)
16259 {
16260 high8 = 0xfe000000;
16261 if (subtype)
16262 size = 16;
16263 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
16264 }
16265 else
16266 {
16267 high8 = 0xfc000000;
16268 size = 32;
16269 if (subtype)
16270 inst.instruction |= (0x1 << 23);
16271 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
16272 }
16273
16274 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
16275
16276 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
16277 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
16278 so we simply pass -1 as size. */
16279 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
16280 neon_three_same (quad_p, 0, size);
16281
16282 /* Undo neon_dp_fixup. Redo the high eight bits. */
16283 inst.instruction &= 0x00ffffff;
16284 inst.instruction |= high8;
16285
16286#define LOW1(R) ((R) & 0x1)
16287#define HI4(R) (((R) >> 1) & 0xf)
16288 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
16289 whether the instruction is in Q form and whether Vm is a scalar indexed
16290 operand. */
16291 if (inst.operands[2].isscalar)
16292 {
16293 unsigned rm
16294 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
16295 inst.instruction &= 0xffffffd0;
16296 inst.instruction |= rm;
16297
16298 if (!quad_p)
16299 {
16300 /* Redo Rn as well. */
16301 inst.instruction &= 0xfff0ff7f;
16302 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16303 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16304 }
16305 }
16306 else if (!quad_p)
16307 {
16308 /* Redo Rn and Rm. */
16309 inst.instruction &= 0xfff0ff50;
16310 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16311 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16312 inst.instruction |= HI4 (inst.operands[2].reg);
16313 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
16314 }
16315}
16316
16317static void
16318do_neon_vfmal (void)
16319{
16320 return do_neon_fmac_maybe_scalar_long (0);
16321}
16322
16323static void
16324do_neon_vfmsl (void)
16325{
16326 return do_neon_fmac_maybe_scalar_long (1);
16327}
16328
5287ad62
JB
16329static void
16330do_neon_dyadic_wide (void)
16331{
16332 struct neon_type_el et = neon_check_type (3, NS_QQD,
16333 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16334 neon_mixed_length (et, et.size);
16335}
16336
16337static void
16338do_neon_dyadic_narrow (void)
16339{
16340 struct neon_type_el et = neon_check_type (3, NS_QDD,
16341 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16342 /* Operand sign is unimportant, and the U bit is part of the opcode,
16343 so force the operand type to integer. */
16344 et.type = NT_integer;
5287ad62
JB
16345 neon_mixed_length (et, et.size / 2);
16346}
16347
16348static void
16349do_neon_mul_sat_scalar_long (void)
16350{
16351 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16352}
16353
16354static void
16355do_neon_vmull (void)
16356{
16357 if (inst.operands[2].isscalar)
16358 do_neon_mac_maybe_scalar_long ();
16359 else
16360 {
16361 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16362 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16363
5287ad62 16364 if (et.type == NT_poly)
477330fc 16365 NEON_ENCODE (POLY, inst);
5287ad62 16366 else
477330fc 16367 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16368
16369 /* For polynomial encoding the U bit must be zero, and the size must
16370 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16371 obviously, as 0b10). */
16372 if (et.size == 64)
16373 {
16374 /* Check we're on the correct architecture. */
16375 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16376 inst.error =
16377 _("Instruction form not available on this architecture.");
16378
16379 et.size = 32;
16380 }
16381
5287ad62
JB
16382 neon_mixed_length (et, et.size);
16383 }
16384}
16385
16386static void
16387do_neon_ext (void)
16388{
037e8744 16389 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16390 struct neon_type_el et = neon_check_type (3, rs,
16391 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16392 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16393
16394 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16395 _("shift out of range"));
5287ad62
JB
16396 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16397 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16398 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16399 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16400 inst.instruction |= LOW4 (inst.operands[2].reg);
16401 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16402 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16403 inst.instruction |= imm << 8;
5f4273c7 16404
88714cb8 16405 neon_dp_fixup (&inst);
5287ad62
JB
16406}
16407
16408static void
16409do_neon_rev (void)
16410{
037e8744 16411 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16412 struct neon_type_el et = neon_check_type (2, rs,
16413 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16414 unsigned op = (inst.instruction >> 7) & 3;
16415 /* N (width of reversed regions) is encoded as part of the bitmask. We
16416 extract it here to check the elements to be reversed are smaller.
16417 Otherwise we'd get a reserved instruction. */
16418 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16419 gas_assert (elsize != 0);
5287ad62 16420 constraint (et.size >= elsize,
477330fc 16421 _("elements must be smaller than reversal region"));
037e8744 16422 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16423}
16424
16425static void
16426do_neon_dup (void)
16427{
16428 if (inst.operands[1].isscalar)
16429 {
037e8744 16430 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16431 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16432 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16433 unsigned sizebits = et.size >> 3;
dcbf9037 16434 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16435 int logsize = neon_logbits (et.size);
dcbf9037 16436 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16437
16438 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16439 return;
037e8744 16440
88714cb8 16441 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16442 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16443 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16444 inst.instruction |= LOW4 (dm);
16445 inst.instruction |= HI1 (dm) << 5;
037e8744 16446 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16447 inst.instruction |= x << 17;
16448 inst.instruction |= sizebits << 16;
5f4273c7 16449
88714cb8 16450 neon_dp_fixup (&inst);
5287ad62
JB
16451 }
16452 else
16453 {
037e8744
JB
16454 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16455 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16456 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16457 /* Duplicate ARM register to lanes of vector. */
88714cb8 16458 NEON_ENCODE (ARMREG, inst);
5287ad62 16459 switch (et.size)
477330fc
RM
16460 {
16461 case 8: inst.instruction |= 0x400000; break;
16462 case 16: inst.instruction |= 0x000020; break;
16463 case 32: inst.instruction |= 0x000000; break;
16464 default: break;
16465 }
5287ad62
JB
16466 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16467 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16468 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16469 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16470 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16471 variants, except for the condition field. */
037e8744 16472 do_vfp_cond_or_thumb ();
5287ad62
JB
16473 }
16474}
16475
16476/* VMOV has particularly many variations. It can be one of:
16477 0. VMOV<c><q> <Qd>, <Qm>
16478 1. VMOV<c><q> <Dd>, <Dm>
16479 (Register operations, which are VORR with Rm = Rn.)
16480 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16481 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16482 (Immediate loads.)
16483 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16484 (ARM register to scalar.)
16485 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16486 (Two ARM registers to vector.)
16487 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16488 (Scalar to ARM register.)
16489 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16490 (Vector to two ARM registers.)
037e8744
JB
16491 8. VMOV.F32 <Sd>, <Sm>
16492 9. VMOV.F64 <Dd>, <Dm>
16493 (VFP register moves.)
16494 10. VMOV.F32 <Sd>, #imm
16495 11. VMOV.F64 <Dd>, #imm
16496 (VFP float immediate load.)
16497 12. VMOV <Rd>, <Sm>
16498 (VFP single to ARM reg.)
16499 13. VMOV <Sd>, <Rm>
16500 (ARM reg to VFP single.)
16501 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16502 (Two ARM regs to two VFP singles.)
16503 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16504 (Two VFP singles to two ARM regs.)
5f4273c7 16505
037e8744
JB
16506 These cases can be disambiguated using neon_select_shape, except cases 1/9
16507 and 3/11 which depend on the operand type too.
5f4273c7 16508
5287ad62 16509 All the encoded bits are hardcoded by this function.
5f4273c7 16510
b7fc2769
JB
16511 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16512 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16513
5287ad62 16514 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16515 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16516
16517static void
16518do_neon_mov (void)
16519{
037e8744 16520 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16521 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16522 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16523 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16524 struct neon_type_el et;
16525 const char *ldconst = 0;
5287ad62 16526
037e8744 16527 switch (rs)
5287ad62 16528 {
037e8744
JB
16529 case NS_DD: /* case 1/9. */
16530 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16531 /* It is not an error here if no type is given. */
16532 inst.error = NULL;
16533 if (et.type == NT_float && et.size == 64)
477330fc
RM
16534 {
16535 do_vfp_nsyn_opcode ("fcpyd");
16536 break;
16537 }
037e8744 16538 /* fall through. */
5287ad62 16539
037e8744
JB
16540 case NS_QQ: /* case 0/1. */
16541 {
477330fc
RM
16542 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16543 return;
16544 /* The architecture manual I have doesn't explicitly state which
16545 value the U bit should have for register->register moves, but
16546 the equivalent VORR instruction has U = 0, so do that. */
16547 inst.instruction = 0x0200110;
16548 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16549 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16550 inst.instruction |= LOW4 (inst.operands[1].reg);
16551 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16552 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16553 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16554 inst.instruction |= neon_quad (rs) << 6;
16555
16556 neon_dp_fixup (&inst);
037e8744
JB
16557 }
16558 break;
5f4273c7 16559
037e8744
JB
16560 case NS_DI: /* case 3/11. */
16561 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16562 inst.error = NULL;
16563 if (et.type == NT_float && et.size == 64)
477330fc
RM
16564 {
16565 /* case 11 (fconstd). */
16566 ldconst = "fconstd";
16567 goto encode_fconstd;
16568 }
037e8744
JB
16569 /* fall through. */
16570
16571 case NS_QI: /* case 2/3. */
16572 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16573 return;
037e8744
JB
16574 inst.instruction = 0x0800010;
16575 neon_move_immediate ();
88714cb8 16576 neon_dp_fixup (&inst);
5287ad62 16577 break;
5f4273c7 16578
037e8744
JB
16579 case NS_SR: /* case 4. */
16580 {
477330fc
RM
16581 unsigned bcdebits = 0;
16582 int logsize;
16583 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16584 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16585
05ac0ffb
JB
16586 /* .<size> is optional here, defaulting to .32. */
16587 if (inst.vectype.elems == 0
16588 && inst.operands[0].vectype.type == NT_invtype
16589 && inst.operands[1].vectype.type == NT_invtype)
16590 {
16591 inst.vectype.el[0].type = NT_untyped;
16592 inst.vectype.el[0].size = 32;
16593 inst.vectype.elems = 1;
16594 }
16595
477330fc
RM
16596 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16597 logsize = neon_logbits (et.size);
16598
16599 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16600 _(BAD_FPU));
16601 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16602 && et.size != 32, _(BAD_FPU));
16603 constraint (et.type == NT_invtype, _("bad type for scalar"));
16604 constraint (x >= 64 / et.size, _("scalar index out of range"));
16605
16606 switch (et.size)
16607 {
16608 case 8: bcdebits = 0x8; break;
16609 case 16: bcdebits = 0x1; break;
16610 case 32: bcdebits = 0x0; break;
16611 default: ;
16612 }
16613
16614 bcdebits |= x << logsize;
16615
16616 inst.instruction = 0xe000b10;
16617 do_vfp_cond_or_thumb ();
16618 inst.instruction |= LOW4 (dn) << 16;
16619 inst.instruction |= HI1 (dn) << 7;
16620 inst.instruction |= inst.operands[1].reg << 12;
16621 inst.instruction |= (bcdebits & 3) << 5;
16622 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16623 }
16624 break;
5f4273c7 16625
037e8744 16626 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16627 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16628 _(BAD_FPU));
b7fc2769 16629
037e8744
JB
16630 inst.instruction = 0xc400b10;
16631 do_vfp_cond_or_thumb ();
16632 inst.instruction |= LOW4 (inst.operands[0].reg);
16633 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16634 inst.instruction |= inst.operands[1].reg << 12;
16635 inst.instruction |= inst.operands[2].reg << 16;
16636 break;
5f4273c7 16637
037e8744
JB
16638 case NS_RS: /* case 6. */
16639 {
477330fc
RM
16640 unsigned logsize;
16641 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16642 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16643 unsigned abcdebits = 0;
037e8744 16644
05ac0ffb
JB
16645 /* .<dt> is optional here, defaulting to .32. */
16646 if (inst.vectype.elems == 0
16647 && inst.operands[0].vectype.type == NT_invtype
16648 && inst.operands[1].vectype.type == NT_invtype)
16649 {
16650 inst.vectype.el[0].type = NT_untyped;
16651 inst.vectype.el[0].size = 32;
16652 inst.vectype.elems = 1;
16653 }
16654
91d6fa6a
NC
16655 et = neon_check_type (2, NS_NULL,
16656 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16657 logsize = neon_logbits (et.size);
16658
16659 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16660 _(BAD_FPU));
16661 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16662 && et.size != 32, _(BAD_FPU));
16663 constraint (et.type == NT_invtype, _("bad type for scalar"));
16664 constraint (x >= 64 / et.size, _("scalar index out of range"));
16665
16666 switch (et.size)
16667 {
16668 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16669 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16670 case 32: abcdebits = 0x00; break;
16671 default: ;
16672 }
16673
16674 abcdebits |= x << logsize;
16675 inst.instruction = 0xe100b10;
16676 do_vfp_cond_or_thumb ();
16677 inst.instruction |= LOW4 (dn) << 16;
16678 inst.instruction |= HI1 (dn) << 7;
16679 inst.instruction |= inst.operands[0].reg << 12;
16680 inst.instruction |= (abcdebits & 3) << 5;
16681 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16682 }
16683 break;
5f4273c7 16684
037e8744
JB
16685 case NS_RRD: /* case 7 (fmrrd). */
16686 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16687 _(BAD_FPU));
037e8744
JB
16688
16689 inst.instruction = 0xc500b10;
16690 do_vfp_cond_or_thumb ();
16691 inst.instruction |= inst.operands[0].reg << 12;
16692 inst.instruction |= inst.operands[1].reg << 16;
16693 inst.instruction |= LOW4 (inst.operands[2].reg);
16694 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16695 break;
5f4273c7 16696
037e8744
JB
16697 case NS_FF: /* case 8 (fcpys). */
16698 do_vfp_nsyn_opcode ("fcpys");
16699 break;
5f4273c7 16700
9db2f6b4 16701 case NS_HI:
037e8744
JB
16702 case NS_FI: /* case 10 (fconsts). */
16703 ldconst = "fconsts";
4ef4710f 16704 encode_fconstd:
58ed5c38
TC
16705 if (!inst.operands[1].immisfloat)
16706 {
4ef4710f 16707 unsigned new_imm;
58ed5c38 16708 /* Immediate has to fit in 8 bits so float is enough. */
4ef4710f
NC
16709 float imm = (float) inst.operands[1].imm;
16710 memcpy (&new_imm, &imm, sizeof (float));
16711 /* But the assembly may have been written to provide an integer
16712 bit pattern that equates to a float, so check that the
16713 conversion has worked. */
16714 if (is_quarter_float (new_imm))
16715 {
16716 if (is_quarter_float (inst.operands[1].imm))
16717 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
16718
16719 inst.operands[1].imm = new_imm;
16720 inst.operands[1].immisfloat = 1;
16721 }
58ed5c38
TC
16722 }
16723
037e8744 16724 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16725 {
16726 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16727 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16728
16729 /* ARMv8.2 fp16 vmov.f16 instruction. */
16730 if (rs == NS_HI)
16731 do_scalar_fp16_v82_encode ();
477330fc 16732 }
5287ad62 16733 else
477330fc 16734 first_error (_("immediate out of range"));
037e8744 16735 break;
5f4273c7 16736
9db2f6b4 16737 case NS_RH:
037e8744
JB
16738 case NS_RF: /* case 12 (fmrs). */
16739 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16740 /* ARMv8.2 fp16 vmov.f16 instruction. */
16741 if (rs == NS_RH)
16742 do_scalar_fp16_v82_encode ();
037e8744 16743 break;
5f4273c7 16744
9db2f6b4 16745 case NS_HR:
037e8744
JB
16746 case NS_FR: /* case 13 (fmsr). */
16747 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16748 /* ARMv8.2 fp16 vmov.f16 instruction. */
16749 if (rs == NS_HR)
16750 do_scalar_fp16_v82_encode ();
037e8744 16751 break;
5f4273c7 16752
037e8744
JB
16753 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16754 (one of which is a list), but we have parsed four. Do some fiddling to
16755 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16756 expect. */
16757 case NS_RRFF: /* case 14 (fmrrs). */
16758 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16759 _("VFP registers must be adjacent"));
037e8744
JB
16760 inst.operands[2].imm = 2;
16761 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16762 do_vfp_nsyn_opcode ("fmrrs");
16763 break;
5f4273c7 16764
037e8744
JB
16765 case NS_FFRR: /* case 15 (fmsrr). */
16766 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16767 _("VFP registers must be adjacent"));
037e8744
JB
16768 inst.operands[1] = inst.operands[2];
16769 inst.operands[2] = inst.operands[3];
16770 inst.operands[0].imm = 2;
16771 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16772 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16773 break;
5f4273c7 16774
4c261dff
NC
16775 case NS_NULL:
16776 /* neon_select_shape has determined that the instruction
16777 shape is wrong and has already set the error message. */
16778 break;
16779
5287ad62
JB
16780 default:
16781 abort ();
16782 }
16783}
16784
16785static void
16786do_neon_rshift_round_imm (void)
16787{
037e8744 16788 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16789 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16790 int imm = inst.operands[2].imm;
16791
16792 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16793 if (imm == 0)
16794 {
16795 inst.operands[2].present = 0;
16796 do_neon_mov ();
16797 return;
16798 }
16799
16800 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16801 _("immediate out of range for shift"));
037e8744 16802 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16803 et.size - imm);
5287ad62
JB
16804}
16805
9db2f6b4
RL
16806static void
16807do_neon_movhf (void)
16808{
16809 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16810 constraint (rs != NS_HH, _("invalid suffix"));
16811
16812 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16813 _(BAD_FPU));
16814
7bdf778b
ASDV
16815 if (inst.cond != COND_ALWAYS)
16816 {
16817 if (thumb_mode)
16818 {
16819 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
16820 " the behaviour is UNPREDICTABLE"));
16821 }
16822 else
16823 {
16824 inst.error = BAD_COND;
16825 return;
16826 }
16827 }
16828
9db2f6b4
RL
16829 do_vfp_sp_monadic ();
16830
16831 inst.is_neon = 1;
16832 inst.instruction |= 0xf0000000;
16833}
16834
5287ad62
JB
16835static void
16836do_neon_movl (void)
16837{
16838 struct neon_type_el et = neon_check_type (2, NS_QD,
16839 N_EQK | N_DBL, N_SU_32 | N_KEY);
16840 unsigned sizebits = et.size >> 3;
16841 inst.instruction |= sizebits << 19;
16842 neon_two_same (0, et.type == NT_unsigned, -1);
16843}
16844
16845static void
16846do_neon_trn (void)
16847{
037e8744 16848 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16849 struct neon_type_el et = neon_check_type (2, rs,
16850 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16851 NEON_ENCODE (INTEGER, inst);
037e8744 16852 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16853}
16854
16855static void
16856do_neon_zip_uzp (void)
16857{
037e8744 16858 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16859 struct neon_type_el et = neon_check_type (2, rs,
16860 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16861 if (rs == NS_DD && et.size == 32)
16862 {
16863 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16864 inst.instruction = N_MNEM_vtrn;
16865 do_neon_trn ();
16866 return;
16867 }
037e8744 16868 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16869}
16870
16871static void
16872do_neon_sat_abs_neg (void)
16873{
037e8744 16874 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16875 struct neon_type_el et = neon_check_type (2, rs,
16876 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16877 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16878}
16879
16880static void
16881do_neon_pair_long (void)
16882{
037e8744 16883 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16884 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16885 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16886 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16887 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16888}
16889
16890static void
16891do_neon_recip_est (void)
16892{
037e8744 16893 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16894 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16895 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16896 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16897 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16898}
16899
16900static void
16901do_neon_cls (void)
16902{
037e8744 16903 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16904 struct neon_type_el et = neon_check_type (2, rs,
16905 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16906 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16907}
16908
16909static void
16910do_neon_clz (void)
16911{
037e8744 16912 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16913 struct neon_type_el et = neon_check_type (2, rs,
16914 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16915 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16916}
16917
16918static void
16919do_neon_cnt (void)
16920{
037e8744 16921 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16922 struct neon_type_el et = neon_check_type (2, rs,
16923 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16924 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16925}
16926
16927static void
16928do_neon_swp (void)
16929{
037e8744
JB
16930 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16931 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16932}
16933
16934static void
16935do_neon_tbl_tbx (void)
16936{
16937 unsigned listlenbits;
dcbf9037 16938 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16939
5287ad62
JB
16940 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16941 {
dcbf9037 16942 first_error (_("bad list length for table lookup"));
5287ad62
JB
16943 return;
16944 }
5f4273c7 16945
5287ad62
JB
16946 listlenbits = inst.operands[1].imm - 1;
16947 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16948 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16949 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16950 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16951 inst.instruction |= LOW4 (inst.operands[2].reg);
16952 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16953 inst.instruction |= listlenbits << 8;
5f4273c7 16954
88714cb8 16955 neon_dp_fixup (&inst);
5287ad62
JB
16956}
16957
16958static void
16959do_neon_ldm_stm (void)
16960{
16961 /* P, U and L bits are part of bitmask. */
16962 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16963 unsigned offsetbits = inst.operands[1].imm * 2;
16964
037e8744
JB
16965 if (inst.operands[1].issingle)
16966 {
16967 do_vfp_nsyn_ldm_stm (is_dbmode);
16968 return;
16969 }
16970
5287ad62 16971 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16972 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16973
16974 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16975 _("register list must contain at least 1 and at most 16 "
16976 "registers"));
5287ad62
JB
16977
16978 inst.instruction |= inst.operands[0].reg << 16;
16979 inst.instruction |= inst.operands[0].writeback << 21;
16980 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16981 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16982
16983 inst.instruction |= offsetbits;
5f4273c7 16984
037e8744 16985 do_vfp_cond_or_thumb ();
5287ad62
JB
16986}
16987
16988static void
16989do_neon_ldr_str (void)
16990{
5287ad62 16991 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16992
6844b2c2
MGD
16993 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16994 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16995 if (!is_ldr
6844b2c2 16996 && inst.operands[1].reg == REG_PC
ba86b375 16997 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16998 {
94dcf8bf 16999 if (thumb_mode)
6844b2c2 17000 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 17001 else if (warn_on_deprecated)
5c3696f8 17002 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
17003 }
17004
037e8744
JB
17005 if (inst.operands[0].issingle)
17006 {
cd2f129f 17007 if (is_ldr)
477330fc 17008 do_vfp_nsyn_opcode ("flds");
cd2f129f 17009 else
477330fc 17010 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
17011
17012 /* ARMv8.2 vldr.16/vstr.16 instruction. */
17013 if (inst.vectype.el[0].size == 16)
17014 do_scalar_fp16_v82_encode ();
5287ad62
JB
17015 }
17016 else
5287ad62 17017 {
cd2f129f 17018 if (is_ldr)
477330fc 17019 do_vfp_nsyn_opcode ("fldd");
5287ad62 17020 else
477330fc 17021 do_vfp_nsyn_opcode ("fstd");
5287ad62 17022 }
5287ad62
JB
17023}
17024
17025/* "interleave" version also handles non-interleaving register VLD1/VST1
17026 instructions. */
17027
17028static void
17029do_neon_ld_st_interleave (void)
17030{
037e8744 17031 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 17032 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
17033 unsigned alignbits = 0;
17034 unsigned idx;
17035 /* The bits in this table go:
17036 0: register stride of one (0) or two (1)
17037 1,2: register list length, minus one (1, 2, 3, 4).
17038 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
17039 We use -1 for invalid entries. */
17040 const int typetable[] =
17041 {
17042 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
17043 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
17044 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
17045 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
17046 };
17047 int typebits;
17048
dcbf9037
JB
17049 if (et.type == NT_invtype)
17050 return;
17051
5287ad62
JB
17052 if (inst.operands[1].immisalign)
17053 switch (inst.operands[1].imm >> 8)
17054 {
17055 case 64: alignbits = 1; break;
17056 case 128:
477330fc 17057 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 17058 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
17059 goto bad_alignment;
17060 alignbits = 2;
17061 break;
5287ad62 17062 case 256:
477330fc
RM
17063 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
17064 goto bad_alignment;
17065 alignbits = 3;
17066 break;
5287ad62
JB
17067 default:
17068 bad_alignment:
477330fc
RM
17069 first_error (_("bad alignment"));
17070 return;
5287ad62
JB
17071 }
17072
17073 inst.instruction |= alignbits << 4;
17074 inst.instruction |= neon_logbits (et.size) << 6;
17075
17076 /* Bits [4:6] of the immediate in a list specifier encode register stride
17077 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
17078 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
17079 up the right value for "type" in a table based on this value and the given
17080 list style, then stick it back. */
17081 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 17082 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
17083
17084 typebits = typetable[idx];
5f4273c7 17085
5287ad62 17086 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
17087 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
17088 _("bad element type for instruction"));
5287ad62
JB
17089
17090 inst.instruction &= ~0xf00;
17091 inst.instruction |= typebits << 8;
17092}
17093
17094/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
17095 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
17096 otherwise. The variable arguments are a list of pairs of legal (size, align)
17097 values, terminated with -1. */
17098
17099static int
aa8a0863 17100neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
17101{
17102 va_list ap;
17103 int result = FAIL, thissize, thisalign;
5f4273c7 17104
5287ad62
JB
17105 if (!inst.operands[1].immisalign)
17106 {
aa8a0863 17107 *do_alignment = 0;
5287ad62
JB
17108 return SUCCESS;
17109 }
5f4273c7 17110
aa8a0863 17111 va_start (ap, do_alignment);
5287ad62
JB
17112
17113 do
17114 {
17115 thissize = va_arg (ap, int);
17116 if (thissize == -1)
477330fc 17117 break;
5287ad62
JB
17118 thisalign = va_arg (ap, int);
17119
17120 if (size == thissize && align == thisalign)
477330fc 17121 result = SUCCESS;
5287ad62
JB
17122 }
17123 while (result != SUCCESS);
17124
17125 va_end (ap);
17126
17127 if (result == SUCCESS)
aa8a0863 17128 *do_alignment = 1;
5287ad62 17129 else
dcbf9037 17130 first_error (_("unsupported alignment for instruction"));
5f4273c7 17131
5287ad62
JB
17132 return result;
17133}
17134
17135static void
17136do_neon_ld_st_lane (void)
17137{
037e8744 17138 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17139 int align_good, do_alignment = 0;
5287ad62
JB
17140 int logsize = neon_logbits (et.size);
17141 int align = inst.operands[1].imm >> 8;
17142 int n = (inst.instruction >> 8) & 3;
17143 int max_el = 64 / et.size;
5f4273c7 17144
dcbf9037
JB
17145 if (et.type == NT_invtype)
17146 return;
5f4273c7 17147
5287ad62 17148 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 17149 _("bad list length"));
5287ad62 17150 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 17151 _("scalar index out of range"));
5287ad62 17152 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
17153 && et.size == 8,
17154 _("stride of 2 unavailable when element size is 8"));
5f4273c7 17155
5287ad62
JB
17156 switch (n)
17157 {
17158 case 0: /* VLD1 / VST1. */
aa8a0863 17159 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 17160 32, 32, -1);
5287ad62 17161 if (align_good == FAIL)
477330fc 17162 return;
aa8a0863 17163 if (do_alignment)
477330fc
RM
17164 {
17165 unsigned alignbits = 0;
17166 switch (et.size)
17167 {
17168 case 16: alignbits = 0x1; break;
17169 case 32: alignbits = 0x3; break;
17170 default: ;
17171 }
17172 inst.instruction |= alignbits << 4;
17173 }
5287ad62
JB
17174 break;
17175
17176 case 1: /* VLD2 / VST2. */
aa8a0863
TS
17177 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
17178 16, 32, 32, 64, -1);
5287ad62 17179 if (align_good == FAIL)
477330fc 17180 return;
aa8a0863 17181 if (do_alignment)
477330fc 17182 inst.instruction |= 1 << 4;
5287ad62
JB
17183 break;
17184
17185 case 2: /* VLD3 / VST3. */
17186 constraint (inst.operands[1].immisalign,
477330fc 17187 _("can't use alignment with this instruction"));
5287ad62
JB
17188 break;
17189
17190 case 3: /* VLD4 / VST4. */
aa8a0863 17191 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 17192 16, 64, 32, 64, 32, 128, -1);
5287ad62 17193 if (align_good == FAIL)
477330fc 17194 return;
aa8a0863 17195 if (do_alignment)
477330fc
RM
17196 {
17197 unsigned alignbits = 0;
17198 switch (et.size)
17199 {
17200 case 8: alignbits = 0x1; break;
17201 case 16: alignbits = 0x1; break;
17202 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
17203 default: ;
17204 }
17205 inst.instruction |= alignbits << 4;
17206 }
5287ad62
JB
17207 break;
17208
17209 default: ;
17210 }
17211
17212 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
17213 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17214 inst.instruction |= 1 << (4 + logsize);
5f4273c7 17215
5287ad62
JB
17216 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
17217 inst.instruction |= logsize << 10;
17218}
17219
17220/* Encode single n-element structure to all lanes VLD<n> instructions. */
17221
17222static void
17223do_neon_ld_dup (void)
17224{
037e8744 17225 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17226 int align_good, do_alignment = 0;
5287ad62 17227
dcbf9037
JB
17228 if (et.type == NT_invtype)
17229 return;
17230
5287ad62
JB
17231 switch ((inst.instruction >> 8) & 3)
17232 {
17233 case 0: /* VLD1. */
9c2799c2 17234 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 17235 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 17236 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 17237 if (align_good == FAIL)
477330fc 17238 return;
5287ad62 17239 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
17240 {
17241 case 1: break;
17242 case 2: inst.instruction |= 1 << 5; break;
17243 default: first_error (_("bad list length")); return;
17244 }
5287ad62
JB
17245 inst.instruction |= neon_logbits (et.size) << 6;
17246 break;
17247
17248 case 1: /* VLD2. */
17249 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
17250 &do_alignment, 8, 16, 16, 32, 32, 64,
17251 -1);
5287ad62 17252 if (align_good == FAIL)
477330fc 17253 return;
5287ad62 17254 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 17255 _("bad list length"));
5287ad62 17256 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17257 inst.instruction |= 1 << 5;
5287ad62
JB
17258 inst.instruction |= neon_logbits (et.size) << 6;
17259 break;
17260
17261 case 2: /* VLD3. */
17262 constraint (inst.operands[1].immisalign,
477330fc 17263 _("can't use alignment with this instruction"));
5287ad62 17264 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 17265 _("bad list length"));
5287ad62 17266 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17267 inst.instruction |= 1 << 5;
5287ad62
JB
17268 inst.instruction |= neon_logbits (et.size) << 6;
17269 break;
17270
17271 case 3: /* VLD4. */
17272 {
477330fc 17273 int align = inst.operands[1].imm >> 8;
aa8a0863 17274 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17275 16, 64, 32, 64, 32, 128, -1);
17276 if (align_good == FAIL)
17277 return;
17278 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17279 _("bad list length"));
17280 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17281 inst.instruction |= 1 << 5;
17282 if (et.size == 32 && align == 128)
17283 inst.instruction |= 0x3 << 6;
17284 else
17285 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
17286 }
17287 break;
17288
17289 default: ;
17290 }
17291
aa8a0863 17292 inst.instruction |= do_alignment << 4;
5287ad62
JB
17293}
17294
17295/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17296 apart from bits [11:4]. */
17297
17298static void
17299do_neon_ldx_stx (void)
17300{
b1a769ed
DG
17301 if (inst.operands[1].isreg)
17302 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17303
5287ad62
JB
17304 switch (NEON_LANE (inst.operands[0].imm))
17305 {
17306 case NEON_INTERLEAVE_LANES:
88714cb8 17307 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
17308 do_neon_ld_st_interleave ();
17309 break;
5f4273c7 17310
5287ad62 17311 case NEON_ALL_LANES:
88714cb8 17312 NEON_ENCODE (DUP, inst);
2d51fb74
JB
17313 if (inst.instruction == N_INV)
17314 {
17315 first_error ("only loads support such operands");
17316 break;
17317 }
5287ad62
JB
17318 do_neon_ld_dup ();
17319 break;
5f4273c7 17320
5287ad62 17321 default:
88714cb8 17322 NEON_ENCODE (LANE, inst);
5287ad62
JB
17323 do_neon_ld_st_lane ();
17324 }
17325
17326 /* L bit comes from bit mask. */
17327 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17328 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17329 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17330
5287ad62
JB
17331 if (inst.operands[1].postind)
17332 {
17333 int postreg = inst.operands[1].imm & 0xf;
17334 constraint (!inst.operands[1].immisreg,
477330fc 17335 _("post-index must be a register"));
5287ad62 17336 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17337 _("bad register for post-index"));
5287ad62
JB
17338 inst.instruction |= postreg;
17339 }
4f2374c7 17340 else
5287ad62 17341 {
4f2374c7
WN
17342 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17343 constraint (inst.reloc.exp.X_op != O_constant
17344 || inst.reloc.exp.X_add_number != 0,
17345 BAD_ADDR_MODE);
17346
17347 if (inst.operands[1].writeback)
17348 {
17349 inst.instruction |= 0xd;
17350 }
17351 else
17352 inst.instruction |= 0xf;
5287ad62 17353 }
5f4273c7 17354
5287ad62
JB
17355 if (thumb_mode)
17356 inst.instruction |= 0xf9000000;
17357 else
17358 inst.instruction |= 0xf4000000;
17359}
33399f07
MGD
17360
17361/* FP v8. */
17362static void
17363do_vfp_nsyn_fpv8 (enum neon_shape rs)
17364{
a715796b
TG
17365 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17366 D register operands. */
17367 if (neon_shape_class[rs] == SC_DOUBLE)
17368 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17369 _(BAD_FPU));
17370
33399f07
MGD
17371 NEON_ENCODE (FPV8, inst);
17372
9db2f6b4
RL
17373 if (rs == NS_FFF || rs == NS_HHH)
17374 {
17375 do_vfp_sp_dyadic ();
17376
17377 /* ARMv8.2 fp16 instruction. */
17378 if (rs == NS_HHH)
17379 do_scalar_fp16_v82_encode ();
17380 }
33399f07
MGD
17381 else
17382 do_vfp_dp_rd_rn_rm ();
17383
17384 if (rs == NS_DDD)
17385 inst.instruction |= 0x100;
17386
17387 inst.instruction |= 0xf0000000;
17388}
17389
17390static void
17391do_vsel (void)
17392{
17393 set_it_insn_type (OUTSIDE_IT_INSN);
17394
17395 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17396 first_error (_("invalid instruction shape"));
17397}
17398
73924fbc
MGD
17399static void
17400do_vmaxnm (void)
17401{
17402 set_it_insn_type (OUTSIDE_IT_INSN);
17403
17404 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17405 return;
17406
17407 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17408 return;
17409
cc933301 17410 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17411}
17412
30bdf752
MGD
17413static void
17414do_vrint_1 (enum neon_cvt_mode mode)
17415{
9db2f6b4 17416 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17417 struct neon_type_el et;
17418
17419 if (rs == NS_NULL)
17420 return;
17421
a715796b
TG
17422 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17423 D register operands. */
17424 if (neon_shape_class[rs] == SC_DOUBLE)
17425 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17426 _(BAD_FPU));
17427
9db2f6b4
RL
17428 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17429 | N_VFP);
30bdf752
MGD
17430 if (et.type != NT_invtype)
17431 {
17432 /* VFP encodings. */
17433 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17434 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17435 set_it_insn_type (OUTSIDE_IT_INSN);
17436
17437 NEON_ENCODE (FPV8, inst);
9db2f6b4 17438 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17439 do_vfp_sp_monadic ();
17440 else
17441 do_vfp_dp_rd_rm ();
17442
17443 switch (mode)
17444 {
17445 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17446 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17447 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17448 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17449 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17450 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17451 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17452 default: abort ();
17453 }
17454
17455 inst.instruction |= (rs == NS_DD) << 8;
17456 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17457
17458 /* ARMv8.2 fp16 vrint instruction. */
17459 if (rs == NS_HH)
17460 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17461 }
17462 else
17463 {
17464 /* Neon encodings (or something broken...). */
17465 inst.error = NULL;
cc933301 17466 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17467
17468 if (et.type == NT_invtype)
17469 return;
17470
17471 set_it_insn_type (OUTSIDE_IT_INSN);
17472 NEON_ENCODE (FLOAT, inst);
17473
17474 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17475 return;
17476
17477 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17478 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17479 inst.instruction |= LOW4 (inst.operands[1].reg);
17480 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17481 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17482 /* Mask off the original size bits and reencode them. */
17483 inst.instruction = ((inst.instruction & 0xfff3ffff)
17484 | neon_logbits (et.size) << 18);
17485
30bdf752
MGD
17486 switch (mode)
17487 {
17488 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17489 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17490 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17491 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17492 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17493 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17494 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17495 default: abort ();
17496 }
17497
17498 if (thumb_mode)
17499 inst.instruction |= 0xfc000000;
17500 else
17501 inst.instruction |= 0xf0000000;
17502 }
17503}
17504
17505static void
17506do_vrintx (void)
17507{
17508 do_vrint_1 (neon_cvt_mode_x);
17509}
17510
17511static void
17512do_vrintz (void)
17513{
17514 do_vrint_1 (neon_cvt_mode_z);
17515}
17516
17517static void
17518do_vrintr (void)
17519{
17520 do_vrint_1 (neon_cvt_mode_r);
17521}
17522
17523static void
17524do_vrinta (void)
17525{
17526 do_vrint_1 (neon_cvt_mode_a);
17527}
17528
17529static void
17530do_vrintn (void)
17531{
17532 do_vrint_1 (neon_cvt_mode_n);
17533}
17534
17535static void
17536do_vrintp (void)
17537{
17538 do_vrint_1 (neon_cvt_mode_p);
17539}
17540
17541static void
17542do_vrintm (void)
17543{
17544 do_vrint_1 (neon_cvt_mode_m);
17545}
17546
c28eeff2
SN
17547static unsigned
17548neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17549{
17550 unsigned regno = NEON_SCALAR_REG (opnd);
17551 unsigned elno = NEON_SCALAR_INDEX (opnd);
17552
17553 if (elsize == 16 && elno < 2 && regno < 16)
17554 return regno | (elno << 4);
17555 else if (elsize == 32 && elno == 0)
17556 return regno;
17557
17558 first_error (_("scalar out of range"));
17559 return 0;
17560}
17561
17562static void
17563do_vcmla (void)
17564{
17565 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17566 _(BAD_FPU));
17567 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17568 unsigned rot = inst.reloc.exp.X_add_number;
17569 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17570 _("immediate out of range"));
17571 rot /= 90;
17572 if (inst.operands[2].isscalar)
17573 {
17574 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17575 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17576 N_KEY | N_F16 | N_F32).size;
17577 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17578 inst.is_neon = 1;
17579 inst.instruction = 0xfe000800;
17580 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17581 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17582 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17583 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17584 inst.instruction |= LOW4 (m);
17585 inst.instruction |= HI1 (m) << 5;
17586 inst.instruction |= neon_quad (rs) << 6;
17587 inst.instruction |= rot << 20;
17588 inst.instruction |= (size == 32) << 23;
17589 }
17590 else
17591 {
17592 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17593 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17594 N_KEY | N_F16 | N_F32).size;
17595 neon_three_same (neon_quad (rs), 0, -1);
17596 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17597 inst.instruction |= 0xfc200800;
17598 inst.instruction |= rot << 23;
17599 inst.instruction |= (size == 32) << 20;
17600 }
17601}
17602
17603static void
17604do_vcadd (void)
17605{
17606 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17607 _(BAD_FPU));
17608 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17609 unsigned rot = inst.reloc.exp.X_add_number;
17610 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17611 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17612 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17613 N_KEY | N_F16 | N_F32).size;
17614 neon_three_same (neon_quad (rs), 0, -1);
17615 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17616 inst.instruction |= 0xfc800800;
17617 inst.instruction |= (rot == 270) << 24;
17618 inst.instruction |= (size == 32) << 20;
17619}
17620
c604a79a
JW
17621/* Dot Product instructions encoding support. */
17622
17623static void
17624do_neon_dotproduct (int unsigned_p)
17625{
17626 enum neon_shape rs;
17627 unsigned scalar_oprd2 = 0;
17628 int high8;
17629
17630 if (inst.cond != COND_ALWAYS)
17631 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
17632 "is UNPREDICTABLE"));
17633
17634 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17635 _(BAD_FPU));
17636
17637 /* Dot Product instructions are in three-same D/Q register format or the third
17638 operand can be a scalar index register. */
17639 if (inst.operands[2].isscalar)
17640 {
17641 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
17642 high8 = 0xfe000000;
17643 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17644 }
17645 else
17646 {
17647 high8 = 0xfc000000;
17648 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17649 }
17650
17651 if (unsigned_p)
17652 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
17653 else
17654 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
17655
17656 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
17657 Product instruction, so we pass 0 as the "ubit" parameter. And the
17658 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
17659 neon_three_same (neon_quad (rs), 0, 32);
17660
17661 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
17662 different NEON three-same encoding. */
17663 inst.instruction &= 0x00ffffff;
17664 inst.instruction |= high8;
17665 /* Encode 'U' bit which indicates signedness. */
17666 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
17667 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
17668 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
17669 the instruction encoding. */
17670 if (inst.operands[2].isscalar)
17671 {
17672 inst.instruction &= 0xffffffd0;
17673 inst.instruction |= LOW4 (scalar_oprd2);
17674 inst.instruction |= HI1 (scalar_oprd2) << 5;
17675 }
17676}
17677
17678/* Dot Product instructions for signed integer. */
17679
17680static void
17681do_neon_dotproduct_s (void)
17682{
17683 return do_neon_dotproduct (0);
17684}
17685
17686/* Dot Product instructions for unsigned integer. */
17687
17688static void
17689do_neon_dotproduct_u (void)
17690{
17691 return do_neon_dotproduct (1);
17692}
17693
91ff7894
MGD
17694/* Crypto v1 instructions. */
17695static void
17696do_crypto_2op_1 (unsigned elttype, int op)
17697{
17698 set_it_insn_type (OUTSIDE_IT_INSN);
17699
17700 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17701 == NT_invtype)
17702 return;
17703
17704 inst.error = NULL;
17705
17706 NEON_ENCODE (INTEGER, inst);
17707 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17708 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17709 inst.instruction |= LOW4 (inst.operands[1].reg);
17710 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17711 if (op != -1)
17712 inst.instruction |= op << 6;
17713
17714 if (thumb_mode)
17715 inst.instruction |= 0xfc000000;
17716 else
17717 inst.instruction |= 0xf0000000;
17718}
17719
48adcd8e
MGD
17720static void
17721do_crypto_3op_1 (int u, int op)
17722{
17723 set_it_insn_type (OUTSIDE_IT_INSN);
17724
17725 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17726 N_32 | N_UNT | N_KEY).type == NT_invtype)
17727 return;
17728
17729 inst.error = NULL;
17730
17731 NEON_ENCODE (INTEGER, inst);
17732 neon_three_same (1, u, 8 << op);
17733}
17734
91ff7894
MGD
17735static void
17736do_aese (void)
17737{
17738 do_crypto_2op_1 (N_8, 0);
17739}
17740
17741static void
17742do_aesd (void)
17743{
17744 do_crypto_2op_1 (N_8, 1);
17745}
17746
17747static void
17748do_aesmc (void)
17749{
17750 do_crypto_2op_1 (N_8, 2);
17751}
17752
17753static void
17754do_aesimc (void)
17755{
17756 do_crypto_2op_1 (N_8, 3);
17757}
17758
48adcd8e
MGD
17759static void
17760do_sha1c (void)
17761{
17762 do_crypto_3op_1 (0, 0);
17763}
17764
17765static void
17766do_sha1p (void)
17767{
17768 do_crypto_3op_1 (0, 1);
17769}
17770
17771static void
17772do_sha1m (void)
17773{
17774 do_crypto_3op_1 (0, 2);
17775}
17776
17777static void
17778do_sha1su0 (void)
17779{
17780 do_crypto_3op_1 (0, 3);
17781}
91ff7894 17782
48adcd8e
MGD
17783static void
17784do_sha256h (void)
17785{
17786 do_crypto_3op_1 (1, 0);
17787}
17788
17789static void
17790do_sha256h2 (void)
17791{
17792 do_crypto_3op_1 (1, 1);
17793}
17794
17795static void
17796do_sha256su1 (void)
17797{
17798 do_crypto_3op_1 (1, 2);
17799}
3c9017d2
MGD
17800
17801static void
17802do_sha1h (void)
17803{
17804 do_crypto_2op_1 (N_32, -1);
17805}
17806
17807static void
17808do_sha1su1 (void)
17809{
17810 do_crypto_2op_1 (N_32, 0);
17811}
17812
17813static void
17814do_sha256su0 (void)
17815{
17816 do_crypto_2op_1 (N_32, 1);
17817}
dd5181d5
KT
17818
17819static void
17820do_crc32_1 (unsigned int poly, unsigned int sz)
17821{
17822 unsigned int Rd = inst.operands[0].reg;
17823 unsigned int Rn = inst.operands[1].reg;
17824 unsigned int Rm = inst.operands[2].reg;
17825
17826 set_it_insn_type (OUTSIDE_IT_INSN);
17827 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17828 inst.instruction |= LOW4 (Rn) << 16;
17829 inst.instruction |= LOW4 (Rm);
17830 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17831 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17832
17833 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17834 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
17835}
17836
17837static void
17838do_crc32b (void)
17839{
17840 do_crc32_1 (0, 0);
17841}
17842
17843static void
17844do_crc32h (void)
17845{
17846 do_crc32_1 (0, 1);
17847}
17848
17849static void
17850do_crc32w (void)
17851{
17852 do_crc32_1 (0, 2);
17853}
17854
17855static void
17856do_crc32cb (void)
17857{
17858 do_crc32_1 (1, 0);
17859}
17860
17861static void
17862do_crc32ch (void)
17863{
17864 do_crc32_1 (1, 1);
17865}
17866
17867static void
17868do_crc32cw (void)
17869{
17870 do_crc32_1 (1, 2);
17871}
17872
49e8a725
SN
17873static void
17874do_vjcvt (void)
17875{
17876 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17877 _(BAD_FPU));
17878 neon_check_type (2, NS_FD, N_S32, N_F64);
17879 do_vfp_sp_dp_cvt ();
17880 do_vfp_cond_or_thumb ();
17881}
17882
5287ad62
JB
17883\f
17884/* Overall per-instruction processing. */
17885
17886/* We need to be able to fix up arbitrary expressions in some statements.
17887 This is so that we can handle symbols that are an arbitrary distance from
17888 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17889 which returns part of an address in a form which will be valid for
17890 a data instruction. We do this by pushing the expression into a symbol
17891 in the expr_section, and creating a fix for that. */
17892
17893static void
17894fix_new_arm (fragS * frag,
17895 int where,
17896 short int size,
17897 expressionS * exp,
17898 int pc_rel,
17899 int reloc)
17900{
17901 fixS * new_fix;
17902
17903 switch (exp->X_op)
17904 {
17905 case O_constant:
6e7ce2cd
PB
17906 if (pc_rel)
17907 {
17908 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17909 refer to in the object file. Unfortunately for us, gas's
17910 generic expression parsing will already have folded out
17911 any use of .set foo/.type foo %function that may have
17912 been used to set type information of the target location,
17913 that's being specified symbolically. We have to presume
17914 the user knows what they are doing. */
6e7ce2cd
PB
17915 char name[16 + 8];
17916 symbolS *symbol;
17917
17918 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17919
17920 symbol = symbol_find_or_make (name);
17921 S_SET_SEGMENT (symbol, absolute_section);
17922 symbol_set_frag (symbol, &zero_address_frag);
17923 S_SET_VALUE (symbol, exp->X_add_number);
17924 exp->X_op = O_symbol;
17925 exp->X_add_symbol = symbol;
17926 exp->X_add_number = 0;
17927 }
17928 /* FALLTHROUGH */
5287ad62
JB
17929 case O_symbol:
17930 case O_add:
17931 case O_subtract:
21d799b5 17932 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17933 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17934 break;
17935
17936 default:
21d799b5 17937 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17938 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17939 break;
17940 }
17941
17942 /* Mark whether the fix is to a THUMB instruction, or an ARM
17943 instruction. */
17944 new_fix->tc_fix_data = thumb_mode;
17945}
17946
17947/* Create a frg for an instruction requiring relaxation. */
17948static void
17949output_relax_insn (void)
17950{
17951 char * to;
17952 symbolS *sym;
0110f2b8
PB
17953 int offset;
17954
6e1cb1a6
PB
17955 /* The size of the instruction is unknown, so tie the debug info to the
17956 start of the instruction. */
17957 dwarf2_emit_insn (0);
6e1cb1a6 17958
0110f2b8
PB
17959 switch (inst.reloc.exp.X_op)
17960 {
17961 case O_symbol:
17962 sym = inst.reloc.exp.X_add_symbol;
17963 offset = inst.reloc.exp.X_add_number;
17964 break;
17965 case O_constant:
17966 sym = NULL;
17967 offset = inst.reloc.exp.X_add_number;
17968 break;
17969 default:
17970 sym = make_expr_symbol (&inst.reloc.exp);
17971 offset = 0;
17972 break;
17973 }
17974 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17975 inst.relax, sym, offset, NULL/*offset, opcode*/);
17976 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17977}
17978
17979/* Write a 32-bit thumb instruction to buf. */
17980static void
17981put_thumb32_insn (char * buf, unsigned long insn)
17982{
17983 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17984 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17985}
17986
b99bd4ef 17987static void
c19d1205 17988output_inst (const char * str)
b99bd4ef 17989{
c19d1205 17990 char * to = NULL;
b99bd4ef 17991
c19d1205 17992 if (inst.error)
b99bd4ef 17993 {
c19d1205 17994 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17995 return;
17996 }
5f4273c7
NC
17997 if (inst.relax)
17998 {
17999 output_relax_insn ();
0110f2b8 18000 return;
5f4273c7 18001 }
c19d1205
ZW
18002 if (inst.size == 0)
18003 return;
b99bd4ef 18004
c19d1205 18005 to = frag_more (inst.size);
8dc2430f
NC
18006 /* PR 9814: Record the thumb mode into the current frag so that we know
18007 what type of NOP padding to use, if necessary. We override any previous
18008 setting so that if the mode has changed then the NOPS that we use will
18009 match the encoding of the last instruction in the frag. */
cd000bff 18010 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
18011
18012 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 18013 {
9c2799c2 18014 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 18015 put_thumb32_insn (to, inst.instruction);
b99bd4ef 18016 }
c19d1205 18017 else if (inst.size > INSN_SIZE)
b99bd4ef 18018 {
9c2799c2 18019 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
18020 md_number_to_chars (to, inst.instruction, INSN_SIZE);
18021 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 18022 }
c19d1205
ZW
18023 else
18024 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 18025
c19d1205
ZW
18026 if (inst.reloc.type != BFD_RELOC_UNUSED)
18027 fix_new_arm (frag_now, to - frag_now->fr_literal,
18028 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
18029 inst.reloc.type);
b99bd4ef 18030
c19d1205 18031 dwarf2_emit_insn (inst.size);
c19d1205 18032}
b99bd4ef 18033
e07e6e58
NC
18034static char *
18035output_it_inst (int cond, int mask, char * to)
18036{
18037 unsigned long instruction = 0xbf00;
18038
18039 mask &= 0xf;
18040 instruction |= mask;
18041 instruction |= cond << 4;
18042
18043 if (to == NULL)
18044 {
18045 to = frag_more (2);
18046#ifdef OBJ_ELF
18047 dwarf2_emit_insn (2);
18048#endif
18049 }
18050
18051 md_number_to_chars (to, instruction, 2);
18052
18053 return to;
18054}
18055
c19d1205
ZW
18056/* Tag values used in struct asm_opcode's tag field. */
18057enum opcode_tag
18058{
18059 OT_unconditional, /* Instruction cannot be conditionalized.
18060 The ARM condition field is still 0xE. */
18061 OT_unconditionalF, /* Instruction cannot be conditionalized
18062 and carries 0xF in its ARM condition field. */
18063 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 18064 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
18065 suffix, others place 0xF where the condition field
18066 would be. */
c19d1205
ZW
18067 OT_cinfix3, /* Instruction takes a conditional infix,
18068 beginning at character index 3. (In
18069 unified mode, it becomes a suffix.) */
088fa78e
KH
18070 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
18071 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
18072 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
18073 character index 3, even in unified mode. Used for
18074 legacy instructions where suffix and infix forms
18075 may be ambiguous. */
c19d1205 18076 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 18077 suffix or an infix at character index 3. */
c19d1205
ZW
18078 OT_odd_infix_unc, /* This is the unconditional variant of an
18079 instruction that takes a conditional infix
18080 at an unusual position. In unified mode,
18081 this variant will accept a suffix. */
18082 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
18083 are the conditional variants of instructions that
18084 take conditional infixes in unusual positions.
18085 The infix appears at character index
18086 (tag - OT_odd_infix_0). These are not accepted
18087 in unified mode. */
18088};
b99bd4ef 18089
c19d1205
ZW
18090/* Subroutine of md_assemble, responsible for looking up the primary
18091 opcode from the mnemonic the user wrote. STR points to the
18092 beginning of the mnemonic.
18093
18094 This is not simply a hash table lookup, because of conditional
18095 variants. Most instructions have conditional variants, which are
18096 expressed with a _conditional affix_ to the mnemonic. If we were
18097 to encode each conditional variant as a literal string in the opcode
18098 table, it would have approximately 20,000 entries.
18099
18100 Most mnemonics take this affix as a suffix, and in unified syntax,
18101 'most' is upgraded to 'all'. However, in the divided syntax, some
18102 instructions take the affix as an infix, notably the s-variants of
18103 the arithmetic instructions. Of those instructions, all but six
18104 have the infix appear after the third character of the mnemonic.
18105
18106 Accordingly, the algorithm for looking up primary opcodes given
18107 an identifier is:
18108
18109 1. Look up the identifier in the opcode table.
18110 If we find a match, go to step U.
18111
18112 2. Look up the last two characters of the identifier in the
18113 conditions table. If we find a match, look up the first N-2
18114 characters of the identifier in the opcode table. If we
18115 find a match, go to step CE.
18116
18117 3. Look up the fourth and fifth characters of the identifier in
18118 the conditions table. If we find a match, extract those
18119 characters from the identifier, and look up the remaining
18120 characters in the opcode table. If we find a match, go
18121 to step CM.
18122
18123 4. Fail.
18124
18125 U. Examine the tag field of the opcode structure, in case this is
18126 one of the six instructions with its conditional infix in an
18127 unusual place. If it is, the tag tells us where to find the
18128 infix; look it up in the conditions table and set inst.cond
18129 accordingly. Otherwise, this is an unconditional instruction.
18130 Again set inst.cond accordingly. Return the opcode structure.
18131
18132 CE. Examine the tag field to make sure this is an instruction that
18133 should receive a conditional suffix. If it is not, fail.
18134 Otherwise, set inst.cond from the suffix we already looked up,
18135 and return the opcode structure.
18136
18137 CM. Examine the tag field to make sure this is an instruction that
18138 should receive a conditional infix after the third character.
18139 If it is not, fail. Otherwise, undo the edits to the current
18140 line of input and proceed as for case CE. */
18141
18142static const struct asm_opcode *
18143opcode_lookup (char **str)
18144{
18145 char *end, *base;
18146 char *affix;
18147 const struct asm_opcode *opcode;
18148 const struct asm_cond *cond;
e3cb604e 18149 char save[2];
c19d1205
ZW
18150
18151 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 18152 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 18153 for (base = end = *str; *end != '\0'; end++)
721a8186 18154 if (*end == ' ' || *end == '.')
c19d1205 18155 break;
b99bd4ef 18156
c19d1205 18157 if (end == base)
c921be7d 18158 return NULL;
b99bd4ef 18159
5287ad62 18160 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 18161 if (end[0] == '.')
b99bd4ef 18162 {
5287ad62 18163 int offset = 2;
5f4273c7 18164
267d2029 18165 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 18166 use. */
267d2029 18167 if (unified_syntax && end[1] == 'w')
c19d1205 18168 inst.size_req = 4;
267d2029 18169 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
18170 inst.size_req = 2;
18171 else
477330fc 18172 offset = 0;
5287ad62
JB
18173
18174 inst.vectype.elems = 0;
18175
18176 *str = end + offset;
b99bd4ef 18177
5f4273c7 18178 if (end[offset] == '.')
5287ad62 18179 {
267d2029 18180 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
18181 non-unified ARM syntax mode). */
18182 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 18183 return NULL;
477330fc 18184 }
5287ad62 18185 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 18186 return NULL;
b99bd4ef 18187 }
c19d1205
ZW
18188 else
18189 *str = end;
b99bd4ef 18190
c19d1205 18191 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 18192 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18193 end - base);
c19d1205 18194 if (opcode)
b99bd4ef 18195 {
c19d1205
ZW
18196 /* step U */
18197 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 18198 {
c19d1205
ZW
18199 inst.cond = COND_ALWAYS;
18200 return opcode;
b99bd4ef 18201 }
b99bd4ef 18202
278df34e 18203 if (warn_on_deprecated && unified_syntax)
5c3696f8 18204 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 18205 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 18206 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 18207 gas_assert (cond);
b99bd4ef 18208
c19d1205
ZW
18209 inst.cond = cond->value;
18210 return opcode;
18211 }
b99bd4ef 18212
c19d1205
ZW
18213 /* Cannot have a conditional suffix on a mnemonic of less than two
18214 characters. */
18215 if (end - base < 3)
c921be7d 18216 return NULL;
b99bd4ef 18217
c19d1205
ZW
18218 /* Look for suffixed mnemonic. */
18219 affix = end - 2;
21d799b5
NC
18220 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18221 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18222 affix - base);
c19d1205
ZW
18223 if (opcode && cond)
18224 {
18225 /* step CE */
18226 switch (opcode->tag)
18227 {
e3cb604e
PB
18228 case OT_cinfix3_legacy:
18229 /* Ignore conditional suffixes matched on infix only mnemonics. */
18230 break;
18231
c19d1205 18232 case OT_cinfix3:
088fa78e 18233 case OT_cinfix3_deprecated:
c19d1205
ZW
18234 case OT_odd_infix_unc:
18235 if (!unified_syntax)
0198d5e6 18236 return NULL;
1a0670f3 18237 /* Fall through. */
c19d1205
ZW
18238
18239 case OT_csuffix:
477330fc 18240 case OT_csuffixF:
c19d1205
ZW
18241 case OT_csuf_or_in3:
18242 inst.cond = cond->value;
18243 return opcode;
18244
18245 case OT_unconditional:
18246 case OT_unconditionalF:
dfa9f0d5 18247 if (thumb_mode)
c921be7d 18248 inst.cond = cond->value;
dfa9f0d5
PB
18249 else
18250 {
c921be7d 18251 /* Delayed diagnostic. */
dfa9f0d5
PB
18252 inst.error = BAD_COND;
18253 inst.cond = COND_ALWAYS;
18254 }
c19d1205 18255 return opcode;
b99bd4ef 18256
c19d1205 18257 default:
c921be7d 18258 return NULL;
c19d1205
ZW
18259 }
18260 }
b99bd4ef 18261
c19d1205
ZW
18262 /* Cannot have a usual-position infix on a mnemonic of less than
18263 six characters (five would be a suffix). */
18264 if (end - base < 6)
c921be7d 18265 return NULL;
b99bd4ef 18266
c19d1205
ZW
18267 /* Look for infixed mnemonic in the usual position. */
18268 affix = base + 3;
21d799b5 18269 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 18270 if (!cond)
c921be7d 18271 return NULL;
e3cb604e
PB
18272
18273 memcpy (save, affix, 2);
18274 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 18275 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18276 (end - base) - 2);
e3cb604e
PB
18277 memmove (affix + 2, affix, (end - affix) - 2);
18278 memcpy (affix, save, 2);
18279
088fa78e
KH
18280 if (opcode
18281 && (opcode->tag == OT_cinfix3
18282 || opcode->tag == OT_cinfix3_deprecated
18283 || opcode->tag == OT_csuf_or_in3
18284 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 18285 {
c921be7d 18286 /* Step CM. */
278df34e 18287 if (warn_on_deprecated && unified_syntax
088fa78e
KH
18288 && (opcode->tag == OT_cinfix3
18289 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 18290 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
18291
18292 inst.cond = cond->value;
18293 return opcode;
b99bd4ef
NC
18294 }
18295
c921be7d 18296 return NULL;
b99bd4ef
NC
18297}
18298
e07e6e58
NC
18299/* This function generates an initial IT instruction, leaving its block
18300 virtually open for the new instructions. Eventually,
18301 the mask will be updated by now_it_add_mask () each time
18302 a new instruction needs to be included in the IT block.
18303 Finally, the block is closed with close_automatic_it_block ().
18304 The block closure can be requested either from md_assemble (),
18305 a tencode (), or due to a label hook. */
18306
18307static void
18308new_automatic_it_block (int cond)
18309{
18310 now_it.state = AUTOMATIC_IT_BLOCK;
18311 now_it.mask = 0x18;
18312 now_it.cc = cond;
18313 now_it.block_length = 1;
cd000bff 18314 mapping_state (MAP_THUMB);
e07e6e58 18315 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
18316 now_it.warn_deprecated = FALSE;
18317 now_it.insn_cond = TRUE;
e07e6e58
NC
18318}
18319
18320/* Close an automatic IT block.
18321 See comments in new_automatic_it_block (). */
18322
18323static void
18324close_automatic_it_block (void)
18325{
18326 now_it.mask = 0x10;
18327 now_it.block_length = 0;
18328}
18329
18330/* Update the mask of the current automatically-generated IT
18331 instruction. See comments in new_automatic_it_block (). */
18332
18333static void
18334now_it_add_mask (int cond)
18335{
18336#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
18337#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 18338 | ((bitvalue) << (nbit)))
e07e6e58 18339 const int resulting_bit = (cond & 1);
c921be7d 18340
e07e6e58
NC
18341 now_it.mask &= 0xf;
18342 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18343 resulting_bit,
18344 (5 - now_it.block_length));
e07e6e58 18345 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18346 1,
18347 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
18348 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18349
18350#undef CLEAR_BIT
18351#undef SET_BIT_VALUE
e07e6e58
NC
18352}
18353
18354/* The IT blocks handling machinery is accessed through the these functions:
18355 it_fsm_pre_encode () from md_assemble ()
18356 set_it_insn_type () optional, from the tencode functions
18357 set_it_insn_type_last () ditto
18358 in_it_block () ditto
18359 it_fsm_post_encode () from md_assemble ()
33eaf5de 18360 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
18361
18362 Rationale:
18363 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
18364 initializing the IT insn type with a generic initial value depending
18365 on the inst.condition.
e07e6e58 18366 2) During the tencode function, two things may happen:
477330fc
RM
18367 a) The tencode function overrides the IT insn type by
18368 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18369 b) The tencode function queries the IT block state by
18370 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18371
18372 Both set_it_insn_type and in_it_block run the internal FSM state
18373 handling function (handle_it_state), because: a) setting the IT insn
18374 type may incur in an invalid state (exiting the function),
18375 and b) querying the state requires the FSM to be updated.
18376 Specifically we want to avoid creating an IT block for conditional
18377 branches, so it_fsm_pre_encode is actually a guess and we can't
18378 determine whether an IT block is required until the tencode () routine
18379 has decided what type of instruction this actually it.
18380 Because of this, if set_it_insn_type and in_it_block have to be used,
18381 set_it_insn_type has to be called first.
18382
18383 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18384 determines the insn IT type depending on the inst.cond code.
18385 When a tencode () routine encodes an instruction that can be
18386 either outside an IT block, or, in the case of being inside, has to be
18387 the last one, set_it_insn_type_last () will determine the proper
18388 IT instruction type based on the inst.cond code. Otherwise,
18389 set_it_insn_type can be called for overriding that logic or
18390 for covering other cases.
18391
18392 Calling handle_it_state () may not transition the IT block state to
2b0f3761 18393 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
477330fc
RM
18394 still queried. Instead, if the FSM determines that the state should
18395 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18396 after the tencode () function: that's what it_fsm_post_encode () does.
18397
18398 Since in_it_block () calls the state handling function to get an
18399 updated state, an error may occur (due to invalid insns combination).
18400 In that case, inst.error is set.
18401 Therefore, inst.error has to be checked after the execution of
18402 the tencode () routine.
e07e6e58
NC
18403
18404 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
18405 any pending state change (if any) that didn't take place in
18406 handle_it_state () as explained above. */
e07e6e58
NC
18407
18408static void
18409it_fsm_pre_encode (void)
18410{
18411 if (inst.cond != COND_ALWAYS)
18412 inst.it_insn_type = INSIDE_IT_INSN;
18413 else
18414 inst.it_insn_type = OUTSIDE_IT_INSN;
18415
18416 now_it.state_handled = 0;
18417}
18418
18419/* IT state FSM handling function. */
18420
18421static int
18422handle_it_state (void)
18423{
18424 now_it.state_handled = 1;
5a01bb1d 18425 now_it.insn_cond = FALSE;
e07e6e58
NC
18426
18427 switch (now_it.state)
18428 {
18429 case OUTSIDE_IT_BLOCK:
18430 switch (inst.it_insn_type)
18431 {
18432 case OUTSIDE_IT_INSN:
18433 break;
18434
18435 case INSIDE_IT_INSN:
18436 case INSIDE_IT_LAST_INSN:
18437 if (thumb_mode == 0)
18438 {
c921be7d 18439 if (unified_syntax
e07e6e58
NC
18440 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18441 as_tsktsk (_("Warning: conditional outside an IT block"\
18442 " for Thumb."));
18443 }
18444 else
18445 {
18446 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 18447 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
18448 {
18449 /* Automatically generate the IT instruction. */
18450 new_automatic_it_block (inst.cond);
18451 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18452 close_automatic_it_block ();
18453 }
18454 else
18455 {
18456 inst.error = BAD_OUT_IT;
18457 return FAIL;
18458 }
18459 }
18460 break;
18461
18462 case IF_INSIDE_IT_LAST_INSN:
18463 case NEUTRAL_IT_INSN:
18464 break;
18465
18466 case IT_INSN:
18467 now_it.state = MANUAL_IT_BLOCK;
18468 now_it.block_length = 0;
18469 break;
18470 }
18471 break;
18472
18473 case AUTOMATIC_IT_BLOCK:
18474 /* Three things may happen now:
18475 a) We should increment current it block size;
18476 b) We should close current it block (closing insn or 4 insns);
18477 c) We should close current it block and start a new one (due
18478 to incompatible conditions or
18479 4 insns-length block reached). */
18480
18481 switch (inst.it_insn_type)
18482 {
18483 case OUTSIDE_IT_INSN:
2b0f3761 18484 /* The closure of the block shall happen immediately,
e07e6e58
NC
18485 so any in_it_block () call reports the block as closed. */
18486 force_automatic_it_block_close ();
18487 break;
18488
18489 case INSIDE_IT_INSN:
18490 case INSIDE_IT_LAST_INSN:
18491 case IF_INSIDE_IT_LAST_INSN:
18492 now_it.block_length++;
18493
18494 if (now_it.block_length > 4
18495 || !now_it_compatible (inst.cond))
18496 {
18497 force_automatic_it_block_close ();
18498 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18499 new_automatic_it_block (inst.cond);
18500 }
18501 else
18502 {
5a01bb1d 18503 now_it.insn_cond = TRUE;
e07e6e58
NC
18504 now_it_add_mask (inst.cond);
18505 }
18506
18507 if (now_it.state == AUTOMATIC_IT_BLOCK
18508 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18509 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18510 close_automatic_it_block ();
18511 break;
18512
18513 case NEUTRAL_IT_INSN:
18514 now_it.block_length++;
5a01bb1d 18515 now_it.insn_cond = TRUE;
e07e6e58
NC
18516
18517 if (now_it.block_length > 4)
18518 force_automatic_it_block_close ();
18519 else
18520 now_it_add_mask (now_it.cc & 1);
18521 break;
18522
18523 case IT_INSN:
18524 close_automatic_it_block ();
18525 now_it.state = MANUAL_IT_BLOCK;
18526 break;
18527 }
18528 break;
18529
18530 case MANUAL_IT_BLOCK:
18531 {
18532 /* Check conditional suffixes. */
18533 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18534 int is_last;
18535 now_it.mask <<= 1;
18536 now_it.mask &= 0x1f;
18537 is_last = (now_it.mask == 0x10);
5a01bb1d 18538 now_it.insn_cond = TRUE;
e07e6e58
NC
18539
18540 switch (inst.it_insn_type)
18541 {
18542 case OUTSIDE_IT_INSN:
18543 inst.error = BAD_NOT_IT;
18544 return FAIL;
18545
18546 case INSIDE_IT_INSN:
18547 if (cond != inst.cond)
18548 {
18549 inst.error = BAD_IT_COND;
18550 return FAIL;
18551 }
18552 break;
18553
18554 case INSIDE_IT_LAST_INSN:
18555 case IF_INSIDE_IT_LAST_INSN:
18556 if (cond != inst.cond)
18557 {
18558 inst.error = BAD_IT_COND;
18559 return FAIL;
18560 }
18561 if (!is_last)
18562 {
18563 inst.error = BAD_BRANCH;
18564 return FAIL;
18565 }
18566 break;
18567
18568 case NEUTRAL_IT_INSN:
18569 /* The BKPT instruction is unconditional even in an IT block. */
18570 break;
18571
18572 case IT_INSN:
18573 inst.error = BAD_IT_IT;
18574 return FAIL;
18575 }
18576 }
18577 break;
18578 }
18579
18580 return SUCCESS;
18581}
18582
5a01bb1d
MGD
18583struct depr_insn_mask
18584{
18585 unsigned long pattern;
18586 unsigned long mask;
18587 const char* description;
18588};
18589
18590/* List of 16-bit instruction patterns deprecated in an IT block in
18591 ARMv8. */
18592static const struct depr_insn_mask depr_it_insns[] = {
18593 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18594 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18595 { 0xa000, 0xb800, N_("ADR") },
18596 { 0x4800, 0xf800, N_("Literal loads") },
18597 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18598 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18599 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18600 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18601 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18602 { 0, 0, NULL }
18603};
18604
e07e6e58
NC
18605static void
18606it_fsm_post_encode (void)
18607{
18608 int is_last;
18609
18610 if (!now_it.state_handled)
18611 handle_it_state ();
18612
5a01bb1d
MGD
18613 if (now_it.insn_cond
18614 && !now_it.warn_deprecated
18615 && warn_on_deprecated
df9909b8
TP
18616 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
18617 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
5a01bb1d
MGD
18618 {
18619 if (inst.instruction >= 0x10000)
18620 {
5c3696f8 18621 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
df9909b8 18622 "performance deprecated in ARMv8-A and ARMv8-R"));
5a01bb1d
MGD
18623 now_it.warn_deprecated = TRUE;
18624 }
18625 else
18626 {
18627 const struct depr_insn_mask *p = depr_it_insns;
18628
18629 while (p->mask != 0)
18630 {
18631 if ((inst.instruction & p->mask) == p->pattern)
18632 {
df9909b8
TP
18633 as_tsktsk (_("IT blocks containing 16-bit Thumb "
18634 "instructions of the following class are "
18635 "performance deprecated in ARMv8-A and "
18636 "ARMv8-R: %s"), p->description);
5a01bb1d
MGD
18637 now_it.warn_deprecated = TRUE;
18638 break;
18639 }
18640
18641 ++p;
18642 }
18643 }
18644
18645 if (now_it.block_length > 1)
18646 {
5c3696f8 18647 as_tsktsk (_("IT blocks containing more than one conditional "
df9909b8
TP
18648 "instruction are performance deprecated in ARMv8-A and "
18649 "ARMv8-R"));
5a01bb1d
MGD
18650 now_it.warn_deprecated = TRUE;
18651 }
18652 }
18653
e07e6e58
NC
18654 is_last = (now_it.mask == 0x10);
18655 if (is_last)
18656 {
18657 now_it.state = OUTSIDE_IT_BLOCK;
18658 now_it.mask = 0;
18659 }
18660}
18661
18662static void
18663force_automatic_it_block_close (void)
18664{
18665 if (now_it.state == AUTOMATIC_IT_BLOCK)
18666 {
18667 close_automatic_it_block ();
18668 now_it.state = OUTSIDE_IT_BLOCK;
18669 now_it.mask = 0;
18670 }
18671}
18672
18673static int
18674in_it_block (void)
18675{
18676 if (!now_it.state_handled)
18677 handle_it_state ();
18678
18679 return now_it.state != OUTSIDE_IT_BLOCK;
18680}
18681
ff8646ee
TP
18682/* Whether OPCODE only has T32 encoding. Since this function is only used by
18683 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18684 here, hence the "known" in the function name. */
fc289b0a
TP
18685
18686static bfd_boolean
ff8646ee 18687known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18688{
18689 /* Original Thumb-1 wide instruction. */
18690 if (opcode->tencode == do_t_blx
18691 || opcode->tencode == do_t_branch23
18692 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18693 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18694 return TRUE;
18695
16a1fa25
TP
18696 /* Wide-only instruction added to ARMv8-M Baseline. */
18697 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18698 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18699 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18700 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18701 return TRUE;
18702
18703 return FALSE;
18704}
18705
18706/* Whether wide instruction variant can be used if available for a valid OPCODE
18707 in ARCH. */
18708
18709static bfd_boolean
18710t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18711{
18712 if (known_t32_only_insn (opcode))
18713 return TRUE;
18714
18715 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18716 of variant T3 of B.W is checked in do_t_branch. */
18717 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18718 && opcode->tencode == do_t_branch)
18719 return TRUE;
18720
bada4342
JW
18721 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18722 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18723 && opcode->tencode == do_t_mov_cmp
18724 /* Make sure CMP instruction is not affected. */
18725 && opcode->aencode == do_mov)
18726 return TRUE;
18727
ff8646ee
TP
18728 /* Wide instruction variants of all instructions with narrow *and* wide
18729 variants become available with ARMv6t2. Other opcodes are either
18730 narrow-only or wide-only and are thus available if OPCODE is valid. */
18731 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18732 return TRUE;
18733
18734 /* OPCODE with narrow only instruction variant or wide variant not
18735 available. */
fc289b0a
TP
18736 return FALSE;
18737}
18738
c19d1205
ZW
18739void
18740md_assemble (char *str)
b99bd4ef 18741{
c19d1205
ZW
18742 char *p = str;
18743 const struct asm_opcode * opcode;
b99bd4ef 18744
c19d1205
ZW
18745 /* Align the previous label if needed. */
18746 if (last_label_seen != NULL)
b99bd4ef 18747 {
c19d1205
ZW
18748 symbol_set_frag (last_label_seen, frag_now);
18749 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18750 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18751 }
18752
c19d1205
ZW
18753 memset (&inst, '\0', sizeof (inst));
18754 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18755
c19d1205
ZW
18756 opcode = opcode_lookup (&p);
18757 if (!opcode)
b99bd4ef 18758 {
c19d1205 18759 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18760 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18761 if (! create_register_alias (str, p)
477330fc 18762 && ! create_neon_reg_alias (str, p))
c19d1205 18763 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18764
b99bd4ef
NC
18765 return;
18766 }
18767
278df34e 18768 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18769 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18770
037e8744
JB
18771 /* The value which unconditional instructions should have in place of the
18772 condition field. */
18773 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18774
c19d1205 18775 if (thumb_mode)
b99bd4ef 18776 {
e74cfd16 18777 arm_feature_set variant;
8f06b2d8
PB
18778
18779 variant = cpu_variant;
18780 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18781 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18782 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18783 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18784 if (!opcode->tvariant
18785 || (thumb_mode == 1
18786 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18787 {
173205ca
TP
18788 if (opcode->tencode == do_t_swi)
18789 as_bad (_("SVC is not permitted on this architecture"));
18790 else
18791 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18792 return;
18793 }
c19d1205
ZW
18794 if (inst.cond != COND_ALWAYS && !unified_syntax
18795 && opcode->tencode != do_t_branch)
b99bd4ef 18796 {
c19d1205 18797 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18798 return;
18799 }
18800
fc289b0a
TP
18801 /* Two things are addressed here:
18802 1) Implicit require narrow instructions on Thumb-1.
18803 This avoids relaxation accidentally introducing Thumb-2
18804 instructions.
18805 2) Reject wide instructions in non Thumb-2 cores.
18806
18807 Only instructions with narrow and wide variants need to be handled
18808 but selecting all non wide-only instructions is easier. */
18809 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18810 && !t32_insn_ok (variant, opcode))
076d447c 18811 {
fc289b0a
TP
18812 if (inst.size_req == 0)
18813 inst.size_req = 2;
18814 else if (inst.size_req == 4)
752d5da4 18815 {
ff8646ee
TP
18816 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18817 as_bad (_("selected processor does not support 32bit wide "
18818 "variant of instruction `%s'"), str);
18819 else
18820 as_bad (_("selected processor does not support `%s' in "
18821 "Thumb-2 mode"), str);
fc289b0a 18822 return;
752d5da4 18823 }
076d447c
PB
18824 }
18825
c19d1205
ZW
18826 inst.instruction = opcode->tvalue;
18827
5be8be5d 18828 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18829 {
18830 /* Prepare the it_insn_type for those encodings that don't set
18831 it. */
18832 it_fsm_pre_encode ();
c19d1205 18833
477330fc 18834 opcode->tencode ();
e07e6e58 18835
477330fc
RM
18836 it_fsm_post_encode ();
18837 }
e27ec89e 18838
0110f2b8 18839 if (!(inst.error || inst.relax))
b99bd4ef 18840 {
9c2799c2 18841 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18842 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18843 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18844 {
c19d1205 18845 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18846 return;
18847 }
18848 }
076d447c
PB
18849
18850 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18851 instruction. */
9c2799c2 18852 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18853
e74cfd16
PB
18854 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18855 *opcode->tvariant);
ee065d83 18856 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18857 set those bits when Thumb-2 32-bit instructions are seen. The impact
18858 of relaxable instructions will be considered later after we finish all
18859 relaxation. */
ff8646ee
TP
18860 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18861 variant = arm_arch_none;
18862 else
18863 variant = cpu_variant;
18864 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18865 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18866 arm_ext_v6t2);
cd000bff 18867
88714cb8
DG
18868 check_neon_suffixes;
18869
cd000bff 18870 if (!inst.error)
c877a2f2
NC
18871 {
18872 mapping_state (MAP_THUMB);
18873 }
c19d1205 18874 }
3e9e4fcf 18875 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18876 {
845b51d6
PB
18877 bfd_boolean is_bx;
18878
18879 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18880 is_bx = (opcode->aencode == do_bx);
18881
c19d1205 18882 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18883 if (!(is_bx && fix_v4bx)
18884 && !(opcode->avariant &&
18885 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18886 {
84b52b66 18887 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18888 return;
b99bd4ef 18889 }
c19d1205 18890 if (inst.size_req)
b99bd4ef 18891 {
c19d1205
ZW
18892 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18893 return;
b99bd4ef
NC
18894 }
18895
c19d1205
ZW
18896 inst.instruction = opcode->avalue;
18897 if (opcode->tag == OT_unconditionalF)
eff0bc54 18898 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18899 else
18900 inst.instruction |= inst.cond << 28;
18901 inst.size = INSN_SIZE;
5be8be5d 18902 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18903 {
18904 it_fsm_pre_encode ();
18905 opcode->aencode ();
18906 it_fsm_post_encode ();
18907 }
ee065d83 18908 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18909 on a hypothetical non-thumb v5 core. */
845b51d6 18910 if (is_bx)
e74cfd16 18911 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18912 else
e74cfd16
PB
18913 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18914 *opcode->avariant);
88714cb8
DG
18915
18916 check_neon_suffixes;
18917
cd000bff 18918 if (!inst.error)
c877a2f2
NC
18919 {
18920 mapping_state (MAP_ARM);
18921 }
b99bd4ef 18922 }
3e9e4fcf
JB
18923 else
18924 {
18925 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18926 "-- `%s'"), str);
18927 return;
18928 }
c19d1205
ZW
18929 output_inst (str);
18930}
b99bd4ef 18931
e07e6e58
NC
18932static void
18933check_it_blocks_finished (void)
18934{
18935#ifdef OBJ_ELF
18936 asection *sect;
18937
18938 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18939 if (seg_info (sect)->tc_segment_info_data.current_it.state
18940 == MANUAL_IT_BLOCK)
18941 {
18942 as_warn (_("section '%s' finished with an open IT block."),
18943 sect->name);
18944 }
18945#else
18946 if (now_it.state == MANUAL_IT_BLOCK)
18947 as_warn (_("file finished with an open IT block."));
18948#endif
18949}
18950
c19d1205
ZW
18951/* Various frobbings of labels and their addresses. */
18952
18953void
18954arm_start_line_hook (void)
18955{
18956 last_label_seen = NULL;
b99bd4ef
NC
18957}
18958
c19d1205
ZW
18959void
18960arm_frob_label (symbolS * sym)
b99bd4ef 18961{
c19d1205 18962 last_label_seen = sym;
b99bd4ef 18963
c19d1205 18964 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18965
c19d1205
ZW
18966#if defined OBJ_COFF || defined OBJ_ELF
18967 ARM_SET_INTERWORK (sym, support_interwork);
18968#endif
b99bd4ef 18969
e07e6e58
NC
18970 force_automatic_it_block_close ();
18971
5f4273c7 18972 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18973 as Thumb functions. This is because these labels, whilst
18974 they exist inside Thumb code, are not the entry points for
18975 possible ARM->Thumb calls. Also, these labels can be used
18976 as part of a computed goto or switch statement. eg gcc
18977 can generate code that looks like this:
b99bd4ef 18978
c19d1205
ZW
18979 ldr r2, [pc, .Laaa]
18980 lsl r3, r3, #2
18981 ldr r2, [r3, r2]
18982 mov pc, r2
b99bd4ef 18983
c19d1205
ZW
18984 .Lbbb: .word .Lxxx
18985 .Lccc: .word .Lyyy
18986 ..etc...
18987 .Laaa: .word Lbbb
b99bd4ef 18988
c19d1205
ZW
18989 The first instruction loads the address of the jump table.
18990 The second instruction converts a table index into a byte offset.
18991 The third instruction gets the jump address out of the table.
18992 The fourth instruction performs the jump.
b99bd4ef 18993
c19d1205
ZW
18994 If the address stored at .Laaa is that of a symbol which has the
18995 Thumb_Func bit set, then the linker will arrange for this address
18996 to have the bottom bit set, which in turn would mean that the
18997 address computation performed by the third instruction would end
18998 up with the bottom bit set. Since the ARM is capable of unaligned
18999 word loads, the instruction would then load the incorrect address
19000 out of the jump table, and chaos would ensue. */
19001 if (label_is_thumb_function_name
19002 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
19003 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 19004 {
c19d1205
ZW
19005 /* When the address of a Thumb function is taken the bottom
19006 bit of that address should be set. This will allow
19007 interworking between Arm and Thumb functions to work
19008 correctly. */
b99bd4ef 19009
c19d1205 19010 THUMB_SET_FUNC (sym, 1);
b99bd4ef 19011
c19d1205 19012 label_is_thumb_function_name = FALSE;
b99bd4ef 19013 }
07a53e5c 19014
07a53e5c 19015 dwarf2_emit_label (sym);
b99bd4ef
NC
19016}
19017
c921be7d 19018bfd_boolean
c19d1205 19019arm_data_in_code (void)
b99bd4ef 19020{
c19d1205 19021 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 19022 {
c19d1205
ZW
19023 *input_line_pointer = '/';
19024 input_line_pointer += 5;
19025 *input_line_pointer = 0;
c921be7d 19026 return TRUE;
b99bd4ef
NC
19027 }
19028
c921be7d 19029 return FALSE;
b99bd4ef
NC
19030}
19031
c19d1205
ZW
19032char *
19033arm_canonicalize_symbol_name (char * name)
b99bd4ef 19034{
c19d1205 19035 int len;
b99bd4ef 19036
c19d1205
ZW
19037 if (thumb_mode && (len = strlen (name)) > 5
19038 && streq (name + len - 5, "/data"))
19039 *(name + len - 5) = 0;
b99bd4ef 19040
c19d1205 19041 return name;
b99bd4ef 19042}
c19d1205
ZW
19043\f
19044/* Table of all register names defined by default. The user can
19045 define additional names with .req. Note that all register names
19046 should appear in both upper and lowercase variants. Some registers
19047 also have mixed-case names. */
b99bd4ef 19048
dcbf9037 19049#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 19050#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 19051#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
19052#define REGSET(p,t) \
19053 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
19054 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
19055 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
19056 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
19057#define REGSETH(p,t) \
19058 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
19059 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
19060 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
19061 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
19062#define REGSET2(p,t) \
19063 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
19064 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
19065 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
19066 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
19067#define SPLRBANK(base,bank,t) \
19068 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
19069 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
19070 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
19071 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
19072 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
19073 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 19074
c19d1205 19075static const struct reg_entry reg_names[] =
7ed4c4c5 19076{
c19d1205
ZW
19077 /* ARM integer registers. */
19078 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 19079
c19d1205
ZW
19080 /* ATPCS synonyms. */
19081 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
19082 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
19083 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 19084
c19d1205
ZW
19085 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
19086 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
19087 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 19088
c19d1205
ZW
19089 /* Well-known aliases. */
19090 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
19091 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
19092
19093 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
19094 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
19095
19096 /* Coprocessor numbers. */
19097 REGSET(p, CP), REGSET(P, CP),
19098
19099 /* Coprocessor register numbers. The "cr" variants are for backward
19100 compatibility. */
19101 REGSET(c, CN), REGSET(C, CN),
19102 REGSET(cr, CN), REGSET(CR, CN),
19103
90ec0d68
MGD
19104 /* ARM banked registers. */
19105 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
19106 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
19107 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
19108 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
19109 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
19110 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
19111 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
19112
19113 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
19114 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
19115 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
19116 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
19117 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 19118 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
19119 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
19120 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
19121
19122 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
19123 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
19124 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
19125 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
19126 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
19127 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
19128 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 19129 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
19130 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
19131
c19d1205
ZW
19132 /* FPA registers. */
19133 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
19134 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
19135
19136 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
19137 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
19138
19139 /* VFP SP registers. */
5287ad62
JB
19140 REGSET(s,VFS), REGSET(S,VFS),
19141 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
19142
19143 /* VFP DP Registers. */
5287ad62
JB
19144 REGSET(d,VFD), REGSET(D,VFD),
19145 /* Extra Neon DP registers. */
19146 REGSETH(d,VFD), REGSETH(D,VFD),
19147
19148 /* Neon QP registers. */
19149 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
19150
19151 /* VFP control registers. */
19152 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
19153 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
19154 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
19155 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
19156 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
19157 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 19158 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
c19d1205
ZW
19159
19160 /* Maverick DSP coprocessor registers. */
19161 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
19162 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
19163
19164 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
19165 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
19166 REGDEF(dspsc,0,DSPSC),
19167
19168 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
19169 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
19170 REGDEF(DSPSC,0,DSPSC),
19171
19172 /* iWMMXt data registers - p0, c0-15. */
19173 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
19174
19175 /* iWMMXt control registers - p1, c0-3. */
19176 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
19177 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
19178 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
19179 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
19180
19181 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
19182 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
19183 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
19184 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
19185 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
19186
19187 /* XScale accumulator registers. */
19188 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
19189};
19190#undef REGDEF
19191#undef REGNUM
19192#undef REGSET
7ed4c4c5 19193
c19d1205
ZW
19194/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
19195 within psr_required_here. */
19196static const struct asm_psr psrs[] =
19197{
19198 /* Backward compatibility notation. Note that "all" is no longer
19199 truly all possible PSR bits. */
19200 {"all", PSR_c | PSR_f},
19201 {"flg", PSR_f},
19202 {"ctl", PSR_c},
19203
19204 /* Individual flags. */
19205 {"f", PSR_f},
19206 {"c", PSR_c},
19207 {"x", PSR_x},
19208 {"s", PSR_s},
59b42a0d 19209
c19d1205
ZW
19210 /* Combinations of flags. */
19211 {"fs", PSR_f | PSR_s},
19212 {"fx", PSR_f | PSR_x},
19213 {"fc", PSR_f | PSR_c},
19214 {"sf", PSR_s | PSR_f},
19215 {"sx", PSR_s | PSR_x},
19216 {"sc", PSR_s | PSR_c},
19217 {"xf", PSR_x | PSR_f},
19218 {"xs", PSR_x | PSR_s},
19219 {"xc", PSR_x | PSR_c},
19220 {"cf", PSR_c | PSR_f},
19221 {"cs", PSR_c | PSR_s},
19222 {"cx", PSR_c | PSR_x},
19223 {"fsx", PSR_f | PSR_s | PSR_x},
19224 {"fsc", PSR_f | PSR_s | PSR_c},
19225 {"fxs", PSR_f | PSR_x | PSR_s},
19226 {"fxc", PSR_f | PSR_x | PSR_c},
19227 {"fcs", PSR_f | PSR_c | PSR_s},
19228 {"fcx", PSR_f | PSR_c | PSR_x},
19229 {"sfx", PSR_s | PSR_f | PSR_x},
19230 {"sfc", PSR_s | PSR_f | PSR_c},
19231 {"sxf", PSR_s | PSR_x | PSR_f},
19232 {"sxc", PSR_s | PSR_x | PSR_c},
19233 {"scf", PSR_s | PSR_c | PSR_f},
19234 {"scx", PSR_s | PSR_c | PSR_x},
19235 {"xfs", PSR_x | PSR_f | PSR_s},
19236 {"xfc", PSR_x | PSR_f | PSR_c},
19237 {"xsf", PSR_x | PSR_s | PSR_f},
19238 {"xsc", PSR_x | PSR_s | PSR_c},
19239 {"xcf", PSR_x | PSR_c | PSR_f},
19240 {"xcs", PSR_x | PSR_c | PSR_s},
19241 {"cfs", PSR_c | PSR_f | PSR_s},
19242 {"cfx", PSR_c | PSR_f | PSR_x},
19243 {"csf", PSR_c | PSR_s | PSR_f},
19244 {"csx", PSR_c | PSR_s | PSR_x},
19245 {"cxf", PSR_c | PSR_x | PSR_f},
19246 {"cxs", PSR_c | PSR_x | PSR_s},
19247 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
19248 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
19249 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
19250 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
19251 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
19252 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
19253 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
19254 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
19255 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
19256 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
19257 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
19258 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
19259 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
19260 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
19261 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
19262 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
19263 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
19264 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
19265 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
19266 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
19267 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
19268 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
19269 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
19270 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
19271};
19272
62b3e311
PB
19273/* Table of V7M psr names. */
19274static const struct asm_psr v7m_psrs[] =
19275{
1a336194
TP
19276 {"apsr", 0x0 }, {"APSR", 0x0 },
19277 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
19278 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
19279 {"psr", 0x3 }, {"PSR", 0x3 },
19280 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
19281 {"ipsr", 0x5 }, {"IPSR", 0x5 },
19282 {"epsr", 0x6 }, {"EPSR", 0x6 },
19283 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
19284 {"msp", 0x8 }, {"MSP", 0x8 },
19285 {"psp", 0x9 }, {"PSP", 0x9 },
19286 {"msplim", 0xa }, {"MSPLIM", 0xa },
19287 {"psplim", 0xb }, {"PSPLIM", 0xb },
19288 {"primask", 0x10}, {"PRIMASK", 0x10},
19289 {"basepri", 0x11}, {"BASEPRI", 0x11},
19290 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
19291 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
19292 {"control", 0x14}, {"CONTROL", 0x14},
19293 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
19294 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
19295 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
19296 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
19297 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
19298 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
19299 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
19300 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
19301 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
19302};
19303
c19d1205
ZW
19304/* Table of all shift-in-operand names. */
19305static const struct asm_shift_name shift_names [] =
b99bd4ef 19306{
c19d1205
ZW
19307 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
19308 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
19309 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
19310 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
19311 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
19312 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
19313};
b99bd4ef 19314
c19d1205
ZW
19315/* Table of all explicit relocation names. */
19316#ifdef OBJ_ELF
19317static struct reloc_entry reloc_names[] =
19318{
19319 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
19320 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
19321 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
19322 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
19323 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
19324 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
19325 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
19326 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
19327 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
19328 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 19329 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
19330 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
19331 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 19332 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 19333 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 19334 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 19335 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
188fd7ae
CL
19336 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
19337 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
19338 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
19339 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
19340 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
19341 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
5c5a4843
CL
19342 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
19343 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
19344 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
19345 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
c19d1205
ZW
19346};
19347#endif
b99bd4ef 19348
c19d1205
ZW
19349/* Table of all conditional affixes. 0xF is not defined as a condition code. */
19350static const struct asm_cond conds[] =
19351{
19352 {"eq", 0x0},
19353 {"ne", 0x1},
19354 {"cs", 0x2}, {"hs", 0x2},
19355 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
19356 {"mi", 0x4},
19357 {"pl", 0x5},
19358 {"vs", 0x6},
19359 {"vc", 0x7},
19360 {"hi", 0x8},
19361 {"ls", 0x9},
19362 {"ge", 0xa},
19363 {"lt", 0xb},
19364 {"gt", 0xc},
19365 {"le", 0xd},
19366 {"al", 0xe}
19367};
bfae80f2 19368
e797f7e0 19369#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
19370 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19371 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 19372
62b3e311
PB
19373static struct asm_barrier_opt barrier_opt_names[] =
19374{
e797f7e0
MGD
19375 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19376 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19377 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19378 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19379 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19380 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19381 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19382 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19383 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19384 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19385 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19386 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19387 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19388 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19389 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19390 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
19391};
19392
e797f7e0
MGD
19393#undef UL_BARRIER
19394
c19d1205
ZW
19395/* Table of ARM-format instructions. */
19396
19397/* Macros for gluing together operand strings. N.B. In all cases
19398 other than OPS0, the trailing OP_stop comes from default
19399 zero-initialization of the unspecified elements of the array. */
19400#define OPS0() { OP_stop, }
19401#define OPS1(a) { OP_##a, }
19402#define OPS2(a,b) { OP_##a,OP_##b, }
19403#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19404#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19405#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19406#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19407
5be8be5d
DG
19408/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19409 This is useful when mixing operands for ARM and THUMB, i.e. using the
19410 MIX_ARM_THUMB_OPERANDS macro.
19411 In order to use these macros, prefix the number of operands with _
19412 e.g. _3. */
19413#define OPS_1(a) { a, }
19414#define OPS_2(a,b) { a,b, }
19415#define OPS_3(a,b,c) { a,b,c, }
19416#define OPS_4(a,b,c,d) { a,b,c,d, }
19417#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19418#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19419
c19d1205
ZW
19420/* These macros abstract out the exact format of the mnemonic table and
19421 save some repeated characters. */
19422
19423/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19424#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19425 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 19426 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19427
19428/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19429 a T_MNEM_xyz enumerator. */
19430#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19431 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19432#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19433 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
19434
19435/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19436 infix after the third character. */
19437#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 19438 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 19439 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 19440#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 19441 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 19442 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19443#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19444 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 19445#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19446 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19447#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19448 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 19449#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19450 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 19451
c19d1205 19452/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
19453 field is still 0xE. Many of the Thumb variants can be executed
19454 conditionally, so this is checked separately. */
c19d1205 19455#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19456 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19457 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19458
dd5181d5
KT
19459/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19460 Used by mnemonics that have very minimal differences in the encoding for
19461 ARM and Thumb variants and can be handled in a common function. */
19462#define TUEc(mnem, op, top, nops, ops, en) \
19463 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19464 THUMB_VARIANT, do_##en, do_##en }
19465
c19d1205
ZW
19466/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19467 condition code field. */
19468#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 19469 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19470 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19471
19472/* ARM-only variants of all the above. */
6a86118a 19473#define CE(mnem, op, nops, ops, ae) \
21d799b5 19474 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
19475
19476#define C3(mnem, op, nops, ops, ae) \
19477 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19478
cf3cf39d
TP
19479/* Thumb-only variants of TCE and TUE. */
19480#define ToC(mnem, top, nops, ops, te) \
19481 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
19482 do_##te }
cf3cf39d
TP
19483
19484#define ToU(mnem, top, nops, ops, te) \
19485 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
19486 NULL, do_##te }
cf3cf39d 19487
e3cb604e
PB
19488/* Legacy mnemonics that always have conditional infix after the third
19489 character. */
19490#define CL(mnem, op, nops, ops, ae) \
21d799b5 19491 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19492 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19493
8f06b2d8
PB
19494/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19495#define cCE(mnem, op, nops, ops, ae) \
21d799b5 19496 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19497
e3cb604e
PB
19498/* Legacy coprocessor instructions where conditional infix and conditional
19499 suffix are ambiguous. For consistency this includes all FPA instructions,
19500 not just the potentially ambiguous ones. */
19501#define cCL(mnem, op, nops, ops, ae) \
21d799b5 19502 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19503 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19504
19505/* Coprocessor, takes either a suffix or a position-3 infix
19506 (for an FPA corner case). */
19507#define C3E(mnem, op, nops, ops, ae) \
21d799b5 19508 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19509 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19510
6a86118a 19511#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19512 { m1 #m2 m3, OPS##nops ops, \
19513 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19514 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19515
19516#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19517 xCM_ (m1, , m2, op, nops, ops, ae), \
19518 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19519 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19520 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19521 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19522 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19523 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19524 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19525 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19526 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19527 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19528 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19529 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19530 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19531 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19532 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19533 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19534 xCM_ (m1, le, m2, op, nops, ops, ae), \
19535 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19536
19537#define UE(mnem, op, nops, ops, ae) \
19538 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19539
19540#define UF(mnem, op, nops, ops, ae) \
19541 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19542
5287ad62
JB
19543/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19544 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19545 use the same encoding function for each. */
19546#define NUF(mnem, op, nops, ops, enc) \
19547 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19548 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19549
19550/* Neon data processing, version which indirects through neon_enc_tab for
19551 the various overloaded versions of opcodes. */
19552#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19553 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19554 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19555
19556/* Neon insn with conditional suffix for the ARM version, non-overloaded
19557 version. */
037e8744
JB
19558#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19559 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19560 THUMB_VARIANT, do_##enc, do_##enc }
19561
037e8744 19562#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19563 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19564
19565#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19566 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19567
5287ad62 19568/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19569#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19570 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19571 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19572
037e8744 19573#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19574 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19575
19576#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19577 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19578
c19d1205
ZW
19579#define do_0 0
19580
c19d1205 19581static const struct asm_opcode insns[] =
bfae80f2 19582{
74db7efb
NC
19583#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19584#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19585 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19586 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19587 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19588 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19589 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19590 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19591 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19592 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19593 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19594 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19595 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19596 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19597 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19598 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19599 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19600 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19601
19602 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19603 for setting PSR flag bits. They are obsolete in V6 and do not
19604 have Thumb equivalents. */
21d799b5
NC
19605 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19606 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19607 CL("tstp", 110f000, 2, (RR, SH), cmp),
19608 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19609 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19610 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19611 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19612 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19613 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19614
19615 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19616 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19617 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19618 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19619
19620 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19621 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19622 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19623 OP_RRnpc),
19624 OP_ADDRGLDR),ldst, t_ldst),
19625 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19626
19627 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19628 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19629 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19630 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19631 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19632 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19633
21d799b5
NC
19634 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19635 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19636
c19d1205 19637 /* Pseudo ops. */
21d799b5 19638 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19639 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19640 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19641 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19642
19643 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19644 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19645 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19646 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19647 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19648 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19649 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19650 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19651 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19652 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19653 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19654 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19655 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19656
16a4cf17 19657 /* These may simplify to neg. */
21d799b5
NC
19658 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19659 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19660
173205ca
TP
19661#undef THUMB_VARIANT
19662#define THUMB_VARIANT & arm_ext_os
19663
19664 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19665 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19666
c921be7d
NC
19667#undef THUMB_VARIANT
19668#define THUMB_VARIANT & arm_ext_v6
19669
21d799b5 19670 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19671
19672 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19673#undef THUMB_VARIANT
19674#define THUMB_VARIANT & arm_ext_v6t2
19675
21d799b5
NC
19676 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19677 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19678 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19679
5be8be5d
DG
19680 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19681 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19682 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19683 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19684
21d799b5
NC
19685 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19686 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19687
21d799b5
NC
19688 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19689 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19690
19691 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19692 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19693 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19694
19695 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19696 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19697 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19698 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19699 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19700 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19701 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19702 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19703
c921be7d
NC
19704#undef ARM_VARIANT
19705#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19706#undef THUMB_VARIANT
19707#define THUMB_VARIANT & arm_ext_v4t
19708
21d799b5
NC
19709 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19710 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19711
c921be7d
NC
19712#undef THUMB_VARIANT
19713#define THUMB_VARIANT & arm_ext_v6t2
19714
21d799b5 19715 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19716 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19717
19718 /* Generic coprocessor instructions. */
21d799b5
NC
19719 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19720 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19721 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19722 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19723 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19724 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19725 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19726
c921be7d
NC
19727#undef ARM_VARIANT
19728#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19729
21d799b5 19730 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19731 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19732
c921be7d
NC
19733#undef ARM_VARIANT
19734#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19735#undef THUMB_VARIANT
19736#define THUMB_VARIANT & arm_ext_msr
19737
d2cd1205
JB
19738 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19739 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19740
c921be7d
NC
19741#undef ARM_VARIANT
19742#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19743#undef THUMB_VARIANT
19744#define THUMB_VARIANT & arm_ext_v6t2
19745
21d799b5
NC
19746 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19747 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19748 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19749 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19750 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19751 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19752 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19753 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19754
c921be7d
NC
19755#undef ARM_VARIANT
19756#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19757#undef THUMB_VARIANT
19758#define THUMB_VARIANT & arm_ext_v4t
19759
5be8be5d
DG
19760 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19761 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19762 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19763 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19764 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19765 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19766
c921be7d
NC
19767#undef ARM_VARIANT
19768#define ARM_VARIANT & arm_ext_v4t_5
19769
c19d1205
ZW
19770 /* ARM Architecture 4T. */
19771 /* Note: bx (and blx) are required on V5, even if the processor does
19772 not support Thumb. */
21d799b5 19773 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19774
c921be7d
NC
19775#undef ARM_VARIANT
19776#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19777#undef THUMB_VARIANT
19778#define THUMB_VARIANT & arm_ext_v5t
19779
c19d1205
ZW
19780 /* Note: blx has 2 variants; the .value coded here is for
19781 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19782 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19783 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19784
c921be7d
NC
19785#undef THUMB_VARIANT
19786#define THUMB_VARIANT & arm_ext_v6t2
19787
21d799b5
NC
19788 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19789 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19790 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19791 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19792 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19793 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19794 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19795 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19796
c921be7d 19797#undef ARM_VARIANT
74db7efb
NC
19798#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19799#undef THUMB_VARIANT
19800#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19801
21d799b5
NC
19802 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19803 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19804 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19805 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19806
21d799b5
NC
19807 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19808 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19809
21d799b5
NC
19810 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19811 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19812 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19813 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19814
21d799b5
NC
19815 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19816 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19817 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19818 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19819
21d799b5
NC
19820 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19821 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19822
03ee1b7f
NC
19823 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19824 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19825 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19826 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19827
c921be7d 19828#undef ARM_VARIANT
74db7efb
NC
19829#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19830#undef THUMB_VARIANT
19831#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19832
21d799b5 19833 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19834 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19835 ldrd, t_ldstd),
19836 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19837 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19838
21d799b5
NC
19839 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19840 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19841
c921be7d
NC
19842#undef ARM_VARIANT
19843#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19844
21d799b5 19845 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19846
c921be7d
NC
19847#undef ARM_VARIANT
19848#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19849#undef THUMB_VARIANT
19850#define THUMB_VARIANT & arm_ext_v6
19851
21d799b5
NC
19852 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19853 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19854 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19855 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19856 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19857 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19858 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19859 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19860 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19861 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19862
c921be7d 19863#undef THUMB_VARIANT
ff8646ee 19864#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19865
5be8be5d
DG
19866 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19867 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19868 strex, t_strex),
ff8646ee
TP
19869#undef THUMB_VARIANT
19870#define THUMB_VARIANT & arm_ext_v6t2
19871
21d799b5
NC
19872 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19873 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19874
21d799b5
NC
19875 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19876 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19877
9e3c6df6 19878/* ARM V6 not included in V7M. */
c921be7d
NC
19879#undef THUMB_VARIANT
19880#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19881 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19882 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19883 UF(rfeib, 9900a00, 1, (RRw), rfe),
19884 UF(rfeda, 8100a00, 1, (RRw), rfe),
19885 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19886 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19887 UF(rfefa, 8100a00, 1, (RRw), rfe),
19888 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19889 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19890 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19891 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19892 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19893 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19894 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19895 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19896 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19897 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19898 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19899 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19900
9e3c6df6
PB
19901/* ARM V6 not included in V7M (eg. integer SIMD). */
19902#undef THUMB_VARIANT
19903#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19904 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19905 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19906 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19907 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19908 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19909 /* Old name for QASX. */
74db7efb 19910 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19911 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19912 /* Old name for QSAX. */
74db7efb 19913 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19914 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19915 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19916 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19917 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19918 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19919 /* Old name for SASX. */
74db7efb 19920 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19921 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19922 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19923 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19924 /* Old name for SHASX. */
21d799b5 19925 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19926 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19927 /* Old name for SHSAX. */
21d799b5
NC
19928 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19929 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19930 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19931 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19932 /* Old name for SSAX. */
74db7efb 19933 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19934 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19935 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19936 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19937 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19938 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19939 /* Old name for UASX. */
74db7efb 19940 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19941 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19942 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19943 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19944 /* Old name for UHASX. */
21d799b5
NC
19945 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19946 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19947 /* Old name for UHSAX. */
21d799b5
NC
19948 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19949 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19950 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19951 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19952 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19953 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19954 /* Old name for UQASX. */
21d799b5
NC
19955 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19956 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19957 /* Old name for UQSAX. */
21d799b5
NC
19958 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19959 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19960 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19961 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19962 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19963 /* Old name for USAX. */
74db7efb 19964 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19965 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19966 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19967 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19968 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19969 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19970 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19971 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19972 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19973 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19974 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19975 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19976 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19977 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19978 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19979 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19980 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19981 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19982 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19983 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19984 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19985 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19986 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19987 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19988 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19989 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19990 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19991 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19992 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19993 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19994 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19995 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19996 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19997 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19998
c921be7d 19999#undef ARM_VARIANT
55e8aae7 20000#define ARM_VARIANT & arm_ext_v6k_v6t2
c921be7d 20001#undef THUMB_VARIANT
55e8aae7 20002#define THUMB_VARIANT & arm_ext_v6k_v6t2
c921be7d 20003
21d799b5
NC
20004 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
20005 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
20006 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
20007 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 20008
c921be7d
NC
20009#undef THUMB_VARIANT
20010#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
20011 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
20012 ldrexd, t_ldrexd),
20013 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
20014 RRnpcb), strexd, t_strexd),
ebdca51a 20015
c921be7d 20016#undef THUMB_VARIANT
ff8646ee 20017#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
20018 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
20019 rd_rn, rd_rn),
20020 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
20021 rd_rn, rd_rn),
20022 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 20023 strex, t_strexbh),
5be8be5d 20024 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 20025 strex, t_strexbh),
21d799b5 20026 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 20027
c921be7d 20028#undef ARM_VARIANT
f4c65163 20029#define ARM_VARIANT & arm_ext_sec
74db7efb 20030#undef THUMB_VARIANT
f4c65163 20031#define THUMB_VARIANT & arm_ext_sec
c921be7d 20032
21d799b5 20033 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 20034
90ec0d68
MGD
20035#undef ARM_VARIANT
20036#define ARM_VARIANT & arm_ext_virt
20037#undef THUMB_VARIANT
20038#define THUMB_VARIANT & arm_ext_virt
20039
20040 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
20041 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
20042
ddfded2f
MW
20043#undef ARM_VARIANT
20044#define ARM_VARIANT & arm_ext_pan
20045#undef THUMB_VARIANT
20046#define THUMB_VARIANT & arm_ext_pan
20047
20048 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
20049
c921be7d 20050#undef ARM_VARIANT
74db7efb 20051#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
20052#undef THUMB_VARIANT
20053#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 20054
21d799b5
NC
20055 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
20056 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
20057 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
20058 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 20059
21d799b5 20060 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 20061 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 20062
5be8be5d
DG
20063 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20064 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20065 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20066 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 20067
91d8b670
JG
20068#undef ARM_VARIANT
20069#define ARM_VARIANT & arm_ext_v3
20070#undef THUMB_VARIANT
20071#define THUMB_VARIANT & arm_ext_v6t2
20072
20073 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
c597cc3d
SD
20074 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
20075 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
91d8b670
JG
20076
20077#undef ARM_VARIANT
20078#define ARM_VARIANT & arm_ext_v6t2
ff8646ee
TP
20079#undef THUMB_VARIANT
20080#define THUMB_VARIANT & arm_ext_v6t2_v8m
20081 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
20082 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
20083
bf3eeda7 20084 /* Thumb-only instructions. */
74db7efb 20085#undef ARM_VARIANT
bf3eeda7
NS
20086#define ARM_VARIANT NULL
20087 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
20088 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
20089
20090 /* ARM does not really have an IT instruction, so always allow it.
20091 The opcode is copied from Thumb in order to allow warnings in
20092 -mimplicit-it=[never | arm] modes. */
20093#undef ARM_VARIANT
20094#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
20095#undef THUMB_VARIANT
20096#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 20097
21d799b5
NC
20098 TUE("it", bf08, bf08, 1, (COND), it, t_it),
20099 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
20100 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
20101 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
20102 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
20103 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
20104 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
20105 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
20106 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
20107 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
20108 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
20109 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
20110 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
20111 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
20112 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 20113 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
20114 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
20115 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 20116
92e90b6e 20117 /* Thumb2 only instructions. */
c921be7d
NC
20118#undef ARM_VARIANT
20119#define ARM_VARIANT NULL
92e90b6e 20120
21d799b5
NC
20121 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20122 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20123 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
20124 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
20125 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
20126 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 20127
eea54501
MGD
20128 /* Hardware division instructions. */
20129#undef ARM_VARIANT
20130#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
20131#undef THUMB_VARIANT
20132#define THUMB_VARIANT & arm_ext_div
20133
eea54501
MGD
20134 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
20135 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 20136
7e806470 20137 /* ARM V6M/V7 instructions. */
c921be7d
NC
20138#undef ARM_VARIANT
20139#define ARM_VARIANT & arm_ext_barrier
20140#undef THUMB_VARIANT
20141#define THUMB_VARIANT & arm_ext_barrier
20142
ccb84d65
JB
20143 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
20144 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
20145 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 20146
62b3e311 20147 /* ARM V7 instructions. */
c921be7d
NC
20148#undef ARM_VARIANT
20149#define ARM_VARIANT & arm_ext_v7
20150#undef THUMB_VARIANT
20151#define THUMB_VARIANT & arm_ext_v7
20152
21d799b5
NC
20153 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
20154 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 20155
74db7efb 20156#undef ARM_VARIANT
60e5ef9f 20157#define ARM_VARIANT & arm_ext_mp
74db7efb 20158#undef THUMB_VARIANT
60e5ef9f
MGD
20159#define THUMB_VARIANT & arm_ext_mp
20160
20161 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
20162
53c4b28b
MGD
20163 /* AArchv8 instructions. */
20164#undef ARM_VARIANT
20165#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
20166
20167/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 20168#undef THUMB_VARIANT
4ed7ed8d 20169#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 20170
4ed7ed8d
TP
20171 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20172 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20173 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20174 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20175 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20176 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 20177 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
20178 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
20179 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20180 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
20181 stlex, t_stlex),
4b8c8c02
RE
20182 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
20183 stlex, t_stlex),
20184 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
20185 stlex, t_stlex),
4ed7ed8d
TP
20186#undef THUMB_VARIANT
20187#define THUMB_VARIANT & arm_ext_v8
53c4b28b 20188
4ed7ed8d 20189 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
4ed7ed8d
TP
20190 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
20191 ldrexd, t_ldrexd),
20192 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
20193 strexd, t_strexd),
f7dd2fb2
TC
20194
20195/* Defined in V8 but is in undefined encoding space for earlier
20196 architectures. However earlier architectures are required to treat
20197 this instuction as a semihosting trap as well. Hence while not explicitly
20198 defined as such, it is in fact correct to define the instruction for all
20199 architectures. */
20200#undef THUMB_VARIANT
20201#define THUMB_VARIANT & arm_ext_v1
20202#undef ARM_VARIANT
20203#define ARM_VARIANT & arm_ext_v1
20204 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
20205
8884b720 20206 /* ARMv8 T32 only. */
74db7efb 20207#undef ARM_VARIANT
b79f7053
MGD
20208#define ARM_VARIANT NULL
20209 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
20210 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
20211 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
20212
33399f07
MGD
20213 /* FP for ARMv8. */
20214#undef ARM_VARIANT
a715796b 20215#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 20216#undef THUMB_VARIANT
a715796b 20217#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
20218
20219 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
20220 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
20221 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
20222 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
20223 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
20224 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
20225 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
20226 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
20227 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
20228 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
20229 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
20230 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
20231 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
20232 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
20233 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
20234 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
20235 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 20236
91ff7894
MGD
20237 /* Crypto v1 extensions. */
20238#undef ARM_VARIANT
20239#define ARM_VARIANT & fpu_crypto_ext_armv8
20240#undef THUMB_VARIANT
20241#define THUMB_VARIANT & fpu_crypto_ext_armv8
20242
20243 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
20244 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
20245 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
20246 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
20247 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
20248 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
20249 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
20250 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
20251 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
20252 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
20253 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
20254 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
20255 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
20256 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 20257
dd5181d5 20258#undef ARM_VARIANT
74db7efb 20259#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
20260#undef THUMB_VARIANT
20261#define THUMB_VARIANT & crc_ext_armv8
20262 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
20263 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
20264 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
20265 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
20266 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
20267 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
20268
105bde57
MW
20269 /* ARMv8.2 RAS extension. */
20270#undef ARM_VARIANT
4d1464f2 20271#define ARM_VARIANT & arm_ext_ras
105bde57 20272#undef THUMB_VARIANT
4d1464f2 20273#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
20274 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
20275
49e8a725
SN
20276#undef ARM_VARIANT
20277#define ARM_VARIANT & arm_ext_v8_3
20278#undef THUMB_VARIANT
20279#define THUMB_VARIANT & arm_ext_v8_3
20280 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
20281 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
20282 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 20283
c604a79a
JW
20284#undef ARM_VARIANT
20285#define ARM_VARIANT & fpu_neon_ext_dotprod
20286#undef THUMB_VARIANT
20287#define THUMB_VARIANT & fpu_neon_ext_dotprod
20288 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
20289 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
20290
c921be7d
NC
20291#undef ARM_VARIANT
20292#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
20293#undef THUMB_VARIANT
20294#define THUMB_VARIANT NULL
c921be7d 20295
21d799b5
NC
20296 cCE("wfs", e200110, 1, (RR), rd),
20297 cCE("rfs", e300110, 1, (RR), rd),
20298 cCE("wfc", e400110, 1, (RR), rd),
20299 cCE("rfc", e500110, 1, (RR), rd),
20300
20301 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
20302 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
20303 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
20304 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
20305
20306 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
20307 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
20308 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
20309 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
20310
20311 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
20312 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
20313 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
20314 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
20315 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
20316 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
20317 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
20318 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
20319 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
20320 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
20321 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
20322 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
20323
20324 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
20325 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
20326 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
20327 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
20328 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
20329 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
20330 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
20331 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
20332 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
20333 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
20334 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
20335 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
20336
20337 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
20338 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
20339 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
20340 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
20341 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
20342 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
20343 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
20344 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
20345 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
20346 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
20347 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
20348 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
20349
20350 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
20351 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
20352 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
20353 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
20354 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
20355 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
20356 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
20357 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
20358 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
20359 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
20360 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
20361 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
20362
20363 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
20364 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
20365 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
20366 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
20367 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
20368 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
20369 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
20370 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
20371 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
20372 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
20373 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
20374 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
20375
20376 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
20377 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
20378 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
20379 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
20380 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
20381 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
20382 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
20383 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
20384 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
20385 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
20386 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
20387 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
20388
20389 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
20390 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
20391 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
20392 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
20393 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
20394 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
20395 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
20396 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
20397 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
20398 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
20399 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
20400 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
20401
20402 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
20403 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20404 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20405 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20406 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20407 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20408 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20409 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20410 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20411 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20412 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20413 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20414
20415 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20416 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20417 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20418 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20419 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20420 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20421 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20422 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20423 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20424 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20425 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20426 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20427
20428 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20429 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20430 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20431 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20432 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20433 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20434 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20435 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20436 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20437 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20438 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20439 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20440
20441 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20442 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20443 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20444 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20445 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20446 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20447 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20448 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20449 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20450 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20451 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20452 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20453
20454 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20455 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20456 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20457 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20458 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20459 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20460 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20461 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20462 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20463 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20464 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20465 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20466
20467 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20468 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20469 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20470 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20471 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20472 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20473 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20474 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20475 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20476 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20477 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20478 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20479
20480 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20481 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20482 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20483 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20484 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20485 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20486 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20487 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20488 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20489 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20490 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20491 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20492
20493 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20494 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20495 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20496 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20497 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20498 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20499 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20500 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20501 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20502 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20503 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20504 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20505
20506 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20507 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20508 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20509 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20510 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20511 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20512 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20513 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20514 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20515 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20516 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20517 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20518
20519 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20520 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20521 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20522 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20523 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20524 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20525 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20526 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20527 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20528 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20529 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20530 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20531
20532 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20533 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20534 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20535 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20536 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20537 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20538 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20539 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20540 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20541 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20542 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20543 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20544
20545 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20546 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20547 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20548 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20549 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20550 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20551 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20552 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20553 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20554 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20555 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20556 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20557
20558 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20559 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20560 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20561 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20562 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20563 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20564 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20565 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20566 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20567 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20568 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20569 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20570
20571 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20572 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20573 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20574 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20575 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20576 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20577 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20578 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20579 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20580 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20581 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20582 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20583
20584 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20585 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20586 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20587 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20588 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20589 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20590 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20591 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20592 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20593 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20594 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20595 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20596
20597 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20598 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20599 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20600 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20601 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20602 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20603 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20604 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20605 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20606 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20607 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20608 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20609
20610 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20611 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20612 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20613 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20614 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20615 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20616 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20617 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20618 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20619 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20620 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20621 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20622
20623 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20624 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20625 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20626 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20627 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20628 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20629 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20630 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20631 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20632 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20633 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20634 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20635
20636 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20637 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20638 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20639 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20640 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20641 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20642 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20643 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20644 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20645 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20646 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20647 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20648
20649 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20650 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20651 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20652 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20653 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20654 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20655 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20656 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20657 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20658 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20659 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20660 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20661
20662 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20663 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20664 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20665 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20666 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20667 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20668 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20669 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20670 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20671 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20672 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20673 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20674
20675 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20676 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20677 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20678 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20679 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20680 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20681 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20682 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20683 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20684 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20685 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20686 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20687
20688 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20689 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20690 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20691 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20692
20693 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20694 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20695 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20696 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20697 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20698 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20699 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20700 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20701 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20702 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20703 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20704 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20705
c19d1205
ZW
20706 /* The implementation of the FIX instruction is broken on some
20707 assemblers, in that it accepts a precision specifier as well as a
20708 rounding specifier, despite the fact that this is meaningless.
20709 To be more compatible, we accept it as well, though of course it
20710 does not set any bits. */
21d799b5
NC
20711 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20712 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20713 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20714 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20715 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20716 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20717 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20718 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20719 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20720 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20721 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20722 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20723 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20724
c19d1205 20725 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20726#undef ARM_VARIANT
20727#define ARM_VARIANT & fpu_fpa_ext_v2
20728
21d799b5
NC
20729 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20730 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20731 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20732 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20733 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20734 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20735
c921be7d
NC
20736#undef ARM_VARIANT
20737#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20738
c19d1205 20739 /* Moves and type conversions. */
21d799b5
NC
20740 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20741 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20742 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20743 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20744 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20745 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20746 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20747 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20748 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20749 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20750 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20751 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20752 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20753 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20754
20755 /* Memory operations. */
21d799b5
NC
20756 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20757 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20758 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20759 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20760 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20761 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20762 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20763 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20764 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20765 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20766 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20767 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20768 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20769 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20770 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20771 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20772 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20773 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20774
c19d1205 20775 /* Monadic operations. */
21d799b5
NC
20776 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20777 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20778 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20779
20780 /* Dyadic operations. */
21d799b5
NC
20781 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20782 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20783 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20784 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20785 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20786 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20787 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20788 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20789 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20790
c19d1205 20791 /* Comparisons. */
21d799b5
NC
20792 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20793 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20794 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20795 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20796
62f3b8c8
PB
20797 /* Double precision load/store are still present on single precision
20798 implementations. */
20799 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20800 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20801 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20802 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20803 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20804 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20805 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20806 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20807 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20808 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20809
c921be7d
NC
20810#undef ARM_VARIANT
20811#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20812
c19d1205 20813 /* Moves and type conversions. */
21d799b5
NC
20814 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20815 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20816 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20817 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20818 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20819 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20820 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20821 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20822 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20823 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20824 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20825 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20826 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20827
c19d1205 20828 /* Monadic operations. */
21d799b5
NC
20829 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20830 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20831 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20832
20833 /* Dyadic operations. */
21d799b5
NC
20834 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20835 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20836 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20837 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20838 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20839 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20840 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20841 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20842 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20843
c19d1205 20844 /* Comparisons. */
21d799b5
NC
20845 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20846 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20847 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20848 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20849
c921be7d
NC
20850#undef ARM_VARIANT
20851#define ARM_VARIANT & fpu_vfp_ext_v2
20852
21d799b5
NC
20853 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20854 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20855 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20856 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20857
037e8744
JB
20858/* Instructions which may belong to either the Neon or VFP instruction sets.
20859 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20860#undef ARM_VARIANT
20861#define ARM_VARIANT & fpu_vfp_ext_v1xd
20862#undef THUMB_VARIANT
20863#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20864
037e8744
JB
20865 /* These mnemonics are unique to VFP. */
20866 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20867 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20868 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20869 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20870 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20871 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20872 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20873 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20874 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20875 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20876
20877 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20878 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20879 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20880 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20881
21d799b5
NC
20882 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20883 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20884
20885 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20886 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20887
55881a11
MGD
20888 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20889 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20890 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20891 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20892 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20893 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20894 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20895 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20896
5f1af56b 20897 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20898 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20899 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20900 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20901
037e8744
JB
20902
20903 /* NOTE: All VMOV encoding is special-cased! */
20904 NCE(vmov, 0, 1, (VMOV), neon_mov),
20905 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20906
9db2f6b4
RL
20907#undef ARM_VARIANT
20908#define ARM_VARIANT & arm_ext_fp16
20909#undef THUMB_VARIANT
20910#define THUMB_VARIANT & arm_ext_fp16
20911 /* New instructions added from v8.2, allowing the extraction and insertion of
20912 the upper 16 bits of a 32-bit vector register. */
20913 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20914 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20915
dec41383
JW
20916 /* New backported fma/fms instructions optional in v8.2. */
20917 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
20918 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
20919
c921be7d
NC
20920#undef THUMB_VARIANT
20921#define THUMB_VARIANT & fpu_neon_ext_v1
20922#undef ARM_VARIANT
20923#define ARM_VARIANT & fpu_neon_ext_v1
20924
5287ad62
JB
20925 /* Data processing with three registers of the same length. */
20926 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20927 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20928 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20929 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20930 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20931 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20932 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20933 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20934 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20935 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20936 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20937 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20938 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20939 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20940 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20941 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20942 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20943 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20944 /* If not immediate, fall back to neon_dyadic_i64_su.
20945 shl_imm should accept I8 I16 I32 I64,
20946 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20947 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20948 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20949 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20950 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20951 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20952 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20953 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20954 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20955 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20956 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20957 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20958 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20959 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20960 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20961 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20962 /* Bitfield ops, untyped. */
20963 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20964 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20965 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20966 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20967 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20968 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20969 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20970 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20971 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20972 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20973 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20974 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20975 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20976 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20977 back to neon_dyadic_if_su. */
21d799b5
NC
20978 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20979 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20980 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20981 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20982 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20983 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20984 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20985 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20986 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20987 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20988 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20989 /* As above, D registers only. */
21d799b5
NC
20990 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20991 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20992 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20993 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20994 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20995 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20996 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20997 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20998 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20999 /* vtst takes sizes 8, 16, 32. */
21000 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
21001 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
21002 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 21003 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 21004 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
21005 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
21006 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
21007 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
21008 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
21009 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
21010 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
21011 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
21012 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
21013 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
21014 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
21015 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
21016 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
21017 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
21018 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
21019 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
21020 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 21021 /* ARM v8.1 extension. */
643afb90
MW
21022 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
21023 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
21024 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
21025 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
21026
21027 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 21028 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
21029 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
21030
21031 /* Data processing with two registers and a shift amount. */
21032 /* Right shifts, and variants with rounding.
21033 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
21034 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
21035 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
21036 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
21037 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
21038 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
21039 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
21040 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
21041 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
21042 /* Shift and insert. Sizes accepted 8 16 32 64. */
21043 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
21044 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
21045 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
21046 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
21047 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
21048 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
21049 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
21050 /* Right shift immediate, saturating & narrowing, with rounding variants.
21051 Types accepted S16 S32 S64 U16 U32 U64. */
21052 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
21053 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
21054 /* As above, unsigned. Types accepted S16 S32 S64. */
21055 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
21056 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
21057 /* Right shift narrowing. Types accepted I16 I32 I64. */
21058 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
21059 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
21060 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 21061 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 21062 /* CVT with optional immediate for fixed-point variant. */
21d799b5 21063 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 21064
4316f0d2
DG
21065 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
21066 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
21067
21068 /* Data processing, three registers of different lengths. */
21069 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
21070 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
21071 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
21072 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
21073 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
21074 /* If not scalar, fall back to neon_dyadic_long.
21075 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
21076 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
21077 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
21078 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
21079 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
21080 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
21081 /* Dyadic, narrowing insns. Types I16 I32 I64. */
21082 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21083 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21084 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21085 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21086 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
21087 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21088 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21089 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
21090 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
21091 S16 S32 U16 U32. */
21d799b5 21092 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
21093
21094 /* Extract. Size 8. */
3b8d421e
PB
21095 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
21096 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
21097
21098 /* Two registers, miscellaneous. */
21099 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
21100 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
21101 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
21102 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
21103 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
21104 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
21105 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
21106 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
21107 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
21108 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
21109 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
21110 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
21111 /* VMOVN. Types I16 I32 I64. */
21d799b5 21112 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 21113 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 21114 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 21115 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 21116 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
21117 /* VZIP / VUZP. Sizes 8 16 32. */
21118 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
21119 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
21120 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
21121 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
21122 /* VQABS / VQNEG. Types S8 S16 S32. */
21123 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21124 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
21125 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21126 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
21127 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
21128 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
21129 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
21130 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
21131 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 21132 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
21133 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
21134 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
21135 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
21136 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
21137 /* VCLS. Types S8 S16 S32. */
21138 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
21139 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
21140 /* VCLZ. Types I8 I16 I32. */
21141 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
21142 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
21143 /* VCNT. Size 8. */
21144 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
21145 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
21146 /* Two address, untyped. */
21147 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
21148 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
21149 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
21150 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
21151 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
21152
21153 /* Table lookup. Size 8. */
21154 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21155 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21156
c921be7d
NC
21157#undef THUMB_VARIANT
21158#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
21159#undef ARM_VARIANT
21160#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
21161
5287ad62 21162 /* Neon element/structure load/store. */
21d799b5
NC
21163 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21164 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21165 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21166 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21167 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21168 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21169 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
21170 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 21171
c921be7d 21172#undef THUMB_VARIANT
74db7efb
NC
21173#define THUMB_VARIANT & fpu_vfp_ext_v3xd
21174#undef ARM_VARIANT
21175#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
21176 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
21177 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21178 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21179 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21180 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21181 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21182 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21183 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21184 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21185
74db7efb 21186#undef THUMB_VARIANT
c921be7d
NC
21187#define THUMB_VARIANT & fpu_vfp_ext_v3
21188#undef ARM_VARIANT
21189#define ARM_VARIANT & fpu_vfp_ext_v3
21190
21d799b5 21191 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 21192 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21193 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21194 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21195 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21196 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21197 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21198 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21199 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 21200
74db7efb
NC
21201#undef ARM_VARIANT
21202#define ARM_VARIANT & fpu_vfp_ext_fma
21203#undef THUMB_VARIANT
21204#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
21205 /* Mnemonics shared by Neon and VFP. These are included in the
21206 VFP FMA variant; NEON and VFP FMA always includes the NEON
21207 FMA instructions. */
21208 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21209 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21210 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
21211 the v form should always be used. */
21212 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21213 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21214 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21215 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21216 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21217 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21218
5287ad62 21219#undef THUMB_VARIANT
c921be7d
NC
21220#undef ARM_VARIANT
21221#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
21222
21d799b5
NC
21223 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21224 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21225 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21226 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21227 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21228 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21229 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
21230 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 21231
c921be7d
NC
21232#undef ARM_VARIANT
21233#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
21234
21d799b5
NC
21235 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
21236 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
21237 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
21238 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
21239 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
21240 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
21241 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
21242 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
21243 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
21244 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21245 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21246 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21247 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21248 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21249 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
21250 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21251 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21252 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21253 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
21254 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
21255 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21256 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21257 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21258 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21259 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21260 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
21261 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
21262 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
21263 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
21264 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
21265 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
21266 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
21267 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
21268 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
21269 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
21270 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
21271 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
21272 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21273 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21274 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21275 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21276 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21277 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21278 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21279 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21280 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21281 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
21282 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21283 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21284 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21285 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21286 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21287 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21288 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21289 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21290 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21291 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21292 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21293 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21294 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21295 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21296 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21297 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21298 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21299 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21300 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21301 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21302 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21303 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21304 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21305 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21306 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21307 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21308 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21309 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21310 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21311 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21312 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21313 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21314 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21315 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21316 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21317 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21318 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21319 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21320 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21321 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21322 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21323 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
21324 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21325 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21326 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21327 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21328 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21329 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21330 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21331 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21332 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21333 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21334 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21335 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21336 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21337 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21338 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21339 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21340 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21341 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21342 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21343 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21344 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21345 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
21346 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21347 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21348 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21349 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21350 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21351 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21352 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21353 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21354 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21355 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21356 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21357 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21358 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21359 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21360 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21361 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21362 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21363 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21364 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21365 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21366 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21367 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21368 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21369 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21370 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21371 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21372 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21373 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21374 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21375 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21376 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21377 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
21378 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
21379 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
21380 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
21381 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
21382 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
21383 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21384 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21385 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21386 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
21387 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
21388 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
21389 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
21390 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
21391 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
21392 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21393 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21394 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21395 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21396 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 21397
c921be7d
NC
21398#undef ARM_VARIANT
21399#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
21400
21d799b5
NC
21401 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
21402 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
21403 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
21404 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
21405 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
21406 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
21407 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21408 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21409 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21410 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21411 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21412 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21413 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21414 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21415 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21416 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21417 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21418 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21419 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21420 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21421 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21422 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21423 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21424 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21425 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21426 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21427 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21428 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21429 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21430 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21431 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21432 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21433 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21434 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21435 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21436 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21437 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21438 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21439 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21440 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21441 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21442 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21443 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21444 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21445 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21446 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21447 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21448 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21449 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21450 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21451 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21452 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21453 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21454 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21455 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21456 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21457 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 21458
c921be7d
NC
21459#undef ARM_VARIANT
21460#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21461
21d799b5
NC
21462 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21463 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21464 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21465 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21466 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21467 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21468 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21469 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21470 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21471 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21472 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21473 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21474 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21475 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
21476 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21477 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21478 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21479 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21480 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21481 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21482 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21483 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21484 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21485 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
21486 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21487 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21488 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21489 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
21490 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21491 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
21492 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21493 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21494 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21495 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
21496 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21497 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21498 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21499 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21500 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21501 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
21502 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21503 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
21504 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21505 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
21506 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21507 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21508 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21509 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21510 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21511 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21512 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21513 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21514 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21515 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21516 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21517 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21518 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21519 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21520 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21521 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21522 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21523 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21524 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21525 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21526 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21527 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21528 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21529 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21530 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21531 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21532 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21533 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
21534 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21535 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
21536 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21537 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 21538
7fadb25d
SD
21539 /* ARMv8.5-A instructions. */
21540#undef ARM_VARIANT
21541#define ARM_VARIANT & arm_ext_sb
21542#undef THUMB_VARIANT
21543#define THUMB_VARIANT & arm_ext_sb
21544 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
21545
dad0c3bf
SD
21546#undef ARM_VARIANT
21547#define ARM_VARIANT & arm_ext_predres
21548#undef THUMB_VARIANT
21549#define THUMB_VARIANT & arm_ext_predres
21550 CE("cfprctx", e070f93, 1, (RRnpc), rd),
21551 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
21552 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
21553
16a1fa25 21554 /* ARMv8-M instructions. */
4ed7ed8d
TP
21555#undef ARM_VARIANT
21556#define ARM_VARIANT NULL
21557#undef THUMB_VARIANT
21558#define THUMB_VARIANT & arm_ext_v8m
cf3cf39d
TP
21559 ToU("sg", e97fe97f, 0, (), noargs),
21560 ToC("blxns", 4784, 1, (RRnpc), t_blx),
21561 ToC("bxns", 4704, 1, (RRnpc), t_bx),
21562 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
21563 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
21564 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
21565 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
16a1fa25
TP
21566
21567 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21568 instructions behave as nop if no VFP is present. */
21569#undef THUMB_VARIANT
21570#define THUMB_VARIANT & arm_ext_v8m_main
cf3cf39d
TP
21571 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
21572 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
c19d1205
ZW
21573};
21574#undef ARM_VARIANT
21575#undef THUMB_VARIANT
21576#undef TCE
c19d1205
ZW
21577#undef TUE
21578#undef TUF
21579#undef TCC
8f06b2d8 21580#undef cCE
e3cb604e
PB
21581#undef cCL
21582#undef C3E
c19d1205
ZW
21583#undef CE
21584#undef CM
21585#undef UE
21586#undef UF
21587#undef UT
5287ad62
JB
21588#undef NUF
21589#undef nUF
21590#undef NCE
21591#undef nCE
c19d1205
ZW
21592#undef OPS0
21593#undef OPS1
21594#undef OPS2
21595#undef OPS3
21596#undef OPS4
21597#undef OPS5
21598#undef OPS6
21599#undef do_0
21600\f
21601/* MD interface: bits in the object file. */
bfae80f2 21602
c19d1205
ZW
21603/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21604 for use in the a.out file, and stores them in the array pointed to by buf.
21605 This knows about the endian-ness of the target machine and does
21606 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21607 2 (short) and 4 (long) Floating numbers are put out as a series of
21608 LITTLENUMS (shorts, here at least). */
b99bd4ef 21609
c19d1205
ZW
21610void
21611md_number_to_chars (char * buf, valueT val, int n)
21612{
21613 if (target_big_endian)
21614 number_to_chars_bigendian (buf, val, n);
21615 else
21616 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21617}
21618
c19d1205
ZW
21619static valueT
21620md_chars_to_number (char * buf, int n)
bfae80f2 21621{
c19d1205
ZW
21622 valueT result = 0;
21623 unsigned char * where = (unsigned char *) buf;
bfae80f2 21624
c19d1205 21625 if (target_big_endian)
b99bd4ef 21626 {
c19d1205
ZW
21627 while (n--)
21628 {
21629 result <<= 8;
21630 result |= (*where++ & 255);
21631 }
b99bd4ef 21632 }
c19d1205 21633 else
b99bd4ef 21634 {
c19d1205
ZW
21635 while (n--)
21636 {
21637 result <<= 8;
21638 result |= (where[n] & 255);
21639 }
bfae80f2 21640 }
b99bd4ef 21641
c19d1205 21642 return result;
bfae80f2 21643}
b99bd4ef 21644
c19d1205 21645/* MD interface: Sections. */
b99bd4ef 21646
fa94de6b
RM
21647/* Calculate the maximum variable size (i.e., excluding fr_fix)
21648 that an rs_machine_dependent frag may reach. */
21649
21650unsigned int
21651arm_frag_max_var (fragS *fragp)
21652{
21653 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21654 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21655
21656 Note that we generate relaxable instructions even for cases that don't
21657 really need it, like an immediate that's a trivial constant. So we're
21658 overestimating the instruction size for some of those cases. Rather
21659 than putting more intelligence here, it would probably be better to
21660 avoid generating a relaxation frag in the first place when it can be
21661 determined up front that a short instruction will suffice. */
21662
21663 gas_assert (fragp->fr_type == rs_machine_dependent);
21664 return INSN_SIZE;
21665}
21666
0110f2b8
PB
21667/* Estimate the size of a frag before relaxing. Assume everything fits in
21668 2 bytes. */
21669
c19d1205 21670int
0110f2b8 21671md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21672 segT segtype ATTRIBUTE_UNUSED)
21673{
0110f2b8
PB
21674 fragp->fr_var = 2;
21675 return 2;
21676}
21677
21678/* Convert a machine dependent frag. */
21679
21680void
21681md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21682{
21683 unsigned long insn;
21684 unsigned long old_op;
21685 char *buf;
21686 expressionS exp;
21687 fixS *fixp;
21688 int reloc_type;
21689 int pc_rel;
21690 int opcode;
21691
21692 buf = fragp->fr_literal + fragp->fr_fix;
21693
21694 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21695 if (fragp->fr_symbol)
21696 {
0110f2b8
PB
21697 exp.X_op = O_symbol;
21698 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21699 }
21700 else
21701 {
0110f2b8 21702 exp.X_op = O_constant;
5f4273c7 21703 }
0110f2b8
PB
21704 exp.X_add_number = fragp->fr_offset;
21705 opcode = fragp->fr_subtype;
21706 switch (opcode)
21707 {
21708 case T_MNEM_ldr_pc:
21709 case T_MNEM_ldr_pc2:
21710 case T_MNEM_ldr_sp:
21711 case T_MNEM_str_sp:
21712 case T_MNEM_ldr:
21713 case T_MNEM_ldrb:
21714 case T_MNEM_ldrh:
21715 case T_MNEM_str:
21716 case T_MNEM_strb:
21717 case T_MNEM_strh:
21718 if (fragp->fr_var == 4)
21719 {
5f4273c7 21720 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21721 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21722 {
21723 insn |= (old_op & 0x700) << 4;
21724 }
21725 else
21726 {
21727 insn |= (old_op & 7) << 12;
21728 insn |= (old_op & 0x38) << 13;
21729 }
21730 insn |= 0x00000c00;
21731 put_thumb32_insn (buf, insn);
21732 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21733 }
21734 else
21735 {
21736 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21737 }
21738 pc_rel = (opcode == T_MNEM_ldr_pc2);
21739 break;
21740 case T_MNEM_adr:
21741 if (fragp->fr_var == 4)
21742 {
21743 insn = THUMB_OP32 (opcode);
21744 insn |= (old_op & 0xf0) << 4;
21745 put_thumb32_insn (buf, insn);
21746 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21747 }
21748 else
21749 {
21750 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21751 exp.X_add_number -= 4;
21752 }
21753 pc_rel = 1;
21754 break;
21755 case T_MNEM_mov:
21756 case T_MNEM_movs:
21757 case T_MNEM_cmp:
21758 case T_MNEM_cmn:
21759 if (fragp->fr_var == 4)
21760 {
21761 int r0off = (opcode == T_MNEM_mov
21762 || opcode == T_MNEM_movs) ? 0 : 8;
21763 insn = THUMB_OP32 (opcode);
21764 insn = (insn & 0xe1ffffff) | 0x10000000;
21765 insn |= (old_op & 0x700) << r0off;
21766 put_thumb32_insn (buf, insn);
21767 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21768 }
21769 else
21770 {
21771 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21772 }
21773 pc_rel = 0;
21774 break;
21775 case T_MNEM_b:
21776 if (fragp->fr_var == 4)
21777 {
21778 insn = THUMB_OP32(opcode);
21779 put_thumb32_insn (buf, insn);
21780 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21781 }
21782 else
21783 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21784 pc_rel = 1;
21785 break;
21786 case T_MNEM_bcond:
21787 if (fragp->fr_var == 4)
21788 {
21789 insn = THUMB_OP32(opcode);
21790 insn |= (old_op & 0xf00) << 14;
21791 put_thumb32_insn (buf, insn);
21792 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21793 }
21794 else
21795 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21796 pc_rel = 1;
21797 break;
21798 case T_MNEM_add_sp:
21799 case T_MNEM_add_pc:
21800 case T_MNEM_inc_sp:
21801 case T_MNEM_dec_sp:
21802 if (fragp->fr_var == 4)
21803 {
21804 /* ??? Choose between add and addw. */
21805 insn = THUMB_OP32 (opcode);
21806 insn |= (old_op & 0xf0) << 4;
21807 put_thumb32_insn (buf, insn);
16805f35
PB
21808 if (opcode == T_MNEM_add_pc)
21809 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21810 else
21811 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21812 }
21813 else
21814 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21815 pc_rel = 0;
21816 break;
21817
21818 case T_MNEM_addi:
21819 case T_MNEM_addis:
21820 case T_MNEM_subi:
21821 case T_MNEM_subis:
21822 if (fragp->fr_var == 4)
21823 {
21824 insn = THUMB_OP32 (opcode);
21825 insn |= (old_op & 0xf0) << 4;
21826 insn |= (old_op & 0xf) << 16;
21827 put_thumb32_insn (buf, insn);
16805f35
PB
21828 if (insn & (1 << 20))
21829 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21830 else
21831 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21832 }
21833 else
21834 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21835 pc_rel = 0;
21836 break;
21837 default:
5f4273c7 21838 abort ();
0110f2b8
PB
21839 }
21840 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21841 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21842 fixp->fx_file = fragp->fr_file;
21843 fixp->fx_line = fragp->fr_line;
21844 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21845
21846 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21847 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21848 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21849 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21850}
21851
21852/* Return the size of a relaxable immediate operand instruction.
21853 SHIFT and SIZE specify the form of the allowable immediate. */
21854static int
21855relax_immediate (fragS *fragp, int size, int shift)
21856{
21857 offsetT offset;
21858 offsetT mask;
21859 offsetT low;
21860
21861 /* ??? Should be able to do better than this. */
21862 if (fragp->fr_symbol)
21863 return 4;
21864
21865 low = (1 << shift) - 1;
21866 mask = (1 << (shift + size)) - (1 << shift);
21867 offset = fragp->fr_offset;
21868 /* Force misaligned offsets to 32-bit variant. */
21869 if (offset & low)
5e77afaa 21870 return 4;
0110f2b8
PB
21871 if (offset & ~mask)
21872 return 4;
21873 return 2;
21874}
21875
5e77afaa
PB
21876/* Get the address of a symbol during relaxation. */
21877static addressT
5f4273c7 21878relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21879{
21880 fragS *sym_frag;
21881 addressT addr;
21882 symbolS *sym;
21883
21884 sym = fragp->fr_symbol;
21885 sym_frag = symbol_get_frag (sym);
21886 know (S_GET_SEGMENT (sym) != absolute_section
21887 || sym_frag == &zero_address_frag);
21888 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21889
21890 /* If frag has yet to be reached on this pass, assume it will
21891 move by STRETCH just as we did. If this is not so, it will
21892 be because some frag between grows, and that will force
21893 another pass. */
21894
21895 if (stretch != 0
21896 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21897 {
21898 fragS *f;
21899
21900 /* Adjust stretch for any alignment frag. Note that if have
21901 been expanding the earlier code, the symbol may be
21902 defined in what appears to be an earlier frag. FIXME:
21903 This doesn't handle the fr_subtype field, which specifies
21904 a maximum number of bytes to skip when doing an
21905 alignment. */
21906 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21907 {
21908 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21909 {
21910 if (stretch < 0)
21911 stretch = - ((- stretch)
21912 & ~ ((1 << (int) f->fr_offset) - 1));
21913 else
21914 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21915 if (stretch == 0)
21916 break;
21917 }
21918 }
21919 if (f != NULL)
21920 addr += stretch;
21921 }
5e77afaa
PB
21922
21923 return addr;
21924}
21925
0110f2b8
PB
21926/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21927 load. */
21928static int
5e77afaa 21929relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21930{
21931 addressT addr;
21932 offsetT val;
21933
21934 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21935 if (fragp->fr_symbol == NULL
21936 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21937 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21938 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21939 return 4;
21940
5f4273c7 21941 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21942 addr = fragp->fr_address + fragp->fr_fix;
21943 addr = (addr + 4) & ~3;
5e77afaa 21944 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21945 if (val & 3)
5e77afaa 21946 return 4;
0110f2b8
PB
21947 val -= addr;
21948 if (val < 0 || val > 1020)
21949 return 4;
21950 return 2;
21951}
21952
21953/* Return the size of a relaxable add/sub immediate instruction. */
21954static int
21955relax_addsub (fragS *fragp, asection *sec)
21956{
21957 char *buf;
21958 int op;
21959
21960 buf = fragp->fr_literal + fragp->fr_fix;
21961 op = bfd_get_16(sec->owner, buf);
21962 if ((op & 0xf) == ((op >> 4) & 0xf))
21963 return relax_immediate (fragp, 8, 0);
21964 else
21965 return relax_immediate (fragp, 3, 0);
21966}
21967
e83a675f
RE
21968/* Return TRUE iff the definition of symbol S could be pre-empted
21969 (overridden) at link or load time. */
21970static bfd_boolean
21971symbol_preemptible (symbolS *s)
21972{
21973 /* Weak symbols can always be pre-empted. */
21974 if (S_IS_WEAK (s))
21975 return TRUE;
21976
21977 /* Non-global symbols cannot be pre-empted. */
21978 if (! S_IS_EXTERNAL (s))
21979 return FALSE;
21980
21981#ifdef OBJ_ELF
21982 /* In ELF, a global symbol can be marked protected, or private. In that
21983 case it can't be pre-empted (other definitions in the same link unit
21984 would violate the ODR). */
21985 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21986 return FALSE;
21987#endif
21988
21989 /* Other global symbols might be pre-empted. */
21990 return TRUE;
21991}
0110f2b8
PB
21992
21993/* Return the size of a relaxable branch instruction. BITS is the
21994 size of the offset field in the narrow instruction. */
21995
21996static int
5e77afaa 21997relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21998{
21999 addressT addr;
22000 offsetT val;
22001 offsetT limit;
22002
22003 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 22004 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
22005 || sec != S_GET_SEGMENT (fragp->fr_symbol)
22006 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
22007 return 4;
22008
267bf995 22009#ifdef OBJ_ELF
e83a675f 22010 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
22011 if (S_IS_DEFINED (fragp->fr_symbol)
22012 && ARM_IS_FUNC (fragp->fr_symbol))
22013 return 4;
e83a675f 22014#endif
0d9b4b55 22015
e83a675f 22016 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 22017 return 4;
267bf995 22018
5f4273c7 22019 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
22020 addr = fragp->fr_address + fragp->fr_fix + 4;
22021 val -= addr;
22022
22023 /* Offset is a signed value *2 */
22024 limit = 1 << bits;
22025 if (val >= limit || val < -limit)
22026 return 4;
22027 return 2;
22028}
22029
22030
22031/* Relax a machine dependent frag. This returns the amount by which
22032 the current size of the frag should change. */
22033
22034int
5e77afaa 22035arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
22036{
22037 int oldsize;
22038 int newsize;
22039
22040 oldsize = fragp->fr_var;
22041 switch (fragp->fr_subtype)
22042 {
22043 case T_MNEM_ldr_pc2:
5f4273c7 22044 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
22045 break;
22046 case T_MNEM_ldr_pc:
22047 case T_MNEM_ldr_sp:
22048 case T_MNEM_str_sp:
5f4273c7 22049 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
22050 break;
22051 case T_MNEM_ldr:
22052 case T_MNEM_str:
5f4273c7 22053 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
22054 break;
22055 case T_MNEM_ldrh:
22056 case T_MNEM_strh:
5f4273c7 22057 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
22058 break;
22059 case T_MNEM_ldrb:
22060 case T_MNEM_strb:
5f4273c7 22061 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
22062 break;
22063 case T_MNEM_adr:
5f4273c7 22064 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
22065 break;
22066 case T_MNEM_mov:
22067 case T_MNEM_movs:
22068 case T_MNEM_cmp:
22069 case T_MNEM_cmn:
5f4273c7 22070 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
22071 break;
22072 case T_MNEM_b:
5f4273c7 22073 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
22074 break;
22075 case T_MNEM_bcond:
5f4273c7 22076 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
22077 break;
22078 case T_MNEM_add_sp:
22079 case T_MNEM_add_pc:
22080 newsize = relax_immediate (fragp, 8, 2);
22081 break;
22082 case T_MNEM_inc_sp:
22083 case T_MNEM_dec_sp:
22084 newsize = relax_immediate (fragp, 7, 2);
22085 break;
22086 case T_MNEM_addi:
22087 case T_MNEM_addis:
22088 case T_MNEM_subi:
22089 case T_MNEM_subis:
22090 newsize = relax_addsub (fragp, sec);
22091 break;
22092 default:
5f4273c7 22093 abort ();
0110f2b8 22094 }
5e77afaa
PB
22095
22096 fragp->fr_var = newsize;
22097 /* Freeze wide instructions that are at or before the same location as
22098 in the previous pass. This avoids infinite loops.
5f4273c7
NC
22099 Don't freeze them unconditionally because targets may be artificially
22100 misaligned by the expansion of preceding frags. */
5e77afaa 22101 if (stretch <= 0 && newsize > 2)
0110f2b8 22102 {
0110f2b8 22103 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 22104 frag_wane (fragp);
0110f2b8 22105 }
5e77afaa 22106
0110f2b8 22107 return newsize - oldsize;
c19d1205 22108}
b99bd4ef 22109
c19d1205 22110/* Round up a section size to the appropriate boundary. */
b99bd4ef 22111
c19d1205
ZW
22112valueT
22113md_section_align (segT segment ATTRIBUTE_UNUSED,
22114 valueT size)
22115{
6844c0cc 22116 return size;
bfae80f2 22117}
b99bd4ef 22118
c19d1205
ZW
22119/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
22120 of an rs_align_code fragment. */
22121
22122void
22123arm_handle_align (fragS * fragP)
bfae80f2 22124{
d9235011 22125 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
22126 {
22127 { /* ARMv1 */
22128 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
22129 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
22130 },
22131 { /* ARMv6k */
22132 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
22133 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
22134 },
22135 };
d9235011 22136 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
22137 {
22138 { /* Thumb-1 */
22139 {0xc0, 0x46}, /* LE */
22140 {0x46, 0xc0}, /* BE */
22141 },
22142 { /* Thumb-2 */
22143 {0x00, 0xbf}, /* LE */
22144 {0xbf, 0x00} /* BE */
22145 }
22146 };
d9235011 22147 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
22148 { /* Wide Thumb-2 */
22149 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
22150 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
22151 };
c921be7d 22152
e7495e45 22153 unsigned bytes, fix, noop_size;
c19d1205 22154 char * p;
d9235011
TS
22155 const unsigned char * noop;
22156 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
22157#ifdef OBJ_ELF
22158 enum mstate state;
22159#endif
bfae80f2 22160
c19d1205 22161 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
22162 return;
22163
c19d1205
ZW
22164 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
22165 p = fragP->fr_literal + fragP->fr_fix;
22166 fix = 0;
bfae80f2 22167
c19d1205
ZW
22168 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
22169 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 22170
cd000bff 22171 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 22172
cd000bff 22173 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 22174 {
7f78eb34
JW
22175 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22176 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
22177 {
22178 narrow_noop = thumb_noop[1][target_big_endian];
22179 noop = wide_thumb_noop[target_big_endian];
22180 }
c19d1205 22181 else
e7495e45
NS
22182 noop = thumb_noop[0][target_big_endian];
22183 noop_size = 2;
cd000bff
DJ
22184#ifdef OBJ_ELF
22185 state = MAP_THUMB;
22186#endif
7ed4c4c5
NC
22187 }
22188 else
22189 {
7f78eb34
JW
22190 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22191 ? selected_cpu : arm_arch_none,
22192 arm_ext_v6k) != 0]
e7495e45
NS
22193 [target_big_endian];
22194 noop_size = 4;
cd000bff
DJ
22195#ifdef OBJ_ELF
22196 state = MAP_ARM;
22197#endif
7ed4c4c5 22198 }
c921be7d 22199
e7495e45 22200 fragP->fr_var = noop_size;
c921be7d 22201
c19d1205 22202 if (bytes & (noop_size - 1))
7ed4c4c5 22203 {
c19d1205 22204 fix = bytes & (noop_size - 1);
cd000bff
DJ
22205#ifdef OBJ_ELF
22206 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
22207#endif
c19d1205
ZW
22208 memset (p, 0, fix);
22209 p += fix;
22210 bytes -= fix;
a737bd4d 22211 }
a737bd4d 22212
e7495e45
NS
22213 if (narrow_noop)
22214 {
22215 if (bytes & noop_size)
22216 {
22217 /* Insert a narrow noop. */
22218 memcpy (p, narrow_noop, noop_size);
22219 p += noop_size;
22220 bytes -= noop_size;
22221 fix += noop_size;
22222 }
22223
22224 /* Use wide noops for the remainder */
22225 noop_size = 4;
22226 }
22227
c19d1205 22228 while (bytes >= noop_size)
a737bd4d 22229 {
c19d1205
ZW
22230 memcpy (p, noop, noop_size);
22231 p += noop_size;
22232 bytes -= noop_size;
22233 fix += noop_size;
a737bd4d
NC
22234 }
22235
c19d1205 22236 fragP->fr_fix += fix;
a737bd4d
NC
22237}
22238
c19d1205
ZW
22239/* Called from md_do_align. Used to create an alignment
22240 frag in a code section. */
22241
22242void
22243arm_frag_align_code (int n, int max)
bfae80f2 22244{
c19d1205 22245 char * p;
7ed4c4c5 22246
c19d1205 22247 /* We assume that there will never be a requirement
6ec8e702 22248 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 22249 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
22250 {
22251 char err_msg[128];
22252
fa94de6b 22253 sprintf (err_msg,
477330fc
RM
22254 _("alignments greater than %d bytes not supported in .text sections."),
22255 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 22256 as_fatal ("%s", err_msg);
6ec8e702 22257 }
bfae80f2 22258
c19d1205
ZW
22259 p = frag_var (rs_align_code,
22260 MAX_MEM_FOR_RS_ALIGN_CODE,
22261 1,
22262 (relax_substateT) max,
22263 (symbolS *) NULL,
22264 (offsetT) n,
22265 (char *) NULL);
22266 *p = 0;
22267}
bfae80f2 22268
8dc2430f
NC
22269/* Perform target specific initialisation of a frag.
22270 Note - despite the name this initialisation is not done when the frag
22271 is created, but only when its type is assigned. A frag can be created
22272 and used a long time before its type is set, so beware of assuming that
33eaf5de 22273 this initialisation is performed first. */
bfae80f2 22274
cd000bff
DJ
22275#ifndef OBJ_ELF
22276void
22277arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
22278{
22279 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 22280 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
22281}
22282
22283#else /* OBJ_ELF is defined. */
c19d1205 22284void
cd000bff 22285arm_init_frag (fragS * fragP, int max_chars)
c19d1205 22286{
e8d84ca1 22287 bfd_boolean frag_thumb_mode;
b968d18a 22288
8dc2430f
NC
22289 /* If the current ARM vs THUMB mode has not already
22290 been recorded into this frag then do so now. */
cd000bff 22291 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
22292 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22293
e8d84ca1
NC
22294 /* PR 21809: Do not set a mapping state for debug sections
22295 - it just confuses other tools. */
22296 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
22297 return;
22298
b968d18a 22299 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 22300
f9c1b181
RL
22301 /* Record a mapping symbol for alignment frags. We will delete this
22302 later if the alignment ends up empty. */
22303 switch (fragP->fr_type)
22304 {
22305 case rs_align:
22306 case rs_align_test:
22307 case rs_fill:
22308 mapping_state_2 (MAP_DATA, max_chars);
22309 break;
22310 case rs_align_code:
b968d18a 22311 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
22312 break;
22313 default:
22314 break;
cd000bff 22315 }
bfae80f2
RE
22316}
22317
c19d1205
ZW
22318/* When we change sections we need to issue a new mapping symbol. */
22319
22320void
22321arm_elf_change_section (void)
bfae80f2 22322{
c19d1205
ZW
22323 /* Link an unlinked unwind index table section to the .text section. */
22324 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
22325 && elf_linked_to_section (now_seg) == NULL)
22326 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
22327}
22328
c19d1205
ZW
22329int
22330arm_elf_section_type (const char * str, size_t len)
e45d0630 22331{
c19d1205
ZW
22332 if (len == 5 && strncmp (str, "exidx", 5) == 0)
22333 return SHT_ARM_EXIDX;
e45d0630 22334
c19d1205
ZW
22335 return -1;
22336}
22337\f
22338/* Code to deal with unwinding tables. */
e45d0630 22339
c19d1205 22340static void add_unwind_adjustsp (offsetT);
e45d0630 22341
5f4273c7 22342/* Generate any deferred unwind frame offset. */
e45d0630 22343
bfae80f2 22344static void
c19d1205 22345flush_pending_unwind (void)
bfae80f2 22346{
c19d1205 22347 offsetT offset;
bfae80f2 22348
c19d1205
ZW
22349 offset = unwind.pending_offset;
22350 unwind.pending_offset = 0;
22351 if (offset != 0)
22352 add_unwind_adjustsp (offset);
bfae80f2
RE
22353}
22354
c19d1205
ZW
22355/* Add an opcode to this list for this function. Two-byte opcodes should
22356 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
22357 order. */
22358
bfae80f2 22359static void
c19d1205 22360add_unwind_opcode (valueT op, int length)
bfae80f2 22361{
c19d1205
ZW
22362 /* Add any deferred stack adjustment. */
22363 if (unwind.pending_offset)
22364 flush_pending_unwind ();
bfae80f2 22365
c19d1205 22366 unwind.sp_restored = 0;
bfae80f2 22367
c19d1205 22368 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 22369 {
c19d1205
ZW
22370 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
22371 if (unwind.opcodes)
325801bd
TS
22372 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
22373 unwind.opcode_alloc);
c19d1205 22374 else
325801bd 22375 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 22376 }
c19d1205 22377 while (length > 0)
bfae80f2 22378 {
c19d1205
ZW
22379 length--;
22380 unwind.opcodes[unwind.opcode_count] = op & 0xff;
22381 op >>= 8;
22382 unwind.opcode_count++;
bfae80f2 22383 }
bfae80f2
RE
22384}
22385
c19d1205
ZW
22386/* Add unwind opcodes to adjust the stack pointer. */
22387
bfae80f2 22388static void
c19d1205 22389add_unwind_adjustsp (offsetT offset)
bfae80f2 22390{
c19d1205 22391 valueT op;
bfae80f2 22392
c19d1205 22393 if (offset > 0x200)
bfae80f2 22394 {
c19d1205
ZW
22395 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
22396 char bytes[5];
22397 int n;
22398 valueT o;
bfae80f2 22399
c19d1205
ZW
22400 /* Long form: 0xb2, uleb128. */
22401 /* This might not fit in a word so add the individual bytes,
22402 remembering the list is built in reverse order. */
22403 o = (valueT) ((offset - 0x204) >> 2);
22404 if (o == 0)
22405 add_unwind_opcode (0, 1);
bfae80f2 22406
c19d1205
ZW
22407 /* Calculate the uleb128 encoding of the offset. */
22408 n = 0;
22409 while (o)
22410 {
22411 bytes[n] = o & 0x7f;
22412 o >>= 7;
22413 if (o)
22414 bytes[n] |= 0x80;
22415 n++;
22416 }
22417 /* Add the insn. */
22418 for (; n; n--)
22419 add_unwind_opcode (bytes[n - 1], 1);
22420 add_unwind_opcode (0xb2, 1);
22421 }
22422 else if (offset > 0x100)
bfae80f2 22423 {
c19d1205
ZW
22424 /* Two short opcodes. */
22425 add_unwind_opcode (0x3f, 1);
22426 op = (offset - 0x104) >> 2;
22427 add_unwind_opcode (op, 1);
bfae80f2 22428 }
c19d1205
ZW
22429 else if (offset > 0)
22430 {
22431 /* Short opcode. */
22432 op = (offset - 4) >> 2;
22433 add_unwind_opcode (op, 1);
22434 }
22435 else if (offset < 0)
bfae80f2 22436 {
c19d1205
ZW
22437 offset = -offset;
22438 while (offset > 0x100)
bfae80f2 22439 {
c19d1205
ZW
22440 add_unwind_opcode (0x7f, 1);
22441 offset -= 0x100;
bfae80f2 22442 }
c19d1205
ZW
22443 op = ((offset - 4) >> 2) | 0x40;
22444 add_unwind_opcode (op, 1);
bfae80f2 22445 }
bfae80f2
RE
22446}
22447
c19d1205 22448/* Finish the list of unwind opcodes for this function. */
0198d5e6 22449
c19d1205
ZW
22450static void
22451finish_unwind_opcodes (void)
bfae80f2 22452{
c19d1205 22453 valueT op;
bfae80f2 22454
c19d1205 22455 if (unwind.fp_used)
bfae80f2 22456 {
708587a4 22457 /* Adjust sp as necessary. */
c19d1205
ZW
22458 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22459 flush_pending_unwind ();
bfae80f2 22460
c19d1205
ZW
22461 /* After restoring sp from the frame pointer. */
22462 op = 0x90 | unwind.fp_reg;
22463 add_unwind_opcode (op, 1);
22464 }
22465 else
22466 flush_pending_unwind ();
bfae80f2
RE
22467}
22468
bfae80f2 22469
c19d1205
ZW
22470/* Start an exception table entry. If idx is nonzero this is an index table
22471 entry. */
bfae80f2
RE
22472
22473static void
c19d1205 22474start_unwind_section (const segT text_seg, int idx)
bfae80f2 22475{
c19d1205
ZW
22476 const char * text_name;
22477 const char * prefix;
22478 const char * prefix_once;
22479 const char * group_name;
c19d1205 22480 char * sec_name;
c19d1205
ZW
22481 int type;
22482 int flags;
22483 int linkonce;
bfae80f2 22484
c19d1205 22485 if (idx)
bfae80f2 22486 {
c19d1205
ZW
22487 prefix = ELF_STRING_ARM_unwind;
22488 prefix_once = ELF_STRING_ARM_unwind_once;
22489 type = SHT_ARM_EXIDX;
bfae80f2 22490 }
c19d1205 22491 else
bfae80f2 22492 {
c19d1205
ZW
22493 prefix = ELF_STRING_ARM_unwind_info;
22494 prefix_once = ELF_STRING_ARM_unwind_info_once;
22495 type = SHT_PROGBITS;
bfae80f2
RE
22496 }
22497
c19d1205
ZW
22498 text_name = segment_name (text_seg);
22499 if (streq (text_name, ".text"))
22500 text_name = "";
22501
22502 if (strncmp (text_name, ".gnu.linkonce.t.",
22503 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 22504 {
c19d1205
ZW
22505 prefix = prefix_once;
22506 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
22507 }
22508
29a2809e 22509 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 22510
c19d1205
ZW
22511 flags = SHF_ALLOC;
22512 linkonce = 0;
22513 group_name = 0;
bfae80f2 22514
c19d1205
ZW
22515 /* Handle COMDAT group. */
22516 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 22517 {
c19d1205
ZW
22518 group_name = elf_group_name (text_seg);
22519 if (group_name == NULL)
22520 {
bd3ba5d1 22521 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
22522 segment_name (text_seg));
22523 ignore_rest_of_line ();
22524 return;
22525 }
22526 flags |= SHF_GROUP;
22527 linkonce = 1;
bfae80f2
RE
22528 }
22529
a91e1603
L
22530 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
22531 linkonce, 0);
bfae80f2 22532
5f4273c7 22533 /* Set the section link for index tables. */
c19d1205
ZW
22534 if (idx)
22535 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
22536}
22537
bfae80f2 22538
c19d1205
ZW
22539/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22540 personality routine data. Returns zero, or the index table value for
cad0da33 22541 an inline entry. */
c19d1205
ZW
22542
22543static valueT
22544create_unwind_entry (int have_data)
bfae80f2 22545{
c19d1205
ZW
22546 int size;
22547 addressT where;
22548 char *ptr;
22549 /* The current word of data. */
22550 valueT data;
22551 /* The number of bytes left in this word. */
22552 int n;
bfae80f2 22553
c19d1205 22554 finish_unwind_opcodes ();
bfae80f2 22555
c19d1205
ZW
22556 /* Remember the current text section. */
22557 unwind.saved_seg = now_seg;
22558 unwind.saved_subseg = now_subseg;
bfae80f2 22559
c19d1205 22560 start_unwind_section (now_seg, 0);
bfae80f2 22561
c19d1205 22562 if (unwind.personality_routine == NULL)
bfae80f2 22563 {
c19d1205
ZW
22564 if (unwind.personality_index == -2)
22565 {
22566 if (have_data)
5f4273c7 22567 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22568 return 1; /* EXIDX_CANTUNWIND. */
22569 }
bfae80f2 22570
c19d1205
ZW
22571 /* Use a default personality routine if none is specified. */
22572 if (unwind.personality_index == -1)
22573 {
22574 if (unwind.opcode_count > 3)
22575 unwind.personality_index = 1;
22576 else
22577 unwind.personality_index = 0;
22578 }
bfae80f2 22579
c19d1205
ZW
22580 /* Space for the personality routine entry. */
22581 if (unwind.personality_index == 0)
22582 {
22583 if (unwind.opcode_count > 3)
22584 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22585
c19d1205
ZW
22586 if (!have_data)
22587 {
22588 /* All the data is inline in the index table. */
22589 data = 0x80;
22590 n = 3;
22591 while (unwind.opcode_count > 0)
22592 {
22593 unwind.opcode_count--;
22594 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22595 n--;
22596 }
bfae80f2 22597
c19d1205
ZW
22598 /* Pad with "finish" opcodes. */
22599 while (n--)
22600 data = (data << 8) | 0xb0;
bfae80f2 22601
c19d1205
ZW
22602 return data;
22603 }
22604 size = 0;
22605 }
22606 else
22607 /* We get two opcodes "free" in the first word. */
22608 size = unwind.opcode_count - 2;
22609 }
22610 else
5011093d 22611 {
cad0da33
NC
22612 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22613 if (unwind.personality_index != -1)
22614 {
22615 as_bad (_("attempt to recreate an unwind entry"));
22616 return 1;
22617 }
5011093d
NC
22618
22619 /* An extra byte is required for the opcode count. */
22620 size = unwind.opcode_count + 1;
22621 }
bfae80f2 22622
c19d1205
ZW
22623 size = (size + 3) >> 2;
22624 if (size > 0xff)
22625 as_bad (_("too many unwind opcodes"));
bfae80f2 22626
c19d1205
ZW
22627 frag_align (2, 0, 0);
22628 record_alignment (now_seg, 2);
22629 unwind.table_entry = expr_build_dot ();
22630
22631 /* Allocate the table entry. */
22632 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22633 /* PR 13449: Zero the table entries in case some of them are not used. */
22634 memset (ptr, 0, (size << 2) + 4);
c19d1205 22635 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22636
c19d1205 22637 switch (unwind.personality_index)
bfae80f2 22638 {
c19d1205
ZW
22639 case -1:
22640 /* ??? Should this be a PLT generating relocation? */
22641 /* Custom personality routine. */
22642 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22643 BFD_RELOC_ARM_PREL31);
bfae80f2 22644
c19d1205
ZW
22645 where += 4;
22646 ptr += 4;
bfae80f2 22647
c19d1205 22648 /* Set the first byte to the number of additional words. */
5011093d 22649 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22650 n = 3;
22651 break;
bfae80f2 22652
c19d1205
ZW
22653 /* ABI defined personality routines. */
22654 case 0:
22655 /* Three opcodes bytes are packed into the first word. */
22656 data = 0x80;
22657 n = 3;
22658 break;
bfae80f2 22659
c19d1205
ZW
22660 case 1:
22661 case 2:
22662 /* The size and first two opcode bytes go in the first word. */
22663 data = ((0x80 + unwind.personality_index) << 8) | size;
22664 n = 2;
22665 break;
bfae80f2 22666
c19d1205
ZW
22667 default:
22668 /* Should never happen. */
22669 abort ();
22670 }
bfae80f2 22671
c19d1205
ZW
22672 /* Pack the opcodes into words (MSB first), reversing the list at the same
22673 time. */
22674 while (unwind.opcode_count > 0)
22675 {
22676 if (n == 0)
22677 {
22678 md_number_to_chars (ptr, data, 4);
22679 ptr += 4;
22680 n = 4;
22681 data = 0;
22682 }
22683 unwind.opcode_count--;
22684 n--;
22685 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22686 }
22687
22688 /* Finish off the last word. */
22689 if (n < 4)
22690 {
22691 /* Pad with "finish" opcodes. */
22692 while (n--)
22693 data = (data << 8) | 0xb0;
22694
22695 md_number_to_chars (ptr, data, 4);
22696 }
22697
22698 if (!have_data)
22699 {
22700 /* Add an empty descriptor if there is no user-specified data. */
22701 ptr = frag_more (4);
22702 md_number_to_chars (ptr, 0, 4);
22703 }
22704
22705 return 0;
bfae80f2
RE
22706}
22707
f0927246
NC
22708
22709/* Initialize the DWARF-2 unwind information for this procedure. */
22710
22711void
22712tc_arm_frame_initial_instructions (void)
22713{
22714 cfi_add_CFA_def_cfa (REG_SP, 0);
22715}
22716#endif /* OBJ_ELF */
22717
c19d1205
ZW
22718/* Convert REGNAME to a DWARF-2 register number. */
22719
22720int
1df69f4f 22721tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22722{
1df69f4f 22723 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22724 if (reg != FAIL)
22725 return reg;
c19d1205 22726
1f5afe1c
NC
22727 /* PR 16694: Allow VFP registers as well. */
22728 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22729 if (reg != FAIL)
22730 return 64 + reg;
c19d1205 22731
1f5afe1c
NC
22732 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22733 if (reg != FAIL)
22734 return reg + 256;
22735
0198d5e6 22736 return FAIL;
bfae80f2
RE
22737}
22738
f0927246 22739#ifdef TE_PE
c19d1205 22740void
f0927246 22741tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22742{
91d6fa6a 22743 expressionS exp;
bfae80f2 22744
91d6fa6a
NC
22745 exp.X_op = O_secrel;
22746 exp.X_add_symbol = symbol;
22747 exp.X_add_number = 0;
22748 emit_expr (&exp, size);
f0927246
NC
22749}
22750#endif
bfae80f2 22751
c19d1205 22752/* MD interface: Symbol and relocation handling. */
bfae80f2 22753
2fc8bdac
ZW
22754/* Return the address within the segment that a PC-relative fixup is
22755 relative to. For ARM, PC-relative fixups applied to instructions
22756 are generally relative to the location of the fixup plus 8 bytes.
22757 Thumb branches are offset by 4, and Thumb loads relative to PC
22758 require special handling. */
bfae80f2 22759
c19d1205 22760long
2fc8bdac 22761md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22762{
2fc8bdac
ZW
22763 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22764
22765 /* If this is pc-relative and we are going to emit a relocation
22766 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22767 will need. Otherwise we want to use the calculated base.
22768 For WinCE we skip the bias for externals as well, since this
22769 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22770 if (fixP->fx_pcrel
2fc8bdac 22771 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22772 || (arm_force_relocation (fixP)
22773#ifdef TE_WINCE
22774 && !S_IS_EXTERNAL (fixP->fx_addsy)
22775#endif
22776 )))
2fc8bdac 22777 base = 0;
bfae80f2 22778
267bf995 22779
c19d1205 22780 switch (fixP->fx_r_type)
bfae80f2 22781 {
2fc8bdac
ZW
22782 /* PC relative addressing on the Thumb is slightly odd as the
22783 bottom two bits of the PC are forced to zero for the
22784 calculation. This happens *after* application of the
22785 pipeline offset. However, Thumb adrl already adjusts for
22786 this, so we need not do it again. */
c19d1205 22787 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22788 return base & ~3;
c19d1205
ZW
22789
22790 case BFD_RELOC_ARM_THUMB_OFFSET:
22791 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22792 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22793 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22794 return (base + 4) & ~3;
c19d1205 22795
2fc8bdac
ZW
22796 /* Thumb branches are simply offset by +4. */
22797 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22798 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22799 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22800 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22801 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22802 return base + 4;
bfae80f2 22803
267bf995 22804 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22805 if (fixP->fx_addsy
22806 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22807 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22808 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22809 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22810 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22811 return base + 4;
22812
00adf2d4
JB
22813 /* BLX is like branches above, but forces the low two bits of PC to
22814 zero. */
486499d0
CL
22815 case BFD_RELOC_THUMB_PCREL_BLX:
22816 if (fixP->fx_addsy
22817 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22818 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22819 && THUMB_IS_FUNC (fixP->fx_addsy)
22820 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22821 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22822 return (base + 4) & ~3;
22823
2fc8bdac
ZW
22824 /* ARM mode branches are offset by +8. However, the Windows CE
22825 loader expects the relocation not to take this into account. */
267bf995 22826 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22827 if (fixP->fx_addsy
22828 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22829 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22830 && ARM_IS_FUNC (fixP->fx_addsy)
22831 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22832 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22833 return base + 8;
267bf995 22834
486499d0
CL
22835 case BFD_RELOC_ARM_PCREL_CALL:
22836 if (fixP->fx_addsy
22837 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22838 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22839 && THUMB_IS_FUNC (fixP->fx_addsy)
22840 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22841 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22842 return base + 8;
267bf995 22843
2fc8bdac 22844 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22845 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22846 case BFD_RELOC_ARM_PLT32:
c19d1205 22847#ifdef TE_WINCE
5f4273c7 22848 /* When handling fixups immediately, because we have already
477330fc 22849 discovered the value of a symbol, or the address of the frag involved
53baae48 22850 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22851 see fixup_segment() in write.c
22852 The S_IS_EXTERNAL test handles the case of global symbols.
22853 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22854 if (fixP->fx_pcrel
22855 && fixP->fx_addsy != NULL
22856 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22857 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22858 return base + 8;
2fc8bdac 22859 return base;
c19d1205 22860#else
2fc8bdac 22861 return base + 8;
c19d1205 22862#endif
2fc8bdac 22863
267bf995 22864
2fc8bdac
ZW
22865 /* ARM mode loads relative to PC are also offset by +8. Unlike
22866 branches, the Windows CE loader *does* expect the relocation
22867 to take this into account. */
22868 case BFD_RELOC_ARM_OFFSET_IMM:
22869 case BFD_RELOC_ARM_OFFSET_IMM8:
22870 case BFD_RELOC_ARM_HWLITERAL:
22871 case BFD_RELOC_ARM_LITERAL:
22872 case BFD_RELOC_ARM_CP_OFF_IMM:
22873 return base + 8;
22874
22875
22876 /* Other PC-relative relocations are un-offset. */
22877 default:
22878 return base;
22879 }
bfae80f2
RE
22880}
22881
8b2d793c
NC
22882static bfd_boolean flag_warn_syms = TRUE;
22883
ae8714c2
NC
22884bfd_boolean
22885arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22886{
8b2d793c
NC
22887 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22888 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22889 does mean that the resulting code might be very confusing to the reader.
22890 Also this warning can be triggered if the user omits an operand before
22891 an immediate address, eg:
22892
22893 LDR =foo
22894
22895 GAS treats this as an assignment of the value of the symbol foo to a
22896 symbol LDR, and so (without this code) it will not issue any kind of
22897 warning or error message.
22898
22899 Note - ARM instructions are case-insensitive but the strings in the hash
22900 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22901 lower case too. */
22902 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22903 {
22904 char * nbuf = strdup (name);
22905 char * p;
22906
22907 for (p = nbuf; *p; p++)
22908 *p = TOLOWER (*p);
22909 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22910 {
22911 static struct hash_control * already_warned = NULL;
22912
22913 if (already_warned == NULL)
22914 already_warned = hash_new ();
22915 /* Only warn about the symbol once. To keep the code
22916 simple we let hash_insert do the lookup for us. */
22917 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22918 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22919 }
22920 else
22921 free (nbuf);
22922 }
3739860c 22923
ae8714c2
NC
22924 return FALSE;
22925}
22926
22927/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22928 Otherwise we have no need to default values of symbols. */
22929
22930symbolS *
22931md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22932{
22933#ifdef OBJ_ELF
22934 if (name[0] == '_' && name[1] == 'G'
22935 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22936 {
22937 if (!GOT_symbol)
22938 {
22939 if (symbol_find (name))
22940 as_bad (_("GOT already in the symbol table"));
22941
22942 GOT_symbol = symbol_new (name, undefined_section,
22943 (valueT) 0, & zero_address_frag);
22944 }
22945
22946 return GOT_symbol;
22947 }
22948#endif
22949
c921be7d 22950 return NULL;
bfae80f2
RE
22951}
22952
55cf6793 22953/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22954 computed as two separate immediate values, added together. We
22955 already know that this value cannot be computed by just one ARM
22956 instruction. */
22957
22958static unsigned int
22959validate_immediate_twopart (unsigned int val,
22960 unsigned int * highpart)
bfae80f2 22961{
c19d1205
ZW
22962 unsigned int a;
22963 unsigned int i;
bfae80f2 22964
c19d1205
ZW
22965 for (i = 0; i < 32; i += 2)
22966 if (((a = rotate_left (val, i)) & 0xff) != 0)
22967 {
22968 if (a & 0xff00)
22969 {
22970 if (a & ~ 0xffff)
22971 continue;
22972 * highpart = (a >> 8) | ((i + 24) << 7);
22973 }
22974 else if (a & 0xff0000)
22975 {
22976 if (a & 0xff000000)
22977 continue;
22978 * highpart = (a >> 16) | ((i + 16) << 7);
22979 }
22980 else
22981 {
9c2799c2 22982 gas_assert (a & 0xff000000);
c19d1205
ZW
22983 * highpart = (a >> 24) | ((i + 8) << 7);
22984 }
bfae80f2 22985
c19d1205
ZW
22986 return (a & 0xff) | (i << 7);
22987 }
bfae80f2 22988
c19d1205 22989 return FAIL;
bfae80f2
RE
22990}
22991
c19d1205
ZW
22992static int
22993validate_offset_imm (unsigned int val, int hwse)
22994{
22995 if ((hwse && val > 255) || val > 4095)
22996 return FAIL;
22997 return val;
22998}
bfae80f2 22999
55cf6793 23000/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
23001 negative immediate constant by altering the instruction. A bit of
23002 a hack really.
23003 MOV <-> MVN
23004 AND <-> BIC
23005 ADC <-> SBC
23006 by inverting the second operand, and
23007 ADD <-> SUB
23008 CMP <-> CMN
23009 by negating the second operand. */
bfae80f2 23010
c19d1205
ZW
23011static int
23012negate_data_op (unsigned long * instruction,
23013 unsigned long value)
bfae80f2 23014{
c19d1205
ZW
23015 int op, new_inst;
23016 unsigned long negated, inverted;
bfae80f2 23017
c19d1205
ZW
23018 negated = encode_arm_immediate (-value);
23019 inverted = encode_arm_immediate (~value);
bfae80f2 23020
c19d1205
ZW
23021 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
23022 switch (op)
bfae80f2 23023 {
c19d1205
ZW
23024 /* First negates. */
23025 case OPCODE_SUB: /* ADD <-> SUB */
23026 new_inst = OPCODE_ADD;
23027 value = negated;
23028 break;
bfae80f2 23029
c19d1205
ZW
23030 case OPCODE_ADD:
23031 new_inst = OPCODE_SUB;
23032 value = negated;
23033 break;
bfae80f2 23034
c19d1205
ZW
23035 case OPCODE_CMP: /* CMP <-> CMN */
23036 new_inst = OPCODE_CMN;
23037 value = negated;
23038 break;
bfae80f2 23039
c19d1205
ZW
23040 case OPCODE_CMN:
23041 new_inst = OPCODE_CMP;
23042 value = negated;
23043 break;
bfae80f2 23044
c19d1205
ZW
23045 /* Now Inverted ops. */
23046 case OPCODE_MOV: /* MOV <-> MVN */
23047 new_inst = OPCODE_MVN;
23048 value = inverted;
23049 break;
bfae80f2 23050
c19d1205
ZW
23051 case OPCODE_MVN:
23052 new_inst = OPCODE_MOV;
23053 value = inverted;
23054 break;
bfae80f2 23055
c19d1205
ZW
23056 case OPCODE_AND: /* AND <-> BIC */
23057 new_inst = OPCODE_BIC;
23058 value = inverted;
23059 break;
bfae80f2 23060
c19d1205
ZW
23061 case OPCODE_BIC:
23062 new_inst = OPCODE_AND;
23063 value = inverted;
23064 break;
bfae80f2 23065
c19d1205
ZW
23066 case OPCODE_ADC: /* ADC <-> SBC */
23067 new_inst = OPCODE_SBC;
23068 value = inverted;
23069 break;
bfae80f2 23070
c19d1205
ZW
23071 case OPCODE_SBC:
23072 new_inst = OPCODE_ADC;
23073 value = inverted;
23074 break;
bfae80f2 23075
c19d1205
ZW
23076 /* We cannot do anything. */
23077 default:
23078 return FAIL;
b99bd4ef
NC
23079 }
23080
c19d1205
ZW
23081 if (value == (unsigned) FAIL)
23082 return FAIL;
23083
23084 *instruction &= OPCODE_MASK;
23085 *instruction |= new_inst << DATA_OP_SHIFT;
23086 return value;
b99bd4ef
NC
23087}
23088
ef8d22e6
PB
23089/* Like negate_data_op, but for Thumb-2. */
23090
23091static unsigned int
16dd5e42 23092thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
23093{
23094 int op, new_inst;
23095 int rd;
16dd5e42 23096 unsigned int negated, inverted;
ef8d22e6
PB
23097
23098 negated = encode_thumb32_immediate (-value);
23099 inverted = encode_thumb32_immediate (~value);
23100
23101 rd = (*instruction >> 8) & 0xf;
23102 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
23103 switch (op)
23104 {
23105 /* ADD <-> SUB. Includes CMP <-> CMN. */
23106 case T2_OPCODE_SUB:
23107 new_inst = T2_OPCODE_ADD;
23108 value = negated;
23109 break;
23110
23111 case T2_OPCODE_ADD:
23112 new_inst = T2_OPCODE_SUB;
23113 value = negated;
23114 break;
23115
23116 /* ORR <-> ORN. Includes MOV <-> MVN. */
23117 case T2_OPCODE_ORR:
23118 new_inst = T2_OPCODE_ORN;
23119 value = inverted;
23120 break;
23121
23122 case T2_OPCODE_ORN:
23123 new_inst = T2_OPCODE_ORR;
23124 value = inverted;
23125 break;
23126
23127 /* AND <-> BIC. TST has no inverted equivalent. */
23128 case T2_OPCODE_AND:
23129 new_inst = T2_OPCODE_BIC;
23130 if (rd == 15)
23131 value = FAIL;
23132 else
23133 value = inverted;
23134 break;
23135
23136 case T2_OPCODE_BIC:
23137 new_inst = T2_OPCODE_AND;
23138 value = inverted;
23139 break;
23140
23141 /* ADC <-> SBC */
23142 case T2_OPCODE_ADC:
23143 new_inst = T2_OPCODE_SBC;
23144 value = inverted;
23145 break;
23146
23147 case T2_OPCODE_SBC:
23148 new_inst = T2_OPCODE_ADC;
23149 value = inverted;
23150 break;
23151
23152 /* We cannot do anything. */
23153 default:
23154 return FAIL;
23155 }
23156
16dd5e42 23157 if (value == (unsigned int)FAIL)
ef8d22e6
PB
23158 return FAIL;
23159
23160 *instruction &= T2_OPCODE_MASK;
23161 *instruction |= new_inst << T2_DATA_OP_SHIFT;
23162 return value;
23163}
23164
8f06b2d8 23165/* Read a 32-bit thumb instruction from buf. */
0198d5e6 23166
8f06b2d8
PB
23167static unsigned long
23168get_thumb32_insn (char * buf)
23169{
23170 unsigned long insn;
23171 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
23172 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23173
23174 return insn;
23175}
23176
a8bc6c78
PB
23177/* We usually want to set the low bit on the address of thumb function
23178 symbols. In particular .word foo - . should have the low bit set.
23179 Generic code tries to fold the difference of two symbols to
23180 a constant. Prevent this and force a relocation when the first symbols
23181 is a thumb function. */
c921be7d
NC
23182
23183bfd_boolean
a8bc6c78
PB
23184arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
23185{
23186 if (op == O_subtract
23187 && l->X_op == O_symbol
23188 && r->X_op == O_symbol
23189 && THUMB_IS_FUNC (l->X_add_symbol))
23190 {
23191 l->X_op = O_subtract;
23192 l->X_op_symbol = r->X_add_symbol;
23193 l->X_add_number -= r->X_add_number;
c921be7d 23194 return TRUE;
a8bc6c78 23195 }
c921be7d 23196
a8bc6c78 23197 /* Process as normal. */
c921be7d 23198 return FALSE;
a8bc6c78
PB
23199}
23200
4a42ebbc
RR
23201/* Encode Thumb2 unconditional branches and calls. The encoding
23202 for the 2 are identical for the immediate values. */
23203
23204static void
23205encode_thumb2_b_bl_offset (char * buf, offsetT value)
23206{
23207#define T2I1I2MASK ((1 << 13) | (1 << 11))
23208 offsetT newval;
23209 offsetT newval2;
23210 addressT S, I1, I2, lo, hi;
23211
23212 S = (value >> 24) & 0x01;
23213 I1 = (value >> 23) & 0x01;
23214 I2 = (value >> 22) & 0x01;
23215 hi = (value >> 12) & 0x3ff;
fa94de6b 23216 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
23217 newval = md_chars_to_number (buf, THUMB_SIZE);
23218 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23219 newval |= (S << 10) | hi;
23220 newval2 &= ~T2I1I2MASK;
23221 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
23222 md_number_to_chars (buf, newval, THUMB_SIZE);
23223 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23224}
23225
c19d1205 23226void
55cf6793 23227md_apply_fix (fixS * fixP,
c19d1205
ZW
23228 valueT * valP,
23229 segT seg)
23230{
23231 offsetT value = * valP;
23232 offsetT newval;
23233 unsigned int newimm;
23234 unsigned long temp;
23235 int sign;
23236 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 23237
9c2799c2 23238 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 23239
c19d1205 23240 /* Note whether this will delete the relocation. */
4962c51a 23241
c19d1205
ZW
23242 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
23243 fixP->fx_done = 1;
b99bd4ef 23244
adbaf948 23245 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 23246 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
23247 for emit_reloc. */
23248 value &= 0xffffffff;
23249 value ^= 0x80000000;
5f4273c7 23250 value -= 0x80000000;
adbaf948
ZW
23251
23252 *valP = value;
c19d1205 23253 fixP->fx_addnumber = value;
b99bd4ef 23254
adbaf948
ZW
23255 /* Same treatment for fixP->fx_offset. */
23256 fixP->fx_offset &= 0xffffffff;
23257 fixP->fx_offset ^= 0x80000000;
23258 fixP->fx_offset -= 0x80000000;
23259
c19d1205 23260 switch (fixP->fx_r_type)
b99bd4ef 23261 {
c19d1205
ZW
23262 case BFD_RELOC_NONE:
23263 /* This will need to go in the object file. */
23264 fixP->fx_done = 0;
23265 break;
b99bd4ef 23266
c19d1205
ZW
23267 case BFD_RELOC_ARM_IMMEDIATE:
23268 /* We claim that this fixup has been processed here,
23269 even if in fact we generate an error because we do
23270 not have a reloc for it, so tc_gen_reloc will reject it. */
23271 fixP->fx_done = 1;
b99bd4ef 23272
77db8e2e 23273 if (fixP->fx_addsy)
b99bd4ef 23274 {
77db8e2e 23275 const char *msg = 0;
b99bd4ef 23276
77db8e2e
NC
23277 if (! S_IS_DEFINED (fixP->fx_addsy))
23278 msg = _("undefined symbol %s used as an immediate value");
23279 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23280 msg = _("symbol %s is in a different section");
23281 else if (S_IS_WEAK (fixP->fx_addsy))
23282 msg = _("symbol %s is weak and may be overridden later");
23283
23284 if (msg)
23285 {
23286 as_bad_where (fixP->fx_file, fixP->fx_line,
23287 msg, S_GET_NAME (fixP->fx_addsy));
23288 break;
23289 }
42e5fcbf
AS
23290 }
23291
c19d1205
ZW
23292 temp = md_chars_to_number (buf, INSN_SIZE);
23293
5e73442d
SL
23294 /* If the offset is negative, we should use encoding A2 for ADR. */
23295 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
23296 newimm = negate_data_op (&temp, value);
23297 else
23298 {
23299 newimm = encode_arm_immediate (value);
23300
23301 /* If the instruction will fail, see if we can fix things up by
23302 changing the opcode. */
23303 if (newimm == (unsigned int) FAIL)
23304 newimm = negate_data_op (&temp, value);
bada4342
JW
23305 /* MOV accepts both ARM modified immediate (A1 encoding) and
23306 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
23307 When disassembling, MOV is preferred when there is no encoding
23308 overlap. */
23309 if (newimm == (unsigned int) FAIL
23310 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
23311 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
23312 && !((temp >> SBIT_SHIFT) & 0x1)
23313 && value >= 0 && value <= 0xffff)
23314 {
23315 /* Clear bits[23:20] to change encoding from A1 to A2. */
23316 temp &= 0xff0fffff;
23317 /* Encoding high 4bits imm. Code below will encode the remaining
23318 low 12bits. */
23319 temp |= (value & 0x0000f000) << 4;
23320 newimm = value & 0x00000fff;
23321 }
5e73442d
SL
23322 }
23323
23324 if (newimm == (unsigned int) FAIL)
b99bd4ef 23325 {
c19d1205
ZW
23326 as_bad_where (fixP->fx_file, fixP->fx_line,
23327 _("invalid constant (%lx) after fixup"),
23328 (unsigned long) value);
23329 break;
b99bd4ef 23330 }
b99bd4ef 23331
c19d1205
ZW
23332 newimm |= (temp & 0xfffff000);
23333 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
23334 break;
b99bd4ef 23335
c19d1205
ZW
23336 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23337 {
23338 unsigned int highpart = 0;
23339 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 23340
77db8e2e 23341 if (fixP->fx_addsy)
42e5fcbf 23342 {
77db8e2e 23343 const char *msg = 0;
42e5fcbf 23344
77db8e2e
NC
23345 if (! S_IS_DEFINED (fixP->fx_addsy))
23346 msg = _("undefined symbol %s used as an immediate value");
23347 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23348 msg = _("symbol %s is in a different section");
23349 else if (S_IS_WEAK (fixP->fx_addsy))
23350 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 23351
77db8e2e
NC
23352 if (msg)
23353 {
23354 as_bad_where (fixP->fx_file, fixP->fx_line,
23355 msg, S_GET_NAME (fixP->fx_addsy));
23356 break;
23357 }
23358 }
fa94de6b 23359
c19d1205
ZW
23360 newimm = encode_arm_immediate (value);
23361 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 23362
c19d1205
ZW
23363 /* If the instruction will fail, see if we can fix things up by
23364 changing the opcode. */
23365 if (newimm == (unsigned int) FAIL
23366 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
23367 {
23368 /* No ? OK - try using two ADD instructions to generate
23369 the value. */
23370 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 23371
c19d1205
ZW
23372 /* Yes - then make sure that the second instruction is
23373 also an add. */
23374 if (newimm != (unsigned int) FAIL)
23375 newinsn = temp;
23376 /* Still No ? Try using a negated value. */
23377 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
23378 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
23379 /* Otherwise - give up. */
23380 else
23381 {
23382 as_bad_where (fixP->fx_file, fixP->fx_line,
23383 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
23384 (long) value);
23385 break;
23386 }
b99bd4ef 23387
c19d1205
ZW
23388 /* Replace the first operand in the 2nd instruction (which
23389 is the PC) with the destination register. We have
23390 already added in the PC in the first instruction and we
23391 do not want to do it again. */
23392 newinsn &= ~ 0xf0000;
23393 newinsn |= ((newinsn & 0x0f000) << 4);
23394 }
b99bd4ef 23395
c19d1205
ZW
23396 newimm |= (temp & 0xfffff000);
23397 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 23398
c19d1205
ZW
23399 highpart |= (newinsn & 0xfffff000);
23400 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
23401 }
23402 break;
b99bd4ef 23403
c19d1205 23404 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23405 if (!fixP->fx_done && seg->use_rela_p)
23406 value = 0;
1a0670f3 23407 /* Fall through. */
00a97672 23408
c19d1205 23409 case BFD_RELOC_ARM_LITERAL:
26d97720 23410 sign = value > 0;
b99bd4ef 23411
c19d1205
ZW
23412 if (value < 0)
23413 value = - value;
b99bd4ef 23414
c19d1205 23415 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 23416 {
c19d1205
ZW
23417 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23418 as_bad_where (fixP->fx_file, fixP->fx_line,
23419 _("invalid literal constant: pool needs to be closer"));
23420 else
23421 as_bad_where (fixP->fx_file, fixP->fx_line,
23422 _("bad immediate value for offset (%ld)"),
23423 (long) value);
23424 break;
f03698e6
RE
23425 }
23426
c19d1205 23427 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23428 if (value == 0)
23429 newval &= 0xfffff000;
23430 else
23431 {
23432 newval &= 0xff7ff000;
23433 newval |= value | (sign ? INDEX_UP : 0);
23434 }
c19d1205
ZW
23435 md_number_to_chars (buf, newval, INSN_SIZE);
23436 break;
b99bd4ef 23437
c19d1205
ZW
23438 case BFD_RELOC_ARM_OFFSET_IMM8:
23439 case BFD_RELOC_ARM_HWLITERAL:
26d97720 23440 sign = value > 0;
b99bd4ef 23441
c19d1205
ZW
23442 if (value < 0)
23443 value = - value;
b99bd4ef 23444
c19d1205 23445 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 23446 {
c19d1205
ZW
23447 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23448 as_bad_where (fixP->fx_file, fixP->fx_line,
23449 _("invalid literal constant: pool needs to be closer"));
23450 else
427d0db6
RM
23451 as_bad_where (fixP->fx_file, fixP->fx_line,
23452 _("bad immediate value for 8-bit offset (%ld)"),
23453 (long) value);
c19d1205 23454 break;
b99bd4ef
NC
23455 }
23456
c19d1205 23457 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23458 if (value == 0)
23459 newval &= 0xfffff0f0;
23460 else
23461 {
23462 newval &= 0xff7ff0f0;
23463 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23464 }
c19d1205
ZW
23465 md_number_to_chars (buf, newval, INSN_SIZE);
23466 break;
b99bd4ef 23467
c19d1205
ZW
23468 case BFD_RELOC_ARM_T32_OFFSET_U8:
23469 if (value < 0 || value > 1020 || value % 4 != 0)
23470 as_bad_where (fixP->fx_file, fixP->fx_line,
23471 _("bad immediate value for offset (%ld)"), (long) value);
23472 value /= 4;
b99bd4ef 23473
c19d1205 23474 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
23475 newval |= value;
23476 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23477 break;
b99bd4ef 23478
c19d1205
ZW
23479 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23480 /* This is a complicated relocation used for all varieties of Thumb32
23481 load/store instruction with immediate offset:
23482
23483 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 23484 *4, optional writeback(W)
c19d1205
ZW
23485 (doubleword load/store)
23486
23487 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23488 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23489 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23490 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23491 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23492
23493 Uppercase letters indicate bits that are already encoded at
23494 this point. Lowercase letters are our problem. For the
23495 second block of instructions, the secondary opcode nybble
23496 (bits 8..11) is present, and bit 23 is zero, even if this is
23497 a PC-relative operation. */
23498 newval = md_chars_to_number (buf, THUMB_SIZE);
23499 newval <<= 16;
23500 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 23501
c19d1205 23502 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 23503 {
c19d1205
ZW
23504 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23505 if (value >= 0)
23506 newval |= (1 << 23);
23507 else
23508 value = -value;
23509 if (value % 4 != 0)
23510 {
23511 as_bad_where (fixP->fx_file, fixP->fx_line,
23512 _("offset not a multiple of 4"));
23513 break;
23514 }
23515 value /= 4;
216d22bc 23516 if (value > 0xff)
c19d1205
ZW
23517 {
23518 as_bad_where (fixP->fx_file, fixP->fx_line,
23519 _("offset out of range"));
23520 break;
23521 }
23522 newval &= ~0xff;
b99bd4ef 23523 }
c19d1205 23524 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 23525 {
c19d1205
ZW
23526 /* PC-relative, 12-bit offset. */
23527 if (value >= 0)
23528 newval |= (1 << 23);
23529 else
23530 value = -value;
216d22bc 23531 if (value > 0xfff)
c19d1205
ZW
23532 {
23533 as_bad_where (fixP->fx_file, fixP->fx_line,
23534 _("offset out of range"));
23535 break;
23536 }
23537 newval &= ~0xfff;
b99bd4ef 23538 }
c19d1205 23539 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 23540 {
c19d1205
ZW
23541 /* Writeback: 8-bit, +/- offset. */
23542 if (value >= 0)
23543 newval |= (1 << 9);
23544 else
23545 value = -value;
216d22bc 23546 if (value > 0xff)
c19d1205
ZW
23547 {
23548 as_bad_where (fixP->fx_file, fixP->fx_line,
23549 _("offset out of range"));
23550 break;
23551 }
23552 newval &= ~0xff;
b99bd4ef 23553 }
c19d1205 23554 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 23555 {
c19d1205 23556 /* T-instruction: positive 8-bit offset. */
216d22bc 23557 if (value < 0 || value > 0xff)
b99bd4ef 23558 {
c19d1205
ZW
23559 as_bad_where (fixP->fx_file, fixP->fx_line,
23560 _("offset out of range"));
23561 break;
b99bd4ef 23562 }
c19d1205
ZW
23563 newval &= ~0xff;
23564 newval |= value;
b99bd4ef
NC
23565 }
23566 else
b99bd4ef 23567 {
c19d1205
ZW
23568 /* Positive 12-bit or negative 8-bit offset. */
23569 int limit;
23570 if (value >= 0)
b99bd4ef 23571 {
c19d1205
ZW
23572 newval |= (1 << 23);
23573 limit = 0xfff;
23574 }
23575 else
23576 {
23577 value = -value;
23578 limit = 0xff;
23579 }
23580 if (value > limit)
23581 {
23582 as_bad_where (fixP->fx_file, fixP->fx_line,
23583 _("offset out of range"));
23584 break;
b99bd4ef 23585 }
c19d1205 23586 newval &= ~limit;
b99bd4ef 23587 }
b99bd4ef 23588
c19d1205
ZW
23589 newval |= value;
23590 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23591 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23592 break;
404ff6b5 23593
c19d1205
ZW
23594 case BFD_RELOC_ARM_SHIFT_IMM:
23595 newval = md_chars_to_number (buf, INSN_SIZE);
23596 if (((unsigned long) value) > 32
23597 || (value == 32
23598 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23599 {
23600 as_bad_where (fixP->fx_file, fixP->fx_line,
23601 _("shift expression is too large"));
23602 break;
23603 }
404ff6b5 23604
c19d1205
ZW
23605 if (value == 0)
23606 /* Shifts of zero must be done as lsl. */
23607 newval &= ~0x60;
23608 else if (value == 32)
23609 value = 0;
23610 newval &= 0xfffff07f;
23611 newval |= (value & 0x1f) << 7;
23612 md_number_to_chars (buf, newval, INSN_SIZE);
23613 break;
404ff6b5 23614
c19d1205 23615 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23616 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23617 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23618 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23619 /* We claim that this fixup has been processed here,
23620 even if in fact we generate an error because we do
23621 not have a reloc for it, so tc_gen_reloc will reject it. */
23622 fixP->fx_done = 1;
404ff6b5 23623
c19d1205
ZW
23624 if (fixP->fx_addsy
23625 && ! S_IS_DEFINED (fixP->fx_addsy))
23626 {
23627 as_bad_where (fixP->fx_file, fixP->fx_line,
23628 _("undefined symbol %s used as an immediate value"),
23629 S_GET_NAME (fixP->fx_addsy));
23630 break;
23631 }
404ff6b5 23632
c19d1205
ZW
23633 newval = md_chars_to_number (buf, THUMB_SIZE);
23634 newval <<= 16;
23635 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23636
16805f35 23637 newimm = FAIL;
bada4342
JW
23638 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23639 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23640 Thumb2 modified immediate encoding (T2). */
23641 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 23642 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23643 {
23644 newimm = encode_thumb32_immediate (value);
23645 if (newimm == (unsigned int) FAIL)
23646 newimm = thumb32_negate_data_op (&newval, value);
23647 }
bada4342 23648 if (newimm == (unsigned int) FAIL)
92e90b6e 23649 {
bada4342 23650 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 23651 {
bada4342
JW
23652 /* Turn add/sum into addw/subw. */
23653 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23654 newval = (newval & 0xfeffffff) | 0x02000000;
23655 /* No flat 12-bit imm encoding for addsw/subsw. */
23656 if ((newval & 0x00100000) == 0)
40f246e3 23657 {
bada4342
JW
23658 /* 12 bit immediate for addw/subw. */
23659 if (value < 0)
23660 {
23661 value = -value;
23662 newval ^= 0x00a00000;
23663 }
23664 if (value > 0xfff)
23665 newimm = (unsigned int) FAIL;
23666 else
23667 newimm = value;
23668 }
23669 }
23670 else
23671 {
23672 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23673 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23674 disassembling, MOV is preferred when there is no encoding
db7bf105 23675 overlap. */
bada4342 23676 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
db7bf105
NC
23677 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
23678 but with the Rn field [19:16] set to 1111. */
23679 && (((newval >> 16) & 0xf) == 0xf)
bada4342
JW
23680 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23681 && !((newval >> T2_SBIT_SHIFT) & 0x1)
db7bf105 23682 && value >= 0 && value <= 0xffff)
bada4342
JW
23683 {
23684 /* Toggle bit[25] to change encoding from T2 to T3. */
23685 newval ^= 1 << 25;
23686 /* Clear bits[19:16]. */
23687 newval &= 0xfff0ffff;
23688 /* Encoding high 4bits imm. Code below will encode the
23689 remaining low 12bits. */
23690 newval |= (value & 0x0000f000) << 4;
23691 newimm = value & 0x00000fff;
40f246e3 23692 }
e9f89963 23693 }
92e90b6e 23694 }
cc8a6dd0 23695
c19d1205 23696 if (newimm == (unsigned int)FAIL)
3631a3c8 23697 {
c19d1205
ZW
23698 as_bad_where (fixP->fx_file, fixP->fx_line,
23699 _("invalid constant (%lx) after fixup"),
23700 (unsigned long) value);
23701 break;
3631a3c8
NC
23702 }
23703
c19d1205
ZW
23704 newval |= (newimm & 0x800) << 15;
23705 newval |= (newimm & 0x700) << 4;
23706 newval |= (newimm & 0x0ff);
cc8a6dd0 23707
c19d1205
ZW
23708 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23709 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23710 break;
a737bd4d 23711
3eb17e6b 23712 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23713 if (((unsigned long) value) > 0xffff)
23714 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23715 _("invalid smc expression"));
2fc8bdac 23716 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23717 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23718 md_number_to_chars (buf, newval, INSN_SIZE);
23719 break;
a737bd4d 23720
90ec0d68
MGD
23721 case BFD_RELOC_ARM_HVC:
23722 if (((unsigned long) value) > 0xffff)
23723 as_bad_where (fixP->fx_file, fixP->fx_line,
23724 _("invalid hvc expression"));
23725 newval = md_chars_to_number (buf, INSN_SIZE);
23726 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23727 md_number_to_chars (buf, newval, INSN_SIZE);
23728 break;
23729
c19d1205 23730 case BFD_RELOC_ARM_SWI:
adbaf948 23731 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23732 {
23733 if (((unsigned long) value) > 0xff)
23734 as_bad_where (fixP->fx_file, fixP->fx_line,
23735 _("invalid swi expression"));
2fc8bdac 23736 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23737 newval |= value;
23738 md_number_to_chars (buf, newval, THUMB_SIZE);
23739 }
23740 else
23741 {
23742 if (((unsigned long) value) > 0x00ffffff)
23743 as_bad_where (fixP->fx_file, fixP->fx_line,
23744 _("invalid swi expression"));
2fc8bdac 23745 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23746 newval |= value;
23747 md_number_to_chars (buf, newval, INSN_SIZE);
23748 }
23749 break;
a737bd4d 23750
c19d1205
ZW
23751 case BFD_RELOC_ARM_MULTI:
23752 if (((unsigned long) value) > 0xffff)
23753 as_bad_where (fixP->fx_file, fixP->fx_line,
23754 _("invalid expression in load/store multiple"));
23755 newval = value | md_chars_to_number (buf, INSN_SIZE);
23756 md_number_to_chars (buf, newval, INSN_SIZE);
23757 break;
a737bd4d 23758
c19d1205 23759#ifdef OBJ_ELF
39b41c9c 23760 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23761
23762 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23763 && fixP->fx_addsy
34e77a92 23764 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23765 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23766 && THUMB_IS_FUNC (fixP->fx_addsy))
23767 /* Flip the bl to blx. This is a simple flip
23768 bit here because we generate PCREL_CALL for
23769 unconditional bls. */
23770 {
23771 newval = md_chars_to_number (buf, INSN_SIZE);
23772 newval = newval | 0x10000000;
23773 md_number_to_chars (buf, newval, INSN_SIZE);
23774 temp = 1;
23775 fixP->fx_done = 1;
23776 }
39b41c9c
PB
23777 else
23778 temp = 3;
23779 goto arm_branch_common;
23780
23781 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23782 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23783 && fixP->fx_addsy
34e77a92 23784 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23785 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23786 && THUMB_IS_FUNC (fixP->fx_addsy))
23787 {
23788 /* This would map to a bl<cond>, b<cond>,
23789 b<always> to a Thumb function. We
23790 need to force a relocation for this particular
23791 case. */
23792 newval = md_chars_to_number (buf, INSN_SIZE);
23793 fixP->fx_done = 0;
23794 }
1a0670f3 23795 /* Fall through. */
267bf995 23796
2fc8bdac 23797 case BFD_RELOC_ARM_PLT32:
c19d1205 23798#endif
39b41c9c
PB
23799 case BFD_RELOC_ARM_PCREL_BRANCH:
23800 temp = 3;
23801 goto arm_branch_common;
a737bd4d 23802
39b41c9c 23803 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23804
39b41c9c 23805 temp = 1;
267bf995
RR
23806 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23807 && fixP->fx_addsy
34e77a92 23808 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23809 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23810 && ARM_IS_FUNC (fixP->fx_addsy))
23811 {
23812 /* Flip the blx to a bl and warn. */
23813 const char *name = S_GET_NAME (fixP->fx_addsy);
23814 newval = 0xeb000000;
23815 as_warn_where (fixP->fx_file, fixP->fx_line,
23816 _("blx to '%s' an ARM ISA state function changed to bl"),
23817 name);
23818 md_number_to_chars (buf, newval, INSN_SIZE);
23819 temp = 3;
23820 fixP->fx_done = 1;
23821 }
23822
23823#ifdef OBJ_ELF
23824 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23825 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23826#endif
23827
39b41c9c 23828 arm_branch_common:
c19d1205 23829 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23830 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23831 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 23832 also be clear. */
39b41c9c 23833 if (value & temp)
c19d1205 23834 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23835 _("misaligned branch destination"));
23836 if ((value & (offsetT)0xfe000000) != (offsetT)0
23837 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23838 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23839
2fc8bdac 23840 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23841 {
2fc8bdac
ZW
23842 newval = md_chars_to_number (buf, INSN_SIZE);
23843 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23844 /* Set the H bit on BLX instructions. */
23845 if (temp == 1)
23846 {
23847 if (value & 2)
23848 newval |= 0x01000000;
23849 else
23850 newval &= ~0x01000000;
23851 }
2fc8bdac 23852 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23853 }
c19d1205 23854 break;
a737bd4d 23855
25fe350b
MS
23856 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23857 /* CBZ can only branch forward. */
a737bd4d 23858
738755b0 23859 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23860 (which, strictly speaking, are prohibited) will be turned into
23861 no-ops.
738755b0
MS
23862
23863 FIXME: It may be better to remove the instruction completely and
23864 perform relaxation. */
23865 if (value == -2)
2fc8bdac
ZW
23866 {
23867 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23868 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23869 md_number_to_chars (buf, newval, THUMB_SIZE);
23870 }
738755b0
MS
23871 else
23872 {
23873 if (value & ~0x7e)
08f10d51 23874 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23875
477330fc 23876 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23877 {
23878 newval = md_chars_to_number (buf, THUMB_SIZE);
23879 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23880 md_number_to_chars (buf, newval, THUMB_SIZE);
23881 }
23882 }
c19d1205 23883 break;
a737bd4d 23884
c19d1205 23885 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23886 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23887 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23888
2fc8bdac
ZW
23889 if (fixP->fx_done || !seg->use_rela_p)
23890 {
23891 newval = md_chars_to_number (buf, THUMB_SIZE);
23892 newval |= (value & 0x1ff) >> 1;
23893 md_number_to_chars (buf, newval, THUMB_SIZE);
23894 }
c19d1205 23895 break;
a737bd4d 23896
c19d1205 23897 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23898 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23899 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23900
2fc8bdac
ZW
23901 if (fixP->fx_done || !seg->use_rela_p)
23902 {
23903 newval = md_chars_to_number (buf, THUMB_SIZE);
23904 newval |= (value & 0xfff) >> 1;
23905 md_number_to_chars (buf, newval, THUMB_SIZE);
23906 }
c19d1205 23907 break;
a737bd4d 23908
c19d1205 23909 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23910 if (fixP->fx_addsy
23911 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23912 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23913 && ARM_IS_FUNC (fixP->fx_addsy)
23914 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23915 {
23916 /* Force a relocation for a branch 20 bits wide. */
23917 fixP->fx_done = 0;
23918 }
08f10d51 23919 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23920 as_bad_where (fixP->fx_file, fixP->fx_line,
23921 _("conditional branch out of range"));
404ff6b5 23922
2fc8bdac
ZW
23923 if (fixP->fx_done || !seg->use_rela_p)
23924 {
23925 offsetT newval2;
23926 addressT S, J1, J2, lo, hi;
404ff6b5 23927
2fc8bdac
ZW
23928 S = (value & 0x00100000) >> 20;
23929 J2 = (value & 0x00080000) >> 19;
23930 J1 = (value & 0x00040000) >> 18;
23931 hi = (value & 0x0003f000) >> 12;
23932 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23933
2fc8bdac
ZW
23934 newval = md_chars_to_number (buf, THUMB_SIZE);
23935 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23936 newval |= (S << 10) | hi;
23937 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23938 md_number_to_chars (buf, newval, THUMB_SIZE);
23939 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23940 }
c19d1205 23941 break;
6c43fab6 23942
c19d1205 23943 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23944 /* If there is a blx from a thumb state function to
23945 another thumb function flip this to a bl and warn
23946 about it. */
23947
23948 if (fixP->fx_addsy
34e77a92 23949 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23950 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23951 && THUMB_IS_FUNC (fixP->fx_addsy))
23952 {
23953 const char *name = S_GET_NAME (fixP->fx_addsy);
23954 as_warn_where (fixP->fx_file, fixP->fx_line,
23955 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23956 name);
23957 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23958 newval = newval | 0x1000;
23959 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23960 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23961 fixP->fx_done = 1;
23962 }
23963
23964
23965 goto thumb_bl_common;
23966
c19d1205 23967 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23968 /* A bl from Thumb state ISA to an internal ARM state function
23969 is converted to a blx. */
23970 if (fixP->fx_addsy
23971 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23972 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23973 && ARM_IS_FUNC (fixP->fx_addsy)
23974 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23975 {
23976 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23977 newval = newval & ~0x1000;
23978 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23979 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23980 fixP->fx_done = 1;
23981 }
23982
23983 thumb_bl_common:
23984
2fc8bdac
ZW
23985 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23986 /* For a BLX instruction, make sure that the relocation is rounded up
23987 to a word boundary. This follows the semantics of the instruction
23988 which specifies that bit 1 of the target address will come from bit
23989 1 of the base address. */
d406f3e4
JB
23990 value = (value + 3) & ~ 3;
23991
23992#ifdef OBJ_ELF
23993 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23994 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23995 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23996#endif
404ff6b5 23997
2b2f5df9
NC
23998 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23999 {
fc289b0a 24000 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
24001 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
24002 else if ((value & ~0x1ffffff)
24003 && ((value & ~0x1ffffff) != ~0x1ffffff))
24004 as_bad_where (fixP->fx_file, fixP->fx_line,
24005 _("Thumb2 branch out of range"));
24006 }
4a42ebbc
RR
24007
24008 if (fixP->fx_done || !seg->use_rela_p)
24009 encode_thumb2_b_bl_offset (buf, value);
24010
c19d1205 24011 break;
404ff6b5 24012
c19d1205 24013 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
24014 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
24015 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 24016
2fc8bdac 24017 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 24018 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 24019
2fc8bdac 24020 break;
a737bd4d 24021
2fc8bdac
ZW
24022 case BFD_RELOC_8:
24023 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 24024 *buf = value;
c19d1205 24025 break;
a737bd4d 24026
c19d1205 24027 case BFD_RELOC_16:
2fc8bdac 24028 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 24029 md_number_to_chars (buf, value, 2);
c19d1205 24030 break;
a737bd4d 24031
c19d1205 24032#ifdef OBJ_ELF
0855e32b
NS
24033 case BFD_RELOC_ARM_TLS_CALL:
24034 case BFD_RELOC_ARM_THM_TLS_CALL:
24035 case BFD_RELOC_ARM_TLS_DESCSEQ:
24036 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 24037 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
24038 case BFD_RELOC_ARM_TLS_GD32:
24039 case BFD_RELOC_ARM_TLS_LE32:
24040 case BFD_RELOC_ARM_TLS_IE32:
24041 case BFD_RELOC_ARM_TLS_LDM32:
24042 case BFD_RELOC_ARM_TLS_LDO32:
24043 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 24044 break;
6c43fab6 24045
5c5a4843
CL
24046 /* Same handling as above, but with the arm_fdpic guard. */
24047 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
24048 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
24049 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
24050 if (arm_fdpic)
24051 {
24052 S_SET_THREAD_LOCAL (fixP->fx_addsy);
24053 }
24054 else
24055 {
24056 as_bad_where (fixP->fx_file, fixP->fx_line,
24057 _("Relocation supported only in FDPIC mode"));
24058 }
24059 break;
24060
c19d1205
ZW
24061 case BFD_RELOC_ARM_GOT32:
24062 case BFD_RELOC_ARM_GOTOFF:
c19d1205 24063 break;
b43420e6
NC
24064
24065 case BFD_RELOC_ARM_GOT_PREL:
24066 if (fixP->fx_done || !seg->use_rela_p)
477330fc 24067 md_number_to_chars (buf, value, 4);
b43420e6
NC
24068 break;
24069
9a6f4e97
NS
24070 case BFD_RELOC_ARM_TARGET2:
24071 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
24072 addend here for REL targets, because it won't be written out
24073 during reloc processing later. */
9a6f4e97
NS
24074 if (fixP->fx_done || !seg->use_rela_p)
24075 md_number_to_chars (buf, fixP->fx_offset, 4);
24076 break;
188fd7ae
CL
24077
24078 /* Relocations for FDPIC. */
24079 case BFD_RELOC_ARM_GOTFUNCDESC:
24080 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
24081 case BFD_RELOC_ARM_FUNCDESC:
24082 if (arm_fdpic)
24083 {
24084 if (fixP->fx_done || !seg->use_rela_p)
24085 md_number_to_chars (buf, 0, 4);
24086 }
24087 else
24088 {
24089 as_bad_where (fixP->fx_file, fixP->fx_line,
24090 _("Relocation supported only in FDPIC mode"));
24091 }
24092 break;
c19d1205 24093#endif
6c43fab6 24094
c19d1205
ZW
24095 case BFD_RELOC_RVA:
24096 case BFD_RELOC_32:
24097 case BFD_RELOC_ARM_TARGET1:
24098 case BFD_RELOC_ARM_ROSEGREL32:
24099 case BFD_RELOC_ARM_SBREL32:
24100 case BFD_RELOC_32_PCREL:
f0927246
NC
24101#ifdef TE_PE
24102 case BFD_RELOC_32_SECREL:
24103#endif
2fc8bdac 24104 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
24105#ifdef TE_WINCE
24106 /* For WinCE we only do this for pcrel fixups. */
24107 if (fixP->fx_done || fixP->fx_pcrel)
24108#endif
24109 md_number_to_chars (buf, value, 4);
c19d1205 24110 break;
6c43fab6 24111
c19d1205
ZW
24112#ifdef OBJ_ELF
24113 case BFD_RELOC_ARM_PREL31:
2fc8bdac 24114 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
24115 {
24116 newval = md_chars_to_number (buf, 4) & 0x80000000;
24117 if ((value ^ (value >> 1)) & 0x40000000)
24118 {
24119 as_bad_where (fixP->fx_file, fixP->fx_line,
24120 _("rel31 relocation overflow"));
24121 }
24122 newval |= value & 0x7fffffff;
24123 md_number_to_chars (buf, newval, 4);
24124 }
24125 break;
c19d1205 24126#endif
a737bd4d 24127
c19d1205 24128 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 24129 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
24130 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
24131 newval = md_chars_to_number (buf, INSN_SIZE);
24132 else
24133 newval = get_thumb32_insn (buf);
24134 if ((newval & 0x0f200f00) == 0x0d000900)
24135 {
24136 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
24137 has permitted values that are multiples of 2, in the range 0
24138 to 510. */
24139 if (value < -510 || value > 510 || (value & 1))
24140 as_bad_where (fixP->fx_file, fixP->fx_line,
24141 _("co-processor offset out of range"));
24142 }
24143 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
24144 as_bad_where (fixP->fx_file, fixP->fx_line,
24145 _("co-processor offset out of range"));
24146 cp_off_common:
26d97720 24147 sign = value > 0;
c19d1205
ZW
24148 if (value < 0)
24149 value = -value;
8f06b2d8
PB
24150 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24151 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24152 newval = md_chars_to_number (buf, INSN_SIZE);
24153 else
24154 newval = get_thumb32_insn (buf);
26d97720
NS
24155 if (value == 0)
24156 newval &= 0xffffff00;
24157 else
24158 {
24159 newval &= 0xff7fff00;
9db2f6b4
RL
24160 if ((newval & 0x0f200f00) == 0x0d000900)
24161 {
24162 /* This is a fp16 vstr/vldr.
24163
24164 It requires the immediate offset in the instruction is shifted
24165 left by 1 to be a half-word offset.
24166
24167 Here, left shift by 1 first, and later right shift by 2
24168 should get the right offset. */
24169 value <<= 1;
24170 }
26d97720
NS
24171 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
24172 }
8f06b2d8
PB
24173 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24174 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24175 md_number_to_chars (buf, newval, INSN_SIZE);
24176 else
24177 put_thumb32_insn (buf, newval);
c19d1205 24178 break;
a737bd4d 24179
c19d1205 24180 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 24181 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
24182 if (value < -255 || value > 255)
24183 as_bad_where (fixP->fx_file, fixP->fx_line,
24184 _("co-processor offset out of range"));
df7849c5 24185 value *= 4;
c19d1205 24186 goto cp_off_common;
6c43fab6 24187
c19d1205
ZW
24188 case BFD_RELOC_ARM_THUMB_OFFSET:
24189 newval = md_chars_to_number (buf, THUMB_SIZE);
24190 /* Exactly what ranges, and where the offset is inserted depends
24191 on the type of instruction, we can establish this from the
24192 top 4 bits. */
24193 switch (newval >> 12)
24194 {
24195 case 4: /* PC load. */
24196 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
24197 forced to zero for these loads; md_pcrel_from has already
24198 compensated for this. */
24199 if (value & 3)
24200 as_bad_where (fixP->fx_file, fixP->fx_line,
24201 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
24202 (((unsigned long) fixP->fx_frag->fr_address
24203 + (unsigned long) fixP->fx_where) & ~3)
24204 + (unsigned long) value);
a737bd4d 24205
c19d1205
ZW
24206 if (value & ~0x3fc)
24207 as_bad_where (fixP->fx_file, fixP->fx_line,
24208 _("invalid offset, value too big (0x%08lX)"),
24209 (long) value);
a737bd4d 24210
c19d1205
ZW
24211 newval |= value >> 2;
24212 break;
a737bd4d 24213
c19d1205
ZW
24214 case 9: /* SP load/store. */
24215 if (value & ~0x3fc)
24216 as_bad_where (fixP->fx_file, fixP->fx_line,
24217 _("invalid offset, value too big (0x%08lX)"),
24218 (long) value);
24219 newval |= value >> 2;
24220 break;
6c43fab6 24221
c19d1205
ZW
24222 case 6: /* Word load/store. */
24223 if (value & ~0x7c)
24224 as_bad_where (fixP->fx_file, fixP->fx_line,
24225 _("invalid offset, value too big (0x%08lX)"),
24226 (long) value);
24227 newval |= value << 4; /* 6 - 2. */
24228 break;
a737bd4d 24229
c19d1205
ZW
24230 case 7: /* Byte load/store. */
24231 if (value & ~0x1f)
24232 as_bad_where (fixP->fx_file, fixP->fx_line,
24233 _("invalid offset, value too big (0x%08lX)"),
24234 (long) value);
24235 newval |= value << 6;
24236 break;
a737bd4d 24237
c19d1205
ZW
24238 case 8: /* Halfword load/store. */
24239 if (value & ~0x3e)
24240 as_bad_where (fixP->fx_file, fixP->fx_line,
24241 _("invalid offset, value too big (0x%08lX)"),
24242 (long) value);
24243 newval |= value << 5; /* 6 - 1. */
24244 break;
a737bd4d 24245
c19d1205
ZW
24246 default:
24247 as_bad_where (fixP->fx_file, fixP->fx_line,
24248 "Unable to process relocation for thumb opcode: %lx",
24249 (unsigned long) newval);
24250 break;
24251 }
24252 md_number_to_chars (buf, newval, THUMB_SIZE);
24253 break;
a737bd4d 24254
c19d1205
ZW
24255 case BFD_RELOC_ARM_THUMB_ADD:
24256 /* This is a complicated relocation, since we use it for all of
24257 the following immediate relocations:
a737bd4d 24258
c19d1205
ZW
24259 3bit ADD/SUB
24260 8bit ADD/SUB
24261 9bit ADD/SUB SP word-aligned
24262 10bit ADD PC/SP word-aligned
a737bd4d 24263
c19d1205
ZW
24264 The type of instruction being processed is encoded in the
24265 instruction field:
a737bd4d 24266
c19d1205
ZW
24267 0x8000 SUB
24268 0x00F0 Rd
24269 0x000F Rs
24270 */
24271 newval = md_chars_to_number (buf, THUMB_SIZE);
24272 {
24273 int rd = (newval >> 4) & 0xf;
24274 int rs = newval & 0xf;
24275 int subtract = !!(newval & 0x8000);
a737bd4d 24276
c19d1205
ZW
24277 /* Check for HI regs, only very restricted cases allowed:
24278 Adjusting SP, and using PC or SP to get an address. */
24279 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
24280 || (rs > 7 && rs != REG_SP && rs != REG_PC))
24281 as_bad_where (fixP->fx_file, fixP->fx_line,
24282 _("invalid Hi register with immediate"));
a737bd4d 24283
c19d1205
ZW
24284 /* If value is negative, choose the opposite instruction. */
24285 if (value < 0)
24286 {
24287 value = -value;
24288 subtract = !subtract;
24289 if (value < 0)
24290 as_bad_where (fixP->fx_file, fixP->fx_line,
24291 _("immediate value out of range"));
24292 }
a737bd4d 24293
c19d1205
ZW
24294 if (rd == REG_SP)
24295 {
75c11999 24296 if (value & ~0x1fc)
c19d1205
ZW
24297 as_bad_where (fixP->fx_file, fixP->fx_line,
24298 _("invalid immediate for stack address calculation"));
24299 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
24300 newval |= value >> 2;
24301 }
24302 else if (rs == REG_PC || rs == REG_SP)
24303 {
c12d2c9d
NC
24304 /* PR gas/18541. If the addition is for a defined symbol
24305 within range of an ADR instruction then accept it. */
24306 if (subtract
24307 && value == 4
24308 && fixP->fx_addsy != NULL)
24309 {
24310 subtract = 0;
24311
24312 if (! S_IS_DEFINED (fixP->fx_addsy)
24313 || S_GET_SEGMENT (fixP->fx_addsy) != seg
24314 || S_IS_WEAK (fixP->fx_addsy))
24315 {
24316 as_bad_where (fixP->fx_file, fixP->fx_line,
24317 _("address calculation needs a strongly defined nearby symbol"));
24318 }
24319 else
24320 {
24321 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
24322
24323 /* Round up to the next 4-byte boundary. */
24324 if (v & 3)
24325 v = (v + 3) & ~ 3;
24326 else
24327 v += 4;
24328 v = S_GET_VALUE (fixP->fx_addsy) - v;
24329
24330 if (v & ~0x3fc)
24331 {
24332 as_bad_where (fixP->fx_file, fixP->fx_line,
24333 _("symbol too far away"));
24334 }
24335 else
24336 {
24337 fixP->fx_done = 1;
24338 value = v;
24339 }
24340 }
24341 }
24342
c19d1205
ZW
24343 if (subtract || value & ~0x3fc)
24344 as_bad_where (fixP->fx_file, fixP->fx_line,
24345 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 24346 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
24347 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
24348 newval |= rd << 8;
24349 newval |= value >> 2;
24350 }
24351 else if (rs == rd)
24352 {
24353 if (value & ~0xff)
24354 as_bad_where (fixP->fx_file, fixP->fx_line,
24355 _("immediate value out of range"));
24356 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
24357 newval |= (rd << 8) | value;
24358 }
24359 else
24360 {
24361 if (value & ~0x7)
24362 as_bad_where (fixP->fx_file, fixP->fx_line,
24363 _("immediate value out of range"));
24364 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
24365 newval |= rd | (rs << 3) | (value << 6);
24366 }
24367 }
24368 md_number_to_chars (buf, newval, THUMB_SIZE);
24369 break;
a737bd4d 24370
c19d1205
ZW
24371 case BFD_RELOC_ARM_THUMB_IMM:
24372 newval = md_chars_to_number (buf, THUMB_SIZE);
24373 if (value < 0 || value > 255)
24374 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 24375 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
24376 (long) value);
24377 newval |= value;
24378 md_number_to_chars (buf, newval, THUMB_SIZE);
24379 break;
a737bd4d 24380
c19d1205
ZW
24381 case BFD_RELOC_ARM_THUMB_SHIFT:
24382 /* 5bit shift value (0..32). LSL cannot take 32. */
24383 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
24384 temp = newval & 0xf800;
24385 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
24386 as_bad_where (fixP->fx_file, fixP->fx_line,
24387 _("invalid shift value: %ld"), (long) value);
24388 /* Shifts of zero must be encoded as LSL. */
24389 if (value == 0)
24390 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
24391 /* Shifts of 32 are encoded as zero. */
24392 else if (value == 32)
24393 value = 0;
24394 newval |= value << 6;
24395 md_number_to_chars (buf, newval, THUMB_SIZE);
24396 break;
a737bd4d 24397
c19d1205
ZW
24398 case BFD_RELOC_VTABLE_INHERIT:
24399 case BFD_RELOC_VTABLE_ENTRY:
24400 fixP->fx_done = 0;
24401 return;
6c43fab6 24402
b6895b4f
PB
24403 case BFD_RELOC_ARM_MOVW:
24404 case BFD_RELOC_ARM_MOVT:
24405 case BFD_RELOC_ARM_THUMB_MOVW:
24406 case BFD_RELOC_ARM_THUMB_MOVT:
24407 if (fixP->fx_done || !seg->use_rela_p)
24408 {
24409 /* REL format relocations are limited to a 16-bit addend. */
24410 if (!fixP->fx_done)
24411 {
39623e12 24412 if (value < -0x8000 || value > 0x7fff)
b6895b4f 24413 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 24414 _("offset out of range"));
b6895b4f
PB
24415 }
24416 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24417 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24418 {
24419 value >>= 16;
24420 }
24421
24422 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24423 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24424 {
24425 newval = get_thumb32_insn (buf);
24426 newval &= 0xfbf08f00;
24427 newval |= (value & 0xf000) << 4;
24428 newval |= (value & 0x0800) << 15;
24429 newval |= (value & 0x0700) << 4;
24430 newval |= (value & 0x00ff);
24431 put_thumb32_insn (buf, newval);
24432 }
24433 else
24434 {
24435 newval = md_chars_to_number (buf, 4);
24436 newval &= 0xfff0f000;
24437 newval |= value & 0x0fff;
24438 newval |= (value & 0xf000) << 4;
24439 md_number_to_chars (buf, newval, 4);
24440 }
24441 }
24442 return;
24443
72d98d16
MG
24444 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24445 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24446 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24447 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24448 gas_assert (!fixP->fx_done);
24449 {
24450 bfd_vma insn;
24451 bfd_boolean is_mov;
24452 bfd_vma encoded_addend = value;
24453
24454 /* Check that addend can be encoded in instruction. */
24455 if (!seg->use_rela_p && (value < 0 || value > 255))
24456 as_bad_where (fixP->fx_file, fixP->fx_line,
24457 _("the offset 0x%08lX is not representable"),
24458 (unsigned long) encoded_addend);
24459
24460 /* Extract the instruction. */
24461 insn = md_chars_to_number (buf, THUMB_SIZE);
24462 is_mov = (insn & 0xf800) == 0x2000;
24463
24464 /* Encode insn. */
24465 if (is_mov)
24466 {
24467 if (!seg->use_rela_p)
24468 insn |= encoded_addend;
24469 }
24470 else
24471 {
24472 int rd, rs;
24473
24474 /* Extract the instruction. */
24475 /* Encoding is the following
24476 0x8000 SUB
24477 0x00F0 Rd
24478 0x000F Rs
24479 */
24480 /* The following conditions must be true :
24481 - ADD
24482 - Rd == Rs
24483 - Rd <= 7
24484 */
24485 rd = (insn >> 4) & 0xf;
24486 rs = insn & 0xf;
24487 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24488 as_bad_where (fixP->fx_file, fixP->fx_line,
24489 _("Unable to process relocation for thumb opcode: %lx"),
24490 (unsigned long) insn);
24491
24492 /* Encode as ADD immediate8 thumb 1 code. */
24493 insn = 0x3000 | (rd << 8);
24494
24495 /* Place the encoded addend into the first 8 bits of the
24496 instruction. */
24497 if (!seg->use_rela_p)
24498 insn |= encoded_addend;
24499 }
24500
24501 /* Update the instruction. */
24502 md_number_to_chars (buf, insn, THUMB_SIZE);
24503 }
24504 break;
24505
4962c51a
MS
24506 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24507 case BFD_RELOC_ARM_ALU_PC_G0:
24508 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24509 case BFD_RELOC_ARM_ALU_PC_G1:
24510 case BFD_RELOC_ARM_ALU_PC_G2:
24511 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24512 case BFD_RELOC_ARM_ALU_SB_G0:
24513 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24514 case BFD_RELOC_ARM_ALU_SB_G1:
24515 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 24516 gas_assert (!fixP->fx_done);
4962c51a
MS
24517 if (!seg->use_rela_p)
24518 {
477330fc
RM
24519 bfd_vma insn;
24520 bfd_vma encoded_addend;
3ca4a8ec 24521 bfd_vma addend_abs = llabs (value);
477330fc
RM
24522
24523 /* Check that the absolute value of the addend can be
24524 expressed as an 8-bit constant plus a rotation. */
24525 encoded_addend = encode_arm_immediate (addend_abs);
24526 if (encoded_addend == (unsigned int) FAIL)
4962c51a 24527 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24528 _("the offset 0x%08lX is not representable"),
24529 (unsigned long) addend_abs);
24530
24531 /* Extract the instruction. */
24532 insn = md_chars_to_number (buf, INSN_SIZE);
24533
24534 /* If the addend is positive, use an ADD instruction.
24535 Otherwise use a SUB. Take care not to destroy the S bit. */
24536 insn &= 0xff1fffff;
24537 if (value < 0)
24538 insn |= 1 << 22;
24539 else
24540 insn |= 1 << 23;
24541
24542 /* Place the encoded addend into the first 12 bits of the
24543 instruction. */
24544 insn &= 0xfffff000;
24545 insn |= encoded_addend;
24546
24547 /* Update the instruction. */
24548 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
24549 }
24550 break;
24551
24552 case BFD_RELOC_ARM_LDR_PC_G0:
24553 case BFD_RELOC_ARM_LDR_PC_G1:
24554 case BFD_RELOC_ARM_LDR_PC_G2:
24555 case BFD_RELOC_ARM_LDR_SB_G0:
24556 case BFD_RELOC_ARM_LDR_SB_G1:
24557 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 24558 gas_assert (!fixP->fx_done);
4962c51a 24559 if (!seg->use_rela_p)
477330fc
RM
24560 {
24561 bfd_vma insn;
3ca4a8ec 24562 bfd_vma addend_abs = llabs (value);
4962c51a 24563
477330fc
RM
24564 /* Check that the absolute value of the addend can be
24565 encoded in 12 bits. */
24566 if (addend_abs >= 0x1000)
4962c51a 24567 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24568 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24569 (unsigned long) addend_abs);
24570
24571 /* Extract the instruction. */
24572 insn = md_chars_to_number (buf, INSN_SIZE);
24573
24574 /* If the addend is negative, clear bit 23 of the instruction.
24575 Otherwise set it. */
24576 if (value < 0)
24577 insn &= ~(1 << 23);
24578 else
24579 insn |= 1 << 23;
24580
24581 /* Place the absolute value of the addend into the first 12 bits
24582 of the instruction. */
24583 insn &= 0xfffff000;
24584 insn |= addend_abs;
24585
24586 /* Update the instruction. */
24587 md_number_to_chars (buf, insn, INSN_SIZE);
24588 }
4962c51a
MS
24589 break;
24590
24591 case BFD_RELOC_ARM_LDRS_PC_G0:
24592 case BFD_RELOC_ARM_LDRS_PC_G1:
24593 case BFD_RELOC_ARM_LDRS_PC_G2:
24594 case BFD_RELOC_ARM_LDRS_SB_G0:
24595 case BFD_RELOC_ARM_LDRS_SB_G1:
24596 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 24597 gas_assert (!fixP->fx_done);
4962c51a 24598 if (!seg->use_rela_p)
477330fc
RM
24599 {
24600 bfd_vma insn;
3ca4a8ec 24601 bfd_vma addend_abs = llabs (value);
4962c51a 24602
477330fc
RM
24603 /* Check that the absolute value of the addend can be
24604 encoded in 8 bits. */
24605 if (addend_abs >= 0x100)
4962c51a 24606 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24607 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24608 (unsigned long) addend_abs);
24609
24610 /* Extract the instruction. */
24611 insn = md_chars_to_number (buf, INSN_SIZE);
24612
24613 /* If the addend is negative, clear bit 23 of the instruction.
24614 Otherwise set it. */
24615 if (value < 0)
24616 insn &= ~(1 << 23);
24617 else
24618 insn |= 1 << 23;
24619
24620 /* Place the first four bits of the absolute value of the addend
24621 into the first 4 bits of the instruction, and the remaining
24622 four into bits 8 .. 11. */
24623 insn &= 0xfffff0f0;
24624 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24625
24626 /* Update the instruction. */
24627 md_number_to_chars (buf, insn, INSN_SIZE);
24628 }
4962c51a
MS
24629 break;
24630
24631 case BFD_RELOC_ARM_LDC_PC_G0:
24632 case BFD_RELOC_ARM_LDC_PC_G1:
24633 case BFD_RELOC_ARM_LDC_PC_G2:
24634 case BFD_RELOC_ARM_LDC_SB_G0:
24635 case BFD_RELOC_ARM_LDC_SB_G1:
24636 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 24637 gas_assert (!fixP->fx_done);
4962c51a 24638 if (!seg->use_rela_p)
477330fc
RM
24639 {
24640 bfd_vma insn;
3ca4a8ec 24641 bfd_vma addend_abs = llabs (value);
4962c51a 24642
477330fc
RM
24643 /* Check that the absolute value of the addend is a multiple of
24644 four and, when divided by four, fits in 8 bits. */
24645 if (addend_abs & 0x3)
4962c51a 24646 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24647 _("bad offset 0x%08lX (must be word-aligned)"),
24648 (unsigned long) addend_abs);
4962c51a 24649
477330fc 24650 if ((addend_abs >> 2) > 0xff)
4962c51a 24651 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24652 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24653 (unsigned long) addend_abs);
24654
24655 /* Extract the instruction. */
24656 insn = md_chars_to_number (buf, INSN_SIZE);
24657
24658 /* If the addend is negative, clear bit 23 of the instruction.
24659 Otherwise set it. */
24660 if (value < 0)
24661 insn &= ~(1 << 23);
24662 else
24663 insn |= 1 << 23;
24664
24665 /* Place the addend (divided by four) into the first eight
24666 bits of the instruction. */
24667 insn &= 0xfffffff0;
24668 insn |= addend_abs >> 2;
24669
24670 /* Update the instruction. */
24671 md_number_to_chars (buf, insn, INSN_SIZE);
24672 }
4962c51a
MS
24673 break;
24674
845b51d6
PB
24675 case BFD_RELOC_ARM_V4BX:
24676 /* This will need to go in the object file. */
24677 fixP->fx_done = 0;
24678 break;
24679
c19d1205
ZW
24680 case BFD_RELOC_UNUSED:
24681 default:
24682 as_bad_where (fixP->fx_file, fixP->fx_line,
24683 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24684 }
6c43fab6
RE
24685}
24686
c19d1205
ZW
24687/* Translate internal representation of relocation info to BFD target
24688 format. */
a737bd4d 24689
c19d1205 24690arelent *
00a97672 24691tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24692{
c19d1205
ZW
24693 arelent * reloc;
24694 bfd_reloc_code_real_type code;
a737bd4d 24695
325801bd 24696 reloc = XNEW (arelent);
a737bd4d 24697
325801bd 24698 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24699 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24700 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24701
2fc8bdac 24702 if (fixp->fx_pcrel)
00a97672
RS
24703 {
24704 if (section->use_rela_p)
24705 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24706 else
24707 fixp->fx_offset = reloc->address;
24708 }
c19d1205 24709 reloc->addend = fixp->fx_offset;
a737bd4d 24710
c19d1205 24711 switch (fixp->fx_r_type)
a737bd4d 24712 {
c19d1205
ZW
24713 case BFD_RELOC_8:
24714 if (fixp->fx_pcrel)
24715 {
24716 code = BFD_RELOC_8_PCREL;
24717 break;
24718 }
1a0670f3 24719 /* Fall through. */
a737bd4d 24720
c19d1205
ZW
24721 case BFD_RELOC_16:
24722 if (fixp->fx_pcrel)
24723 {
24724 code = BFD_RELOC_16_PCREL;
24725 break;
24726 }
1a0670f3 24727 /* Fall through. */
6c43fab6 24728
c19d1205
ZW
24729 case BFD_RELOC_32:
24730 if (fixp->fx_pcrel)
24731 {
24732 code = BFD_RELOC_32_PCREL;
24733 break;
24734 }
1a0670f3 24735 /* Fall through. */
a737bd4d 24736
b6895b4f
PB
24737 case BFD_RELOC_ARM_MOVW:
24738 if (fixp->fx_pcrel)
24739 {
24740 code = BFD_RELOC_ARM_MOVW_PCREL;
24741 break;
24742 }
1a0670f3 24743 /* Fall through. */
b6895b4f
PB
24744
24745 case BFD_RELOC_ARM_MOVT:
24746 if (fixp->fx_pcrel)
24747 {
24748 code = BFD_RELOC_ARM_MOVT_PCREL;
24749 break;
24750 }
1a0670f3 24751 /* Fall through. */
b6895b4f
PB
24752
24753 case BFD_RELOC_ARM_THUMB_MOVW:
24754 if (fixp->fx_pcrel)
24755 {
24756 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24757 break;
24758 }
1a0670f3 24759 /* Fall through. */
b6895b4f
PB
24760
24761 case BFD_RELOC_ARM_THUMB_MOVT:
24762 if (fixp->fx_pcrel)
24763 {
24764 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24765 break;
24766 }
1a0670f3 24767 /* Fall through. */
b6895b4f 24768
c19d1205
ZW
24769 case BFD_RELOC_NONE:
24770 case BFD_RELOC_ARM_PCREL_BRANCH:
24771 case BFD_RELOC_ARM_PCREL_BLX:
24772 case BFD_RELOC_RVA:
24773 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24774 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24775 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24776 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24777 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24778 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24779 case BFD_RELOC_VTABLE_ENTRY:
24780 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24781#ifdef TE_PE
24782 case BFD_RELOC_32_SECREL:
24783#endif
c19d1205
ZW
24784 code = fixp->fx_r_type;
24785 break;
a737bd4d 24786
00adf2d4
JB
24787 case BFD_RELOC_THUMB_PCREL_BLX:
24788#ifdef OBJ_ELF
24789 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24790 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24791 else
24792#endif
24793 code = BFD_RELOC_THUMB_PCREL_BLX;
24794 break;
24795
c19d1205
ZW
24796 case BFD_RELOC_ARM_LITERAL:
24797 case BFD_RELOC_ARM_HWLITERAL:
24798 /* If this is called then the a literal has
24799 been referenced across a section boundary. */
24800 as_bad_where (fixp->fx_file, fixp->fx_line,
24801 _("literal referenced across section boundary"));
24802 return NULL;
a737bd4d 24803
c19d1205 24804#ifdef OBJ_ELF
0855e32b
NS
24805 case BFD_RELOC_ARM_TLS_CALL:
24806 case BFD_RELOC_ARM_THM_TLS_CALL:
24807 case BFD_RELOC_ARM_TLS_DESCSEQ:
24808 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24809 case BFD_RELOC_ARM_GOT32:
24810 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24811 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24812 case BFD_RELOC_ARM_PLT32:
24813 case BFD_RELOC_ARM_TARGET1:
24814 case BFD_RELOC_ARM_ROSEGREL32:
24815 case BFD_RELOC_ARM_SBREL32:
24816 case BFD_RELOC_ARM_PREL31:
24817 case BFD_RELOC_ARM_TARGET2:
c19d1205 24818 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24819 case BFD_RELOC_ARM_PCREL_CALL:
24820 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24821 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24822 case BFD_RELOC_ARM_ALU_PC_G0:
24823 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24824 case BFD_RELOC_ARM_ALU_PC_G1:
24825 case BFD_RELOC_ARM_ALU_PC_G2:
24826 case BFD_RELOC_ARM_LDR_PC_G0:
24827 case BFD_RELOC_ARM_LDR_PC_G1:
24828 case BFD_RELOC_ARM_LDR_PC_G2:
24829 case BFD_RELOC_ARM_LDRS_PC_G0:
24830 case BFD_RELOC_ARM_LDRS_PC_G1:
24831 case BFD_RELOC_ARM_LDRS_PC_G2:
24832 case BFD_RELOC_ARM_LDC_PC_G0:
24833 case BFD_RELOC_ARM_LDC_PC_G1:
24834 case BFD_RELOC_ARM_LDC_PC_G2:
24835 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24836 case BFD_RELOC_ARM_ALU_SB_G0:
24837 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24838 case BFD_RELOC_ARM_ALU_SB_G1:
24839 case BFD_RELOC_ARM_ALU_SB_G2:
24840 case BFD_RELOC_ARM_LDR_SB_G0:
24841 case BFD_RELOC_ARM_LDR_SB_G1:
24842 case BFD_RELOC_ARM_LDR_SB_G2:
24843 case BFD_RELOC_ARM_LDRS_SB_G0:
24844 case BFD_RELOC_ARM_LDRS_SB_G1:
24845 case BFD_RELOC_ARM_LDRS_SB_G2:
24846 case BFD_RELOC_ARM_LDC_SB_G0:
24847 case BFD_RELOC_ARM_LDC_SB_G1:
24848 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24849 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24850 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24851 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24852 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24853 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
188fd7ae
CL
24854 case BFD_RELOC_ARM_GOTFUNCDESC:
24855 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
24856 case BFD_RELOC_ARM_FUNCDESC:
c19d1205
ZW
24857 code = fixp->fx_r_type;
24858 break;
a737bd4d 24859
0855e32b 24860 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24861 case BFD_RELOC_ARM_TLS_GD32:
5c5a4843 24862 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
75c11999 24863 case BFD_RELOC_ARM_TLS_LE32:
c19d1205 24864 case BFD_RELOC_ARM_TLS_IE32:
5c5a4843 24865 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
c19d1205 24866 case BFD_RELOC_ARM_TLS_LDM32:
5c5a4843 24867 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
c19d1205
ZW
24868 /* BFD will include the symbol's address in the addend.
24869 But we don't want that, so subtract it out again here. */
24870 if (!S_IS_COMMON (fixp->fx_addsy))
24871 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24872 code = fixp->fx_r_type;
24873 break;
24874#endif
a737bd4d 24875
c19d1205
ZW
24876 case BFD_RELOC_ARM_IMMEDIATE:
24877 as_bad_where (fixp->fx_file, fixp->fx_line,
24878 _("internal relocation (type: IMMEDIATE) not fixed up"));
24879 return NULL;
a737bd4d 24880
c19d1205
ZW
24881 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24882 as_bad_where (fixp->fx_file, fixp->fx_line,
24883 _("ADRL used for a symbol not defined in the same file"));
24884 return NULL;
a737bd4d 24885
c19d1205 24886 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24887 if (section->use_rela_p)
24888 {
24889 code = fixp->fx_r_type;
24890 break;
24891 }
24892
c19d1205
ZW
24893 if (fixp->fx_addsy != NULL
24894 && !S_IS_DEFINED (fixp->fx_addsy)
24895 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24896 {
c19d1205
ZW
24897 as_bad_where (fixp->fx_file, fixp->fx_line,
24898 _("undefined local label `%s'"),
24899 S_GET_NAME (fixp->fx_addsy));
24900 return NULL;
a737bd4d
NC
24901 }
24902
c19d1205
ZW
24903 as_bad_where (fixp->fx_file, fixp->fx_line,
24904 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24905 return NULL;
a737bd4d 24906
c19d1205
ZW
24907 default:
24908 {
e0471c16 24909 const char * type;
6c43fab6 24910
c19d1205
ZW
24911 switch (fixp->fx_r_type)
24912 {
24913 case BFD_RELOC_NONE: type = "NONE"; break;
24914 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24915 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24916 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24917 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24918 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24919 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24920 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24921 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24922 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24923 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24924 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24925 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24926 default: type = _("<unknown>"); break;
24927 }
24928 as_bad_where (fixp->fx_file, fixp->fx_line,
24929 _("cannot represent %s relocation in this object file format"),
24930 type);
24931 return NULL;
24932 }
a737bd4d 24933 }
6c43fab6 24934
c19d1205
ZW
24935#ifdef OBJ_ELF
24936 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24937 && GOT_symbol
24938 && fixp->fx_addsy == GOT_symbol)
24939 {
24940 code = BFD_RELOC_ARM_GOTPC;
24941 reloc->addend = fixp->fx_offset = reloc->address;
24942 }
24943#endif
6c43fab6 24944
c19d1205 24945 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24946
c19d1205
ZW
24947 if (reloc->howto == NULL)
24948 {
24949 as_bad_where (fixp->fx_file, fixp->fx_line,
24950 _("cannot represent %s relocation in this object file format"),
24951 bfd_get_reloc_code_name (code));
24952 return NULL;
24953 }
6c43fab6 24954
c19d1205
ZW
24955 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24956 vtable entry to be used in the relocation's section offset. */
24957 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24958 reloc->address = fixp->fx_offset;
6c43fab6 24959
c19d1205 24960 return reloc;
6c43fab6
RE
24961}
24962
c19d1205 24963/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24964
c19d1205
ZW
24965void
24966cons_fix_new_arm (fragS * frag,
24967 int where,
24968 int size,
62ebcb5c
AM
24969 expressionS * exp,
24970 bfd_reloc_code_real_type reloc)
6c43fab6 24971{
c19d1205 24972 int pcrel = 0;
6c43fab6 24973
c19d1205
ZW
24974 /* Pick a reloc.
24975 FIXME: @@ Should look at CPU word size. */
24976 switch (size)
24977 {
24978 case 1:
62ebcb5c 24979 reloc = BFD_RELOC_8;
c19d1205
ZW
24980 break;
24981 case 2:
62ebcb5c 24982 reloc = BFD_RELOC_16;
c19d1205
ZW
24983 break;
24984 case 4:
24985 default:
62ebcb5c 24986 reloc = BFD_RELOC_32;
c19d1205
ZW
24987 break;
24988 case 8:
62ebcb5c 24989 reloc = BFD_RELOC_64;
c19d1205
ZW
24990 break;
24991 }
6c43fab6 24992
f0927246
NC
24993#ifdef TE_PE
24994 if (exp->X_op == O_secrel)
24995 {
24996 exp->X_op = O_symbol;
62ebcb5c 24997 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24998 }
24999#endif
25000
62ebcb5c 25001 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 25002}
6c43fab6 25003
4343666d 25004#if defined (OBJ_COFF)
c19d1205
ZW
25005void
25006arm_validate_fix (fixS * fixP)
6c43fab6 25007{
c19d1205
ZW
25008 /* If the destination of the branch is a defined symbol which does not have
25009 the THUMB_FUNC attribute, then we must be calling a function which has
25010 the (interfacearm) attribute. We look for the Thumb entry point to that
25011 function and change the branch to refer to that function instead. */
25012 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
25013 && fixP->fx_addsy != NULL
25014 && S_IS_DEFINED (fixP->fx_addsy)
25015 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 25016 {
c19d1205 25017 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 25018 }
c19d1205
ZW
25019}
25020#endif
6c43fab6 25021
267bf995 25022
c19d1205
ZW
25023int
25024arm_force_relocation (struct fix * fixp)
25025{
25026#if defined (OBJ_COFF) && defined (TE_PE)
25027 if (fixp->fx_r_type == BFD_RELOC_RVA)
25028 return 1;
25029#endif
6c43fab6 25030
267bf995
RR
25031 /* In case we have a call or a branch to a function in ARM ISA mode from
25032 a thumb function or vice-versa force the relocation. These relocations
25033 are cleared off for some cores that might have blx and simple transformations
25034 are possible. */
25035
25036#ifdef OBJ_ELF
25037 switch (fixp->fx_r_type)
25038 {
25039 case BFD_RELOC_ARM_PCREL_JUMP:
25040 case BFD_RELOC_ARM_PCREL_CALL:
25041 case BFD_RELOC_THUMB_PCREL_BLX:
25042 if (THUMB_IS_FUNC (fixp->fx_addsy))
25043 return 1;
25044 break;
25045
25046 case BFD_RELOC_ARM_PCREL_BLX:
25047 case BFD_RELOC_THUMB_PCREL_BRANCH25:
25048 case BFD_RELOC_THUMB_PCREL_BRANCH20:
25049 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25050 if (ARM_IS_FUNC (fixp->fx_addsy))
25051 return 1;
25052 break;
25053
25054 default:
25055 break;
25056 }
25057#endif
25058
b5884301
PB
25059 /* Resolve these relocations even if the symbol is extern or weak.
25060 Technically this is probably wrong due to symbol preemption.
25061 In practice these relocations do not have enough range to be useful
25062 at dynamic link time, and some code (e.g. in the Linux kernel)
25063 expects these references to be resolved. */
c19d1205
ZW
25064 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
25065 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 25066 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 25067 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
25068 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
25069 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
25070 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 25071 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
25072 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
25073 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
25074 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
25075 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
25076 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
25077 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 25078 return 0;
a737bd4d 25079
4962c51a
MS
25080 /* Always leave these relocations for the linker. */
25081 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25082 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25083 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
25084 return 1;
25085
f0291e4c
PB
25086 /* Always generate relocations against function symbols. */
25087 if (fixp->fx_r_type == BFD_RELOC_32
25088 && fixp->fx_addsy
25089 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
25090 return 1;
25091
c19d1205 25092 return generic_force_reloc (fixp);
404ff6b5
AH
25093}
25094
0ffdc86c 25095#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
25096/* Relocations against function names must be left unadjusted,
25097 so that the linker can use this information to generate interworking
25098 stubs. The MIPS version of this function
c19d1205
ZW
25099 also prevents relocations that are mips-16 specific, but I do not
25100 know why it does this.
404ff6b5 25101
c19d1205
ZW
25102 FIXME:
25103 There is one other problem that ought to be addressed here, but
25104 which currently is not: Taking the address of a label (rather
25105 than a function) and then later jumping to that address. Such
25106 addresses also ought to have their bottom bit set (assuming that
25107 they reside in Thumb code), but at the moment they will not. */
404ff6b5 25108
c19d1205
ZW
25109bfd_boolean
25110arm_fix_adjustable (fixS * fixP)
404ff6b5 25111{
c19d1205
ZW
25112 if (fixP->fx_addsy == NULL)
25113 return 1;
404ff6b5 25114
e28387c3
PB
25115 /* Preserve relocations against symbols with function type. */
25116 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 25117 return FALSE;
e28387c3 25118
c19d1205
ZW
25119 if (THUMB_IS_FUNC (fixP->fx_addsy)
25120 && fixP->fx_subsy == NULL)
c921be7d 25121 return FALSE;
a737bd4d 25122
c19d1205
ZW
25123 /* We need the symbol name for the VTABLE entries. */
25124 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
25125 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 25126 return FALSE;
404ff6b5 25127
c19d1205
ZW
25128 /* Don't allow symbols to be discarded on GOT related relocs. */
25129 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
25130 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
25131 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
25132 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
5c5a4843 25133 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
c19d1205
ZW
25134 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
25135 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
5c5a4843 25136 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
c19d1205 25137 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
5c5a4843 25138 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
c19d1205 25139 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
25140 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
25141 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
25142 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
25143 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
25144 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 25145 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 25146 return FALSE;
a737bd4d 25147
4962c51a
MS
25148 /* Similarly for group relocations. */
25149 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25150 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25151 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 25152 return FALSE;
4962c51a 25153
79947c54
CD
25154 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
25155 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
25156 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
25157 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
25158 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
25159 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
25160 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
25161 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
25162 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 25163 return FALSE;
79947c54 25164
72d98d16
MG
25165 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
25166 offsets, so keep these symbols. */
25167 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
25168 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
25169 return FALSE;
25170
c921be7d 25171 return TRUE;
a737bd4d 25172}
0ffdc86c
NC
25173#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
25174
25175#ifdef OBJ_ELF
c19d1205
ZW
25176const char *
25177elf32_arm_target_format (void)
404ff6b5 25178{
c19d1205
ZW
25179#ifdef TE_SYMBIAN
25180 return (target_big_endian
25181 ? "elf32-bigarm-symbian"
25182 : "elf32-littlearm-symbian");
25183#elif defined (TE_VXWORKS)
25184 return (target_big_endian
25185 ? "elf32-bigarm-vxworks"
25186 : "elf32-littlearm-vxworks");
b38cadfb
NC
25187#elif defined (TE_NACL)
25188 return (target_big_endian
25189 ? "elf32-bigarm-nacl"
25190 : "elf32-littlearm-nacl");
c19d1205 25191#else
18a20338
CL
25192 if (arm_fdpic)
25193 {
25194 if (target_big_endian)
25195 return "elf32-bigarm-fdpic";
25196 else
25197 return "elf32-littlearm-fdpic";
25198 }
c19d1205 25199 else
18a20338
CL
25200 {
25201 if (target_big_endian)
25202 return "elf32-bigarm";
25203 else
25204 return "elf32-littlearm";
25205 }
c19d1205 25206#endif
404ff6b5
AH
25207}
25208
c19d1205
ZW
25209void
25210armelf_frob_symbol (symbolS * symp,
25211 int * puntp)
404ff6b5 25212{
c19d1205
ZW
25213 elf_frob_symbol (symp, puntp);
25214}
25215#endif
404ff6b5 25216
c19d1205 25217/* MD interface: Finalization. */
a737bd4d 25218
c19d1205
ZW
25219void
25220arm_cleanup (void)
25221{
25222 literal_pool * pool;
a737bd4d 25223
e07e6e58
NC
25224 /* Ensure that all the IT blocks are properly closed. */
25225 check_it_blocks_finished ();
25226
c19d1205
ZW
25227 for (pool = list_of_pools; pool; pool = pool->next)
25228 {
5f4273c7 25229 /* Put it at the end of the relevant section. */
c19d1205
ZW
25230 subseg_set (pool->section, pool->sub_section);
25231#ifdef OBJ_ELF
25232 arm_elf_change_section ();
25233#endif
25234 s_ltorg (0);
25235 }
404ff6b5
AH
25236}
25237
cd000bff
DJ
25238#ifdef OBJ_ELF
25239/* Remove any excess mapping symbols generated for alignment frags in
25240 SEC. We may have created a mapping symbol before a zero byte
25241 alignment; remove it if there's a mapping symbol after the
25242 alignment. */
25243static void
25244check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
25245 void *dummy ATTRIBUTE_UNUSED)
25246{
25247 segment_info_type *seginfo = seg_info (sec);
25248 fragS *fragp;
25249
25250 if (seginfo == NULL || seginfo->frchainP == NULL)
25251 return;
25252
25253 for (fragp = seginfo->frchainP->frch_root;
25254 fragp != NULL;
25255 fragp = fragp->fr_next)
25256 {
25257 symbolS *sym = fragp->tc_frag_data.last_map;
25258 fragS *next = fragp->fr_next;
25259
25260 /* Variable-sized frags have been converted to fixed size by
25261 this point. But if this was variable-sized to start with,
25262 there will be a fixed-size frag after it. So don't handle
25263 next == NULL. */
25264 if (sym == NULL || next == NULL)
25265 continue;
25266
25267 if (S_GET_VALUE (sym) < next->fr_address)
25268 /* Not at the end of this frag. */
25269 continue;
25270 know (S_GET_VALUE (sym) == next->fr_address);
25271
25272 do
25273 {
25274 if (next->tc_frag_data.first_map != NULL)
25275 {
25276 /* Next frag starts with a mapping symbol. Discard this
25277 one. */
25278 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25279 break;
25280 }
25281
25282 if (next->fr_next == NULL)
25283 {
25284 /* This mapping symbol is at the end of the section. Discard
25285 it. */
25286 know (next->fr_fix == 0 && next->fr_var == 0);
25287 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25288 break;
25289 }
25290
25291 /* As long as we have empty frags without any mapping symbols,
25292 keep looking. */
25293 /* If the next frag is non-empty and does not start with a
25294 mapping symbol, then this mapping symbol is required. */
25295 if (next->fr_address != next->fr_next->fr_address)
25296 break;
25297
25298 next = next->fr_next;
25299 }
25300 while (next != NULL);
25301 }
25302}
25303#endif
25304
c19d1205
ZW
25305/* Adjust the symbol table. This marks Thumb symbols as distinct from
25306 ARM ones. */
404ff6b5 25307
c19d1205
ZW
25308void
25309arm_adjust_symtab (void)
404ff6b5 25310{
c19d1205
ZW
25311#ifdef OBJ_COFF
25312 symbolS * sym;
404ff6b5 25313
c19d1205
ZW
25314 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
25315 {
25316 if (ARM_IS_THUMB (sym))
25317 {
25318 if (THUMB_IS_FUNC (sym))
25319 {
25320 /* Mark the symbol as a Thumb function. */
25321 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
25322 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
25323 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 25324
c19d1205
ZW
25325 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
25326 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
25327 else
25328 as_bad (_("%s: unexpected function type: %d"),
25329 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
25330 }
25331 else switch (S_GET_STORAGE_CLASS (sym))
25332 {
25333 case C_EXT:
25334 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
25335 break;
25336 case C_STAT:
25337 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
25338 break;
25339 case C_LABEL:
25340 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
25341 break;
25342 default:
25343 /* Do nothing. */
25344 break;
25345 }
25346 }
a737bd4d 25347
c19d1205
ZW
25348 if (ARM_IS_INTERWORK (sym))
25349 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 25350 }
c19d1205
ZW
25351#endif
25352#ifdef OBJ_ELF
25353 symbolS * sym;
25354 char bind;
404ff6b5 25355
c19d1205 25356 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 25357 {
c19d1205
ZW
25358 if (ARM_IS_THUMB (sym))
25359 {
25360 elf_symbol_type * elf_sym;
404ff6b5 25361
c19d1205
ZW
25362 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
25363 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 25364
b0796911
PB
25365 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
25366 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
25367 {
25368 /* If it's a .thumb_func, declare it as so,
25369 otherwise tag label as .code 16. */
25370 if (THUMB_IS_FUNC (sym))
39d911fc
TP
25371 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
25372 ST_BRANCH_TO_THUMB);
3ba67470 25373 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
25374 elf_sym->internal_elf_sym.st_info =
25375 ELF_ST_INFO (bind, STT_ARM_16BIT);
25376 }
25377 }
25378 }
cd000bff
DJ
25379
25380 /* Remove any overlapping mapping symbols generated by alignment frags. */
25381 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
25382 /* Now do generic ELF adjustments. */
25383 elf_adjust_symtab ();
c19d1205 25384#endif
404ff6b5
AH
25385}
25386
c19d1205 25387/* MD interface: Initialization. */
404ff6b5 25388
a737bd4d 25389static void
c19d1205 25390set_constant_flonums (void)
a737bd4d 25391{
c19d1205 25392 int i;
404ff6b5 25393
c19d1205
ZW
25394 for (i = 0; i < NUM_FLOAT_VALS; i++)
25395 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
25396 abort ();
a737bd4d 25397}
404ff6b5 25398
3e9e4fcf
JB
25399/* Auto-select Thumb mode if it's the only available instruction set for the
25400 given architecture. */
25401
25402static void
25403autoselect_thumb_from_cpu_variant (void)
25404{
25405 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
25406 opcode_select (16);
25407}
25408
c19d1205
ZW
25409void
25410md_begin (void)
a737bd4d 25411{
c19d1205
ZW
25412 unsigned mach;
25413 unsigned int i;
404ff6b5 25414
c19d1205
ZW
25415 if ( (arm_ops_hsh = hash_new ()) == NULL
25416 || (arm_cond_hsh = hash_new ()) == NULL
25417 || (arm_shift_hsh = hash_new ()) == NULL
25418 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 25419 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 25420 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
25421 || (arm_reloc_hsh = hash_new ()) == NULL
25422 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
25423 as_fatal (_("virtual memory exhausted"));
25424
25425 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 25426 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 25427 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 25428 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 25429 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 25430 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 25431 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25432 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 25433 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25434 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 25435 (void *) (v7m_psrs + i));
c19d1205 25436 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 25437 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
25438 for (i = 0;
25439 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
25440 i++)
d3ce72d0 25441 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 25442 (void *) (barrier_opt_names + i));
c19d1205 25443#ifdef OBJ_ELF
3da1d841
NC
25444 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
25445 {
25446 struct reloc_entry * entry = reloc_names + i;
25447
25448 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
25449 /* This makes encode_branch() use the EABI versions of this relocation. */
25450 entry->reloc = BFD_RELOC_UNUSED;
25451
25452 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
25453 }
c19d1205
ZW
25454#endif
25455
25456 set_constant_flonums ();
404ff6b5 25457
c19d1205
ZW
25458 /* Set the cpu variant based on the command-line options. We prefer
25459 -mcpu= over -march= if both are set (as for GCC); and we prefer
25460 -mfpu= over any other way of setting the floating point unit.
25461 Use of legacy options with new options are faulted. */
e74cfd16 25462 if (legacy_cpu)
404ff6b5 25463 {
e74cfd16 25464 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
25465 as_bad (_("use of old and new-style options to set CPU type"));
25466
4d354d8b 25467 selected_arch = *legacy_cpu;
404ff6b5 25468 }
4d354d8b
TP
25469 else if (mcpu_cpu_opt)
25470 {
25471 selected_arch = *mcpu_cpu_opt;
25472 selected_ext = *mcpu_ext_opt;
25473 }
25474 else if (march_cpu_opt)
c168ce07 25475 {
4d354d8b
TP
25476 selected_arch = *march_cpu_opt;
25477 selected_ext = *march_ext_opt;
c168ce07 25478 }
4d354d8b 25479 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
404ff6b5 25480
e74cfd16 25481 if (legacy_fpu)
c19d1205 25482 {
e74cfd16 25483 if (mfpu_opt)
c19d1205 25484 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f 25485
4d354d8b 25486 selected_fpu = *legacy_fpu;
03b1477f 25487 }
4d354d8b
TP
25488 else if (mfpu_opt)
25489 selected_fpu = *mfpu_opt;
25490 else
03b1477f 25491 {
45eb4c1b
NS
25492#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25493 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
25494 /* Some environments specify a default FPU. If they don't, infer it
25495 from the processor. */
e74cfd16 25496 if (mcpu_fpu_opt)
4d354d8b 25497 selected_fpu = *mcpu_fpu_opt;
e7da50fa 25498 else if (march_fpu_opt)
4d354d8b 25499 selected_fpu = *march_fpu_opt;
39c2da32 25500#else
4d354d8b 25501 selected_fpu = fpu_default;
39c2da32 25502#endif
03b1477f
RE
25503 }
25504
4d354d8b 25505 if (ARM_FEATURE_ZERO (selected_fpu))
03b1477f 25506 {
4d354d8b
TP
25507 if (!no_cpu_selected ())
25508 selected_fpu = fpu_default;
03b1477f 25509 else
4d354d8b 25510 selected_fpu = fpu_arch_fpa;
03b1477f
RE
25511 }
25512
ee065d83 25513#ifdef CPU_DEFAULT
4d354d8b 25514 if (ARM_FEATURE_ZERO (selected_arch))
ee065d83 25515 {
4d354d8b
TP
25516 selected_arch = cpu_default;
25517 selected_cpu = selected_arch;
ee065d83 25518 }
4d354d8b 25519 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
e74cfd16 25520#else
4d354d8b
TP
25521 /* Autodection of feature mode: allow all features in cpu_variant but leave
25522 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
25523 after all instruction have been processed and we can decide what CPU
25524 should be selected. */
25525 if (ARM_FEATURE_ZERO (selected_arch))
25526 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
ee065d83 25527 else
4d354d8b 25528 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83 25529#endif
03b1477f 25530
3e9e4fcf
JB
25531 autoselect_thumb_from_cpu_variant ();
25532
e74cfd16 25533 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 25534
f17c130b 25535#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 25536 {
7cc69913
NC
25537 unsigned int flags = 0;
25538
25539#if defined OBJ_ELF
25540 flags = meabi_flags;
d507cf36
PB
25541
25542 switch (meabi_flags)
33a392fb 25543 {
d507cf36 25544 case EF_ARM_EABI_UNKNOWN:
7cc69913 25545#endif
d507cf36
PB
25546 /* Set the flags in the private structure. */
25547 if (uses_apcs_26) flags |= F_APCS26;
25548 if (support_interwork) flags |= F_INTERWORK;
25549 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 25550 if (pic_code) flags |= F_PIC;
e74cfd16 25551 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
25552 flags |= F_SOFT_FLOAT;
25553
d507cf36
PB
25554 switch (mfloat_abi_opt)
25555 {
25556 case ARM_FLOAT_ABI_SOFT:
25557 case ARM_FLOAT_ABI_SOFTFP:
25558 flags |= F_SOFT_FLOAT;
25559 break;
33a392fb 25560
d507cf36
PB
25561 case ARM_FLOAT_ABI_HARD:
25562 if (flags & F_SOFT_FLOAT)
25563 as_bad (_("hard-float conflicts with specified fpu"));
25564 break;
25565 }
03b1477f 25566
e74cfd16
PB
25567 /* Using pure-endian doubles (even if soft-float). */
25568 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 25569 flags |= F_VFP_FLOAT;
f17c130b 25570
fde78edd 25571#if defined OBJ_ELF
e74cfd16 25572 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 25573 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
25574 break;
25575
8cb51566 25576 case EF_ARM_EABI_VER4:
3a4a14e9 25577 case EF_ARM_EABI_VER5:
c19d1205 25578 /* No additional flags to set. */
d507cf36
PB
25579 break;
25580
25581 default:
25582 abort ();
25583 }
7cc69913 25584#endif
b99bd4ef
NC
25585 bfd_set_private_flags (stdoutput, flags);
25586
25587 /* We have run out flags in the COFF header to encode the
25588 status of ATPCS support, so instead we create a dummy,
c19d1205 25589 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
25590 if (atpcs)
25591 {
25592 asection * sec;
25593
25594 sec = bfd_make_section (stdoutput, ".arm.atpcs");
25595
25596 if (sec != NULL)
25597 {
25598 bfd_set_section_flags
25599 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
25600 bfd_set_section_size (stdoutput, sec, 0);
25601 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
25602 }
25603 }
7cc69913 25604 }
f17c130b 25605#endif
b99bd4ef
NC
25606
25607 /* Record the CPU type as well. */
2d447fca
JM
25608 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
25609 mach = bfd_mach_arm_iWMMXt2;
25610 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 25611 mach = bfd_mach_arm_iWMMXt;
e74cfd16 25612 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 25613 mach = bfd_mach_arm_XScale;
e74cfd16 25614 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 25615 mach = bfd_mach_arm_ep9312;
e74cfd16 25616 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 25617 mach = bfd_mach_arm_5TE;
e74cfd16 25618 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 25619 {
e74cfd16 25620 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25621 mach = bfd_mach_arm_5T;
25622 else
25623 mach = bfd_mach_arm_5;
25624 }
e74cfd16 25625 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 25626 {
e74cfd16 25627 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25628 mach = bfd_mach_arm_4T;
25629 else
25630 mach = bfd_mach_arm_4;
25631 }
e74cfd16 25632 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 25633 mach = bfd_mach_arm_3M;
e74cfd16
PB
25634 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25635 mach = bfd_mach_arm_3;
25636 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25637 mach = bfd_mach_arm_2a;
25638 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25639 mach = bfd_mach_arm_2;
25640 else
25641 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
25642
25643 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25644}
25645
c19d1205 25646/* Command line processing. */
b99bd4ef 25647
c19d1205
ZW
25648/* md_parse_option
25649 Invocation line includes a switch not recognized by the base assembler.
25650 See if it's a processor-specific option.
b99bd4ef 25651
c19d1205
ZW
25652 This routine is somewhat complicated by the need for backwards
25653 compatibility (since older releases of gcc can't be changed).
25654 The new options try to make the interface as compatible as
25655 possible with GCC.
b99bd4ef 25656
c19d1205 25657 New options (supported) are:
b99bd4ef 25658
c19d1205
ZW
25659 -mcpu=<cpu name> Assemble for selected processor
25660 -march=<architecture name> Assemble for selected architecture
25661 -mfpu=<fpu architecture> Assemble for selected FPU.
25662 -EB/-mbig-endian Big-endian
25663 -EL/-mlittle-endian Little-endian
25664 -k Generate PIC code
25665 -mthumb Start in Thumb mode
25666 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 25667
278df34e 25668 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 25669 -m[no-]warn-syms Warn when symbols match instructions
267bf995 25670
c19d1205 25671 For now we will also provide support for:
b99bd4ef 25672
c19d1205
ZW
25673 -mapcs-32 32-bit Program counter
25674 -mapcs-26 26-bit Program counter
25675 -macps-float Floats passed in FP registers
25676 -mapcs-reentrant Reentrant code
25677 -matpcs
25678 (sometime these will probably be replaced with -mapcs=<list of options>
25679 and -matpcs=<list of options>)
b99bd4ef 25680
c19d1205
ZW
25681 The remaining options are only supported for back-wards compatibility.
25682 Cpu variants, the arm part is optional:
25683 -m[arm]1 Currently not supported.
25684 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25685 -m[arm]3 Arm 3 processor
25686 -m[arm]6[xx], Arm 6 processors
25687 -m[arm]7[xx][t][[d]m] Arm 7 processors
25688 -m[arm]8[10] Arm 8 processors
25689 -m[arm]9[20][tdmi] Arm 9 processors
25690 -mstrongarm[110[0]] StrongARM processors
25691 -mxscale XScale processors
25692 -m[arm]v[2345[t[e]]] Arm architectures
25693 -mall All (except the ARM1)
25694 FP variants:
25695 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25696 -mfpe-old (No float load/store multiples)
25697 -mvfpxd VFP Single precision
25698 -mvfp All VFP
25699 -mno-fpu Disable all floating point instructions
b99bd4ef 25700
c19d1205
ZW
25701 The following CPU names are recognized:
25702 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25703 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25704 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25705 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25706 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25707 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25708 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25709
c19d1205 25710 */
b99bd4ef 25711
c19d1205 25712const char * md_shortopts = "m:k";
b99bd4ef 25713
c19d1205
ZW
25714#ifdef ARM_BI_ENDIAN
25715#define OPTION_EB (OPTION_MD_BASE + 0)
25716#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25717#else
c19d1205
ZW
25718#if TARGET_BYTES_BIG_ENDIAN
25719#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25720#else
c19d1205
ZW
25721#define OPTION_EL (OPTION_MD_BASE + 1)
25722#endif
b99bd4ef 25723#endif
845b51d6 25724#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
18a20338 25725#define OPTION_FDPIC (OPTION_MD_BASE + 3)
b99bd4ef 25726
c19d1205 25727struct option md_longopts[] =
b99bd4ef 25728{
c19d1205
ZW
25729#ifdef OPTION_EB
25730 {"EB", no_argument, NULL, OPTION_EB},
25731#endif
25732#ifdef OPTION_EL
25733 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25734#endif
845b51d6 25735 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
18a20338
CL
25736#ifdef OBJ_ELF
25737 {"fdpic", no_argument, NULL, OPTION_FDPIC},
25738#endif
c19d1205
ZW
25739 {NULL, no_argument, NULL, 0}
25740};
b99bd4ef 25741
c19d1205 25742size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25743
c19d1205 25744struct arm_option_table
b99bd4ef 25745{
0198d5e6
TC
25746 const char * option; /* Option name to match. */
25747 const char * help; /* Help information. */
25748 int * var; /* Variable to change. */
25749 int value; /* What to change it to. */
25750 const char * deprecated; /* If non-null, print this message. */
c19d1205 25751};
b99bd4ef 25752
c19d1205
ZW
25753struct arm_option_table arm_opts[] =
25754{
25755 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25756 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25757 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25758 &support_interwork, 1, NULL},
25759 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25760 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25761 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25762 1, NULL},
25763 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25764 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25765 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25766 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25767 NULL},
b99bd4ef 25768
c19d1205
ZW
25769 /* These are recognized by the assembler, but have no affect on code. */
25770 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25771 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25772
25773 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25774 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25775 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25776 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25777 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25778 {NULL, NULL, NULL, 0, NULL}
25779};
25780
25781struct arm_legacy_option_table
25782{
0198d5e6
TC
25783 const char * option; /* Option name to match. */
25784 const arm_feature_set ** var; /* Variable to change. */
25785 const arm_feature_set value; /* What to change it to. */
25786 const char * deprecated; /* If non-null, print this message. */
e74cfd16 25787};
b99bd4ef 25788
e74cfd16
PB
25789const struct arm_legacy_option_table arm_legacy_opts[] =
25790{
c19d1205
ZW
25791 /* DON'T add any new processors to this list -- we want the whole list
25792 to go away... Add them to the processors table instead. */
e74cfd16
PB
25793 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25794 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25795 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25796 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25797 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25798 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25799 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25800 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25801 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25802 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25803 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25804 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25805 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25806 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25807 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25808 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25809 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25810 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25811 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25812 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25813 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25814 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25815 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25816 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25817 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25818 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25819 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25820 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25821 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25822 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25823 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25824 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25825 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25826 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25827 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25828 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25829 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25830 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25831 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25832 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25833 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25834 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25835 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25836 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25837 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25838 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25839 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25840 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25841 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25842 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25843 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25844 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25845 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25846 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25847 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25848 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25849 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25850 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25851 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25852 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25853 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25854 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25855 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25856 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25857 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25858 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25859 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25860 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25861 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25862 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25863 N_("use -mcpu=strongarm110")},
e74cfd16 25864 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25865 N_("use -mcpu=strongarm1100")},
e74cfd16 25866 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25867 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25868 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25869 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25870 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25871
c19d1205 25872 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25873 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25874 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25875 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25876 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25877 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25878 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25879 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25880 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25881 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25882 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25883 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25884 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25885 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25886 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25887 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25888 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25889 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25890 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25891
c19d1205 25892 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
25893 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25894 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25895 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25896 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25897 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25898
e74cfd16 25899 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25900};
7ed4c4c5 25901
c19d1205 25902struct arm_cpu_option_table
7ed4c4c5 25903{
0198d5e6
TC
25904 const char * name;
25905 size_t name_len;
25906 const arm_feature_set value;
25907 const arm_feature_set ext;
c19d1205
ZW
25908 /* For some CPUs we assume an FPU unless the user explicitly sets
25909 -mfpu=... */
0198d5e6 25910 const arm_feature_set default_fpu;
ee065d83
PB
25911 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25912 case. */
0198d5e6 25913 const char * canonical_name;
c19d1205 25914};
7ed4c4c5 25915
c19d1205
ZW
25916/* This list should, at a minimum, contain all the cpu names
25917 recognized by GCC. */
996b5569 25918#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 25919
e74cfd16 25920static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25921{
996b5569
TP
25922 ARM_CPU_OPT ("all", NULL, ARM_ANY,
25923 ARM_ARCH_NONE,
25924 FPU_ARCH_FPA),
25925 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
25926 ARM_ARCH_NONE,
25927 FPU_ARCH_FPA),
25928 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
25929 ARM_ARCH_NONE,
25930 FPU_ARCH_FPA),
25931 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
25932 ARM_ARCH_NONE,
25933 FPU_ARCH_FPA),
25934 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
25935 ARM_ARCH_NONE,
25936 FPU_ARCH_FPA),
25937 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
25938 ARM_ARCH_NONE,
25939 FPU_ARCH_FPA),
25940 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
25941 ARM_ARCH_NONE,
25942 FPU_ARCH_FPA),
25943 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
25944 ARM_ARCH_NONE,
25945 FPU_ARCH_FPA),
25946 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
25947 ARM_ARCH_NONE,
25948 FPU_ARCH_FPA),
25949 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
25950 ARM_ARCH_NONE,
25951 FPU_ARCH_FPA),
25952 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
25953 ARM_ARCH_NONE,
25954 FPU_ARCH_FPA),
25955 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
25956 ARM_ARCH_NONE,
25957 FPU_ARCH_FPA),
25958 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
25959 ARM_ARCH_NONE,
25960 FPU_ARCH_FPA),
25961 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
25962 ARM_ARCH_NONE,
25963 FPU_ARCH_FPA),
25964 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
25965 ARM_ARCH_NONE,
25966 FPU_ARCH_FPA),
25967 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
25968 ARM_ARCH_NONE,
25969 FPU_ARCH_FPA),
25970 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
25971 ARM_ARCH_NONE,
25972 FPU_ARCH_FPA),
25973 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
25974 ARM_ARCH_NONE,
25975 FPU_ARCH_FPA),
25976 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
25977 ARM_ARCH_NONE,
25978 FPU_ARCH_FPA),
25979 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
25980 ARM_ARCH_NONE,
25981 FPU_ARCH_FPA),
25982 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
25983 ARM_ARCH_NONE,
25984 FPU_ARCH_FPA),
25985 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
25986 ARM_ARCH_NONE,
25987 FPU_ARCH_FPA),
25988 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
25989 ARM_ARCH_NONE,
25990 FPU_ARCH_FPA),
25991 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
25992 ARM_ARCH_NONE,
25993 FPU_ARCH_FPA),
25994 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
25995 ARM_ARCH_NONE,
25996 FPU_ARCH_FPA),
25997 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
25998 ARM_ARCH_NONE,
25999 FPU_ARCH_FPA),
26000 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
26001 ARM_ARCH_NONE,
26002 FPU_ARCH_FPA),
26003 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
26004 ARM_ARCH_NONE,
26005 FPU_ARCH_FPA),
26006 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
26007 ARM_ARCH_NONE,
26008 FPU_ARCH_FPA),
26009 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
26010 ARM_ARCH_NONE,
26011 FPU_ARCH_FPA),
26012 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
26013 ARM_ARCH_NONE,
26014 FPU_ARCH_FPA),
26015 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
26016 ARM_ARCH_NONE,
26017 FPU_ARCH_FPA),
26018 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
26019 ARM_ARCH_NONE,
26020 FPU_ARCH_FPA),
26021 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
26022 ARM_ARCH_NONE,
26023 FPU_ARCH_FPA),
26024 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
26025 ARM_ARCH_NONE,
26026 FPU_ARCH_FPA),
26027 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
26028 ARM_ARCH_NONE,
26029 FPU_ARCH_FPA),
26030 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
26031 ARM_ARCH_NONE,
26032 FPU_ARCH_FPA),
26033 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
26034 ARM_ARCH_NONE,
26035 FPU_ARCH_FPA),
26036 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
26037 ARM_ARCH_NONE,
26038 FPU_ARCH_FPA),
26039 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
26040 ARM_ARCH_NONE,
26041 FPU_ARCH_FPA),
26042 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
26043 ARM_ARCH_NONE,
26044 FPU_ARCH_FPA),
26045 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
26046 ARM_ARCH_NONE,
26047 FPU_ARCH_FPA),
26048 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
26049 ARM_ARCH_NONE,
26050 FPU_ARCH_FPA),
26051 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
26052 ARM_ARCH_NONE,
26053 FPU_ARCH_FPA),
26054 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
26055 ARM_ARCH_NONE,
26056 FPU_ARCH_FPA),
26057 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
26058 ARM_ARCH_NONE,
26059 FPU_ARCH_FPA),
26060
c19d1205
ZW
26061 /* For V5 or later processors we default to using VFP; but the user
26062 should really set the FPU type explicitly. */
996b5569
TP
26063 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
26064 ARM_ARCH_NONE,
26065 FPU_ARCH_VFP_V2),
26066 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
26067 ARM_ARCH_NONE,
26068 FPU_ARCH_VFP_V2),
26069 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
26070 ARM_ARCH_NONE,
26071 FPU_ARCH_VFP_V2),
26072 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
26073 ARM_ARCH_NONE,
26074 FPU_ARCH_VFP_V2),
26075 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
26076 ARM_ARCH_NONE,
26077 FPU_ARCH_VFP_V2),
26078 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
26079 ARM_ARCH_NONE,
26080 FPU_ARCH_VFP_V2),
26081 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
26082 ARM_ARCH_NONE,
26083 FPU_ARCH_VFP_V2),
26084 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
26085 ARM_ARCH_NONE,
26086 FPU_ARCH_VFP_V2),
26087 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
26088 ARM_ARCH_NONE,
26089 FPU_ARCH_VFP_V2),
26090 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
26091 ARM_ARCH_NONE,
26092 FPU_ARCH_VFP_V2),
26093 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
26094 ARM_ARCH_NONE,
26095 FPU_ARCH_VFP_V2),
26096 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
26097 ARM_ARCH_NONE,
26098 FPU_ARCH_VFP_V2),
26099 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
26100 ARM_ARCH_NONE,
26101 FPU_ARCH_VFP_V1),
26102 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
26103 ARM_ARCH_NONE,
26104 FPU_ARCH_VFP_V1),
26105 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
26106 ARM_ARCH_NONE,
26107 FPU_ARCH_VFP_V2),
26108 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
26109 ARM_ARCH_NONE,
26110 FPU_ARCH_VFP_V2),
26111 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
26112 ARM_ARCH_NONE,
26113 FPU_ARCH_VFP_V1),
26114 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
26115 ARM_ARCH_NONE,
26116 FPU_ARCH_VFP_V2),
26117 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
26118 ARM_ARCH_NONE,
26119 FPU_ARCH_VFP_V2),
26120 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
26121 ARM_ARCH_NONE,
26122 FPU_ARCH_VFP_V2),
26123 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
26124 ARM_ARCH_NONE,
26125 FPU_ARCH_VFP_V2),
26126 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
26127 ARM_ARCH_NONE,
26128 FPU_ARCH_VFP_V2),
26129 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
26130 ARM_ARCH_NONE,
26131 FPU_ARCH_VFP_V2),
26132 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
26133 ARM_ARCH_NONE,
26134 FPU_ARCH_VFP_V2),
26135 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
26136 ARM_ARCH_NONE,
26137 FPU_ARCH_VFP_V2),
26138 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
26139 ARM_ARCH_NONE,
26140 FPU_ARCH_VFP_V2),
26141 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
26142 ARM_ARCH_NONE,
26143 FPU_NONE),
26144 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
26145 ARM_ARCH_NONE,
26146 FPU_NONE),
26147 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
26148 ARM_ARCH_NONE,
26149 FPU_ARCH_VFP_V2),
26150 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
26151 ARM_ARCH_NONE,
26152 FPU_ARCH_VFP_V2),
26153 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
26154 ARM_ARCH_NONE,
26155 FPU_ARCH_VFP_V2),
26156 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
26157 ARM_ARCH_NONE,
26158 FPU_NONE),
26159 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
26160 ARM_ARCH_NONE,
26161 FPU_NONE),
26162 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
26163 ARM_ARCH_NONE,
26164 FPU_ARCH_VFP_V2),
26165 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
26166 ARM_ARCH_NONE,
26167 FPU_NONE),
26168 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
26169 ARM_ARCH_NONE,
26170 FPU_ARCH_VFP_V2),
26171 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
26172 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26173 FPU_NONE),
26174 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
26175 ARM_ARCH_NONE,
26176 FPU_ARCH_NEON_VFP_V4),
26177 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
26178 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
26179 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26180 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
26181 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26182 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26183 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
26184 ARM_ARCH_NONE,
26185 FPU_ARCH_NEON_VFP_V4),
26186 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
26187 ARM_ARCH_NONE,
26188 FPU_ARCH_NEON_VFP_V4),
26189 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
26190 ARM_ARCH_NONE,
26191 FPU_ARCH_NEON_VFP_V4),
26192 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
26193 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26194 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26195 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
26196 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26197 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26198 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
26199 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26200 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
26201 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
26202 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 26203 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
26204 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
26205 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26206 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26207 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
26208 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26209 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26210 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
26211 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26212 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
26213 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
26214 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 26215 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
7ebd1359 26216 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
26217 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26218 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
ef8df4ca
KT
26219 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
26220 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26221 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
26222 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
26223 ARM_ARCH_NONE,
26224 FPU_NONE),
26225 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
26226 ARM_ARCH_NONE,
26227 FPU_ARCH_VFP_V3D16),
26228 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
26229 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26230 FPU_NONE),
26231 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
26232 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26233 FPU_ARCH_VFP_V3D16),
26234 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
26235 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26236 FPU_ARCH_VFP_V3D16),
0cda1e19
TP
26237 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
26238 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26239 FPU_ARCH_NEON_VFP_ARMV8),
996b5569
TP
26240 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
26241 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26242 FPU_NONE),
26243 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
26244 ARM_ARCH_NONE,
26245 FPU_NONE),
26246 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
26247 ARM_ARCH_NONE,
26248 FPU_NONE),
26249 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
26250 ARM_ARCH_NONE,
26251 FPU_NONE),
26252 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
26253 ARM_ARCH_NONE,
26254 FPU_NONE),
26255 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
26256 ARM_ARCH_NONE,
26257 FPU_NONE),
26258 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
26259 ARM_ARCH_NONE,
26260 FPU_NONE),
26261 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
26262 ARM_ARCH_NONE,
26263 FPU_NONE),
26264 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
26265 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26266 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
83f43c83
KT
26267 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
26268 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26269 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
c19d1205 26270 /* ??? XSCALE is really an architecture. */
996b5569
TP
26271 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
26272 ARM_ARCH_NONE,
26273 FPU_ARCH_VFP_V2),
26274
c19d1205 26275 /* ??? iwmmxt is not a processor. */
996b5569
TP
26276 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
26277 ARM_ARCH_NONE,
26278 FPU_ARCH_VFP_V2),
26279 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
26280 ARM_ARCH_NONE,
26281 FPU_ARCH_VFP_V2),
26282 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
26283 ARM_ARCH_NONE,
26284 FPU_ARCH_VFP_V2),
26285
0198d5e6 26286 /* Maverick. */
996b5569
TP
26287 ARM_CPU_OPT ("ep9312", "ARM920T",
26288 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
26289 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
26290
da4339ed 26291 /* Marvell processors. */
996b5569
TP
26292 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
26293 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26294 FPU_ARCH_VFP_V3D16),
26295 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
26296 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26297 FPU_ARCH_NEON_VFP_V4),
da4339ed 26298
996b5569
TP
26299 /* APM X-Gene family. */
26300 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
26301 ARM_ARCH_NONE,
26302 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26303 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
26304 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26305 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26306
26307 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 26308};
f3bad469 26309#undef ARM_CPU_OPT
7ed4c4c5 26310
c19d1205 26311struct arm_arch_option_table
7ed4c4c5 26312{
0198d5e6
TC
26313 const char * name;
26314 size_t name_len;
26315 const arm_feature_set value;
26316 const arm_feature_set default_fpu;
c19d1205 26317};
7ed4c4c5 26318
c19d1205
ZW
26319/* This list should, at a minimum, contain all the architecture names
26320 recognized by GCC. */
f3bad469 26321#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
0198d5e6 26322
e74cfd16 26323static const struct arm_arch_option_table arm_archs[] =
c19d1205 26324{
497d849d
TP
26325 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
26326 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
26327 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
26328 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
26329 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
26330 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
26331 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
26332 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
26333 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
26334 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
26335 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
26336 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
26337 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
26338 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
26339 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
26340 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
26341 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
26342 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
26343 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
26344 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
26345 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
26346 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
26347 kept to preserve existing behaviour. */
497d849d
TP
26348 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
26349 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
26350 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
26351 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
26352 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
26353 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
26354 kept to preserve existing behaviour. */
497d849d
TP
26355 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
26356 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
26357 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
26358 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
26359 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
26360 /* The official spelling of the ARMv7 profile variants is the dashed form.
26361 Accept the non-dashed form for compatibility with old toolchains. */
497d849d
TP
26362 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
26363 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
26364 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26365 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26366 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
26367 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26368 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26369 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
26370 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
26371 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
26372 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
26373 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
26374 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
26375 ARM_ARCH_OPT ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP),
26376 ARM_ARCH_OPT ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP),
26377 ARM_ARCH_OPT ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP),
26378 ARM_ARCH_OPT ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP),
26379 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
26380 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
26381 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
f3bad469 26382 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 26383};
f3bad469 26384#undef ARM_ARCH_OPT
7ed4c4c5 26385
69133863 26386/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 26387
69133863 26388struct arm_option_extension_value_table
c19d1205 26389{
0198d5e6
TC
26390 const char * name;
26391 size_t name_len;
26392 const arm_feature_set merge_value;
26393 const arm_feature_set clear_value;
d942732e
TP
26394 /* List of architectures for which an extension is available. ARM_ARCH_NONE
26395 indicates that an extension is available for all architectures while
26396 ARM_ANY marks an empty entry. */
0198d5e6 26397 const arm_feature_set allowed_archs[2];
c19d1205 26398};
7ed4c4c5 26399
0198d5e6
TC
26400/* The following table must be in alphabetical order with a NULL last entry. */
26401
d942732e
TP
26402#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
26403#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 26404
69133863 26405static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 26406{
823d2571
TG
26407 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26408 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 26409 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
26410 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
26411 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
26412 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
26413 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
26414 ARM_ARCH_V8_2A),
15afaa63
TP
26415 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26416 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26417 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
26418 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
26419 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
26420 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26421 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26422 ARM_ARCH_V8_2A),
01f48020
TC
26423 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
26424 | ARM_EXT2_FP16_FML),
26425 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
26426 | ARM_EXT2_FP16_FML),
26427 ARM_ARCH_V8_2A),
d942732e 26428 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 26429 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
26430 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26431 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
26432 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
26433 Thumb divide instruction. Due to this having the same name as the
26434 previous entry, this will be ignored when doing command-line parsing and
26435 only considered by build attribute selection code. */
26436 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26437 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26438 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 26439 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 26440 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 26441 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 26442 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 26443 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
26444 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
26445 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 26446 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
26447 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26448 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
26449 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26450 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26451 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
26452 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
26453 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 26454 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
dad0c3bf
SD
26455 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
26456 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
26457 ARM_ARCH_V8A),
4d1464f2
MW
26458 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
26459 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 26460 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
26461 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
26462 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 26463 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
7fadb25d
SD
26464 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
26465 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
26466 ARM_ARCH_V8A),
d942732e 26467 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 26468 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
26469 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
26470 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
26471 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
26472 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
26473 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
26474 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
26475 | ARM_EXT_DIV),
26476 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
26477 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
26478 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
26479 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
26480 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 26481};
f3bad469 26482#undef ARM_EXT_OPT
69133863
MGD
26483
26484/* ISA floating-point and Advanced SIMD extensions. */
26485struct arm_option_fpu_value_table
26486{
0198d5e6
TC
26487 const char * name;
26488 const arm_feature_set value;
c19d1205 26489};
7ed4c4c5 26490
c19d1205
ZW
26491/* This list should, at a minimum, contain all the fpu names
26492 recognized by GCC. */
69133863 26493static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
26494{
26495 {"softfpa", FPU_NONE},
26496 {"fpe", FPU_ARCH_FPE},
26497 {"fpe2", FPU_ARCH_FPE},
26498 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
26499 {"fpa", FPU_ARCH_FPA},
26500 {"fpa10", FPU_ARCH_FPA},
26501 {"fpa11", FPU_ARCH_FPA},
26502 {"arm7500fe", FPU_ARCH_FPA},
26503 {"softvfp", FPU_ARCH_VFP},
26504 {"softvfp+vfp", FPU_ARCH_VFP_V2},
26505 {"vfp", FPU_ARCH_VFP_V2},
26506 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 26507 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
26508 {"vfp10", FPU_ARCH_VFP_V2},
26509 {"vfp10-r0", FPU_ARCH_VFP_V1},
26510 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
26511 {"vfpv2", FPU_ARCH_VFP_V2},
26512 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 26513 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 26514 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
26515 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
26516 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
26517 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
26518 {"arm1020t", FPU_ARCH_VFP_V1},
26519 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 26520 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
26521 {"arm1136jf-s", FPU_ARCH_VFP_V2},
26522 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 26523 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 26524 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 26525 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
26526 {"vfpv4", FPU_ARCH_VFP_V4},
26527 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 26528 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
26529 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
26530 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 26531 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
26532 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
26533 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
26534 {"crypto-neon-fp-armv8",
26535 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 26536 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
26537 {"crypto-neon-fp-armv8.1",
26538 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
26539 {NULL, ARM_ARCH_NONE}
26540};
26541
26542struct arm_option_value_table
26543{
e0471c16 26544 const char *name;
e74cfd16 26545 long value;
c19d1205 26546};
7ed4c4c5 26547
e74cfd16 26548static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
26549{
26550 {"hard", ARM_FLOAT_ABI_HARD},
26551 {"softfp", ARM_FLOAT_ABI_SOFTFP},
26552 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 26553 {NULL, 0}
c19d1205 26554};
7ed4c4c5 26555
c19d1205 26556#ifdef OBJ_ELF
3a4a14e9 26557/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 26558static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
26559{
26560 {"gnu", EF_ARM_EABI_UNKNOWN},
26561 {"4", EF_ARM_EABI_VER4},
3a4a14e9 26562 {"5", EF_ARM_EABI_VER5},
e74cfd16 26563 {NULL, 0}
c19d1205
ZW
26564};
26565#endif
7ed4c4c5 26566
c19d1205
ZW
26567struct arm_long_option_table
26568{
0198d5e6 26569 const char * option; /* Substring to match. */
e0471c16 26570 const char * help; /* Help information. */
17b9d67d 26571 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 26572 const char * deprecated; /* If non-null, print this message. */
c19d1205 26573};
7ed4c4c5 26574
c921be7d 26575static bfd_boolean
c168ce07 26576arm_parse_extension (const char *str, const arm_feature_set *opt_set,
4d354d8b 26577 arm_feature_set *ext_set)
7ed4c4c5 26578{
69133863 26579 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
26580 extensions being added before being removed. We achieve this by having
26581 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 26582 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 26583 or removing it (0) and only allowing it to change in the order
69133863
MGD
26584 -1 -> 1 -> 0. */
26585 const struct arm_option_extension_value_table * opt = NULL;
d942732e 26586 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26587 int adding_value = -1;
26588
c19d1205 26589 while (str != NULL && *str != 0)
7ed4c4c5 26590 {
82b8a785 26591 const char *ext;
f3bad469 26592 size_t len;
7ed4c4c5 26593
c19d1205
ZW
26594 if (*str != '+')
26595 {
26596 as_bad (_("invalid architectural extension"));
c921be7d 26597 return FALSE;
c19d1205 26598 }
7ed4c4c5 26599
c19d1205
ZW
26600 str++;
26601 ext = strchr (str, '+');
7ed4c4c5 26602
c19d1205 26603 if (ext != NULL)
f3bad469 26604 len = ext - str;
c19d1205 26605 else
f3bad469 26606 len = strlen (str);
7ed4c4c5 26607
f3bad469 26608 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
26609 {
26610 if (adding_value != 0)
26611 {
26612 adding_value = 0;
26613 opt = arm_extensions;
26614 }
26615
f3bad469 26616 len -= 2;
69133863
MGD
26617 str += 2;
26618 }
f3bad469 26619 else if (len > 0)
69133863
MGD
26620 {
26621 if (adding_value == -1)
26622 {
26623 adding_value = 1;
26624 opt = arm_extensions;
26625 }
26626 else if (adding_value != 1)
26627 {
26628 as_bad (_("must specify extensions to add before specifying "
26629 "those to remove"));
26630 return FALSE;
26631 }
26632 }
26633
f3bad469 26634 if (len == 0)
c19d1205
ZW
26635 {
26636 as_bad (_("missing architectural extension"));
c921be7d 26637 return FALSE;
c19d1205 26638 }
7ed4c4c5 26639
69133863
MGD
26640 gas_assert (adding_value != -1);
26641 gas_assert (opt != NULL);
26642
26643 /* Scan over the options table trying to find an exact match. */
26644 for (; opt->name != NULL; opt++)
f3bad469 26645 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26646 {
d942732e
TP
26647 int i, nb_allowed_archs =
26648 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 26649 /* Check we can apply the extension to this architecture. */
d942732e
TP
26650 for (i = 0; i < nb_allowed_archs; i++)
26651 {
26652 /* Empty entry. */
26653 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26654 continue;
c168ce07 26655 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
26656 break;
26657 }
26658 if (i == nb_allowed_archs)
69133863
MGD
26659 {
26660 as_bad (_("extension does not apply to the base architecture"));
26661 return FALSE;
26662 }
26663
26664 /* Add or remove the extension. */
26665 if (adding_value)
4d354d8b 26666 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 26667 else
4d354d8b 26668 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 26669
3d030cdb
TP
26670 /* Allowing Thumb division instructions for ARMv7 in autodetection
26671 rely on this break so that duplicate extensions (extensions
26672 with the same name as a previous extension in the list) are not
26673 considered for command-line parsing. */
c19d1205
ZW
26674 break;
26675 }
7ed4c4c5 26676
c19d1205
ZW
26677 if (opt->name == NULL)
26678 {
69133863
MGD
26679 /* Did we fail to find an extension because it wasn't specified in
26680 alphabetical order, or because it does not exist? */
26681
26682 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 26683 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
26684 break;
26685
26686 if (opt->name == NULL)
26687 as_bad (_("unknown architectural extension `%s'"), str);
26688 else
26689 as_bad (_("architectural extensions must be specified in "
26690 "alphabetical order"));
26691
c921be7d 26692 return FALSE;
c19d1205 26693 }
69133863
MGD
26694 else
26695 {
26696 /* We should skip the extension we've just matched the next time
26697 round. */
26698 opt++;
26699 }
7ed4c4c5 26700
c19d1205
ZW
26701 str = ext;
26702 };
7ed4c4c5 26703
c921be7d 26704 return TRUE;
c19d1205 26705}
7ed4c4c5 26706
c921be7d 26707static bfd_boolean
17b9d67d 26708arm_parse_cpu (const char *str)
7ed4c4c5 26709{
f3bad469 26710 const struct arm_cpu_option_table *opt;
82b8a785 26711 const char *ext = strchr (str, '+');
f3bad469 26712 size_t len;
7ed4c4c5 26713
c19d1205 26714 if (ext != NULL)
f3bad469 26715 len = ext - str;
7ed4c4c5 26716 else
f3bad469 26717 len = strlen (str);
7ed4c4c5 26718
f3bad469 26719 if (len == 0)
7ed4c4c5 26720 {
c19d1205 26721 as_bad (_("missing cpu name `%s'"), str);
c921be7d 26722 return FALSE;
7ed4c4c5
NC
26723 }
26724
c19d1205 26725 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 26726 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26727 {
c168ce07 26728 mcpu_cpu_opt = &opt->value;
4d354d8b
TP
26729 if (mcpu_ext_opt == NULL)
26730 mcpu_ext_opt = XNEW (arm_feature_set);
26731 *mcpu_ext_opt = opt->ext;
e74cfd16 26732 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 26733 if (opt->canonical_name)
ef8e6722
JW
26734 {
26735 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
26736 strcpy (selected_cpu_name, opt->canonical_name);
26737 }
ee065d83
PB
26738 else
26739 {
f3bad469 26740 size_t i;
c921be7d 26741
ef8e6722
JW
26742 if (len >= sizeof selected_cpu_name)
26743 len = (sizeof selected_cpu_name) - 1;
26744
f3bad469 26745 for (i = 0; i < len; i++)
ee065d83
PB
26746 selected_cpu_name[i] = TOUPPER (opt->name[i]);
26747 selected_cpu_name[i] = 0;
26748 }
7ed4c4c5 26749
c19d1205 26750 if (ext != NULL)
4d354d8b 26751 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt);
7ed4c4c5 26752
c921be7d 26753 return TRUE;
c19d1205 26754 }
7ed4c4c5 26755
c19d1205 26756 as_bad (_("unknown cpu `%s'"), str);
c921be7d 26757 return FALSE;
7ed4c4c5
NC
26758}
26759
c921be7d 26760static bfd_boolean
17b9d67d 26761arm_parse_arch (const char *str)
7ed4c4c5 26762{
e74cfd16 26763 const struct arm_arch_option_table *opt;
82b8a785 26764 const char *ext = strchr (str, '+');
f3bad469 26765 size_t len;
7ed4c4c5 26766
c19d1205 26767 if (ext != NULL)
f3bad469 26768 len = ext - str;
7ed4c4c5 26769 else
f3bad469 26770 len = strlen (str);
7ed4c4c5 26771
f3bad469 26772 if (len == 0)
7ed4c4c5 26773 {
c19d1205 26774 as_bad (_("missing architecture name `%s'"), str);
c921be7d 26775 return FALSE;
7ed4c4c5
NC
26776 }
26777
c19d1205 26778 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 26779 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26780 {
e74cfd16 26781 march_cpu_opt = &opt->value;
4d354d8b
TP
26782 if (march_ext_opt == NULL)
26783 march_ext_opt = XNEW (arm_feature_set);
26784 *march_ext_opt = arm_arch_none;
e74cfd16 26785 march_fpu_opt = &opt->default_fpu;
5f4273c7 26786 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 26787
c19d1205 26788 if (ext != NULL)
4d354d8b 26789 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt);
7ed4c4c5 26790
c921be7d 26791 return TRUE;
c19d1205
ZW
26792 }
26793
26794 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 26795 return FALSE;
7ed4c4c5 26796}
eb043451 26797
c921be7d 26798static bfd_boolean
17b9d67d 26799arm_parse_fpu (const char * str)
c19d1205 26800{
69133863 26801 const struct arm_option_fpu_value_table * opt;
b99bd4ef 26802
c19d1205
ZW
26803 for (opt = arm_fpus; opt->name != NULL; opt++)
26804 if (streq (opt->name, str))
26805 {
e74cfd16 26806 mfpu_opt = &opt->value;
c921be7d 26807 return TRUE;
c19d1205 26808 }
b99bd4ef 26809
c19d1205 26810 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 26811 return FALSE;
c19d1205
ZW
26812}
26813
c921be7d 26814static bfd_boolean
17b9d67d 26815arm_parse_float_abi (const char * str)
b99bd4ef 26816{
e74cfd16 26817 const struct arm_option_value_table * opt;
b99bd4ef 26818
c19d1205
ZW
26819 for (opt = arm_float_abis; opt->name != NULL; opt++)
26820 if (streq (opt->name, str))
26821 {
26822 mfloat_abi_opt = opt->value;
c921be7d 26823 return TRUE;
c19d1205 26824 }
cc8a6dd0 26825
c19d1205 26826 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 26827 return FALSE;
c19d1205 26828}
b99bd4ef 26829
c19d1205 26830#ifdef OBJ_ELF
c921be7d 26831static bfd_boolean
17b9d67d 26832arm_parse_eabi (const char * str)
c19d1205 26833{
e74cfd16 26834 const struct arm_option_value_table *opt;
cc8a6dd0 26835
c19d1205
ZW
26836 for (opt = arm_eabis; opt->name != NULL; opt++)
26837 if (streq (opt->name, str))
26838 {
26839 meabi_flags = opt->value;
c921be7d 26840 return TRUE;
c19d1205
ZW
26841 }
26842 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 26843 return FALSE;
c19d1205
ZW
26844}
26845#endif
cc8a6dd0 26846
c921be7d 26847static bfd_boolean
17b9d67d 26848arm_parse_it_mode (const char * str)
e07e6e58 26849{
c921be7d 26850 bfd_boolean ret = TRUE;
e07e6e58
NC
26851
26852 if (streq ("arm", str))
26853 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
26854 else if (streq ("thumb", str))
26855 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
26856 else if (streq ("always", str))
26857 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
26858 else if (streq ("never", str))
26859 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
26860 else
26861 {
26862 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 26863 "arm, thumb, always, or never."), str);
c921be7d 26864 ret = FALSE;
e07e6e58
NC
26865 }
26866
26867 return ret;
26868}
26869
2e6976a8 26870static bfd_boolean
17b9d67d 26871arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
26872{
26873 codecomposer_syntax = TRUE;
26874 arm_comment_chars[0] = ';';
26875 arm_line_separator_chars[0] = 0;
26876 return TRUE;
26877}
26878
c19d1205
ZW
26879struct arm_long_option_table arm_long_opts[] =
26880{
26881 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
26882 arm_parse_cpu, NULL},
26883 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
26884 arm_parse_arch, NULL},
26885 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
26886 arm_parse_fpu, NULL},
26887 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
26888 arm_parse_float_abi, NULL},
26889#ifdef OBJ_ELF
7fac0536 26890 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
26891 arm_parse_eabi, NULL},
26892#endif
e07e6e58
NC
26893 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
26894 arm_parse_it_mode, NULL},
2e6976a8
DG
26895 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
26896 arm_ccs_mode, NULL},
c19d1205
ZW
26897 {NULL, NULL, 0, NULL}
26898};
cc8a6dd0 26899
c19d1205 26900int
17b9d67d 26901md_parse_option (int c, const char * arg)
c19d1205
ZW
26902{
26903 struct arm_option_table *opt;
e74cfd16 26904 const struct arm_legacy_option_table *fopt;
c19d1205 26905 struct arm_long_option_table *lopt;
b99bd4ef 26906
c19d1205 26907 switch (c)
b99bd4ef 26908 {
c19d1205
ZW
26909#ifdef OPTION_EB
26910 case OPTION_EB:
26911 target_big_endian = 1;
26912 break;
26913#endif
cc8a6dd0 26914
c19d1205
ZW
26915#ifdef OPTION_EL
26916 case OPTION_EL:
26917 target_big_endian = 0;
26918 break;
26919#endif
b99bd4ef 26920
845b51d6
PB
26921 case OPTION_FIX_V4BX:
26922 fix_v4bx = TRUE;
26923 break;
26924
18a20338
CL
26925#ifdef OBJ_ELF
26926 case OPTION_FDPIC:
26927 arm_fdpic = TRUE;
26928 break;
26929#endif /* OBJ_ELF */
26930
c19d1205
ZW
26931 case 'a':
26932 /* Listing option. Just ignore these, we don't support additional
26933 ones. */
26934 return 0;
b99bd4ef 26935
c19d1205
ZW
26936 default:
26937 for (opt = arm_opts; opt->option != NULL; opt++)
26938 {
26939 if (c == opt->option[0]
26940 && ((arg == NULL && opt->option[1] == 0)
26941 || streq (arg, opt->option + 1)))
26942 {
c19d1205 26943 /* If the option is deprecated, tell the user. */
278df34e 26944 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
26945 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26946 arg ? arg : "", _(opt->deprecated));
b99bd4ef 26947
c19d1205
ZW
26948 if (opt->var != NULL)
26949 *opt->var = opt->value;
cc8a6dd0 26950
c19d1205
ZW
26951 return 1;
26952 }
26953 }
b99bd4ef 26954
e74cfd16
PB
26955 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26956 {
26957 if (c == fopt->option[0]
26958 && ((arg == NULL && fopt->option[1] == 0)
26959 || streq (arg, fopt->option + 1)))
26960 {
e74cfd16 26961 /* If the option is deprecated, tell the user. */
278df34e 26962 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
26963 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26964 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
26965
26966 if (fopt->var != NULL)
26967 *fopt->var = &fopt->value;
26968
26969 return 1;
26970 }
26971 }
26972
c19d1205
ZW
26973 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26974 {
26975 /* These options are expected to have an argument. */
26976 if (c == lopt->option[0]
26977 && arg != NULL
26978 && strncmp (arg, lopt->option + 1,
26979 strlen (lopt->option + 1)) == 0)
26980 {
c19d1205 26981 /* If the option is deprecated, tell the user. */
278df34e 26982 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
26983 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26984 _(lopt->deprecated));
b99bd4ef 26985
c19d1205
ZW
26986 /* Call the sup-option parser. */
26987 return lopt->func (arg + strlen (lopt->option) - 1);
26988 }
26989 }
a737bd4d 26990
c19d1205
ZW
26991 return 0;
26992 }
a394c00f 26993
c19d1205
ZW
26994 return 1;
26995}
a394c00f 26996
c19d1205
ZW
26997void
26998md_show_usage (FILE * fp)
a394c00f 26999{
c19d1205
ZW
27000 struct arm_option_table *opt;
27001 struct arm_long_option_table *lopt;
a394c00f 27002
c19d1205 27003 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 27004
c19d1205
ZW
27005 for (opt = arm_opts; opt->option != NULL; opt++)
27006 if (opt->help != NULL)
27007 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 27008
c19d1205
ZW
27009 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
27010 if (lopt->help != NULL)
27011 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 27012
c19d1205
ZW
27013#ifdef OPTION_EB
27014 fprintf (fp, _("\
27015 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
27016#endif
27017
c19d1205
ZW
27018#ifdef OPTION_EL
27019 fprintf (fp, _("\
27020 -EL assemble code for a little-endian cpu\n"));
a737bd4d 27021#endif
845b51d6
PB
27022
27023 fprintf (fp, _("\
27024 --fix-v4bx Allow BX in ARMv4 code\n"));
18a20338
CL
27025
27026#ifdef OBJ_ELF
27027 fprintf (fp, _("\
27028 --fdpic generate an FDPIC object file\n"));
27029#endif /* OBJ_ELF */
c19d1205 27030}
ee065d83 27031
ee065d83 27032#ifdef OBJ_ELF
0198d5e6 27033
62b3e311
PB
27034typedef struct
27035{
27036 int val;
27037 arm_feature_set flags;
27038} cpu_arch_ver_table;
27039
2c6b98ea
TP
27040/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
27041 chronologically for architectures, with an exception for ARMv6-M and
27042 ARMv6S-M due to legacy reasons. No new architecture should have a
27043 special case. This allows for build attribute selection results to be
27044 stable when new architectures are added. */
62b3e311
PB
27045static const cpu_arch_ver_table cpu_arch_ver[] =
27046{
c0c468d5
TP
27047 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
27048 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
27049 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
27050 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
27051 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
27052 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
27053 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
27054 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
27055 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
27056 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
27057 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
27058 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
27059 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
27060 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
27061 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
27062 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
27063 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
27064 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
27065 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
27066 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
27067 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
27068 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
27069 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
27070 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
2c6b98ea
TP
27071
27072 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
27073 always selected build attributes to match those of ARMv6-M
27074 (resp. ARMv6S-M). However, due to these architectures being a strict
27075 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
27076 would be selected when fully respecting chronology of architectures.
27077 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
27078 move them before ARMv7 architectures. */
c0c468d5
TP
27079 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
27080 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
27081
27082 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
27083 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
27084 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
27085 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
27086 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
27087 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
27088 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
27089 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
27090 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
27091 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
27092 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
27093 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
27094 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
27095 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
23f233a5 27096 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
c0c468d5 27097 {-1, ARM_ARCH_NONE}
62b3e311
PB
27098};
27099
ee3c0378 27100/* Set an attribute if it has not already been set by the user. */
0198d5e6 27101
ee3c0378
AS
27102static void
27103aeabi_set_attribute_int (int tag, int value)
27104{
27105 if (tag < 1
27106 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
27107 || !attributes_set_explicitly[tag])
27108 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
27109}
27110
27111static void
27112aeabi_set_attribute_string (int tag, const char *value)
27113{
27114 if (tag < 1
27115 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
27116 || !attributes_set_explicitly[tag])
27117 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
27118}
27119
2c6b98ea
TP
27120/* Return whether features in the *NEEDED feature set are available via
27121 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 27122
2c6b98ea
TP
27123static bfd_boolean
27124have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
27125 const arm_feature_set *needed)
27126{
27127 int i, nb_allowed_archs;
27128 arm_feature_set ext_fset;
27129 const struct arm_option_extension_value_table *opt;
27130
27131 ext_fset = arm_arch_none;
27132 for (opt = arm_extensions; opt->name != NULL; opt++)
27133 {
27134 /* Extension does not provide any feature we need. */
27135 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
27136 continue;
27137
27138 nb_allowed_archs =
27139 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
27140 for (i = 0; i < nb_allowed_archs; i++)
27141 {
27142 /* Empty entry. */
27143 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
27144 break;
27145
27146 /* Extension is available, add it. */
27147 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
27148 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
27149 }
27150 }
27151
27152 /* Can we enable all features in *needed? */
27153 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
27154}
27155
27156/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
27157 a given architecture feature set *ARCH_EXT_FSET including extension feature
27158 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
27159 - if true, check for an exact match of the architecture modulo extensions;
27160 - otherwise, select build attribute value of the first superset
27161 architecture released so that results remains stable when new architectures
27162 are added.
27163 For -march/-mcpu=all the build attribute value of the most featureful
27164 architecture is returned. Tag_CPU_arch_profile result is returned in
27165 PROFILE. */
0198d5e6 27166
2c6b98ea
TP
27167static int
27168get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
27169 const arm_feature_set *ext_fset,
27170 char *profile, int exact_match)
27171{
27172 arm_feature_set arch_fset;
27173 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
27174
27175 /* Select most featureful architecture with all its extensions if building
27176 for -march=all as the feature sets used to set build attributes. */
27177 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
27178 {
27179 /* Force revisiting of decision for each new architecture. */
27180 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8M_MAIN);
27181 *profile = 'A';
27182 return TAG_CPU_ARCH_V8;
27183 }
27184
27185 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
27186
27187 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
27188 {
27189 arm_feature_set known_arch_fset;
27190
27191 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
27192 if (exact_match)
27193 {
27194 /* Base architecture match user-specified architecture and
27195 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
27196 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
27197 {
27198 p_ver_ret = p_ver;
27199 goto found;
27200 }
27201 /* Base architecture match user-specified architecture only
27202 (eg. ARMv6-M in the same case as above). Record it in case we
27203 find a match with above condition. */
27204 else if (p_ver_ret == NULL
27205 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
27206 p_ver_ret = p_ver;
27207 }
27208 else
27209 {
27210
27211 /* Architecture has all features wanted. */
27212 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
27213 {
27214 arm_feature_set added_fset;
27215
27216 /* Compute features added by this architecture over the one
27217 recorded in p_ver_ret. */
27218 if (p_ver_ret != NULL)
27219 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
27220 p_ver_ret->flags);
27221 /* First architecture that match incl. with extensions, or the
27222 only difference in features over the recorded match is
27223 features that were optional and are now mandatory. */
27224 if (p_ver_ret == NULL
27225 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
27226 {
27227 p_ver_ret = p_ver;
27228 goto found;
27229 }
27230 }
27231 else if (p_ver_ret == NULL)
27232 {
27233 arm_feature_set needed_ext_fset;
27234
27235 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
27236
27237 /* Architecture has all features needed when using some
27238 extensions. Record it and continue searching in case there
27239 exist an architecture providing all needed features without
27240 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
27241 OS extension). */
27242 if (have_ext_for_needed_feat_p (&known_arch_fset,
27243 &needed_ext_fset))
27244 p_ver_ret = p_ver;
27245 }
27246 }
27247 }
27248
27249 if (p_ver_ret == NULL)
27250 return -1;
27251
27252found:
27253 /* Tag_CPU_arch_profile. */
27254 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
27255 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
27256 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
27257 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
27258 *profile = 'A';
27259 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
27260 *profile = 'R';
27261 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
27262 *profile = 'M';
27263 else
27264 *profile = '\0';
27265 return p_ver_ret->val;
27266}
27267
ee065d83 27268/* Set the public EABI object attributes. */
0198d5e6 27269
c168ce07 27270static void
ee065d83
PB
27271aeabi_set_public_attributes (void)
27272{
b90d5ba0 27273 char profile = '\0';
2c6b98ea 27274 int arch = -1;
90ec0d68 27275 int virt_sec = 0;
bca38921 27276 int fp16_optional = 0;
2c6b98ea
TP
27277 int skip_exact_match = 0;
27278 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 27279
54bab281
TP
27280 /* Autodetection mode, choose the architecture based the instructions
27281 actually used. */
27282 if (no_cpu_selected ())
27283 {
27284 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 27285
54bab281
TP
27286 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
27287 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 27288
54bab281
TP
27289 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
27290 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 27291
54bab281 27292 /* Code run during relaxation relies on selected_cpu being set. */
4d354d8b
TP
27293 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
27294 flags_ext = arm_arch_none;
27295 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
27296 selected_ext = flags_ext;
54bab281
TP
27297 selected_cpu = flags;
27298 }
27299 /* Otherwise, choose the architecture based on the capabilities of the
27300 requested cpu. */
27301 else
4d354d8b
TP
27302 {
27303 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
27304 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
27305 flags_ext = selected_ext;
27306 flags = selected_cpu;
27307 }
27308 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
7f78eb34 27309
ddd7f988 27310 /* Allow the user to override the reported architecture. */
4d354d8b 27311 if (!ARM_FEATURE_ZERO (selected_object_arch))
7a1d4c38 27312 {
4d354d8b 27313 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
2c6b98ea 27314 flags_ext = arm_arch_none;
7a1d4c38 27315 }
2c6b98ea 27316 else
4d354d8b 27317 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
2c6b98ea
TP
27318
27319 /* When this function is run again after relaxation has happened there is no
27320 way to determine whether an architecture or CPU was specified by the user:
27321 - selected_cpu is set above for relaxation to work;
27322 - march_cpu_opt is not set if only -mcpu or .cpu is used;
27323 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
27324 Therefore, if not in -march=all case we first try an exact match and fall
27325 back to autodetection. */
27326 if (!skip_exact_match)
27327 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
27328 if (arch == -1)
27329 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
27330 if (arch == -1)
27331 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 27332
ee065d83
PB
27333 /* Tag_CPU_name. */
27334 if (selected_cpu_name[0])
27335 {
91d6fa6a 27336 char *q;
ee065d83 27337
91d6fa6a
NC
27338 q = selected_cpu_name;
27339 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
27340 {
27341 int i;
5f4273c7 27342
91d6fa6a
NC
27343 q += 4;
27344 for (i = 0; q[i]; i++)
27345 q[i] = TOUPPER (q[i]);
ee065d83 27346 }
91d6fa6a 27347 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 27348 }
62f3b8c8 27349
ee065d83 27350 /* Tag_CPU_arch. */
ee3c0378 27351 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 27352
62b3e311 27353 /* Tag_CPU_arch_profile. */
69239280
MGD
27354 if (profile != '\0')
27355 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 27356
15afaa63 27357 /* Tag_DSP_extension. */
4d354d8b 27358 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
6c290d53 27359 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 27360
2c6b98ea 27361 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 27362 /* Tag_ARM_ISA_use. */
ee3c0378 27363 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 27364 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 27365 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 27366
ee065d83 27367 /* Tag_THUMB_ISA_use. */
ee3c0378 27368 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 27369 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
27370 {
27371 int thumb_isa_use;
27372
27373 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 27374 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
27375 thumb_isa_use = 3;
27376 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
27377 thumb_isa_use = 2;
27378 else
27379 thumb_isa_use = 1;
27380 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
27381 }
62f3b8c8 27382
ee065d83 27383 /* Tag_VFP_arch. */
a715796b
TG
27384 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
27385 aeabi_set_attribute_int (Tag_VFP_arch,
27386 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27387 ? 7 : 8);
bca38921 27388 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
27389 aeabi_set_attribute_int (Tag_VFP_arch,
27390 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27391 ? 5 : 6);
27392 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
27393 {
27394 fp16_optional = 1;
27395 aeabi_set_attribute_int (Tag_VFP_arch, 3);
27396 }
ada65aa3 27397 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
27398 {
27399 aeabi_set_attribute_int (Tag_VFP_arch, 4);
27400 fp16_optional = 1;
27401 }
ee3c0378
AS
27402 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
27403 aeabi_set_attribute_int (Tag_VFP_arch, 2);
27404 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 27405 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 27406 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 27407
4547cb56
NC
27408 /* Tag_ABI_HardFP_use. */
27409 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
27410 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
27411 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
27412
ee065d83 27413 /* Tag_WMMX_arch. */
ee3c0378
AS
27414 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
27415 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
27416 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
27417 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 27418
ee3c0378 27419 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
27420 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
27421 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
27422 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
27423 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
27424 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
27425 {
27426 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
27427 {
27428 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
27429 }
27430 else
27431 {
27432 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
27433 fp16_optional = 1;
27434 }
27435 }
fa94de6b 27436
ee3c0378 27437 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 27438 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 27439 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 27440
69239280
MGD
27441 /* Tag_DIV_use.
27442
27443 We set Tag_DIV_use to two when integer divide instructions have been used
27444 in ARM state, or when Thumb integer divide instructions have been used,
27445 but we have no architecture profile set, nor have we any ARM instructions.
27446
4ed7ed8d
TP
27447 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
27448 by the base architecture.
bca38921 27449
69239280 27450 For new architectures we will have to check these tests. */
ced40572 27451 gas_assert (arch <= TAG_CPU_ARCH_V8M_MAIN);
4ed7ed8d
TP
27452 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
27453 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
27454 aeabi_set_attribute_int (Tag_DIV_use, 0);
27455 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
27456 || (profile == '\0'
27457 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
27458 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 27459 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
27460
27461 /* Tag_MP_extension_use. */
27462 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
27463 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
27464
27465 /* Tag Virtualization_use. */
27466 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
27467 virt_sec |= 1;
27468 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
27469 virt_sec |= 2;
27470 if (virt_sec != 0)
27471 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
27472}
27473
c168ce07
TP
27474/* Post relaxation hook. Recompute ARM attributes now that relaxation is
27475 finished and free extension feature bits which will not be used anymore. */
0198d5e6 27476
c168ce07
TP
27477void
27478arm_md_post_relax (void)
27479{
27480 aeabi_set_public_attributes ();
4d354d8b
TP
27481 XDELETE (mcpu_ext_opt);
27482 mcpu_ext_opt = NULL;
27483 XDELETE (march_ext_opt);
27484 march_ext_opt = NULL;
c168ce07
TP
27485}
27486
104d59d1 27487/* Add the default contents for the .ARM.attributes section. */
0198d5e6 27488
ee065d83
PB
27489void
27490arm_md_end (void)
27491{
ee065d83
PB
27492 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
27493 return;
27494
27495 aeabi_set_public_attributes ();
ee065d83 27496}
8463be01 27497#endif /* OBJ_ELF */
ee065d83 27498
ee065d83
PB
27499/* Parse a .cpu directive. */
27500
27501static void
27502s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
27503{
e74cfd16 27504 const struct arm_cpu_option_table *opt;
ee065d83
PB
27505 char *name;
27506 char saved_char;
27507
27508 name = input_line_pointer;
5f4273c7 27509 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27510 input_line_pointer++;
27511 saved_char = *input_line_pointer;
27512 *input_line_pointer = 0;
27513
27514 /* Skip the first "all" entry. */
27515 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
27516 if (streq (opt->name, name))
27517 {
4d354d8b
TP
27518 selected_arch = opt->value;
27519 selected_ext = opt->ext;
27520 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
ee065d83 27521 if (opt->canonical_name)
5f4273c7 27522 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
27523 else
27524 {
27525 int i;
27526 for (i = 0; opt->name[i]; i++)
27527 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 27528
ee065d83
PB
27529 selected_cpu_name[i] = 0;
27530 }
4d354d8b
TP
27531 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
27532
ee065d83
PB
27533 *input_line_pointer = saved_char;
27534 demand_empty_rest_of_line ();
27535 return;
27536 }
27537 as_bad (_("unknown cpu `%s'"), name);
27538 *input_line_pointer = saved_char;
27539 ignore_rest_of_line ();
27540}
27541
ee065d83
PB
27542/* Parse a .arch directive. */
27543
27544static void
27545s_arm_arch (int ignored ATTRIBUTE_UNUSED)
27546{
e74cfd16 27547 const struct arm_arch_option_table *opt;
ee065d83
PB
27548 char saved_char;
27549 char *name;
27550
27551 name = input_line_pointer;
5f4273c7 27552 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27553 input_line_pointer++;
27554 saved_char = *input_line_pointer;
27555 *input_line_pointer = 0;
27556
27557 /* Skip the first "all" entry. */
27558 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27559 if (streq (opt->name, name))
27560 {
4d354d8b
TP
27561 selected_arch = opt->value;
27562 selected_ext = arm_arch_none;
27563 selected_cpu = selected_arch;
5f4273c7 27564 strcpy (selected_cpu_name, opt->name);
4d354d8b 27565 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
27566 *input_line_pointer = saved_char;
27567 demand_empty_rest_of_line ();
27568 return;
27569 }
27570
27571 as_bad (_("unknown architecture `%s'\n"), name);
27572 *input_line_pointer = saved_char;
27573 ignore_rest_of_line ();
27574}
27575
7a1d4c38
PB
27576/* Parse a .object_arch directive. */
27577
27578static void
27579s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
27580{
27581 const struct arm_arch_option_table *opt;
27582 char saved_char;
27583 char *name;
27584
27585 name = input_line_pointer;
5f4273c7 27586 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
27587 input_line_pointer++;
27588 saved_char = *input_line_pointer;
27589 *input_line_pointer = 0;
27590
27591 /* Skip the first "all" entry. */
27592 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27593 if (streq (opt->name, name))
27594 {
4d354d8b 27595 selected_object_arch = opt->value;
7a1d4c38
PB
27596 *input_line_pointer = saved_char;
27597 demand_empty_rest_of_line ();
27598 return;
27599 }
27600
27601 as_bad (_("unknown architecture `%s'\n"), name);
27602 *input_line_pointer = saved_char;
27603 ignore_rest_of_line ();
27604}
27605
69133863
MGD
27606/* Parse a .arch_extension directive. */
27607
27608static void
27609s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
27610{
27611 const struct arm_option_extension_value_table *opt;
27612 char saved_char;
27613 char *name;
27614 int adding_value = 1;
27615
27616 name = input_line_pointer;
27617 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27618 input_line_pointer++;
27619 saved_char = *input_line_pointer;
27620 *input_line_pointer = 0;
27621
27622 if (strlen (name) >= 2
27623 && strncmp (name, "no", 2) == 0)
27624 {
27625 adding_value = 0;
27626 name += 2;
27627 }
27628
27629 for (opt = arm_extensions; opt->name != NULL; opt++)
27630 if (streq (opt->name, name))
27631 {
d942732e
TP
27632 int i, nb_allowed_archs =
27633 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
27634 for (i = 0; i < nb_allowed_archs; i++)
27635 {
27636 /* Empty entry. */
4d354d8b 27637 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
d942732e 27638 continue;
4d354d8b 27639 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
d942732e
TP
27640 break;
27641 }
27642
27643 if (i == nb_allowed_archs)
69133863
MGD
27644 {
27645 as_bad (_("architectural extension `%s' is not allowed for the "
27646 "current base architecture"), name);
27647 break;
27648 }
27649
27650 if (adding_value)
4d354d8b 27651 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
5a70a223 27652 opt->merge_value);
69133863 27653 else
4d354d8b 27654 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
69133863 27655
4d354d8b
TP
27656 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
27657 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
69133863
MGD
27658 *input_line_pointer = saved_char;
27659 demand_empty_rest_of_line ();
3d030cdb
TP
27660 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
27661 on this return so that duplicate extensions (extensions with the
27662 same name as a previous extension in the list) are not considered
27663 for command-line parsing. */
69133863
MGD
27664 return;
27665 }
27666
27667 if (opt->name == NULL)
e673710a 27668 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
27669
27670 *input_line_pointer = saved_char;
27671 ignore_rest_of_line ();
27672}
27673
ee065d83
PB
27674/* Parse a .fpu directive. */
27675
27676static void
27677s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
27678{
69133863 27679 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
27680 char saved_char;
27681 char *name;
27682
27683 name = input_line_pointer;
5f4273c7 27684 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27685 input_line_pointer++;
27686 saved_char = *input_line_pointer;
27687 *input_line_pointer = 0;
5f4273c7 27688
ee065d83
PB
27689 for (opt = arm_fpus; opt->name != NULL; opt++)
27690 if (streq (opt->name, name))
27691 {
4d354d8b
TP
27692 selected_fpu = opt->value;
27693#ifndef CPU_DEFAULT
27694 if (no_cpu_selected ())
27695 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
27696 else
27697#endif
27698 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
27699 *input_line_pointer = saved_char;
27700 demand_empty_rest_of_line ();
27701 return;
27702 }
27703
27704 as_bad (_("unknown floating point format `%s'\n"), name);
27705 *input_line_pointer = saved_char;
27706 ignore_rest_of_line ();
27707}
ee065d83 27708
794ba86a 27709/* Copy symbol information. */
f31fef98 27710
794ba86a
DJ
27711void
27712arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
27713{
27714 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
27715}
e04befd0 27716
f31fef98 27717#ifdef OBJ_ELF
e04befd0
AS
27718/* Given a symbolic attribute NAME, return the proper integer value.
27719 Returns -1 if the attribute is not known. */
f31fef98 27720
e04befd0
AS
27721int
27722arm_convert_symbolic_attribute (const char *name)
27723{
f31fef98
NC
27724 static const struct
27725 {
27726 const char * name;
27727 const int tag;
27728 }
27729 attribute_table[] =
27730 {
27731 /* When you modify this table you should
27732 also modify the list in doc/c-arm.texi. */
e04befd0 27733#define T(tag) {#tag, tag}
f31fef98
NC
27734 T (Tag_CPU_raw_name),
27735 T (Tag_CPU_name),
27736 T (Tag_CPU_arch),
27737 T (Tag_CPU_arch_profile),
27738 T (Tag_ARM_ISA_use),
27739 T (Tag_THUMB_ISA_use),
75375b3e 27740 T (Tag_FP_arch),
f31fef98
NC
27741 T (Tag_VFP_arch),
27742 T (Tag_WMMX_arch),
27743 T (Tag_Advanced_SIMD_arch),
27744 T (Tag_PCS_config),
27745 T (Tag_ABI_PCS_R9_use),
27746 T (Tag_ABI_PCS_RW_data),
27747 T (Tag_ABI_PCS_RO_data),
27748 T (Tag_ABI_PCS_GOT_use),
27749 T (Tag_ABI_PCS_wchar_t),
27750 T (Tag_ABI_FP_rounding),
27751 T (Tag_ABI_FP_denormal),
27752 T (Tag_ABI_FP_exceptions),
27753 T (Tag_ABI_FP_user_exceptions),
27754 T (Tag_ABI_FP_number_model),
75375b3e 27755 T (Tag_ABI_align_needed),
f31fef98 27756 T (Tag_ABI_align8_needed),
75375b3e 27757 T (Tag_ABI_align_preserved),
f31fef98
NC
27758 T (Tag_ABI_align8_preserved),
27759 T (Tag_ABI_enum_size),
27760 T (Tag_ABI_HardFP_use),
27761 T (Tag_ABI_VFP_args),
27762 T (Tag_ABI_WMMX_args),
27763 T (Tag_ABI_optimization_goals),
27764 T (Tag_ABI_FP_optimization_goals),
27765 T (Tag_compatibility),
27766 T (Tag_CPU_unaligned_access),
75375b3e 27767 T (Tag_FP_HP_extension),
f31fef98
NC
27768 T (Tag_VFP_HP_extension),
27769 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
27770 T (Tag_MPextension_use),
27771 T (Tag_DIV_use),
f31fef98
NC
27772 T (Tag_nodefaults),
27773 T (Tag_also_compatible_with),
27774 T (Tag_conformance),
27775 T (Tag_T2EE_use),
27776 T (Tag_Virtualization_use),
15afaa63 27777 T (Tag_DSP_extension),
cd21e546 27778 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 27779#undef T
f31fef98 27780 };
e04befd0
AS
27781 unsigned int i;
27782
27783 if (name == NULL)
27784 return -1;
27785
f31fef98 27786 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 27787 if (streq (name, attribute_table[i].name))
e04befd0
AS
27788 return attribute_table[i].tag;
27789
27790 return -1;
27791}
267bf995 27792
93ef582d
NC
27793/* Apply sym value for relocations only in the case that they are for
27794 local symbols in the same segment as the fixup and you have the
27795 respective architectural feature for blx and simple switches. */
0198d5e6 27796
267bf995 27797int
93ef582d 27798arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
27799{
27800 if (fixP->fx_addsy
27801 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
27802 /* PR 17444: If the local symbol is in a different section then a reloc
27803 will always be generated for it, so applying the symbol value now
27804 will result in a double offset being stored in the relocation. */
27805 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 27806 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
27807 {
27808 switch (fixP->fx_r_type)
27809 {
27810 case BFD_RELOC_ARM_PCREL_BLX:
27811 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27812 if (ARM_IS_FUNC (fixP->fx_addsy))
27813 return 1;
27814 break;
27815
27816 case BFD_RELOC_ARM_PCREL_CALL:
27817 case BFD_RELOC_THUMB_PCREL_BLX:
27818 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 27819 return 1;
267bf995
RR
27820 break;
27821
27822 default:
27823 break;
27824 }
27825
27826 }
27827 return 0;
27828}
f31fef98 27829#endif /* OBJ_ELF */