]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
MIPS/BFD: Fix TLS relocation resolution for regular executables
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
219d1afa 2 Copyright (C) 1994-2018 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);
823d2571
TG
207static const arm_feature_set arm_ext_v6_notm =
208 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
209static const arm_feature_set arm_ext_v6_dsp =
210 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
211static const arm_feature_set arm_ext_barrier =
212 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
213static const arm_feature_set arm_ext_msr =
214 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
215static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
216static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
217static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
218static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 219#ifdef OBJ_ELF
e7d39ed3 220static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 221#endif
823d2571 222static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 223static const arm_feature_set arm_ext_m =
173205ca 224 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
16a1fa25 225 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
226static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
227static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
228static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
229static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
230static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 231static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 232static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
233static const arm_feature_set arm_ext_v8m_main =
234 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
235/* Instructions in ARMv8-M only found in M profile architectures. */
236static const arm_feature_set arm_ext_v8m_m_only =
237 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
238static const arm_feature_set arm_ext_v6t2_v8m =
239 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
240/* Instructions shared between ARMv8-A and ARMv8-M. */
241static const arm_feature_set arm_ext_atomics =
242 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 243#ifdef OBJ_ELF
15afaa63
TP
244/* DSP instructions Tag_DSP_extension refers to. */
245static const arm_feature_set arm_ext_dsp =
246 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 247#endif
4d1464f2
MW
248static const arm_feature_set arm_ext_ras =
249 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
250/* FP16 instructions. */
251static const arm_feature_set arm_ext_fp16 =
252 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
01f48020
TC
253static const arm_feature_set arm_ext_fp16_fml =
254 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
dec41383
JW
255static const arm_feature_set arm_ext_v8_2 =
256 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
49e8a725
SN
257static const arm_feature_set arm_ext_v8_3 =
258 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
e74cfd16
PB
259
260static const arm_feature_set arm_arch_any = ARM_ANY;
49fa50ef 261#ifdef OBJ_ELF
2c6b98ea 262static const arm_feature_set fpu_any = FPU_ANY;
49fa50ef 263#endif
f85d59c3 264static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
265static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
266static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
267
2d447fca 268static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 269 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 270static const arm_feature_set arm_cext_iwmmxt =
823d2571 271 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 272static const arm_feature_set arm_cext_xscale =
823d2571 273 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 274static const arm_feature_set arm_cext_maverick =
823d2571
TG
275 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
276static const arm_feature_set fpu_fpa_ext_v1 =
277 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
278static const arm_feature_set fpu_fpa_ext_v2 =
279 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 280static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
281 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
282static const arm_feature_set fpu_vfp_ext_v1 =
283 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
284static const arm_feature_set fpu_vfp_ext_v2 =
285 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
286static const arm_feature_set fpu_vfp_ext_v3xd =
287 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
288static const arm_feature_set fpu_vfp_ext_v3 =
289 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 290static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
291 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
292static const arm_feature_set fpu_neon_ext_v1 =
293 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 294static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 295 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
69c9e028 296#ifdef OBJ_ELF
823d2571
TG
297static const arm_feature_set fpu_vfp_fp16 =
298 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
299static const arm_feature_set fpu_neon_ext_fma =
300 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 301#endif
823d2571
TG
302static const arm_feature_set fpu_vfp_ext_fma =
303 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 304static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 305 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 306static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 307 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 308static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 309 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 310static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 311 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 312static const arm_feature_set crc_ext_armv8 =
823d2571 313 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 314static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 315 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
316static const arm_feature_set fpu_neon_ext_dotprod =
317 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 318
33a392fb 319static int mfloat_abi_opt = -1;
4d354d8b
TP
320/* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
321 directive. */
322static arm_feature_set selected_arch = ARM_ARCH_NONE;
323/* Extension feature bits selected by the last -mcpu/-march or .arch_extension
324 directive. */
325static arm_feature_set selected_ext = ARM_ARCH_NONE;
326/* Feature bits selected by the last -mcpu/-march or by the combination of the
327 last .cpu/.arch directive .arch_extension directives since that
328 directive. */
e74cfd16 329static arm_feature_set selected_cpu = ARM_ARCH_NONE;
4d354d8b
TP
330/* FPU feature bits selected by the last -mfpu or .fpu directive. */
331static arm_feature_set selected_fpu = FPU_NONE;
332/* Feature bits selected by the last .object_arch directive. */
333static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
ee065d83 334/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 335static char selected_cpu_name[20];
8d67f500 336
aacf0b33
KT
337extern FLONUM_TYPE generic_floating_point_number;
338
8d67f500
NC
339/* Return if no cpu was selected on command-line. */
340static bfd_boolean
341no_cpu_selected (void)
342{
823d2571 343 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
344}
345
7cc69913 346#ifdef OBJ_ELF
deeaaff8
DJ
347# ifdef EABI_DEFAULT
348static int meabi_flags = EABI_DEFAULT;
349# else
d507cf36 350static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 351# endif
e1da3f5b 352
ee3c0378
AS
353static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
354
e1da3f5b 355bfd_boolean
5f4273c7 356arm_is_eabi (void)
e1da3f5b
PB
357{
358 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
359}
7cc69913 360#endif
b99bd4ef 361
b99bd4ef 362#ifdef OBJ_ELF
c19d1205 363/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
364symbolS * GOT_symbol;
365#endif
366
b99bd4ef
NC
367/* 0: assemble for ARM,
368 1: assemble for Thumb,
369 2: assemble for Thumb even though target CPU does not support thumb
370 instructions. */
371static int thumb_mode = 0;
8dc2430f
NC
372/* A value distinct from the possible values for thumb_mode that we
373 can use to record whether thumb_mode has been copied into the
374 tc_frag_data field of a frag. */
375#define MODE_RECORDED (1 << 4)
b99bd4ef 376
e07e6e58
NC
377/* Specifies the intrinsic IT insn behavior mode. */
378enum implicit_it_mode
379{
380 IMPLICIT_IT_MODE_NEVER = 0x00,
381 IMPLICIT_IT_MODE_ARM = 0x01,
382 IMPLICIT_IT_MODE_THUMB = 0x02,
383 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
384};
385static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
386
c19d1205
ZW
387/* If unified_syntax is true, we are processing the new unified
388 ARM/Thumb syntax. Important differences from the old ARM mode:
389
390 - Immediate operands do not require a # prefix.
391 - Conditional affixes always appear at the end of the
392 instruction. (For backward compatibility, those instructions
393 that formerly had them in the middle, continue to accept them
394 there.)
395 - The IT instruction may appear, and if it does is validated
396 against subsequent conditional affixes. It does not generate
397 machine code.
398
399 Important differences from the old Thumb mode:
400
401 - Immediate operands do not require a # prefix.
402 - Most of the V6T2 instructions are only available in unified mode.
403 - The .N and .W suffixes are recognized and honored (it is an error
404 if they cannot be honored).
405 - All instructions set the flags if and only if they have an 's' affix.
406 - Conditional affixes may be used. They are validated against
407 preceding IT instructions. Unlike ARM mode, you cannot use a
408 conditional affix except in the scope of an IT instruction. */
409
410static bfd_boolean unified_syntax = FALSE;
b99bd4ef 411
bacebabc
RM
412/* An immediate operand can start with #, and ld*, st*, pld operands
413 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
414 before a [, which can appear as the first operand for pld.
415 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
416const char arm_symbol_chars[] = "#[]{}";
bacebabc 417
5287ad62
JB
418enum neon_el_type
419{
dcbf9037 420 NT_invtype,
5287ad62
JB
421 NT_untyped,
422 NT_integer,
423 NT_float,
424 NT_poly,
425 NT_signed,
dcbf9037 426 NT_unsigned
5287ad62
JB
427};
428
429struct neon_type_el
430{
431 enum neon_el_type type;
432 unsigned size;
433};
434
435#define NEON_MAX_TYPE_ELS 4
436
437struct neon_type
438{
439 struct neon_type_el el[NEON_MAX_TYPE_ELS];
440 unsigned elems;
441};
442
e07e6e58
NC
443enum it_instruction_type
444{
445 OUTSIDE_IT_INSN,
446 INSIDE_IT_INSN,
447 INSIDE_IT_LAST_INSN,
448 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 449 if inside, should be the last one. */
e07e6e58 450 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 451 i.e. BKPT and NOP. */
e07e6e58
NC
452 IT_INSN /* The IT insn has been parsed. */
453};
454
ad6cec43
MGD
455/* The maximum number of operands we need. */
456#define ARM_IT_MAX_OPERANDS 6
457
b99bd4ef
NC
458struct arm_it
459{
c19d1205 460 const char * error;
b99bd4ef 461 unsigned long instruction;
c19d1205
ZW
462 int size;
463 int size_req;
464 int cond;
037e8744
JB
465 /* "uncond_value" is set to the value in place of the conditional field in
466 unconditional versions of the instruction, or -1 if nothing is
467 appropriate. */
468 int uncond_value;
5287ad62 469 struct neon_type vectype;
88714cb8
DG
470 /* This does not indicate an actual NEON instruction, only that
471 the mnemonic accepts neon-style type suffixes. */
472 int is_neon;
0110f2b8
PB
473 /* Set to the opcode if the instruction needs relaxation.
474 Zero if the instruction is not relaxed. */
475 unsigned long relax;
b99bd4ef
NC
476 struct
477 {
478 bfd_reloc_code_real_type type;
c19d1205
ZW
479 expressionS exp;
480 int pc_rel;
b99bd4ef 481 } reloc;
b99bd4ef 482
e07e6e58
NC
483 enum it_instruction_type it_insn_type;
484
c19d1205
ZW
485 struct
486 {
487 unsigned reg;
ca3f61f7 488 signed int imm;
dcbf9037 489 struct neon_type_el vectype;
ca3f61f7
NC
490 unsigned present : 1; /* Operand present. */
491 unsigned isreg : 1; /* Operand was a register. */
492 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
493 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
494 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 495 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
496 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
497 instructions. This allows us to disambiguate ARM <-> vector insns. */
498 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 499 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 500 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 501 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
502 unsigned hasreloc : 1; /* Operand has relocation suffix. */
503 unsigned writeback : 1; /* Operand has trailing ! */
504 unsigned preind : 1; /* Preindexed address. */
505 unsigned postind : 1; /* Postindexed address. */
506 unsigned negative : 1; /* Index register was negated. */
507 unsigned shifted : 1; /* Shift applied to operation. */
508 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 509 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
510};
511
c19d1205 512static struct arm_it inst;
b99bd4ef
NC
513
514#define NUM_FLOAT_VALS 8
515
05d2d07e 516const char * fp_const[] =
b99bd4ef
NC
517{
518 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
519};
520
c19d1205 521/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
522#define MAX_LITTLENUMS 6
523
524LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
525
526#define FAIL (-1)
527#define SUCCESS (0)
528
529#define SUFF_S 1
530#define SUFF_D 2
531#define SUFF_E 3
532#define SUFF_P 4
533
c19d1205
ZW
534#define CP_T_X 0x00008000
535#define CP_T_Y 0x00400000
b99bd4ef 536
c19d1205
ZW
537#define CONDS_BIT 0x00100000
538#define LOAD_BIT 0x00100000
b99bd4ef
NC
539
540#define DOUBLE_LOAD_FLAG 0x00000001
541
542struct asm_cond
543{
d3ce72d0 544 const char * template_name;
c921be7d 545 unsigned long value;
b99bd4ef
NC
546};
547
c19d1205 548#define COND_ALWAYS 0xE
b99bd4ef 549
b99bd4ef
NC
550struct asm_psr
551{
d3ce72d0 552 const char * template_name;
c921be7d 553 unsigned long field;
b99bd4ef
NC
554};
555
62b3e311
PB
556struct asm_barrier_opt
557{
e797f7e0
MGD
558 const char * template_name;
559 unsigned long value;
560 const arm_feature_set arch;
62b3e311
PB
561};
562
2d2255b5 563/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
564#define SPSR_BIT (1 << 22)
565
c19d1205
ZW
566/* The individual PSR flag bits. */
567#define PSR_c (1 << 16)
568#define PSR_x (1 << 17)
569#define PSR_s (1 << 18)
570#define PSR_f (1 << 19)
b99bd4ef 571
c19d1205 572struct reloc_entry
bfae80f2 573{
0198d5e6 574 const char * name;
c921be7d 575 bfd_reloc_code_real_type reloc;
bfae80f2
RE
576};
577
5287ad62 578enum vfp_reg_pos
bfae80f2 579{
5287ad62
JB
580 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
581 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
582};
583
584enum vfp_ldstm_type
585{
586 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
587};
588
dcbf9037
JB
589/* Bits for DEFINED field in neon_typed_alias. */
590#define NTA_HASTYPE 1
591#define NTA_HASINDEX 2
592
593struct neon_typed_alias
594{
c921be7d
NC
595 unsigned char defined;
596 unsigned char index;
597 struct neon_type_el eltype;
dcbf9037
JB
598};
599
c19d1205 600/* ARM register categories. This includes coprocessor numbers and various
5aa75429
TP
601 architecture extensions' registers. Each entry should have an error message
602 in reg_expected_msgs below. */
c19d1205 603enum arm_reg_type
bfae80f2 604{
c19d1205
ZW
605 REG_TYPE_RN,
606 REG_TYPE_CP,
607 REG_TYPE_CN,
608 REG_TYPE_FN,
609 REG_TYPE_VFS,
610 REG_TYPE_VFD,
5287ad62 611 REG_TYPE_NQ,
037e8744 612 REG_TYPE_VFSD,
5287ad62 613 REG_TYPE_NDQ,
dec41383 614 REG_TYPE_NSD,
037e8744 615 REG_TYPE_NSDQ,
c19d1205
ZW
616 REG_TYPE_VFC,
617 REG_TYPE_MVF,
618 REG_TYPE_MVD,
619 REG_TYPE_MVFX,
620 REG_TYPE_MVDX,
621 REG_TYPE_MVAX,
622 REG_TYPE_DSPSC,
623 REG_TYPE_MMXWR,
624 REG_TYPE_MMXWC,
625 REG_TYPE_MMXWCG,
626 REG_TYPE_XSCALE,
90ec0d68 627 REG_TYPE_RNB
bfae80f2
RE
628};
629
dcbf9037
JB
630/* Structure for a hash table entry for a register.
631 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
632 information which states whether a vector type or index is specified (for a
633 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
634struct reg_entry
635{
c921be7d 636 const char * name;
90ec0d68 637 unsigned int number;
c921be7d
NC
638 unsigned char type;
639 unsigned char builtin;
640 struct neon_typed_alias * neon;
6c43fab6
RE
641};
642
c19d1205 643/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 644const char * const reg_expected_msgs[] =
c19d1205 645{
5aa75429
TP
646 [REG_TYPE_RN] = N_("ARM register expected"),
647 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
648 [REG_TYPE_CN] = N_("co-processor register expected"),
649 [REG_TYPE_FN] = N_("FPA register expected"),
650 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
651 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
652 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
653 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
654 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
655 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
656 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
657 " expected"),
658 [REG_TYPE_VFC] = N_("VFP system register expected"),
659 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
660 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
661 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
662 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
663 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
664 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
665 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
666 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
667 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
668 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
669 [REG_TYPE_RNB] = N_("")
6c43fab6
RE
670};
671
c19d1205 672/* Some well known registers that we refer to directly elsewhere. */
bd340a04 673#define REG_R12 12
c19d1205
ZW
674#define REG_SP 13
675#define REG_LR 14
676#define REG_PC 15
404ff6b5 677
b99bd4ef
NC
678/* ARM instructions take 4bytes in the object file, Thumb instructions
679 take 2: */
c19d1205 680#define INSN_SIZE 4
b99bd4ef
NC
681
682struct asm_opcode
683{
684 /* Basic string to match. */
d3ce72d0 685 const char * template_name;
c19d1205
ZW
686
687 /* Parameters to instruction. */
5be8be5d 688 unsigned int operands[8];
c19d1205
ZW
689
690 /* Conditional tag - see opcode_lookup. */
691 unsigned int tag : 4;
b99bd4ef
NC
692
693 /* Basic instruction code. */
c19d1205 694 unsigned int avalue : 28;
b99bd4ef 695
c19d1205
ZW
696 /* Thumb-format instruction code. */
697 unsigned int tvalue;
b99bd4ef 698
90e4755a 699 /* Which architecture variant provides this instruction. */
c921be7d
NC
700 const arm_feature_set * avariant;
701 const arm_feature_set * tvariant;
c19d1205
ZW
702
703 /* Function to call to encode instruction in ARM format. */
704 void (* aencode) (void);
b99bd4ef 705
c19d1205
ZW
706 /* Function to call to encode instruction in Thumb format. */
707 void (* tencode) (void);
b99bd4ef
NC
708};
709
a737bd4d
NC
710/* Defines for various bits that we will want to toggle. */
711#define INST_IMMEDIATE 0x02000000
712#define OFFSET_REG 0x02000000
c19d1205 713#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
714#define SHIFT_BY_REG 0x00000010
715#define PRE_INDEX 0x01000000
716#define INDEX_UP 0x00800000
717#define WRITE_BACK 0x00200000
718#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 719#define CPSI_MMOD 0x00020000
90e4755a 720
a737bd4d
NC
721#define LITERAL_MASK 0xf000f000
722#define OPCODE_MASK 0xfe1fffff
723#define V4_STR_BIT 0x00000020
8335d6aa 724#define VLDR_VMOV_SAME 0x0040f000
90e4755a 725
efd81785
PB
726#define T2_SUBS_PC_LR 0xf3de8f00
727
a737bd4d 728#define DATA_OP_SHIFT 21
bada4342 729#define SBIT_SHIFT 20
90e4755a 730
ef8d22e6
PB
731#define T2_OPCODE_MASK 0xfe1fffff
732#define T2_DATA_OP_SHIFT 21
bada4342 733#define T2_SBIT_SHIFT 20
ef8d22e6 734
6530b175
NC
735#define A_COND_MASK 0xf0000000
736#define A_PUSH_POP_OP_MASK 0x0fff0000
737
738/* Opcodes for pushing/poping registers to/from the stack. */
739#define A1_OPCODE_PUSH 0x092d0000
740#define A2_OPCODE_PUSH 0x052d0004
741#define A2_OPCODE_POP 0x049d0004
742
a737bd4d
NC
743/* Codes to distinguish the arithmetic instructions. */
744#define OPCODE_AND 0
745#define OPCODE_EOR 1
746#define OPCODE_SUB 2
747#define OPCODE_RSB 3
748#define OPCODE_ADD 4
749#define OPCODE_ADC 5
750#define OPCODE_SBC 6
751#define OPCODE_RSC 7
752#define OPCODE_TST 8
753#define OPCODE_TEQ 9
754#define OPCODE_CMP 10
755#define OPCODE_CMN 11
756#define OPCODE_ORR 12
757#define OPCODE_MOV 13
758#define OPCODE_BIC 14
759#define OPCODE_MVN 15
90e4755a 760
ef8d22e6
PB
761#define T2_OPCODE_AND 0
762#define T2_OPCODE_BIC 1
763#define T2_OPCODE_ORR 2
764#define T2_OPCODE_ORN 3
765#define T2_OPCODE_EOR 4
766#define T2_OPCODE_ADD 8
767#define T2_OPCODE_ADC 10
768#define T2_OPCODE_SBC 11
769#define T2_OPCODE_SUB 13
770#define T2_OPCODE_RSB 14
771
a737bd4d
NC
772#define T_OPCODE_MUL 0x4340
773#define T_OPCODE_TST 0x4200
774#define T_OPCODE_CMN 0x42c0
775#define T_OPCODE_NEG 0x4240
776#define T_OPCODE_MVN 0x43c0
90e4755a 777
a737bd4d
NC
778#define T_OPCODE_ADD_R3 0x1800
779#define T_OPCODE_SUB_R3 0x1a00
780#define T_OPCODE_ADD_HI 0x4400
781#define T_OPCODE_ADD_ST 0xb000
782#define T_OPCODE_SUB_ST 0xb080
783#define T_OPCODE_ADD_SP 0xa800
784#define T_OPCODE_ADD_PC 0xa000
785#define T_OPCODE_ADD_I8 0x3000
786#define T_OPCODE_SUB_I8 0x3800
787#define T_OPCODE_ADD_I3 0x1c00
788#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 789
a737bd4d
NC
790#define T_OPCODE_ASR_R 0x4100
791#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
792#define T_OPCODE_LSR_R 0x40c0
793#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
794#define T_OPCODE_ASR_I 0x1000
795#define T_OPCODE_LSL_I 0x0000
796#define T_OPCODE_LSR_I 0x0800
b99bd4ef 797
a737bd4d
NC
798#define T_OPCODE_MOV_I8 0x2000
799#define T_OPCODE_CMP_I8 0x2800
800#define T_OPCODE_CMP_LR 0x4280
801#define T_OPCODE_MOV_HR 0x4600
802#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 803
a737bd4d
NC
804#define T_OPCODE_LDR_PC 0x4800
805#define T_OPCODE_LDR_SP 0x9800
806#define T_OPCODE_STR_SP 0x9000
807#define T_OPCODE_LDR_IW 0x6800
808#define T_OPCODE_STR_IW 0x6000
809#define T_OPCODE_LDR_IH 0x8800
810#define T_OPCODE_STR_IH 0x8000
811#define T_OPCODE_LDR_IB 0x7800
812#define T_OPCODE_STR_IB 0x7000
813#define T_OPCODE_LDR_RW 0x5800
814#define T_OPCODE_STR_RW 0x5000
815#define T_OPCODE_LDR_RH 0x5a00
816#define T_OPCODE_STR_RH 0x5200
817#define T_OPCODE_LDR_RB 0x5c00
818#define T_OPCODE_STR_RB 0x5400
c9b604bd 819
a737bd4d
NC
820#define T_OPCODE_PUSH 0xb400
821#define T_OPCODE_POP 0xbc00
b99bd4ef 822
2fc8bdac 823#define T_OPCODE_BRANCH 0xe000
b99bd4ef 824
a737bd4d 825#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 826#define THUMB_PP_PC_LR 0x0100
c19d1205 827#define THUMB_LOAD_BIT 0x0800
53365c0d 828#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
829
830#define BAD_ARGS _("bad arguments to instruction")
fdfde340 831#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
832#define BAD_PC _("r15 not allowed here")
833#define BAD_COND _("instruction cannot be conditional")
834#define BAD_OVERLAP _("registers may not be the same")
835#define BAD_HIREG _("lo register required")
836#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 837#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
838#define BAD_BRANCH _("branch must be last instruction in IT block")
839#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 840#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
841#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
842#define BAD_IT_COND _("incorrect condition in IT block")
843#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 844#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
845#define BAD_PC_ADDRESSING \
846 _("cannot use register index with PC-relative addressing")
847#define BAD_PC_WRITEBACK \
848 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
849#define BAD_RANGE _("branch out of range")
850#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 851#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 852#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
c19d1205 853
c921be7d
NC
854static struct hash_control * arm_ops_hsh;
855static struct hash_control * arm_cond_hsh;
856static struct hash_control * arm_shift_hsh;
857static struct hash_control * arm_psr_hsh;
858static struct hash_control * arm_v7m_psr_hsh;
859static struct hash_control * arm_reg_hsh;
860static struct hash_control * arm_reloc_hsh;
861static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 862
b99bd4ef
NC
863/* Stuff needed to resolve the label ambiguity
864 As:
865 ...
866 label: <insn>
867 may differ from:
868 ...
869 label:
5f4273c7 870 <insn> */
b99bd4ef
NC
871
872symbolS * last_label_seen;
b34976b6 873static int label_is_thumb_function_name = FALSE;
e07e6e58 874
3d0c9500
NC
875/* Literal pool structure. Held on a per-section
876 and per-sub-section basis. */
a737bd4d 877
c19d1205 878#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 879typedef struct literal_pool
b99bd4ef 880{
c921be7d
NC
881 expressionS literals [MAX_LITERAL_POOL_SIZE];
882 unsigned int next_free_entry;
883 unsigned int id;
884 symbolS * symbol;
885 segT section;
886 subsegT sub_section;
a8040cf2
NC
887#ifdef OBJ_ELF
888 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
889#endif
c921be7d 890 struct literal_pool * next;
8335d6aa 891 unsigned int alignment;
3d0c9500 892} literal_pool;
b99bd4ef 893
3d0c9500
NC
894/* Pointer to a linked list of literal pools. */
895literal_pool * list_of_pools = NULL;
e27ec89e 896
2e6976a8
DG
897typedef enum asmfunc_states
898{
899 OUTSIDE_ASMFUNC,
900 WAITING_ASMFUNC_NAME,
901 WAITING_ENDASMFUNC
902} asmfunc_states;
903
904static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
905
e07e6e58
NC
906#ifdef OBJ_ELF
907# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
908#else
909static struct current_it now_it;
910#endif
911
912static inline int
913now_it_compatible (int cond)
914{
915 return (cond & ~1) == (now_it.cc & ~1);
916}
917
918static inline int
919conditional_insn (void)
920{
921 return inst.cond != COND_ALWAYS;
922}
923
924static int in_it_block (void);
925
926static int handle_it_state (void);
927
928static void force_automatic_it_block_close (void);
929
c921be7d
NC
930static void it_fsm_post_encode (void);
931
e07e6e58
NC
932#define set_it_insn_type(type) \
933 do \
934 { \
935 inst.it_insn_type = type; \
936 if (handle_it_state () == FAIL) \
477330fc 937 return; \
e07e6e58
NC
938 } \
939 while (0)
940
c921be7d
NC
941#define set_it_insn_type_nonvoid(type, failret) \
942 do \
943 { \
944 inst.it_insn_type = type; \
945 if (handle_it_state () == FAIL) \
477330fc 946 return failret; \
c921be7d
NC
947 } \
948 while(0)
949
e07e6e58
NC
950#define set_it_insn_type_last() \
951 do \
952 { \
953 if (inst.cond == COND_ALWAYS) \
477330fc 954 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 955 else \
477330fc 956 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
957 } \
958 while (0)
959
c19d1205 960/* Pure syntax. */
b99bd4ef 961
c19d1205
ZW
962/* This array holds the chars that always start a comment. If the
963 pre-processor is disabled, these aren't very useful. */
2e6976a8 964char arm_comment_chars[] = "@";
3d0c9500 965
c19d1205
ZW
966/* This array holds the chars that only start a comment at the beginning of
967 a line. If the line seems to have the form '# 123 filename'
968 .line and .file directives will appear in the pre-processed output. */
969/* Note that input_file.c hand checks for '#' at the beginning of the
970 first line of the input file. This is because the compiler outputs
971 #NO_APP at the beginning of its output. */
972/* Also note that comments like this one will always work. */
973const char line_comment_chars[] = "#";
3d0c9500 974
2e6976a8 975char arm_line_separator_chars[] = ";";
b99bd4ef 976
c19d1205
ZW
977/* Chars that can be used to separate mant
978 from exp in floating point numbers. */
979const char EXP_CHARS[] = "eE";
3d0c9500 980
c19d1205
ZW
981/* Chars that mean this number is a floating point constant. */
982/* As in 0f12.456 */
983/* or 0d1.2345e12 */
b99bd4ef 984
c19d1205 985const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 986
c19d1205
ZW
987/* Prefix characters that indicate the start of an immediate
988 value. */
989#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 990
c19d1205
ZW
991/* Separator character handling. */
992
993#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
994
995static inline int
996skip_past_char (char ** str, char c)
997{
8ab8155f
NC
998 /* PR gas/14987: Allow for whitespace before the expected character. */
999 skip_whitespace (*str);
427d0db6 1000
c19d1205
ZW
1001 if (**str == c)
1002 {
1003 (*str)++;
1004 return SUCCESS;
3d0c9500 1005 }
c19d1205
ZW
1006 else
1007 return FAIL;
1008}
c921be7d 1009
c19d1205 1010#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 1011
c19d1205
ZW
1012/* Arithmetic expressions (possibly involving symbols). */
1013
1014/* Return TRUE if anything in the expression is a bignum. */
1015
0198d5e6 1016static bfd_boolean
c19d1205
ZW
1017walk_no_bignums (symbolS * sp)
1018{
1019 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 1020 return TRUE;
c19d1205
ZW
1021
1022 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 1023 {
c19d1205
ZW
1024 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1025 || (symbol_get_value_expression (sp)->X_op_symbol
1026 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
1027 }
1028
0198d5e6 1029 return FALSE;
3d0c9500
NC
1030}
1031
0198d5e6 1032static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
1033
1034/* Third argument to my_get_expression. */
1035#define GE_NO_PREFIX 0
1036#define GE_IMM_PREFIX 1
1037#define GE_OPT_PREFIX 2
5287ad62
JB
1038/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1039 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1040#define GE_OPT_PREFIX_BIG 3
a737bd4d 1041
b99bd4ef 1042static int
c19d1205 1043my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1044{
c19d1205 1045 char * save_in;
b99bd4ef 1046
c19d1205
ZW
1047 /* In unified syntax, all prefixes are optional. */
1048 if (unified_syntax)
5287ad62 1049 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1050 : GE_OPT_PREFIX;
b99bd4ef 1051
c19d1205 1052 switch (prefix_mode)
b99bd4ef 1053 {
c19d1205
ZW
1054 case GE_NO_PREFIX: break;
1055 case GE_IMM_PREFIX:
1056 if (!is_immediate_prefix (**str))
1057 {
1058 inst.error = _("immediate expression requires a # prefix");
1059 return FAIL;
1060 }
1061 (*str)++;
1062 break;
1063 case GE_OPT_PREFIX:
5287ad62 1064 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1065 if (is_immediate_prefix (**str))
1066 (*str)++;
1067 break;
0198d5e6
TC
1068 default:
1069 abort ();
c19d1205 1070 }
b99bd4ef 1071
c19d1205 1072 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1073
c19d1205
ZW
1074 save_in = input_line_pointer;
1075 input_line_pointer = *str;
0198d5e6 1076 in_my_get_expression = TRUE;
2ac93be7 1077 expression (ep);
0198d5e6 1078 in_my_get_expression = FALSE;
c19d1205 1079
f86adc07 1080 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1081 {
f86adc07 1082 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1083 *str = input_line_pointer;
1084 input_line_pointer = save_in;
1085 if (inst.error == NULL)
f86adc07
NS
1086 inst.error = (ep->X_op == O_absent
1087 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1088 return 1;
1089 }
b99bd4ef 1090
c19d1205
ZW
1091 /* Get rid of any bignums now, so that we don't generate an error for which
1092 we can't establish a line number later on. Big numbers are never valid
1093 in instructions, which is where this routine is always called. */
5287ad62
JB
1094 if (prefix_mode != GE_OPT_PREFIX_BIG
1095 && (ep->X_op == O_big
477330fc 1096 || (ep->X_add_symbol
5287ad62 1097 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1098 || (ep->X_op_symbol
5287ad62 1099 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1100 {
1101 inst.error = _("invalid constant");
1102 *str = input_line_pointer;
1103 input_line_pointer = save_in;
1104 return 1;
1105 }
b99bd4ef 1106
c19d1205
ZW
1107 *str = input_line_pointer;
1108 input_line_pointer = save_in;
0198d5e6 1109 return SUCCESS;
b99bd4ef
NC
1110}
1111
c19d1205
ZW
1112/* Turn a string in input_line_pointer into a floating point constant
1113 of type TYPE, and store the appropriate bytes in *LITP. The number
1114 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1115 returned, or NULL on OK.
b99bd4ef 1116
c19d1205
ZW
1117 Note that fp constants aren't represent in the normal way on the ARM.
1118 In big endian mode, things are as expected. However, in little endian
1119 mode fp constants are big-endian word-wise, and little-endian byte-wise
1120 within the words. For example, (double) 1.1 in big endian mode is
1121 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1122 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1123
c19d1205 1124 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1125
6d4af3c2 1126const char *
c19d1205
ZW
1127md_atof (int type, char * litP, int * sizeP)
1128{
1129 int prec;
1130 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1131 char *t;
1132 int i;
b99bd4ef 1133
c19d1205
ZW
1134 switch (type)
1135 {
1136 case 'f':
1137 case 'F':
1138 case 's':
1139 case 'S':
1140 prec = 2;
1141 break;
b99bd4ef 1142
c19d1205
ZW
1143 case 'd':
1144 case 'D':
1145 case 'r':
1146 case 'R':
1147 prec = 4;
1148 break;
b99bd4ef 1149
c19d1205
ZW
1150 case 'x':
1151 case 'X':
499ac353 1152 prec = 5;
c19d1205 1153 break;
b99bd4ef 1154
c19d1205
ZW
1155 case 'p':
1156 case 'P':
499ac353 1157 prec = 5;
c19d1205 1158 break;
a737bd4d 1159
c19d1205
ZW
1160 default:
1161 *sizeP = 0;
499ac353 1162 return _("Unrecognized or unsupported floating point constant");
c19d1205 1163 }
b99bd4ef 1164
c19d1205
ZW
1165 t = atof_ieee (input_line_pointer, type, words);
1166 if (t)
1167 input_line_pointer = t;
499ac353 1168 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1169
c19d1205
ZW
1170 if (target_big_endian)
1171 {
1172 for (i = 0; i < prec; i++)
1173 {
499ac353
NC
1174 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1175 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1176 }
1177 }
1178 else
1179 {
e74cfd16 1180 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1181 for (i = prec - 1; i >= 0; i--)
1182 {
499ac353
NC
1183 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1184 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1185 }
1186 else
1187 /* For a 4 byte float the order of elements in `words' is 1 0.
1188 For an 8 byte float the order is 1 0 3 2. */
1189 for (i = 0; i < prec; i += 2)
1190 {
499ac353
NC
1191 md_number_to_chars (litP, (valueT) words[i + 1],
1192 sizeof (LITTLENUM_TYPE));
1193 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1194 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1195 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1196 }
1197 }
b99bd4ef 1198
499ac353 1199 return NULL;
c19d1205 1200}
b99bd4ef 1201
c19d1205
ZW
1202/* We handle all bad expressions here, so that we can report the faulty
1203 instruction in the error message. */
0198d5e6 1204
c19d1205 1205void
91d6fa6a 1206md_operand (expressionS * exp)
c19d1205
ZW
1207{
1208 if (in_my_get_expression)
91d6fa6a 1209 exp->X_op = O_illegal;
b99bd4ef
NC
1210}
1211
c19d1205 1212/* Immediate values. */
b99bd4ef 1213
0198d5e6 1214#ifdef OBJ_ELF
c19d1205
ZW
1215/* Generic immediate-value read function for use in directives.
1216 Accepts anything that 'expression' can fold to a constant.
1217 *val receives the number. */
0198d5e6 1218
c19d1205
ZW
1219static int
1220immediate_for_directive (int *val)
b99bd4ef 1221{
c19d1205
ZW
1222 expressionS exp;
1223 exp.X_op = O_illegal;
b99bd4ef 1224
c19d1205
ZW
1225 if (is_immediate_prefix (*input_line_pointer))
1226 {
1227 input_line_pointer++;
1228 expression (&exp);
1229 }
b99bd4ef 1230
c19d1205
ZW
1231 if (exp.X_op != O_constant)
1232 {
1233 as_bad (_("expected #constant"));
1234 ignore_rest_of_line ();
1235 return FAIL;
1236 }
1237 *val = exp.X_add_number;
1238 return SUCCESS;
b99bd4ef 1239}
c19d1205 1240#endif
b99bd4ef 1241
c19d1205 1242/* Register parsing. */
b99bd4ef 1243
c19d1205
ZW
1244/* Generic register parser. CCP points to what should be the
1245 beginning of a register name. If it is indeed a valid register
1246 name, advance CCP over it and return the reg_entry structure;
1247 otherwise return NULL. Does not issue diagnostics. */
1248
1249static struct reg_entry *
1250arm_reg_parse_multi (char **ccp)
b99bd4ef 1251{
c19d1205
ZW
1252 char *start = *ccp;
1253 char *p;
1254 struct reg_entry *reg;
b99bd4ef 1255
477330fc
RM
1256 skip_whitespace (start);
1257
c19d1205
ZW
1258#ifdef REGISTER_PREFIX
1259 if (*start != REGISTER_PREFIX)
01cfc07f 1260 return NULL;
c19d1205
ZW
1261 start++;
1262#endif
1263#ifdef OPTIONAL_REGISTER_PREFIX
1264 if (*start == OPTIONAL_REGISTER_PREFIX)
1265 start++;
1266#endif
b99bd4ef 1267
c19d1205
ZW
1268 p = start;
1269 if (!ISALPHA (*p) || !is_name_beginner (*p))
1270 return NULL;
b99bd4ef 1271
c19d1205
ZW
1272 do
1273 p++;
1274 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1275
1276 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1277
1278 if (!reg)
1279 return NULL;
1280
1281 *ccp = p;
1282 return reg;
b99bd4ef
NC
1283}
1284
1285static int
dcbf9037 1286arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1287 enum arm_reg_type type)
b99bd4ef 1288{
c19d1205
ZW
1289 /* Alternative syntaxes are accepted for a few register classes. */
1290 switch (type)
1291 {
1292 case REG_TYPE_MVF:
1293 case REG_TYPE_MVD:
1294 case REG_TYPE_MVFX:
1295 case REG_TYPE_MVDX:
1296 /* Generic coprocessor register names are allowed for these. */
79134647 1297 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1298 return reg->number;
1299 break;
69b97547 1300
c19d1205
ZW
1301 case REG_TYPE_CP:
1302 /* For backward compatibility, a bare number is valid here. */
1303 {
1304 unsigned long processor = strtoul (start, ccp, 10);
1305 if (*ccp != start && processor <= 15)
1306 return processor;
1307 }
1a0670f3 1308 /* Fall through. */
6057a28f 1309
c19d1205
ZW
1310 case REG_TYPE_MMXWC:
1311 /* WC includes WCG. ??? I'm not sure this is true for all
1312 instructions that take WC registers. */
79134647 1313 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1314 return reg->number;
6057a28f 1315 break;
c19d1205 1316
6057a28f 1317 default:
c19d1205 1318 break;
6057a28f
NC
1319 }
1320
dcbf9037
JB
1321 return FAIL;
1322}
1323
1324/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1325 return value is the register number or FAIL. */
1326
1327static int
1328arm_reg_parse (char **ccp, enum arm_reg_type type)
1329{
1330 char *start = *ccp;
1331 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1332 int ret;
1333
1334 /* Do not allow a scalar (reg+index) to parse as a register. */
1335 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1336 return FAIL;
1337
1338 if (reg && reg->type == type)
1339 return reg->number;
1340
1341 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1342 return ret;
1343
c19d1205
ZW
1344 *ccp = start;
1345 return FAIL;
1346}
69b97547 1347
dcbf9037
JB
1348/* Parse a Neon type specifier. *STR should point at the leading '.'
1349 character. Does no verification at this stage that the type fits the opcode
1350 properly. E.g.,
1351
1352 .i32.i32.s16
1353 .s32.f32
1354 .u16
1355
1356 Can all be legally parsed by this function.
1357
1358 Fills in neon_type struct pointer with parsed information, and updates STR
1359 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1360 type, FAIL if not. */
1361
1362static int
1363parse_neon_type (struct neon_type *type, char **str)
1364{
1365 char *ptr = *str;
1366
1367 if (type)
1368 type->elems = 0;
1369
1370 while (type->elems < NEON_MAX_TYPE_ELS)
1371 {
1372 enum neon_el_type thistype = NT_untyped;
1373 unsigned thissize = -1u;
1374
1375 if (*ptr != '.')
1376 break;
1377
1378 ptr++;
1379
1380 /* Just a size without an explicit type. */
1381 if (ISDIGIT (*ptr))
1382 goto parsesize;
1383
1384 switch (TOLOWER (*ptr))
1385 {
1386 case 'i': thistype = NT_integer; break;
1387 case 'f': thistype = NT_float; break;
1388 case 'p': thistype = NT_poly; break;
1389 case 's': thistype = NT_signed; break;
1390 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1391 case 'd':
1392 thistype = NT_float;
1393 thissize = 64;
1394 ptr++;
1395 goto done;
dcbf9037
JB
1396 default:
1397 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1398 return FAIL;
1399 }
1400
1401 ptr++;
1402
1403 /* .f is an abbreviation for .f32. */
1404 if (thistype == NT_float && !ISDIGIT (*ptr))
1405 thissize = 32;
1406 else
1407 {
1408 parsesize:
1409 thissize = strtoul (ptr, &ptr, 10);
1410
1411 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1412 && thissize != 64)
1413 {
1414 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1415 return FAIL;
1416 }
1417 }
1418
037e8744 1419 done:
dcbf9037 1420 if (type)
477330fc
RM
1421 {
1422 type->el[type->elems].type = thistype;
dcbf9037
JB
1423 type->el[type->elems].size = thissize;
1424 type->elems++;
1425 }
1426 }
1427
1428 /* Empty/missing type is not a successful parse. */
1429 if (type->elems == 0)
1430 return FAIL;
1431
1432 *str = ptr;
1433
1434 return SUCCESS;
1435}
1436
1437/* Errors may be set multiple times during parsing or bit encoding
1438 (particularly in the Neon bits), but usually the earliest error which is set
1439 will be the most meaningful. Avoid overwriting it with later (cascading)
1440 errors by calling this function. */
1441
1442static void
1443first_error (const char *err)
1444{
1445 if (!inst.error)
1446 inst.error = err;
1447}
1448
1449/* Parse a single type, e.g. ".s32", leading period included. */
1450static int
1451parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1452{
1453 char *str = *ccp;
1454 struct neon_type optype;
1455
1456 if (*str == '.')
1457 {
1458 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1459 {
1460 if (optype.elems == 1)
1461 *vectype = optype.el[0];
1462 else
1463 {
1464 first_error (_("only one type should be specified for operand"));
1465 return FAIL;
1466 }
1467 }
dcbf9037 1468 else
477330fc
RM
1469 {
1470 first_error (_("vector type expected"));
1471 return FAIL;
1472 }
dcbf9037
JB
1473 }
1474 else
1475 return FAIL;
5f4273c7 1476
dcbf9037 1477 *ccp = str;
5f4273c7 1478
dcbf9037
JB
1479 return SUCCESS;
1480}
1481
1482/* Special meanings for indices (which have a range of 0-7), which will fit into
1483 a 4-bit integer. */
1484
1485#define NEON_ALL_LANES 15
1486#define NEON_INTERLEAVE_LANES 14
1487
1488/* Parse either a register or a scalar, with an optional type. Return the
1489 register number, and optionally fill in the actual type of the register
1490 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1491 type/index information in *TYPEINFO. */
1492
1493static int
1494parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1495 enum arm_reg_type *rtype,
1496 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1497{
1498 char *str = *ccp;
1499 struct reg_entry *reg = arm_reg_parse_multi (&str);
1500 struct neon_typed_alias atype;
1501 struct neon_type_el parsetype;
1502
1503 atype.defined = 0;
1504 atype.index = -1;
1505 atype.eltype.type = NT_invtype;
1506 atype.eltype.size = -1;
1507
1508 /* Try alternate syntax for some types of register. Note these are mutually
1509 exclusive with the Neon syntax extensions. */
1510 if (reg == NULL)
1511 {
1512 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1513 if (altreg != FAIL)
477330fc 1514 *ccp = str;
dcbf9037 1515 if (typeinfo)
477330fc 1516 *typeinfo = atype;
dcbf9037
JB
1517 return altreg;
1518 }
1519
037e8744
JB
1520 /* Undo polymorphism when a set of register types may be accepted. */
1521 if ((type == REG_TYPE_NDQ
1522 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1523 || (type == REG_TYPE_VFSD
477330fc 1524 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1525 || (type == REG_TYPE_NSDQ
477330fc
RM
1526 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1527 || reg->type == REG_TYPE_NQ))
dec41383
JW
1528 || (type == REG_TYPE_NSD
1529 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
f512f76f
NC
1530 || (type == REG_TYPE_MMXWC
1531 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1532 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1533
1534 if (type != reg->type)
1535 return FAIL;
1536
1537 if (reg->neon)
1538 atype = *reg->neon;
5f4273c7 1539
dcbf9037
JB
1540 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1541 {
1542 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1543 {
1544 first_error (_("can't redefine type for operand"));
1545 return FAIL;
1546 }
dcbf9037
JB
1547 atype.defined |= NTA_HASTYPE;
1548 atype.eltype = parsetype;
1549 }
5f4273c7 1550
dcbf9037
JB
1551 if (skip_past_char (&str, '[') == SUCCESS)
1552 {
dec41383
JW
1553 if (type != REG_TYPE_VFD
1554 && !(type == REG_TYPE_VFS
1555 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2)))
477330fc
RM
1556 {
1557 first_error (_("only D registers may be indexed"));
1558 return FAIL;
1559 }
5f4273c7 1560
dcbf9037 1561 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1562 {
1563 first_error (_("can't change index for operand"));
1564 return FAIL;
1565 }
dcbf9037
JB
1566
1567 atype.defined |= NTA_HASINDEX;
1568
1569 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1570 atype.index = NEON_ALL_LANES;
dcbf9037 1571 else
477330fc
RM
1572 {
1573 expressionS exp;
dcbf9037 1574
477330fc 1575 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1576
477330fc
RM
1577 if (exp.X_op != O_constant)
1578 {
1579 first_error (_("constant expression required"));
1580 return FAIL;
1581 }
dcbf9037 1582
477330fc
RM
1583 if (skip_past_char (&str, ']') == FAIL)
1584 return FAIL;
dcbf9037 1585
477330fc
RM
1586 atype.index = exp.X_add_number;
1587 }
dcbf9037 1588 }
5f4273c7 1589
dcbf9037
JB
1590 if (typeinfo)
1591 *typeinfo = atype;
5f4273c7 1592
dcbf9037
JB
1593 if (rtype)
1594 *rtype = type;
5f4273c7 1595
dcbf9037 1596 *ccp = str;
5f4273c7 1597
dcbf9037
JB
1598 return reg->number;
1599}
1600
1601/* Like arm_reg_parse, but allow allow the following extra features:
1602 - If RTYPE is non-zero, return the (possibly restricted) type of the
1603 register (e.g. Neon double or quad reg when either has been requested).
1604 - If this is a Neon vector type with additional type information, fill
1605 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1606 This function will fault on encountering a scalar. */
dcbf9037
JB
1607
1608static int
1609arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1610 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1611{
1612 struct neon_typed_alias atype;
1613 char *str = *ccp;
1614 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1615
1616 if (reg == FAIL)
1617 return FAIL;
1618
0855e32b
NS
1619 /* Do not allow regname(... to parse as a register. */
1620 if (*str == '(')
1621 return FAIL;
1622
dcbf9037
JB
1623 /* Do not allow a scalar (reg+index) to parse as a register. */
1624 if ((atype.defined & NTA_HASINDEX) != 0)
1625 {
1626 first_error (_("register operand expected, but got scalar"));
1627 return FAIL;
1628 }
1629
1630 if (vectype)
1631 *vectype = atype.eltype;
1632
1633 *ccp = str;
1634
1635 return reg;
1636}
1637
1638#define NEON_SCALAR_REG(X) ((X) >> 4)
1639#define NEON_SCALAR_INDEX(X) ((X) & 15)
1640
5287ad62
JB
1641/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1642 have enough information to be able to do a good job bounds-checking. So, we
1643 just do easy checks here, and do further checks later. */
1644
1645static int
dcbf9037 1646parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1647{
dcbf9037 1648 int reg;
5287ad62 1649 char *str = *ccp;
dcbf9037 1650 struct neon_typed_alias atype;
dec41383
JW
1651 enum arm_reg_type reg_type = REG_TYPE_VFD;
1652
1653 if (elsize == 4)
1654 reg_type = REG_TYPE_VFS;
5f4273c7 1655
dec41383 1656 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
5f4273c7 1657
dcbf9037 1658 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1659 return FAIL;
5f4273c7 1660
dcbf9037 1661 if (atype.index == NEON_ALL_LANES)
5287ad62 1662 {
dcbf9037 1663 first_error (_("scalar must have an index"));
5287ad62
JB
1664 return FAIL;
1665 }
dcbf9037 1666 else if (atype.index >= 64 / elsize)
5287ad62 1667 {
dcbf9037 1668 first_error (_("scalar index out of range"));
5287ad62
JB
1669 return FAIL;
1670 }
5f4273c7 1671
dcbf9037
JB
1672 if (type)
1673 *type = atype.eltype;
5f4273c7 1674
5287ad62 1675 *ccp = str;
5f4273c7 1676
dcbf9037 1677 return reg * 16 + atype.index;
5287ad62
JB
1678}
1679
c19d1205 1680/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1681
c19d1205
ZW
1682static long
1683parse_reg_list (char ** strp)
1684{
1685 char * str = * strp;
1686 long range = 0;
1687 int another_range;
a737bd4d 1688
c19d1205
ZW
1689 /* We come back here if we get ranges concatenated by '+' or '|'. */
1690 do
6057a28f 1691 {
477330fc
RM
1692 skip_whitespace (str);
1693
c19d1205 1694 another_range = 0;
a737bd4d 1695
c19d1205
ZW
1696 if (*str == '{')
1697 {
1698 int in_range = 0;
1699 int cur_reg = -1;
a737bd4d 1700
c19d1205
ZW
1701 str++;
1702 do
1703 {
1704 int reg;
6057a28f 1705
dcbf9037 1706 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1707 {
dcbf9037 1708 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1709 return FAIL;
1710 }
a737bd4d 1711
c19d1205
ZW
1712 if (in_range)
1713 {
1714 int i;
a737bd4d 1715
c19d1205
ZW
1716 if (reg <= cur_reg)
1717 {
dcbf9037 1718 first_error (_("bad range in register list"));
c19d1205
ZW
1719 return FAIL;
1720 }
40a18ebd 1721
c19d1205
ZW
1722 for (i = cur_reg + 1; i < reg; i++)
1723 {
1724 if (range & (1 << i))
1725 as_tsktsk
1726 (_("Warning: duplicated register (r%d) in register list"),
1727 i);
1728 else
1729 range |= 1 << i;
1730 }
1731 in_range = 0;
1732 }
a737bd4d 1733
c19d1205
ZW
1734 if (range & (1 << reg))
1735 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1736 reg);
1737 else if (reg <= cur_reg)
1738 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1739
c19d1205
ZW
1740 range |= 1 << reg;
1741 cur_reg = reg;
1742 }
1743 while (skip_past_comma (&str) != FAIL
1744 || (in_range = 1, *str++ == '-'));
1745 str--;
a737bd4d 1746
d996d970 1747 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1748 {
dcbf9037 1749 first_error (_("missing `}'"));
c19d1205
ZW
1750 return FAIL;
1751 }
1752 }
1753 else
1754 {
91d6fa6a 1755 expressionS exp;
40a18ebd 1756
91d6fa6a 1757 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1758 return FAIL;
40a18ebd 1759
91d6fa6a 1760 if (exp.X_op == O_constant)
c19d1205 1761 {
91d6fa6a
NC
1762 if (exp.X_add_number
1763 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1764 {
1765 inst.error = _("invalid register mask");
1766 return FAIL;
1767 }
a737bd4d 1768
91d6fa6a 1769 if ((range & exp.X_add_number) != 0)
c19d1205 1770 {
91d6fa6a 1771 int regno = range & exp.X_add_number;
a737bd4d 1772
c19d1205
ZW
1773 regno &= -regno;
1774 regno = (1 << regno) - 1;
1775 as_tsktsk
1776 (_("Warning: duplicated register (r%d) in register list"),
1777 regno);
1778 }
a737bd4d 1779
91d6fa6a 1780 range |= exp.X_add_number;
c19d1205
ZW
1781 }
1782 else
1783 {
1784 if (inst.reloc.type != 0)
1785 {
1786 inst.error = _("expression too complex");
1787 return FAIL;
1788 }
a737bd4d 1789
91d6fa6a 1790 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1791 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1792 inst.reloc.pc_rel = 0;
1793 }
1794 }
a737bd4d 1795
c19d1205
ZW
1796 if (*str == '|' || *str == '+')
1797 {
1798 str++;
1799 another_range = 1;
1800 }
a737bd4d 1801 }
c19d1205 1802 while (another_range);
a737bd4d 1803
c19d1205
ZW
1804 *strp = str;
1805 return range;
a737bd4d
NC
1806}
1807
5287ad62
JB
1808/* Types of registers in a list. */
1809
1810enum reg_list_els
1811{
1812 REGLIST_VFP_S,
1813 REGLIST_VFP_D,
1814 REGLIST_NEON_D
1815};
1816
c19d1205
ZW
1817/* Parse a VFP register list. If the string is invalid return FAIL.
1818 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1819 register. Parses registers of type ETYPE.
1820 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1821 - Q registers can be used to specify pairs of D registers
1822 - { } can be omitted from around a singleton register list
477330fc
RM
1823 FIXME: This is not implemented, as it would require backtracking in
1824 some cases, e.g.:
1825 vtbl.8 d3,d4,d5
1826 This could be done (the meaning isn't really ambiguous), but doesn't
1827 fit in well with the current parsing framework.
dcbf9037
JB
1828 - 32 D registers may be used (also true for VFPv3).
1829 FIXME: Types are ignored in these register lists, which is probably a
1830 bug. */
6057a28f 1831
c19d1205 1832static int
037e8744 1833parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1834{
037e8744 1835 char *str = *ccp;
c19d1205
ZW
1836 int base_reg;
1837 int new_base;
21d799b5 1838 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1839 int max_regs = 0;
c19d1205
ZW
1840 int count = 0;
1841 int warned = 0;
1842 unsigned long mask = 0;
a737bd4d 1843 int i;
6057a28f 1844
477330fc 1845 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1846 {
1847 inst.error = _("expecting {");
1848 return FAIL;
1849 }
6057a28f 1850
5287ad62 1851 switch (etype)
c19d1205 1852 {
5287ad62 1853 case REGLIST_VFP_S:
c19d1205
ZW
1854 regtype = REG_TYPE_VFS;
1855 max_regs = 32;
5287ad62 1856 break;
5f4273c7 1857
5287ad62
JB
1858 case REGLIST_VFP_D:
1859 regtype = REG_TYPE_VFD;
b7fc2769 1860 break;
5f4273c7 1861
b7fc2769
JB
1862 case REGLIST_NEON_D:
1863 regtype = REG_TYPE_NDQ;
1864 break;
1865 }
1866
1867 if (etype != REGLIST_VFP_S)
1868 {
b1cc4aeb
PB
1869 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1870 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1871 {
1872 max_regs = 32;
1873 if (thumb_mode)
1874 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1875 fpu_vfp_ext_d32);
1876 else
1877 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1878 fpu_vfp_ext_d32);
1879 }
5287ad62 1880 else
477330fc 1881 max_regs = 16;
c19d1205 1882 }
6057a28f 1883
c19d1205 1884 base_reg = max_regs;
a737bd4d 1885
c19d1205
ZW
1886 do
1887 {
5287ad62 1888 int setmask = 1, addregs = 1;
dcbf9037 1889
037e8744 1890 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1891
c19d1205 1892 if (new_base == FAIL)
a737bd4d 1893 {
dcbf9037 1894 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1895 return FAIL;
1896 }
5f4273c7 1897
b7fc2769 1898 if (new_base >= max_regs)
477330fc
RM
1899 {
1900 first_error (_("register out of range in list"));
1901 return FAIL;
1902 }
5f4273c7 1903
5287ad62
JB
1904 /* Note: a value of 2 * n is returned for the register Q<n>. */
1905 if (regtype == REG_TYPE_NQ)
477330fc
RM
1906 {
1907 setmask = 3;
1908 addregs = 2;
1909 }
5287ad62 1910
c19d1205
ZW
1911 if (new_base < base_reg)
1912 base_reg = new_base;
a737bd4d 1913
5287ad62 1914 if (mask & (setmask << new_base))
c19d1205 1915 {
dcbf9037 1916 first_error (_("invalid register list"));
c19d1205 1917 return FAIL;
a737bd4d 1918 }
a737bd4d 1919
c19d1205
ZW
1920 if ((mask >> new_base) != 0 && ! warned)
1921 {
1922 as_tsktsk (_("register list not in ascending order"));
1923 warned = 1;
1924 }
0bbf2aa4 1925
5287ad62
JB
1926 mask |= setmask << new_base;
1927 count += addregs;
0bbf2aa4 1928
037e8744 1929 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1930 {
1931 int high_range;
0bbf2aa4 1932
037e8744 1933 str++;
0bbf2aa4 1934
037e8744 1935 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1936 == FAIL)
c19d1205
ZW
1937 {
1938 inst.error = gettext (reg_expected_msgs[regtype]);
1939 return FAIL;
1940 }
0bbf2aa4 1941
477330fc
RM
1942 if (high_range >= max_regs)
1943 {
1944 first_error (_("register out of range in list"));
1945 return FAIL;
1946 }
b7fc2769 1947
477330fc
RM
1948 if (regtype == REG_TYPE_NQ)
1949 high_range = high_range + 1;
5287ad62 1950
c19d1205
ZW
1951 if (high_range <= new_base)
1952 {
1953 inst.error = _("register range not in ascending order");
1954 return FAIL;
1955 }
0bbf2aa4 1956
5287ad62 1957 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1958 {
5287ad62 1959 if (mask & (setmask << new_base))
0bbf2aa4 1960 {
c19d1205
ZW
1961 inst.error = _("invalid register list");
1962 return FAIL;
0bbf2aa4 1963 }
c19d1205 1964
5287ad62
JB
1965 mask |= setmask << new_base;
1966 count += addregs;
0bbf2aa4 1967 }
0bbf2aa4 1968 }
0bbf2aa4 1969 }
037e8744 1970 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1971
037e8744 1972 str++;
0bbf2aa4 1973
c19d1205
ZW
1974 /* Sanity check -- should have raised a parse error above. */
1975 if (count == 0 || count > max_regs)
1976 abort ();
1977
1978 *pbase = base_reg;
1979
1980 /* Final test -- the registers must be consecutive. */
1981 mask >>= base_reg;
1982 for (i = 0; i < count; i++)
1983 {
1984 if ((mask & (1u << i)) == 0)
1985 {
1986 inst.error = _("non-contiguous register range");
1987 return FAIL;
1988 }
1989 }
1990
037e8744
JB
1991 *ccp = str;
1992
c19d1205 1993 return count;
b99bd4ef
NC
1994}
1995
dcbf9037
JB
1996/* True if two alias types are the same. */
1997
c921be7d 1998static bfd_boolean
dcbf9037
JB
1999neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2000{
2001 if (!a && !b)
c921be7d 2002 return TRUE;
5f4273c7 2003
dcbf9037 2004 if (!a || !b)
c921be7d 2005 return FALSE;
dcbf9037
JB
2006
2007 if (a->defined != b->defined)
c921be7d 2008 return FALSE;
5f4273c7 2009
dcbf9037
JB
2010 if ((a->defined & NTA_HASTYPE) != 0
2011 && (a->eltype.type != b->eltype.type
477330fc 2012 || a->eltype.size != b->eltype.size))
c921be7d 2013 return FALSE;
dcbf9037
JB
2014
2015 if ((a->defined & NTA_HASINDEX) != 0
2016 && (a->index != b->index))
c921be7d 2017 return FALSE;
5f4273c7 2018
c921be7d 2019 return TRUE;
dcbf9037
JB
2020}
2021
5287ad62
JB
2022/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2023 The base register is put in *PBASE.
dcbf9037 2024 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
2025 the return value.
2026 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2027 Bits [6:5] encode the list length (minus one).
2028 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2029
5287ad62 2030#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2031#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2032#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2033
2034static int
dcbf9037 2035parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 2036 struct neon_type_el *eltype)
5287ad62
JB
2037{
2038 char *ptr = *str;
2039 int base_reg = -1;
2040 int reg_incr = -1;
2041 int count = 0;
2042 int lane = -1;
2043 int leading_brace = 0;
2044 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
2045 const char *const incr_error = _("register stride must be 1 or 2");
2046 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2047 struct neon_typed_alias firsttype;
f85d59c3
KT
2048 firsttype.defined = 0;
2049 firsttype.eltype.type = NT_invtype;
2050 firsttype.eltype.size = -1;
2051 firsttype.index = -1;
5f4273c7 2052
5287ad62
JB
2053 if (skip_past_char (&ptr, '{') == SUCCESS)
2054 leading_brace = 1;
5f4273c7 2055
5287ad62
JB
2056 do
2057 {
dcbf9037
JB
2058 struct neon_typed_alias atype;
2059 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2060
5287ad62 2061 if (getreg == FAIL)
477330fc
RM
2062 {
2063 first_error (_(reg_expected_msgs[rtype]));
2064 return FAIL;
2065 }
5f4273c7 2066
5287ad62 2067 if (base_reg == -1)
477330fc
RM
2068 {
2069 base_reg = getreg;
2070 if (rtype == REG_TYPE_NQ)
2071 {
2072 reg_incr = 1;
2073 }
2074 firsttype = atype;
2075 }
5287ad62 2076 else if (reg_incr == -1)
477330fc
RM
2077 {
2078 reg_incr = getreg - base_reg;
2079 if (reg_incr < 1 || reg_incr > 2)
2080 {
2081 first_error (_(incr_error));
2082 return FAIL;
2083 }
2084 }
5287ad62 2085 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2086 {
2087 first_error (_(incr_error));
2088 return FAIL;
2089 }
dcbf9037 2090
c921be7d 2091 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2092 {
2093 first_error (_(type_error));
2094 return FAIL;
2095 }
5f4273c7 2096
5287ad62 2097 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2098 modes. */
5287ad62 2099 if (ptr[0] == '-')
477330fc
RM
2100 {
2101 struct neon_typed_alias htype;
2102 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2103 if (lane == -1)
2104 lane = NEON_INTERLEAVE_LANES;
2105 else if (lane != NEON_INTERLEAVE_LANES)
2106 {
2107 first_error (_(type_error));
2108 return FAIL;
2109 }
2110 if (reg_incr == -1)
2111 reg_incr = 1;
2112 else if (reg_incr != 1)
2113 {
2114 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2115 return FAIL;
2116 }
2117 ptr++;
2118 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2119 if (hireg == FAIL)
2120 {
2121 first_error (_(reg_expected_msgs[rtype]));
2122 return FAIL;
2123 }
2124 if (! neon_alias_types_same (&htype, &firsttype))
2125 {
2126 first_error (_(type_error));
2127 return FAIL;
2128 }
2129 count += hireg + dregs - getreg;
2130 continue;
2131 }
5f4273c7 2132
5287ad62
JB
2133 /* If we're using Q registers, we can't use [] or [n] syntax. */
2134 if (rtype == REG_TYPE_NQ)
477330fc
RM
2135 {
2136 count += 2;
2137 continue;
2138 }
5f4273c7 2139
dcbf9037 2140 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2141 {
2142 if (lane == -1)
2143 lane = atype.index;
2144 else if (lane != atype.index)
2145 {
2146 first_error (_(type_error));
2147 return FAIL;
2148 }
2149 }
5287ad62 2150 else if (lane == -1)
477330fc 2151 lane = NEON_INTERLEAVE_LANES;
5287ad62 2152 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2153 {
2154 first_error (_(type_error));
2155 return FAIL;
2156 }
5287ad62
JB
2157 count++;
2158 }
2159 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2160
5287ad62
JB
2161 /* No lane set by [x]. We must be interleaving structures. */
2162 if (lane == -1)
2163 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2164
5287ad62
JB
2165 /* Sanity check. */
2166 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2167 || (count > 1 && reg_incr == -1))
2168 {
dcbf9037 2169 first_error (_("error parsing element/structure list"));
5287ad62
JB
2170 return FAIL;
2171 }
2172
2173 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2174 {
dcbf9037 2175 first_error (_("expected }"));
5287ad62
JB
2176 return FAIL;
2177 }
5f4273c7 2178
5287ad62
JB
2179 if (reg_incr == -1)
2180 reg_incr = 1;
2181
dcbf9037
JB
2182 if (eltype)
2183 *eltype = firsttype.eltype;
2184
5287ad62
JB
2185 *pbase = base_reg;
2186 *str = ptr;
5f4273c7 2187
5287ad62
JB
2188 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2189}
2190
c19d1205
ZW
2191/* Parse an explicit relocation suffix on an expression. This is
2192 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2193 arm_reloc_hsh contains no entries, so this function can only
2194 succeed if there is no () after the word. Returns -1 on error,
2195 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2196
c19d1205
ZW
2197static int
2198parse_reloc (char **str)
b99bd4ef 2199{
c19d1205
ZW
2200 struct reloc_entry *r;
2201 char *p, *q;
b99bd4ef 2202
c19d1205
ZW
2203 if (**str != '(')
2204 return BFD_RELOC_UNUSED;
b99bd4ef 2205
c19d1205
ZW
2206 p = *str + 1;
2207 q = p;
2208
2209 while (*q && *q != ')' && *q != ',')
2210 q++;
2211 if (*q != ')')
2212 return -1;
2213
21d799b5
NC
2214 if ((r = (struct reloc_entry *)
2215 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2216 return -1;
2217
2218 *str = q + 1;
2219 return r->reloc;
b99bd4ef
NC
2220}
2221
c19d1205
ZW
2222/* Directives: register aliases. */
2223
dcbf9037 2224static struct reg_entry *
90ec0d68 2225insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2226{
d3ce72d0 2227 struct reg_entry *new_reg;
c19d1205 2228 const char *name;
b99bd4ef 2229
d3ce72d0 2230 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2231 {
d3ce72d0 2232 if (new_reg->builtin)
c19d1205 2233 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2234
c19d1205
ZW
2235 /* Only warn about a redefinition if it's not defined as the
2236 same register. */
d3ce72d0 2237 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2238 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2239
d929913e 2240 return NULL;
c19d1205 2241 }
b99bd4ef 2242
c19d1205 2243 name = xstrdup (str);
325801bd 2244 new_reg = XNEW (struct reg_entry);
b99bd4ef 2245
d3ce72d0
NC
2246 new_reg->name = name;
2247 new_reg->number = number;
2248 new_reg->type = type;
2249 new_reg->builtin = FALSE;
2250 new_reg->neon = NULL;
b99bd4ef 2251
d3ce72d0 2252 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2253 abort ();
5f4273c7 2254
d3ce72d0 2255 return new_reg;
dcbf9037
JB
2256}
2257
2258static void
2259insert_neon_reg_alias (char *str, int number, int type,
477330fc 2260 struct neon_typed_alias *atype)
dcbf9037
JB
2261{
2262 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2263
dcbf9037
JB
2264 if (!reg)
2265 {
2266 first_error (_("attempt to redefine typed alias"));
2267 return;
2268 }
5f4273c7 2269
dcbf9037
JB
2270 if (atype)
2271 {
325801bd 2272 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2273 *reg->neon = *atype;
2274 }
c19d1205 2275}
b99bd4ef 2276
c19d1205 2277/* Look for the .req directive. This is of the form:
b99bd4ef 2278
c19d1205 2279 new_register_name .req existing_register_name
b99bd4ef 2280
c19d1205 2281 If we find one, or if it looks sufficiently like one that we want to
d929913e 2282 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2283
d929913e 2284static bfd_boolean
c19d1205
ZW
2285create_register_alias (char * newname, char *p)
2286{
2287 struct reg_entry *old;
2288 char *oldname, *nbuf;
2289 size_t nlen;
b99bd4ef 2290
c19d1205
ZW
2291 /* The input scrubber ensures that whitespace after the mnemonic is
2292 collapsed to single spaces. */
2293 oldname = p;
2294 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2295 return FALSE;
b99bd4ef 2296
c19d1205
ZW
2297 oldname += 6;
2298 if (*oldname == '\0')
d929913e 2299 return FALSE;
b99bd4ef 2300
21d799b5 2301 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2302 if (!old)
b99bd4ef 2303 {
c19d1205 2304 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2305 return TRUE;
b99bd4ef
NC
2306 }
2307
c19d1205
ZW
2308 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2309 the desired alias name, and p points to its end. If not, then
2310 the desired alias name is in the global original_case_string. */
2311#ifdef TC_CASE_SENSITIVE
2312 nlen = p - newname;
2313#else
2314 newname = original_case_string;
2315 nlen = strlen (newname);
2316#endif
b99bd4ef 2317
29a2809e 2318 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2319
c19d1205
ZW
2320 /* Create aliases under the new name as stated; an all-lowercase
2321 version of the new name; and an all-uppercase version of the new
2322 name. */
d929913e
NC
2323 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2324 {
2325 for (p = nbuf; *p; p++)
2326 *p = TOUPPER (*p);
c19d1205 2327
d929913e
NC
2328 if (strncmp (nbuf, newname, nlen))
2329 {
2330 /* If this attempt to create an additional alias fails, do not bother
2331 trying to create the all-lower case alias. We will fail and issue
2332 a second, duplicate error message. This situation arises when the
2333 programmer does something like:
2334 foo .req r0
2335 Foo .req r1
2336 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2337 the artificial FOO alias because it has already been created by the
d929913e
NC
2338 first .req. */
2339 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2340 {
2341 free (nbuf);
2342 return TRUE;
2343 }
d929913e 2344 }
c19d1205 2345
d929913e
NC
2346 for (p = nbuf; *p; p++)
2347 *p = TOLOWER (*p);
c19d1205 2348
d929913e
NC
2349 if (strncmp (nbuf, newname, nlen))
2350 insert_reg_alias (nbuf, old->number, old->type);
2351 }
c19d1205 2352
e1fa0163 2353 free (nbuf);
d929913e 2354 return TRUE;
b99bd4ef
NC
2355}
2356
dcbf9037
JB
2357/* Create a Neon typed/indexed register alias using directives, e.g.:
2358 X .dn d5.s32[1]
2359 Y .qn 6.s16
2360 Z .dn d7
2361 T .dn Z[0]
2362 These typed registers can be used instead of the types specified after the
2363 Neon mnemonic, so long as all operands given have types. Types can also be
2364 specified directly, e.g.:
5f4273c7 2365 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2366
c921be7d 2367static bfd_boolean
dcbf9037
JB
2368create_neon_reg_alias (char *newname, char *p)
2369{
2370 enum arm_reg_type basetype;
2371 struct reg_entry *basereg;
2372 struct reg_entry mybasereg;
2373 struct neon_type ntype;
2374 struct neon_typed_alias typeinfo;
12d6b0b7 2375 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2376 int namelen;
5f4273c7 2377
dcbf9037
JB
2378 typeinfo.defined = 0;
2379 typeinfo.eltype.type = NT_invtype;
2380 typeinfo.eltype.size = -1;
2381 typeinfo.index = -1;
5f4273c7 2382
dcbf9037 2383 nameend = p;
5f4273c7 2384
dcbf9037
JB
2385 if (strncmp (p, " .dn ", 5) == 0)
2386 basetype = REG_TYPE_VFD;
2387 else if (strncmp (p, " .qn ", 5) == 0)
2388 basetype = REG_TYPE_NQ;
2389 else
c921be7d 2390 return FALSE;
5f4273c7 2391
dcbf9037 2392 p += 5;
5f4273c7 2393
dcbf9037 2394 if (*p == '\0')
c921be7d 2395 return FALSE;
5f4273c7 2396
dcbf9037
JB
2397 basereg = arm_reg_parse_multi (&p);
2398
2399 if (basereg && basereg->type != basetype)
2400 {
2401 as_bad (_("bad type for register"));
c921be7d 2402 return FALSE;
dcbf9037
JB
2403 }
2404
2405 if (basereg == NULL)
2406 {
2407 expressionS exp;
2408 /* Try parsing as an integer. */
2409 my_get_expression (&exp, &p, GE_NO_PREFIX);
2410 if (exp.X_op != O_constant)
477330fc
RM
2411 {
2412 as_bad (_("expression must be constant"));
2413 return FALSE;
2414 }
dcbf9037
JB
2415 basereg = &mybasereg;
2416 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2417 : exp.X_add_number;
dcbf9037
JB
2418 basereg->neon = 0;
2419 }
2420
2421 if (basereg->neon)
2422 typeinfo = *basereg->neon;
2423
2424 if (parse_neon_type (&ntype, &p) == SUCCESS)
2425 {
2426 /* We got a type. */
2427 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2428 {
2429 as_bad (_("can't redefine the type of a register alias"));
2430 return FALSE;
2431 }
5f4273c7 2432
dcbf9037
JB
2433 typeinfo.defined |= NTA_HASTYPE;
2434 if (ntype.elems != 1)
477330fc
RM
2435 {
2436 as_bad (_("you must specify a single type only"));
2437 return FALSE;
2438 }
dcbf9037
JB
2439 typeinfo.eltype = ntype.el[0];
2440 }
5f4273c7 2441
dcbf9037
JB
2442 if (skip_past_char (&p, '[') == SUCCESS)
2443 {
2444 expressionS exp;
2445 /* We got a scalar index. */
5f4273c7 2446
dcbf9037 2447 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2448 {
2449 as_bad (_("can't redefine the index of a scalar alias"));
2450 return FALSE;
2451 }
5f4273c7 2452
dcbf9037 2453 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2454
dcbf9037 2455 if (exp.X_op != O_constant)
477330fc
RM
2456 {
2457 as_bad (_("scalar index must be constant"));
2458 return FALSE;
2459 }
5f4273c7 2460
dcbf9037
JB
2461 typeinfo.defined |= NTA_HASINDEX;
2462 typeinfo.index = exp.X_add_number;
5f4273c7 2463
dcbf9037 2464 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2465 {
2466 as_bad (_("expecting ]"));
2467 return FALSE;
2468 }
dcbf9037
JB
2469 }
2470
15735687
NS
2471 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2472 the desired alias name, and p points to its end. If not, then
2473 the desired alias name is in the global original_case_string. */
2474#ifdef TC_CASE_SENSITIVE
dcbf9037 2475 namelen = nameend - newname;
15735687
NS
2476#else
2477 newname = original_case_string;
2478 namelen = strlen (newname);
2479#endif
2480
29a2809e 2481 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2482
dcbf9037 2483 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2484 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2485
dcbf9037
JB
2486 /* Insert name in all uppercase. */
2487 for (p = namebuf; *p; p++)
2488 *p = TOUPPER (*p);
5f4273c7 2489
dcbf9037
JB
2490 if (strncmp (namebuf, newname, namelen))
2491 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2492 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2493
dcbf9037
JB
2494 /* Insert name in all lowercase. */
2495 for (p = namebuf; *p; p++)
2496 *p = TOLOWER (*p);
5f4273c7 2497
dcbf9037
JB
2498 if (strncmp (namebuf, newname, namelen))
2499 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2500 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2501
e1fa0163 2502 free (namebuf);
c921be7d 2503 return TRUE;
dcbf9037
JB
2504}
2505
c19d1205
ZW
2506/* Should never be called, as .req goes between the alias and the
2507 register name, not at the beginning of the line. */
c921be7d 2508
b99bd4ef 2509static void
c19d1205 2510s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2511{
c19d1205
ZW
2512 as_bad (_("invalid syntax for .req directive"));
2513}
b99bd4ef 2514
dcbf9037
JB
2515static void
2516s_dn (int a ATTRIBUTE_UNUSED)
2517{
2518 as_bad (_("invalid syntax for .dn directive"));
2519}
2520
2521static void
2522s_qn (int a ATTRIBUTE_UNUSED)
2523{
2524 as_bad (_("invalid syntax for .qn directive"));
2525}
2526
c19d1205
ZW
2527/* The .unreq directive deletes an alias which was previously defined
2528 by .req. For example:
b99bd4ef 2529
c19d1205
ZW
2530 my_alias .req r11
2531 .unreq my_alias */
b99bd4ef
NC
2532
2533static void
c19d1205 2534s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2535{
c19d1205
ZW
2536 char * name;
2537 char saved_char;
b99bd4ef 2538
c19d1205
ZW
2539 name = input_line_pointer;
2540
2541 while (*input_line_pointer != 0
2542 && *input_line_pointer != ' '
2543 && *input_line_pointer != '\n')
2544 ++input_line_pointer;
2545
2546 saved_char = *input_line_pointer;
2547 *input_line_pointer = 0;
2548
2549 if (!*name)
2550 as_bad (_("invalid syntax for .unreq directive"));
2551 else
2552 {
21d799b5 2553 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2554 name);
c19d1205
ZW
2555
2556 if (!reg)
2557 as_bad (_("unknown register alias '%s'"), name);
2558 else if (reg->builtin)
a1727c1a 2559 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2560 name);
2561 else
2562 {
d929913e
NC
2563 char * p;
2564 char * nbuf;
2565
db0bc284 2566 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2567 free ((char *) reg->name);
477330fc
RM
2568 if (reg->neon)
2569 free (reg->neon);
c19d1205 2570 free (reg);
d929913e
NC
2571
2572 /* Also locate the all upper case and all lower case versions.
2573 Do not complain if we cannot find one or the other as it
2574 was probably deleted above. */
5f4273c7 2575
d929913e
NC
2576 nbuf = strdup (name);
2577 for (p = nbuf; *p; p++)
2578 *p = TOUPPER (*p);
21d799b5 2579 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2580 if (reg)
2581 {
db0bc284 2582 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2583 free ((char *) reg->name);
2584 if (reg->neon)
2585 free (reg->neon);
2586 free (reg);
2587 }
2588
2589 for (p = nbuf; *p; p++)
2590 *p = TOLOWER (*p);
21d799b5 2591 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2592 if (reg)
2593 {
db0bc284 2594 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2595 free ((char *) reg->name);
2596 if (reg->neon)
2597 free (reg->neon);
2598 free (reg);
2599 }
2600
2601 free (nbuf);
c19d1205
ZW
2602 }
2603 }
b99bd4ef 2604
c19d1205 2605 *input_line_pointer = saved_char;
b99bd4ef
NC
2606 demand_empty_rest_of_line ();
2607}
2608
c19d1205
ZW
2609/* Directives: Instruction set selection. */
2610
2611#ifdef OBJ_ELF
2612/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2613 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2614 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2615 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2616
cd000bff
DJ
2617/* Create a new mapping symbol for the transition to STATE. */
2618
2619static void
2620make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2621{
a737bd4d 2622 symbolS * symbolP;
c19d1205
ZW
2623 const char * symname;
2624 int type;
b99bd4ef 2625
c19d1205 2626 switch (state)
b99bd4ef 2627 {
c19d1205
ZW
2628 case MAP_DATA:
2629 symname = "$d";
2630 type = BSF_NO_FLAGS;
2631 break;
2632 case MAP_ARM:
2633 symname = "$a";
2634 type = BSF_NO_FLAGS;
2635 break;
2636 case MAP_THUMB:
2637 symname = "$t";
2638 type = BSF_NO_FLAGS;
2639 break;
c19d1205
ZW
2640 default:
2641 abort ();
2642 }
2643
cd000bff 2644 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2645 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2646
2647 switch (state)
2648 {
2649 case MAP_ARM:
2650 THUMB_SET_FUNC (symbolP, 0);
2651 ARM_SET_THUMB (symbolP, 0);
2652 ARM_SET_INTERWORK (symbolP, support_interwork);
2653 break;
2654
2655 case MAP_THUMB:
2656 THUMB_SET_FUNC (symbolP, 1);
2657 ARM_SET_THUMB (symbolP, 1);
2658 ARM_SET_INTERWORK (symbolP, support_interwork);
2659 break;
2660
2661 case MAP_DATA:
2662 default:
cd000bff
DJ
2663 break;
2664 }
2665
2666 /* Save the mapping symbols for future reference. Also check that
2667 we do not place two mapping symbols at the same offset within a
2668 frag. We'll handle overlap between frags in
2de7820f
JZ
2669 check_mapping_symbols.
2670
2671 If .fill or other data filling directive generates zero sized data,
2672 the mapping symbol for the following code will have the same value
2673 as the one generated for the data filling directive. In this case,
2674 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2675 if (value == 0)
2676 {
2de7820f
JZ
2677 if (frag->tc_frag_data.first_map != NULL)
2678 {
2679 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2680 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2681 }
cd000bff
DJ
2682 frag->tc_frag_data.first_map = symbolP;
2683 }
2684 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2685 {
2686 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2687 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2688 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2689 }
cd000bff
DJ
2690 frag->tc_frag_data.last_map = symbolP;
2691}
2692
2693/* We must sometimes convert a region marked as code to data during
2694 code alignment, if an odd number of bytes have to be padded. The
2695 code mapping symbol is pushed to an aligned address. */
2696
2697static void
2698insert_data_mapping_symbol (enum mstate state,
2699 valueT value, fragS *frag, offsetT bytes)
2700{
2701 /* If there was already a mapping symbol, remove it. */
2702 if (frag->tc_frag_data.last_map != NULL
2703 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2704 {
2705 symbolS *symp = frag->tc_frag_data.last_map;
2706
2707 if (value == 0)
2708 {
2709 know (frag->tc_frag_data.first_map == symp);
2710 frag->tc_frag_data.first_map = NULL;
2711 }
2712 frag->tc_frag_data.last_map = NULL;
2713 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2714 }
cd000bff
DJ
2715
2716 make_mapping_symbol (MAP_DATA, value, frag);
2717 make_mapping_symbol (state, value + bytes, frag);
2718}
2719
2720static void mapping_state_2 (enum mstate state, int max_chars);
2721
2722/* Set the mapping state to STATE. Only call this when about to
2723 emit some STATE bytes to the file. */
2724
4e9aaefb 2725#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2726void
2727mapping_state (enum mstate state)
2728{
940b5ce0
DJ
2729 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2730
cd000bff
DJ
2731 if (mapstate == state)
2732 /* The mapping symbol has already been emitted.
2733 There is nothing else to do. */
2734 return;
49c62a33
NC
2735
2736 if (state == MAP_ARM || state == MAP_THUMB)
2737 /* PR gas/12931
2738 All ARM instructions require 4-byte alignment.
2739 (Almost) all Thumb instructions require 2-byte alignment.
2740
2741 When emitting instructions into any section, mark the section
2742 appropriately.
2743
2744 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2745 but themselves require 2-byte alignment; this applies to some
33eaf5de 2746 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
2747 literal pool generation or an explicit .align >=2, both of
2748 which will cause the section to me marked with sufficient
2749 alignment. Thus, we don't handle those cases here. */
2750 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2751
2752 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2753 /* This case will be evaluated later. */
cd000bff 2754 return;
cd000bff
DJ
2755
2756 mapping_state_2 (state, 0);
cd000bff
DJ
2757}
2758
2759/* Same as mapping_state, but MAX_CHARS bytes have already been
2760 allocated. Put the mapping symbol that far back. */
2761
2762static void
2763mapping_state_2 (enum mstate state, int max_chars)
2764{
940b5ce0
DJ
2765 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2766
2767 if (!SEG_NORMAL (now_seg))
2768 return;
2769
cd000bff
DJ
2770 if (mapstate == state)
2771 /* The mapping symbol has already been emitted.
2772 There is nothing else to do. */
2773 return;
2774
4e9aaefb
SA
2775 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2776 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2777 {
2778 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2779 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2780
2781 if (add_symbol)
2782 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2783 }
2784
cd000bff
DJ
2785 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2786 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2787}
4e9aaefb 2788#undef TRANSITION
c19d1205 2789#else
d3106081
NS
2790#define mapping_state(x) ((void)0)
2791#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2792#endif
2793
2794/* Find the real, Thumb encoded start of a Thumb function. */
2795
4343666d 2796#ifdef OBJ_COFF
c19d1205
ZW
2797static symbolS *
2798find_real_start (symbolS * symbolP)
2799{
2800 char * real_start;
2801 const char * name = S_GET_NAME (symbolP);
2802 symbolS * new_target;
2803
2804 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2805#define STUB_NAME ".real_start_of"
2806
2807 if (name == NULL)
2808 abort ();
2809
37f6032b
ZW
2810 /* The compiler may generate BL instructions to local labels because
2811 it needs to perform a branch to a far away location. These labels
2812 do not have a corresponding ".real_start_of" label. We check
2813 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2814 the ".real_start_of" convention for nonlocal branches. */
2815 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2816 return symbolP;
2817
e1fa0163 2818 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2819 new_target = symbol_find (real_start);
e1fa0163 2820 free (real_start);
c19d1205
ZW
2821
2822 if (new_target == NULL)
2823 {
bd3ba5d1 2824 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2825 new_target = symbolP;
2826 }
2827
c19d1205
ZW
2828 return new_target;
2829}
4343666d 2830#endif
c19d1205
ZW
2831
2832static void
2833opcode_select (int width)
2834{
2835 switch (width)
2836 {
2837 case 16:
2838 if (! thumb_mode)
2839 {
e74cfd16 2840 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2841 as_bad (_("selected processor does not support THUMB opcodes"));
2842
2843 thumb_mode = 1;
2844 /* No need to force the alignment, since we will have been
2845 coming from ARM mode, which is word-aligned. */
2846 record_alignment (now_seg, 1);
2847 }
c19d1205
ZW
2848 break;
2849
2850 case 32:
2851 if (thumb_mode)
2852 {
e74cfd16 2853 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2854 as_bad (_("selected processor does not support ARM opcodes"));
2855
2856 thumb_mode = 0;
2857
2858 if (!need_pass_2)
2859 frag_align (2, 0, 0);
2860
2861 record_alignment (now_seg, 1);
2862 }
c19d1205
ZW
2863 break;
2864
2865 default:
2866 as_bad (_("invalid instruction size selected (%d)"), width);
2867 }
2868}
2869
2870static void
2871s_arm (int ignore ATTRIBUTE_UNUSED)
2872{
2873 opcode_select (32);
2874 demand_empty_rest_of_line ();
2875}
2876
2877static void
2878s_thumb (int ignore ATTRIBUTE_UNUSED)
2879{
2880 opcode_select (16);
2881 demand_empty_rest_of_line ();
2882}
2883
2884static void
2885s_code (int unused ATTRIBUTE_UNUSED)
2886{
2887 int temp;
2888
2889 temp = get_absolute_expression ();
2890 switch (temp)
2891 {
2892 case 16:
2893 case 32:
2894 opcode_select (temp);
2895 break;
2896
2897 default:
2898 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2899 }
2900}
2901
2902static void
2903s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2904{
2905 /* If we are not already in thumb mode go into it, EVEN if
2906 the target processor does not support thumb instructions.
2907 This is used by gcc/config/arm/lib1funcs.asm for example
2908 to compile interworking support functions even if the
2909 target processor should not support interworking. */
2910 if (! thumb_mode)
2911 {
2912 thumb_mode = 2;
2913 record_alignment (now_seg, 1);
2914 }
2915
2916 demand_empty_rest_of_line ();
2917}
2918
2919static void
2920s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2921{
2922 s_thumb (0);
2923
2924 /* The following label is the name/address of the start of a Thumb function.
2925 We need to know this for the interworking support. */
2926 label_is_thumb_function_name = TRUE;
2927}
2928
2929/* Perform a .set directive, but also mark the alias as
2930 being a thumb function. */
2931
2932static void
2933s_thumb_set (int equiv)
2934{
2935 /* XXX the following is a duplicate of the code for s_set() in read.c
2936 We cannot just call that code as we need to get at the symbol that
2937 is created. */
2938 char * name;
2939 char delim;
2940 char * end_name;
2941 symbolS * symbolP;
2942
2943 /* Especial apologies for the random logic:
2944 This just grew, and could be parsed much more simply!
2945 Dean - in haste. */
d02603dc 2946 delim = get_symbol_name (& name);
c19d1205 2947 end_name = input_line_pointer;
d02603dc 2948 (void) restore_line_pointer (delim);
c19d1205
ZW
2949
2950 if (*input_line_pointer != ',')
2951 {
2952 *end_name = 0;
2953 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2954 *end_name = delim;
2955 ignore_rest_of_line ();
2956 return;
2957 }
2958
2959 input_line_pointer++;
2960 *end_name = 0;
2961
2962 if (name[0] == '.' && name[1] == '\0')
2963 {
2964 /* XXX - this should not happen to .thumb_set. */
2965 abort ();
2966 }
2967
2968 if ((symbolP = symbol_find (name)) == NULL
2969 && (symbolP = md_undefined_symbol (name)) == NULL)
2970 {
2971#ifndef NO_LISTING
2972 /* When doing symbol listings, play games with dummy fragments living
2973 outside the normal fragment chain to record the file and line info
c19d1205 2974 for this symbol. */
b99bd4ef
NC
2975 if (listing & LISTING_SYMBOLS)
2976 {
2977 extern struct list_info_struct * listing_tail;
21d799b5 2978 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2979
2980 memset (dummy_frag, 0, sizeof (fragS));
2981 dummy_frag->fr_type = rs_fill;
2982 dummy_frag->line = listing_tail;
2983 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2984 dummy_frag->fr_symbol = symbolP;
2985 }
2986 else
2987#endif
2988 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2989
2990#ifdef OBJ_COFF
2991 /* "set" symbols are local unless otherwise specified. */
2992 SF_SET_LOCAL (symbolP);
2993#endif /* OBJ_COFF */
2994 } /* Make a new symbol. */
2995
2996 symbol_table_insert (symbolP);
2997
2998 * end_name = delim;
2999
3000 if (equiv
3001 && S_IS_DEFINED (symbolP)
3002 && S_GET_SEGMENT (symbolP) != reg_section)
3003 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3004
3005 pseudo_set (symbolP);
3006
3007 demand_empty_rest_of_line ();
3008
c19d1205 3009 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
3010
3011 THUMB_SET_FUNC (symbolP, 1);
3012 ARM_SET_THUMB (symbolP, 1);
3013#if defined OBJ_ELF || defined OBJ_COFF
3014 ARM_SET_INTERWORK (symbolP, support_interwork);
3015#endif
3016}
3017
c19d1205 3018/* Directives: Mode selection. */
b99bd4ef 3019
c19d1205
ZW
3020/* .syntax [unified|divided] - choose the new unified syntax
3021 (same for Arm and Thumb encoding, modulo slight differences in what
3022 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 3023static void
c19d1205 3024s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 3025{
c19d1205
ZW
3026 char *name, delim;
3027
d02603dc 3028 delim = get_symbol_name (& name);
c19d1205
ZW
3029
3030 if (!strcasecmp (name, "unified"))
3031 unified_syntax = TRUE;
3032 else if (!strcasecmp (name, "divided"))
3033 unified_syntax = FALSE;
3034 else
3035 {
3036 as_bad (_("unrecognized syntax mode \"%s\""), name);
3037 return;
3038 }
d02603dc 3039 (void) restore_line_pointer (delim);
b99bd4ef
NC
3040 demand_empty_rest_of_line ();
3041}
3042
c19d1205
ZW
3043/* Directives: sectioning and alignment. */
3044
c19d1205
ZW
3045static void
3046s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3047{
c19d1205
ZW
3048 /* We don't support putting frags in the BSS segment, we fake it by
3049 marking in_bss, then looking at s_skip for clues. */
3050 subseg_set (bss_section, 0);
3051 demand_empty_rest_of_line ();
cd000bff
DJ
3052
3053#ifdef md_elf_section_change_hook
3054 md_elf_section_change_hook ();
3055#endif
c19d1205 3056}
b99bd4ef 3057
c19d1205
ZW
3058static void
3059s_even (int ignore ATTRIBUTE_UNUSED)
3060{
3061 /* Never make frag if expect extra pass. */
3062 if (!need_pass_2)
3063 frag_align (1, 0, 0);
b99bd4ef 3064
c19d1205 3065 record_alignment (now_seg, 1);
b99bd4ef 3066
c19d1205 3067 demand_empty_rest_of_line ();
b99bd4ef
NC
3068}
3069
2e6976a8
DG
3070/* Directives: CodeComposer Studio. */
3071
3072/* .ref (for CodeComposer Studio syntax only). */
3073static void
3074s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3075{
3076 if (codecomposer_syntax)
3077 ignore_rest_of_line ();
3078 else
3079 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3080}
3081
3082/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3083 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3084static void
3085asmfunc_debug (const char * name)
3086{
3087 static const char * last_name = NULL;
3088
3089 if (name != NULL)
3090 {
3091 gas_assert (last_name == NULL);
3092 last_name = name;
3093
3094 if (debug_type == DEBUG_STABS)
3095 stabs_generate_asm_func (name, name);
3096 }
3097 else
3098 {
3099 gas_assert (last_name != NULL);
3100
3101 if (debug_type == DEBUG_STABS)
3102 stabs_generate_asm_endfunc (last_name, last_name);
3103
3104 last_name = NULL;
3105 }
3106}
3107
3108static void
3109s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3110{
3111 if (codecomposer_syntax)
3112 {
3113 switch (asmfunc_state)
3114 {
3115 case OUTSIDE_ASMFUNC:
3116 asmfunc_state = WAITING_ASMFUNC_NAME;
3117 break;
3118
3119 case WAITING_ASMFUNC_NAME:
3120 as_bad (_(".asmfunc repeated."));
3121 break;
3122
3123 case WAITING_ENDASMFUNC:
3124 as_bad (_(".asmfunc without function."));
3125 break;
3126 }
3127 demand_empty_rest_of_line ();
3128 }
3129 else
3130 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3131}
3132
3133static void
3134s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3135{
3136 if (codecomposer_syntax)
3137 {
3138 switch (asmfunc_state)
3139 {
3140 case OUTSIDE_ASMFUNC:
3141 as_bad (_(".endasmfunc without a .asmfunc."));
3142 break;
3143
3144 case WAITING_ASMFUNC_NAME:
3145 as_bad (_(".endasmfunc without function."));
3146 break;
3147
3148 case WAITING_ENDASMFUNC:
3149 asmfunc_state = OUTSIDE_ASMFUNC;
3150 asmfunc_debug (NULL);
3151 break;
3152 }
3153 demand_empty_rest_of_line ();
3154 }
3155 else
3156 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3157}
3158
3159static void
3160s_ccs_def (int name)
3161{
3162 if (codecomposer_syntax)
3163 s_globl (name);
3164 else
3165 as_bad (_(".def pseudo-op only available with -mccs flag."));
3166}
3167
c19d1205 3168/* Directives: Literal pools. */
a737bd4d 3169
c19d1205
ZW
3170static literal_pool *
3171find_literal_pool (void)
a737bd4d 3172{
c19d1205 3173 literal_pool * pool;
a737bd4d 3174
c19d1205 3175 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3176 {
c19d1205
ZW
3177 if (pool->section == now_seg
3178 && pool->sub_section == now_subseg)
3179 break;
a737bd4d
NC
3180 }
3181
c19d1205 3182 return pool;
a737bd4d
NC
3183}
3184
c19d1205
ZW
3185static literal_pool *
3186find_or_make_literal_pool (void)
a737bd4d 3187{
c19d1205
ZW
3188 /* Next literal pool ID number. */
3189 static unsigned int latest_pool_num = 1;
3190 literal_pool * pool;
a737bd4d 3191
c19d1205 3192 pool = find_literal_pool ();
a737bd4d 3193
c19d1205 3194 if (pool == NULL)
a737bd4d 3195 {
c19d1205 3196 /* Create a new pool. */
325801bd 3197 pool = XNEW (literal_pool);
c19d1205
ZW
3198 if (! pool)
3199 return NULL;
a737bd4d 3200
c19d1205
ZW
3201 pool->next_free_entry = 0;
3202 pool->section = now_seg;
3203 pool->sub_section = now_subseg;
3204 pool->next = list_of_pools;
3205 pool->symbol = NULL;
8335d6aa 3206 pool->alignment = 2;
c19d1205
ZW
3207
3208 /* Add it to the list. */
3209 list_of_pools = pool;
a737bd4d 3210 }
a737bd4d 3211
c19d1205
ZW
3212 /* New pools, and emptied pools, will have a NULL symbol. */
3213 if (pool->symbol == NULL)
a737bd4d 3214 {
c19d1205
ZW
3215 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3216 (valueT) 0, &zero_address_frag);
3217 pool->id = latest_pool_num ++;
a737bd4d
NC
3218 }
3219
c19d1205
ZW
3220 /* Done. */
3221 return pool;
a737bd4d
NC
3222}
3223
c19d1205 3224/* Add the literal in the global 'inst'
5f4273c7 3225 structure to the relevant literal pool. */
b99bd4ef
NC
3226
3227static int
8335d6aa 3228add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3229{
8335d6aa
JW
3230#define PADDING_SLOT 0x1
3231#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3232 literal_pool * pool;
8335d6aa
JW
3233 unsigned int entry, pool_size = 0;
3234 bfd_boolean padding_slot_p = FALSE;
e56c722b 3235 unsigned imm1 = 0;
8335d6aa
JW
3236 unsigned imm2 = 0;
3237
3238 if (nbytes == 8)
3239 {
3240 imm1 = inst.operands[1].imm;
3241 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3242 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3243 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3244 if (target_big_endian)
3245 {
3246 imm1 = imm2;
3247 imm2 = inst.operands[1].imm;
3248 }
3249 }
b99bd4ef 3250
c19d1205
ZW
3251 pool = find_or_make_literal_pool ();
3252
3253 /* Check if this literal value is already in the pool. */
3254 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3255 {
8335d6aa
JW
3256 if (nbytes == 4)
3257 {
3258 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3259 && (inst.reloc.exp.X_op == O_constant)
3260 && (pool->literals[entry].X_add_number
3261 == inst.reloc.exp.X_add_number)
3262 && (pool->literals[entry].X_md == nbytes)
3263 && (pool->literals[entry].X_unsigned
3264 == inst.reloc.exp.X_unsigned))
3265 break;
3266
3267 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3268 && (inst.reloc.exp.X_op == O_symbol)
3269 && (pool->literals[entry].X_add_number
3270 == inst.reloc.exp.X_add_number)
3271 && (pool->literals[entry].X_add_symbol
3272 == inst.reloc.exp.X_add_symbol)
3273 && (pool->literals[entry].X_op_symbol
3274 == inst.reloc.exp.X_op_symbol)
3275 && (pool->literals[entry].X_md == nbytes))
3276 break;
3277 }
3278 else if ((nbytes == 8)
3279 && !(pool_size & 0x7)
3280 && ((entry + 1) != pool->next_free_entry)
3281 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3282 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3283 && (pool->literals[entry].X_unsigned
3284 == inst.reloc.exp.X_unsigned)
3285 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3286 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3287 && (pool->literals[entry + 1].X_unsigned
3288 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3289 break;
3290
8335d6aa
JW
3291 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3292 if (padding_slot_p && (nbytes == 4))
c19d1205 3293 break;
8335d6aa
JW
3294
3295 pool_size += 4;
b99bd4ef
NC
3296 }
3297
c19d1205
ZW
3298 /* Do we need to create a new entry? */
3299 if (entry == pool->next_free_entry)
3300 {
3301 if (entry >= MAX_LITERAL_POOL_SIZE)
3302 {
3303 inst.error = _("literal pool overflow");
3304 return FAIL;
3305 }
3306
8335d6aa
JW
3307 if (nbytes == 8)
3308 {
3309 /* For 8-byte entries, we align to an 8-byte boundary,
3310 and split it into two 4-byte entries, because on 32-bit
3311 host, 8-byte constants are treated as big num, thus
3312 saved in "generic_bignum" which will be overwritten
3313 by later assignments.
3314
3315 We also need to make sure there is enough space for
3316 the split.
3317
3318 We also check to make sure the literal operand is a
3319 constant number. */
19f2f6a9
JW
3320 if (!(inst.reloc.exp.X_op == O_constant
3321 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3322 {
3323 inst.error = _("invalid type for literal pool");
3324 return FAIL;
3325 }
3326 else if (pool_size & 0x7)
3327 {
3328 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3329 {
3330 inst.error = _("literal pool overflow");
3331 return FAIL;
3332 }
3333
3334 pool->literals[entry] = inst.reloc.exp;
a6684f0d 3335 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3336 pool->literals[entry].X_add_number = 0;
3337 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3338 pool->next_free_entry += 1;
3339 pool_size += 4;
3340 }
3341 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3342 {
3343 inst.error = _("literal pool overflow");
3344 return FAIL;
3345 }
3346
3347 pool->literals[entry] = inst.reloc.exp;
3348 pool->literals[entry].X_op = O_constant;
3349 pool->literals[entry].X_add_number = imm1;
3350 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3351 pool->literals[entry++].X_md = 4;
3352 pool->literals[entry] = inst.reloc.exp;
3353 pool->literals[entry].X_op = O_constant;
3354 pool->literals[entry].X_add_number = imm2;
3355 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3356 pool->literals[entry].X_md = 4;
3357 pool->alignment = 3;
3358 pool->next_free_entry += 1;
3359 }
3360 else
3361 {
3362 pool->literals[entry] = inst.reloc.exp;
3363 pool->literals[entry].X_md = 4;
3364 }
3365
a8040cf2
NC
3366#ifdef OBJ_ELF
3367 /* PR ld/12974: Record the location of the first source line to reference
3368 this entry in the literal pool. If it turns out during linking that the
3369 symbol does not exist we will be able to give an accurate line number for
3370 the (first use of the) missing reference. */
3371 if (debug_type == DEBUG_DWARF2)
3372 dwarf2_where (pool->locs + entry);
3373#endif
c19d1205
ZW
3374 pool->next_free_entry += 1;
3375 }
8335d6aa
JW
3376 else if (padding_slot_p)
3377 {
3378 pool->literals[entry] = inst.reloc.exp;
3379 pool->literals[entry].X_md = nbytes;
3380 }
b99bd4ef 3381
c19d1205 3382 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3383 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3384 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3385
c19d1205 3386 return SUCCESS;
b99bd4ef
NC
3387}
3388
2e6976a8 3389bfd_boolean
2e57ce7b 3390tc_start_label_without_colon (void)
2e6976a8
DG
3391{
3392 bfd_boolean ret = TRUE;
3393
3394 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3395 {
2e57ce7b 3396 const char *label = input_line_pointer;
2e6976a8
DG
3397
3398 while (!is_end_of_line[(int) label[-1]])
3399 --label;
3400
3401 if (*label == '.')
3402 {
3403 as_bad (_("Invalid label '%s'"), label);
3404 ret = FALSE;
3405 }
3406
3407 asmfunc_debug (label);
3408
3409 asmfunc_state = WAITING_ENDASMFUNC;
3410 }
3411
3412 return ret;
3413}
3414
c19d1205 3415/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3416 a later date assign it a value. That's what these functions do. */
e16bb312 3417
c19d1205
ZW
3418static void
3419symbol_locate (symbolS * symbolP,
3420 const char * name, /* It is copied, the caller can modify. */
3421 segT segment, /* Segment identifier (SEG_<something>). */
3422 valueT valu, /* Symbol value. */
3423 fragS * frag) /* Associated fragment. */
3424{
e57e6ddc 3425 size_t name_length;
c19d1205 3426 char * preserved_copy_of_name;
e16bb312 3427
c19d1205
ZW
3428 name_length = strlen (name) + 1; /* +1 for \0. */
3429 obstack_grow (&notes, name, name_length);
21d799b5 3430 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3431
c19d1205
ZW
3432#ifdef tc_canonicalize_symbol_name
3433 preserved_copy_of_name =
3434 tc_canonicalize_symbol_name (preserved_copy_of_name);
3435#endif
b99bd4ef 3436
c19d1205 3437 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3438
c19d1205
ZW
3439 S_SET_SEGMENT (symbolP, segment);
3440 S_SET_VALUE (symbolP, valu);
3441 symbol_clear_list_pointers (symbolP);
b99bd4ef 3442
c19d1205 3443 symbol_set_frag (symbolP, frag);
b99bd4ef 3444
c19d1205
ZW
3445 /* Link to end of symbol chain. */
3446 {
3447 extern int symbol_table_frozen;
b99bd4ef 3448
c19d1205
ZW
3449 if (symbol_table_frozen)
3450 abort ();
3451 }
b99bd4ef 3452
c19d1205 3453 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3454
c19d1205 3455 obj_symbol_new_hook (symbolP);
b99bd4ef 3456
c19d1205
ZW
3457#ifdef tc_symbol_new_hook
3458 tc_symbol_new_hook (symbolP);
3459#endif
3460
3461#ifdef DEBUG_SYMS
3462 verify_symbol_chain (symbol_rootP, symbol_lastP);
3463#endif /* DEBUG_SYMS */
b99bd4ef
NC
3464}
3465
c19d1205
ZW
3466static void
3467s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3468{
c19d1205
ZW
3469 unsigned int entry;
3470 literal_pool * pool;
3471 char sym_name[20];
b99bd4ef 3472
c19d1205
ZW
3473 pool = find_literal_pool ();
3474 if (pool == NULL
3475 || pool->symbol == NULL
3476 || pool->next_free_entry == 0)
3477 return;
b99bd4ef 3478
c19d1205
ZW
3479 /* Align pool as you have word accesses.
3480 Only make a frag if we have to. */
3481 if (!need_pass_2)
8335d6aa 3482 frag_align (pool->alignment, 0, 0);
b99bd4ef 3483
c19d1205 3484 record_alignment (now_seg, 2);
b99bd4ef 3485
aaca88ef 3486#ifdef OBJ_ELF
47fc6e36
WN
3487 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3488 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3489#endif
c19d1205 3490 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3491
c19d1205
ZW
3492 symbol_locate (pool->symbol, sym_name, now_seg,
3493 (valueT) frag_now_fix (), frag_now);
3494 symbol_table_insert (pool->symbol);
b99bd4ef 3495
c19d1205 3496 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3497
c19d1205
ZW
3498#if defined OBJ_COFF || defined OBJ_ELF
3499 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3500#endif
6c43fab6 3501
c19d1205 3502 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3503 {
3504#ifdef OBJ_ELF
3505 if (debug_type == DEBUG_DWARF2)
3506 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3507#endif
3508 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3509 emit_expr (&(pool->literals[entry]),
3510 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3511 }
b99bd4ef 3512
c19d1205
ZW
3513 /* Mark the pool as empty. */
3514 pool->next_free_entry = 0;
3515 pool->symbol = NULL;
b99bd4ef
NC
3516}
3517
c19d1205
ZW
3518#ifdef OBJ_ELF
3519/* Forward declarations for functions below, in the MD interface
3520 section. */
3521static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3522static valueT create_unwind_entry (int);
3523static void start_unwind_section (const segT, int);
3524static void add_unwind_opcode (valueT, int);
3525static void flush_pending_unwind (void);
b99bd4ef 3526
c19d1205 3527/* Directives: Data. */
b99bd4ef 3528
c19d1205
ZW
3529static void
3530s_arm_elf_cons (int nbytes)
3531{
3532 expressionS exp;
b99bd4ef 3533
c19d1205
ZW
3534#ifdef md_flush_pending_output
3535 md_flush_pending_output ();
3536#endif
b99bd4ef 3537
c19d1205 3538 if (is_it_end_of_statement ())
b99bd4ef 3539 {
c19d1205
ZW
3540 demand_empty_rest_of_line ();
3541 return;
b99bd4ef
NC
3542 }
3543
c19d1205
ZW
3544#ifdef md_cons_align
3545 md_cons_align (nbytes);
3546#endif
b99bd4ef 3547
c19d1205
ZW
3548 mapping_state (MAP_DATA);
3549 do
b99bd4ef 3550 {
c19d1205
ZW
3551 int reloc;
3552 char *base = input_line_pointer;
b99bd4ef 3553
c19d1205 3554 expression (& exp);
b99bd4ef 3555
c19d1205
ZW
3556 if (exp.X_op != O_symbol)
3557 emit_expr (&exp, (unsigned int) nbytes);
3558 else
3559 {
3560 char *before_reloc = input_line_pointer;
3561 reloc = parse_reloc (&input_line_pointer);
3562 if (reloc == -1)
3563 {
3564 as_bad (_("unrecognized relocation suffix"));
3565 ignore_rest_of_line ();
3566 return;
3567 }
3568 else if (reloc == BFD_RELOC_UNUSED)
3569 emit_expr (&exp, (unsigned int) nbytes);
3570 else
3571 {
21d799b5 3572 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3573 bfd_reloc_type_lookup (stdoutput,
3574 (bfd_reloc_code_real_type) reloc);
c19d1205 3575 int size = bfd_get_reloc_size (howto);
b99bd4ef 3576
2fc8bdac
ZW
3577 if (reloc == BFD_RELOC_ARM_PLT32)
3578 {
3579 as_bad (_("(plt) is only valid on branch targets"));
3580 reloc = BFD_RELOC_UNUSED;
3581 size = 0;
3582 }
3583
c19d1205 3584 if (size > nbytes)
992a06ee
AM
3585 as_bad (ngettext ("%s relocations do not fit in %d byte",
3586 "%s relocations do not fit in %d bytes",
3587 nbytes),
c19d1205
ZW
3588 howto->name, nbytes);
3589 else
3590 {
3591 /* We've parsed an expression stopping at O_symbol.
3592 But there may be more expression left now that we
3593 have parsed the relocation marker. Parse it again.
3594 XXX Surely there is a cleaner way to do this. */
3595 char *p = input_line_pointer;
3596 int offset;
325801bd 3597 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3598
c19d1205
ZW
3599 memcpy (save_buf, base, input_line_pointer - base);
3600 memmove (base + (input_line_pointer - before_reloc),
3601 base, before_reloc - base);
3602
3603 input_line_pointer = base + (input_line_pointer-before_reloc);
3604 expression (&exp);
3605 memcpy (base, save_buf, p - base);
3606
3607 offset = nbytes - size;
4b1a927e
AM
3608 p = frag_more (nbytes);
3609 memset (p, 0, nbytes);
c19d1205 3610 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3611 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3612 free (save_buf);
c19d1205
ZW
3613 }
3614 }
3615 }
b99bd4ef 3616 }
c19d1205 3617 while (*input_line_pointer++ == ',');
b99bd4ef 3618
c19d1205
ZW
3619 /* Put terminator back into stream. */
3620 input_line_pointer --;
3621 demand_empty_rest_of_line ();
b99bd4ef
NC
3622}
3623
c921be7d
NC
3624/* Emit an expression containing a 32-bit thumb instruction.
3625 Implementation based on put_thumb32_insn. */
3626
3627static void
3628emit_thumb32_expr (expressionS * exp)
3629{
3630 expressionS exp_high = *exp;
3631
3632 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3633 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3634 exp->X_add_number &= 0xffff;
3635 emit_expr (exp, (unsigned int) THUMB_SIZE);
3636}
3637
3638/* Guess the instruction size based on the opcode. */
3639
3640static int
3641thumb_insn_size (int opcode)
3642{
3643 if ((unsigned int) opcode < 0xe800u)
3644 return 2;
3645 else if ((unsigned int) opcode >= 0xe8000000u)
3646 return 4;
3647 else
3648 return 0;
3649}
3650
3651static bfd_boolean
3652emit_insn (expressionS *exp, int nbytes)
3653{
3654 int size = 0;
3655
3656 if (exp->X_op == O_constant)
3657 {
3658 size = nbytes;
3659
3660 if (size == 0)
3661 size = thumb_insn_size (exp->X_add_number);
3662
3663 if (size != 0)
3664 {
3665 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3666 {
3667 as_bad (_(".inst.n operand too big. "\
3668 "Use .inst.w instead"));
3669 size = 0;
3670 }
3671 else
3672 {
3673 if (now_it.state == AUTOMATIC_IT_BLOCK)
3674 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3675 else
3676 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3677
3678 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3679 emit_thumb32_expr (exp);
3680 else
3681 emit_expr (exp, (unsigned int) size);
3682
3683 it_fsm_post_encode ();
3684 }
3685 }
3686 else
3687 as_bad (_("cannot determine Thumb instruction size. " \
3688 "Use .inst.n/.inst.w instead"));
3689 }
3690 else
3691 as_bad (_("constant expression required"));
3692
3693 return (size != 0);
3694}
3695
3696/* Like s_arm_elf_cons but do not use md_cons_align and
3697 set the mapping state to MAP_ARM/MAP_THUMB. */
3698
3699static void
3700s_arm_elf_inst (int nbytes)
3701{
3702 if (is_it_end_of_statement ())
3703 {
3704 demand_empty_rest_of_line ();
3705 return;
3706 }
3707
3708 /* Calling mapping_state () here will not change ARM/THUMB,
3709 but will ensure not to be in DATA state. */
3710
3711 if (thumb_mode)
3712 mapping_state (MAP_THUMB);
3713 else
3714 {
3715 if (nbytes != 0)
3716 {
3717 as_bad (_("width suffixes are invalid in ARM mode"));
3718 ignore_rest_of_line ();
3719 return;
3720 }
3721
3722 nbytes = 4;
3723
3724 mapping_state (MAP_ARM);
3725 }
3726
3727 do
3728 {
3729 expressionS exp;
3730
3731 expression (& exp);
3732
3733 if (! emit_insn (& exp, nbytes))
3734 {
3735 ignore_rest_of_line ();
3736 return;
3737 }
3738 }
3739 while (*input_line_pointer++ == ',');
3740
3741 /* Put terminator back into stream. */
3742 input_line_pointer --;
3743 demand_empty_rest_of_line ();
3744}
b99bd4ef 3745
c19d1205 3746/* Parse a .rel31 directive. */
b99bd4ef 3747
c19d1205
ZW
3748static void
3749s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3750{
3751 expressionS exp;
3752 char *p;
3753 valueT highbit;
b99bd4ef 3754
c19d1205
ZW
3755 highbit = 0;
3756 if (*input_line_pointer == '1')
3757 highbit = 0x80000000;
3758 else if (*input_line_pointer != '0')
3759 as_bad (_("expected 0 or 1"));
b99bd4ef 3760
c19d1205
ZW
3761 input_line_pointer++;
3762 if (*input_line_pointer != ',')
3763 as_bad (_("missing comma"));
3764 input_line_pointer++;
b99bd4ef 3765
c19d1205
ZW
3766#ifdef md_flush_pending_output
3767 md_flush_pending_output ();
3768#endif
b99bd4ef 3769
c19d1205
ZW
3770#ifdef md_cons_align
3771 md_cons_align (4);
3772#endif
b99bd4ef 3773
c19d1205 3774 mapping_state (MAP_DATA);
b99bd4ef 3775
c19d1205 3776 expression (&exp);
b99bd4ef 3777
c19d1205
ZW
3778 p = frag_more (4);
3779 md_number_to_chars (p, highbit, 4);
3780 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3781 BFD_RELOC_ARM_PREL31);
b99bd4ef 3782
c19d1205 3783 demand_empty_rest_of_line ();
b99bd4ef
NC
3784}
3785
c19d1205 3786/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3787
c19d1205 3788/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3789
c19d1205
ZW
3790static void
3791s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3792{
3793 demand_empty_rest_of_line ();
921e5f0a
PB
3794 if (unwind.proc_start)
3795 {
c921be7d 3796 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3797 return;
3798 }
3799
c19d1205
ZW
3800 /* Mark the start of the function. */
3801 unwind.proc_start = expr_build_dot ();
b99bd4ef 3802
c19d1205
ZW
3803 /* Reset the rest of the unwind info. */
3804 unwind.opcode_count = 0;
3805 unwind.table_entry = NULL;
3806 unwind.personality_routine = NULL;
3807 unwind.personality_index = -1;
3808 unwind.frame_size = 0;
3809 unwind.fp_offset = 0;
fdfde340 3810 unwind.fp_reg = REG_SP;
c19d1205
ZW
3811 unwind.fp_used = 0;
3812 unwind.sp_restored = 0;
3813}
b99bd4ef 3814
b99bd4ef 3815
c19d1205
ZW
3816/* Parse a handlerdata directive. Creates the exception handling table entry
3817 for the function. */
b99bd4ef 3818
c19d1205
ZW
3819static void
3820s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3821{
3822 demand_empty_rest_of_line ();
921e5f0a 3823 if (!unwind.proc_start)
c921be7d 3824 as_bad (MISSING_FNSTART);
921e5f0a 3825
c19d1205 3826 if (unwind.table_entry)
6decc662 3827 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3828
c19d1205
ZW
3829 create_unwind_entry (1);
3830}
a737bd4d 3831
c19d1205 3832/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3833
c19d1205
ZW
3834static void
3835s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3836{
3837 long where;
3838 char *ptr;
3839 valueT val;
940b5ce0 3840 unsigned int marked_pr_dependency;
f02232aa 3841
c19d1205 3842 demand_empty_rest_of_line ();
f02232aa 3843
921e5f0a
PB
3844 if (!unwind.proc_start)
3845 {
c921be7d 3846 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3847 return;
3848 }
3849
c19d1205
ZW
3850 /* Add eh table entry. */
3851 if (unwind.table_entry == NULL)
3852 val = create_unwind_entry (0);
3853 else
3854 val = 0;
f02232aa 3855
c19d1205
ZW
3856 /* Add index table entry. This is two words. */
3857 start_unwind_section (unwind.saved_seg, 1);
3858 frag_align (2, 0, 0);
3859 record_alignment (now_seg, 2);
b99bd4ef 3860
c19d1205 3861 ptr = frag_more (8);
5011093d 3862 memset (ptr, 0, 8);
c19d1205 3863 where = frag_now_fix () - 8;
f02232aa 3864
c19d1205
ZW
3865 /* Self relative offset of the function start. */
3866 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3867 BFD_RELOC_ARM_PREL31);
f02232aa 3868
c19d1205
ZW
3869 /* Indicate dependency on EHABI-defined personality routines to the
3870 linker, if it hasn't been done already. */
940b5ce0
DJ
3871 marked_pr_dependency
3872 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3873 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3874 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3875 {
5f4273c7
NC
3876 static const char *const name[] =
3877 {
3878 "__aeabi_unwind_cpp_pr0",
3879 "__aeabi_unwind_cpp_pr1",
3880 "__aeabi_unwind_cpp_pr2"
3881 };
c19d1205
ZW
3882 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3883 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3884 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3885 |= 1 << unwind.personality_index;
c19d1205 3886 }
f02232aa 3887
c19d1205
ZW
3888 if (val)
3889 /* Inline exception table entry. */
3890 md_number_to_chars (ptr + 4, val, 4);
3891 else
3892 /* Self relative offset of the table entry. */
3893 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3894 BFD_RELOC_ARM_PREL31);
f02232aa 3895
c19d1205
ZW
3896 /* Restore the original section. */
3897 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3898
3899 unwind.proc_start = NULL;
c19d1205 3900}
f02232aa 3901
f02232aa 3902
c19d1205 3903/* Parse an unwind_cantunwind directive. */
b99bd4ef 3904
c19d1205
ZW
3905static void
3906s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3907{
3908 demand_empty_rest_of_line ();
921e5f0a 3909 if (!unwind.proc_start)
c921be7d 3910 as_bad (MISSING_FNSTART);
921e5f0a 3911
c19d1205
ZW
3912 if (unwind.personality_routine || unwind.personality_index != -1)
3913 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3914
c19d1205
ZW
3915 unwind.personality_index = -2;
3916}
b99bd4ef 3917
b99bd4ef 3918
c19d1205 3919/* Parse a personalityindex directive. */
b99bd4ef 3920
c19d1205
ZW
3921static void
3922s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3923{
3924 expressionS exp;
b99bd4ef 3925
921e5f0a 3926 if (!unwind.proc_start)
c921be7d 3927 as_bad (MISSING_FNSTART);
921e5f0a 3928
c19d1205
ZW
3929 if (unwind.personality_routine || unwind.personality_index != -1)
3930 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3931
c19d1205 3932 expression (&exp);
b99bd4ef 3933
c19d1205
ZW
3934 if (exp.X_op != O_constant
3935 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3936 {
c19d1205
ZW
3937 as_bad (_("bad personality routine number"));
3938 ignore_rest_of_line ();
3939 return;
b99bd4ef
NC
3940 }
3941
c19d1205 3942 unwind.personality_index = exp.X_add_number;
b99bd4ef 3943
c19d1205
ZW
3944 demand_empty_rest_of_line ();
3945}
e16bb312 3946
e16bb312 3947
c19d1205 3948/* Parse a personality directive. */
e16bb312 3949
c19d1205
ZW
3950static void
3951s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3952{
3953 char *name, *p, c;
a737bd4d 3954
921e5f0a 3955 if (!unwind.proc_start)
c921be7d 3956 as_bad (MISSING_FNSTART);
921e5f0a 3957
c19d1205
ZW
3958 if (unwind.personality_routine || unwind.personality_index != -1)
3959 as_bad (_("duplicate .personality directive"));
a737bd4d 3960
d02603dc 3961 c = get_symbol_name (& name);
c19d1205 3962 p = input_line_pointer;
d02603dc
NC
3963 if (c == '"')
3964 ++ input_line_pointer;
c19d1205
ZW
3965 unwind.personality_routine = symbol_find_or_make (name);
3966 *p = c;
3967 demand_empty_rest_of_line ();
3968}
e16bb312 3969
e16bb312 3970
c19d1205 3971/* Parse a directive saving core registers. */
e16bb312 3972
c19d1205
ZW
3973static void
3974s_arm_unwind_save_core (void)
e16bb312 3975{
c19d1205
ZW
3976 valueT op;
3977 long range;
3978 int n;
e16bb312 3979
c19d1205
ZW
3980 range = parse_reg_list (&input_line_pointer);
3981 if (range == FAIL)
e16bb312 3982 {
c19d1205
ZW
3983 as_bad (_("expected register list"));
3984 ignore_rest_of_line ();
3985 return;
3986 }
e16bb312 3987
c19d1205 3988 demand_empty_rest_of_line ();
e16bb312 3989
c19d1205
ZW
3990 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3991 into .unwind_save {..., sp...}. We aren't bothered about the value of
3992 ip because it is clobbered by calls. */
3993 if (unwind.sp_restored && unwind.fp_reg == 12
3994 && (range & 0x3000) == 0x1000)
3995 {
3996 unwind.opcode_count--;
3997 unwind.sp_restored = 0;
3998 range = (range | 0x2000) & ~0x1000;
3999 unwind.pending_offset = 0;
4000 }
e16bb312 4001
01ae4198
DJ
4002 /* Pop r4-r15. */
4003 if (range & 0xfff0)
c19d1205 4004 {
01ae4198
DJ
4005 /* See if we can use the short opcodes. These pop a block of up to 8
4006 registers starting with r4, plus maybe r14. */
4007 for (n = 0; n < 8; n++)
4008 {
4009 /* Break at the first non-saved register. */
4010 if ((range & (1 << (n + 4))) == 0)
4011 break;
4012 }
4013 /* See if there are any other bits set. */
4014 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4015 {
4016 /* Use the long form. */
4017 op = 0x8000 | ((range >> 4) & 0xfff);
4018 add_unwind_opcode (op, 2);
4019 }
0dd132b6 4020 else
01ae4198
DJ
4021 {
4022 /* Use the short form. */
4023 if (range & 0x4000)
4024 op = 0xa8; /* Pop r14. */
4025 else
4026 op = 0xa0; /* Do not pop r14. */
4027 op |= (n - 1);
4028 add_unwind_opcode (op, 1);
4029 }
c19d1205 4030 }
0dd132b6 4031
c19d1205
ZW
4032 /* Pop r0-r3. */
4033 if (range & 0xf)
4034 {
4035 op = 0xb100 | (range & 0xf);
4036 add_unwind_opcode (op, 2);
0dd132b6
NC
4037 }
4038
c19d1205
ZW
4039 /* Record the number of bytes pushed. */
4040 for (n = 0; n < 16; n++)
4041 {
4042 if (range & (1 << n))
4043 unwind.frame_size += 4;
4044 }
0dd132b6
NC
4045}
4046
c19d1205
ZW
4047
4048/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4049
4050static void
c19d1205 4051s_arm_unwind_save_fpa (int reg)
b99bd4ef 4052{
c19d1205
ZW
4053 expressionS exp;
4054 int num_regs;
4055 valueT op;
b99bd4ef 4056
c19d1205
ZW
4057 /* Get Number of registers to transfer. */
4058 if (skip_past_comma (&input_line_pointer) != FAIL)
4059 expression (&exp);
4060 else
4061 exp.X_op = O_illegal;
b99bd4ef 4062
c19d1205 4063 if (exp.X_op != O_constant)
b99bd4ef 4064 {
c19d1205
ZW
4065 as_bad (_("expected , <constant>"));
4066 ignore_rest_of_line ();
b99bd4ef
NC
4067 return;
4068 }
4069
c19d1205
ZW
4070 num_regs = exp.X_add_number;
4071
4072 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4073 {
c19d1205
ZW
4074 as_bad (_("number of registers must be in the range [1:4]"));
4075 ignore_rest_of_line ();
b99bd4ef
NC
4076 return;
4077 }
4078
c19d1205 4079 demand_empty_rest_of_line ();
b99bd4ef 4080
c19d1205
ZW
4081 if (reg == 4)
4082 {
4083 /* Short form. */
4084 op = 0xb4 | (num_regs - 1);
4085 add_unwind_opcode (op, 1);
4086 }
b99bd4ef
NC
4087 else
4088 {
c19d1205
ZW
4089 /* Long form. */
4090 op = 0xc800 | (reg << 4) | (num_regs - 1);
4091 add_unwind_opcode (op, 2);
b99bd4ef 4092 }
c19d1205 4093 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4094}
4095
c19d1205 4096
fa073d69
MS
4097/* Parse a directive saving VFP registers for ARMv6 and above. */
4098
4099static void
4100s_arm_unwind_save_vfp_armv6 (void)
4101{
4102 int count;
4103 unsigned int start;
4104 valueT op;
4105 int num_vfpv3_regs = 0;
4106 int num_regs_below_16;
4107
4108 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4109 if (count == FAIL)
4110 {
4111 as_bad (_("expected register list"));
4112 ignore_rest_of_line ();
4113 return;
4114 }
4115
4116 demand_empty_rest_of_line ();
4117
4118 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4119 than FSTMX/FLDMX-style ones). */
4120
4121 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4122 if (start >= 16)
4123 num_vfpv3_regs = count;
4124 else if (start + count > 16)
4125 num_vfpv3_regs = start + count - 16;
4126
4127 if (num_vfpv3_regs > 0)
4128 {
4129 int start_offset = start > 16 ? start - 16 : 0;
4130 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4131 add_unwind_opcode (op, 2);
4132 }
4133
4134 /* Generate opcode for registers numbered in the range 0 .. 15. */
4135 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4136 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4137 if (num_regs_below_16 > 0)
4138 {
4139 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4140 add_unwind_opcode (op, 2);
4141 }
4142
4143 unwind.frame_size += count * 8;
4144}
4145
4146
4147/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4148
4149static void
c19d1205 4150s_arm_unwind_save_vfp (void)
b99bd4ef 4151{
c19d1205 4152 int count;
ca3f61f7 4153 unsigned int reg;
c19d1205 4154 valueT op;
b99bd4ef 4155
5287ad62 4156 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4157 if (count == FAIL)
b99bd4ef 4158 {
c19d1205
ZW
4159 as_bad (_("expected register list"));
4160 ignore_rest_of_line ();
b99bd4ef
NC
4161 return;
4162 }
4163
c19d1205 4164 demand_empty_rest_of_line ();
b99bd4ef 4165
c19d1205 4166 if (reg == 8)
b99bd4ef 4167 {
c19d1205
ZW
4168 /* Short form. */
4169 op = 0xb8 | (count - 1);
4170 add_unwind_opcode (op, 1);
b99bd4ef 4171 }
c19d1205 4172 else
b99bd4ef 4173 {
c19d1205
ZW
4174 /* Long form. */
4175 op = 0xb300 | (reg << 4) | (count - 1);
4176 add_unwind_opcode (op, 2);
b99bd4ef 4177 }
c19d1205
ZW
4178 unwind.frame_size += count * 8 + 4;
4179}
b99bd4ef 4180
b99bd4ef 4181
c19d1205
ZW
4182/* Parse a directive saving iWMMXt data registers. */
4183
4184static void
4185s_arm_unwind_save_mmxwr (void)
4186{
4187 int reg;
4188 int hi_reg;
4189 int i;
4190 unsigned mask = 0;
4191 valueT op;
b99bd4ef 4192
c19d1205
ZW
4193 if (*input_line_pointer == '{')
4194 input_line_pointer++;
b99bd4ef 4195
c19d1205 4196 do
b99bd4ef 4197 {
dcbf9037 4198 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4199
c19d1205 4200 if (reg == FAIL)
b99bd4ef 4201 {
9b7132d3 4202 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4203 goto error;
b99bd4ef
NC
4204 }
4205
c19d1205
ZW
4206 if (mask >> reg)
4207 as_tsktsk (_("register list not in ascending order"));
4208 mask |= 1 << reg;
b99bd4ef 4209
c19d1205
ZW
4210 if (*input_line_pointer == '-')
4211 {
4212 input_line_pointer++;
dcbf9037 4213 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4214 if (hi_reg == FAIL)
4215 {
9b7132d3 4216 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4217 goto error;
4218 }
4219 else if (reg >= hi_reg)
4220 {
4221 as_bad (_("bad register range"));
4222 goto error;
4223 }
4224 for (; reg < hi_reg; reg++)
4225 mask |= 1 << reg;
4226 }
4227 }
4228 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4229
d996d970 4230 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4231
c19d1205 4232 demand_empty_rest_of_line ();
b99bd4ef 4233
708587a4 4234 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4235 the list. */
4236 flush_pending_unwind ();
b99bd4ef 4237
c19d1205 4238 for (i = 0; i < 16; i++)
b99bd4ef 4239 {
c19d1205
ZW
4240 if (mask & (1 << i))
4241 unwind.frame_size += 8;
b99bd4ef
NC
4242 }
4243
c19d1205
ZW
4244 /* Attempt to combine with a previous opcode. We do this because gcc
4245 likes to output separate unwind directives for a single block of
4246 registers. */
4247 if (unwind.opcode_count > 0)
b99bd4ef 4248 {
c19d1205
ZW
4249 i = unwind.opcodes[unwind.opcode_count - 1];
4250 if ((i & 0xf8) == 0xc0)
4251 {
4252 i &= 7;
4253 /* Only merge if the blocks are contiguous. */
4254 if (i < 6)
4255 {
4256 if ((mask & 0xfe00) == (1 << 9))
4257 {
4258 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4259 unwind.opcode_count--;
4260 }
4261 }
4262 else if (i == 6 && unwind.opcode_count >= 2)
4263 {
4264 i = unwind.opcodes[unwind.opcode_count - 2];
4265 reg = i >> 4;
4266 i &= 0xf;
b99bd4ef 4267
c19d1205
ZW
4268 op = 0xffff << (reg - 1);
4269 if (reg > 0
87a1fd79 4270 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4271 {
4272 op = (1 << (reg + i + 1)) - 1;
4273 op &= ~((1 << reg) - 1);
4274 mask |= op;
4275 unwind.opcode_count -= 2;
4276 }
4277 }
4278 }
b99bd4ef
NC
4279 }
4280
c19d1205
ZW
4281 hi_reg = 15;
4282 /* We want to generate opcodes in the order the registers have been
4283 saved, ie. descending order. */
4284 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4285 {
c19d1205
ZW
4286 /* Save registers in blocks. */
4287 if (reg < 0
4288 || !(mask & (1 << reg)))
4289 {
4290 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4291 preceding block. */
c19d1205
ZW
4292 if (reg != hi_reg)
4293 {
4294 if (reg == 9)
4295 {
4296 /* Short form. */
4297 op = 0xc0 | (hi_reg - 10);
4298 add_unwind_opcode (op, 1);
4299 }
4300 else
4301 {
4302 /* Long form. */
4303 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4304 add_unwind_opcode (op, 2);
4305 }
4306 }
4307 hi_reg = reg - 1;
4308 }
b99bd4ef
NC
4309 }
4310
c19d1205
ZW
4311 return;
4312error:
4313 ignore_rest_of_line ();
b99bd4ef
NC
4314}
4315
4316static void
c19d1205 4317s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4318{
c19d1205
ZW
4319 int reg;
4320 int hi_reg;
4321 unsigned mask = 0;
4322 valueT op;
b99bd4ef 4323
c19d1205
ZW
4324 if (*input_line_pointer == '{')
4325 input_line_pointer++;
b99bd4ef 4326
477330fc
RM
4327 skip_whitespace (input_line_pointer);
4328
c19d1205 4329 do
b99bd4ef 4330 {
dcbf9037 4331 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4332
c19d1205
ZW
4333 if (reg == FAIL)
4334 {
9b7132d3 4335 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4336 goto error;
4337 }
b99bd4ef 4338
c19d1205
ZW
4339 reg -= 8;
4340 if (mask >> reg)
4341 as_tsktsk (_("register list not in ascending order"));
4342 mask |= 1 << reg;
b99bd4ef 4343
c19d1205
ZW
4344 if (*input_line_pointer == '-')
4345 {
4346 input_line_pointer++;
dcbf9037 4347 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4348 if (hi_reg == FAIL)
4349 {
9b7132d3 4350 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4351 goto error;
4352 }
4353 else if (reg >= hi_reg)
4354 {
4355 as_bad (_("bad register range"));
4356 goto error;
4357 }
4358 for (; reg < hi_reg; reg++)
4359 mask |= 1 << reg;
4360 }
b99bd4ef 4361 }
c19d1205 4362 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4363
d996d970 4364 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4365
c19d1205
ZW
4366 demand_empty_rest_of_line ();
4367
708587a4 4368 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4369 the list. */
4370 flush_pending_unwind ();
b99bd4ef 4371
c19d1205 4372 for (reg = 0; reg < 16; reg++)
b99bd4ef 4373 {
c19d1205
ZW
4374 if (mask & (1 << reg))
4375 unwind.frame_size += 4;
b99bd4ef 4376 }
c19d1205
ZW
4377 op = 0xc700 | mask;
4378 add_unwind_opcode (op, 2);
4379 return;
4380error:
4381 ignore_rest_of_line ();
b99bd4ef
NC
4382}
4383
c19d1205 4384
fa073d69
MS
4385/* Parse an unwind_save directive.
4386 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4387
b99bd4ef 4388static void
fa073d69 4389s_arm_unwind_save (int arch_v6)
b99bd4ef 4390{
c19d1205
ZW
4391 char *peek;
4392 struct reg_entry *reg;
4393 bfd_boolean had_brace = FALSE;
b99bd4ef 4394
921e5f0a 4395 if (!unwind.proc_start)
c921be7d 4396 as_bad (MISSING_FNSTART);
921e5f0a 4397
c19d1205
ZW
4398 /* Figure out what sort of save we have. */
4399 peek = input_line_pointer;
b99bd4ef 4400
c19d1205 4401 if (*peek == '{')
b99bd4ef 4402 {
c19d1205
ZW
4403 had_brace = TRUE;
4404 peek++;
b99bd4ef
NC
4405 }
4406
c19d1205 4407 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4408
c19d1205 4409 if (!reg)
b99bd4ef 4410 {
c19d1205
ZW
4411 as_bad (_("register expected"));
4412 ignore_rest_of_line ();
b99bd4ef
NC
4413 return;
4414 }
4415
c19d1205 4416 switch (reg->type)
b99bd4ef 4417 {
c19d1205
ZW
4418 case REG_TYPE_FN:
4419 if (had_brace)
4420 {
4421 as_bad (_("FPA .unwind_save does not take a register list"));
4422 ignore_rest_of_line ();
4423 return;
4424 }
93ac2687 4425 input_line_pointer = peek;
c19d1205 4426 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4427 return;
c19d1205 4428
1f5afe1c
NC
4429 case REG_TYPE_RN:
4430 s_arm_unwind_save_core ();
4431 return;
4432
fa073d69
MS
4433 case REG_TYPE_VFD:
4434 if (arch_v6)
477330fc 4435 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4436 else
477330fc 4437 s_arm_unwind_save_vfp ();
fa073d69 4438 return;
1f5afe1c
NC
4439
4440 case REG_TYPE_MMXWR:
4441 s_arm_unwind_save_mmxwr ();
4442 return;
4443
4444 case REG_TYPE_MMXWCG:
4445 s_arm_unwind_save_mmxwcg ();
4446 return;
c19d1205
ZW
4447
4448 default:
4449 as_bad (_(".unwind_save does not support this kind of register"));
4450 ignore_rest_of_line ();
b99bd4ef 4451 }
c19d1205 4452}
b99bd4ef 4453
b99bd4ef 4454
c19d1205
ZW
4455/* Parse an unwind_movsp directive. */
4456
4457static void
4458s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4459{
4460 int reg;
4461 valueT op;
4fa3602b 4462 int offset;
c19d1205 4463
921e5f0a 4464 if (!unwind.proc_start)
c921be7d 4465 as_bad (MISSING_FNSTART);
921e5f0a 4466
dcbf9037 4467 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4468 if (reg == FAIL)
b99bd4ef 4469 {
9b7132d3 4470 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4471 ignore_rest_of_line ();
b99bd4ef
NC
4472 return;
4473 }
4fa3602b
PB
4474
4475 /* Optional constant. */
4476 if (skip_past_comma (&input_line_pointer) != FAIL)
4477 {
4478 if (immediate_for_directive (&offset) == FAIL)
4479 return;
4480 }
4481 else
4482 offset = 0;
4483
c19d1205 4484 demand_empty_rest_of_line ();
b99bd4ef 4485
c19d1205 4486 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4487 {
c19d1205 4488 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4489 return;
4490 }
4491
c19d1205
ZW
4492 if (unwind.fp_reg != REG_SP)
4493 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4494
c19d1205
ZW
4495 /* Generate opcode to restore the value. */
4496 op = 0x90 | reg;
4497 add_unwind_opcode (op, 1);
4498
4499 /* Record the information for later. */
4500 unwind.fp_reg = reg;
4fa3602b 4501 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4502 unwind.sp_restored = 1;
b05fe5cf
ZW
4503}
4504
c19d1205
ZW
4505/* Parse an unwind_pad directive. */
4506
b05fe5cf 4507static void
c19d1205 4508s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4509{
c19d1205 4510 int offset;
b05fe5cf 4511
921e5f0a 4512 if (!unwind.proc_start)
c921be7d 4513 as_bad (MISSING_FNSTART);
921e5f0a 4514
c19d1205
ZW
4515 if (immediate_for_directive (&offset) == FAIL)
4516 return;
b99bd4ef 4517
c19d1205
ZW
4518 if (offset & 3)
4519 {
4520 as_bad (_("stack increment must be multiple of 4"));
4521 ignore_rest_of_line ();
4522 return;
4523 }
b99bd4ef 4524
c19d1205
ZW
4525 /* Don't generate any opcodes, just record the details for later. */
4526 unwind.frame_size += offset;
4527 unwind.pending_offset += offset;
4528
4529 demand_empty_rest_of_line ();
4530}
4531
4532/* Parse an unwind_setfp directive. */
4533
4534static void
4535s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4536{
c19d1205
ZW
4537 int sp_reg;
4538 int fp_reg;
4539 int offset;
4540
921e5f0a 4541 if (!unwind.proc_start)
c921be7d 4542 as_bad (MISSING_FNSTART);
921e5f0a 4543
dcbf9037 4544 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4545 if (skip_past_comma (&input_line_pointer) == FAIL)
4546 sp_reg = FAIL;
4547 else
dcbf9037 4548 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4549
c19d1205
ZW
4550 if (fp_reg == FAIL || sp_reg == FAIL)
4551 {
4552 as_bad (_("expected <reg>, <reg>"));
4553 ignore_rest_of_line ();
4554 return;
4555 }
b99bd4ef 4556
c19d1205
ZW
4557 /* Optional constant. */
4558 if (skip_past_comma (&input_line_pointer) != FAIL)
4559 {
4560 if (immediate_for_directive (&offset) == FAIL)
4561 return;
4562 }
4563 else
4564 offset = 0;
a737bd4d 4565
c19d1205 4566 demand_empty_rest_of_line ();
a737bd4d 4567
fdfde340 4568 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4569 {
c19d1205
ZW
4570 as_bad (_("register must be either sp or set by a previous"
4571 "unwind_movsp directive"));
4572 return;
a737bd4d
NC
4573 }
4574
c19d1205
ZW
4575 /* Don't generate any opcodes, just record the information for later. */
4576 unwind.fp_reg = fp_reg;
4577 unwind.fp_used = 1;
fdfde340 4578 if (sp_reg == REG_SP)
c19d1205
ZW
4579 unwind.fp_offset = unwind.frame_size - offset;
4580 else
4581 unwind.fp_offset -= offset;
a737bd4d
NC
4582}
4583
c19d1205
ZW
4584/* Parse an unwind_raw directive. */
4585
4586static void
4587s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4588{
c19d1205 4589 expressionS exp;
708587a4 4590 /* This is an arbitrary limit. */
c19d1205
ZW
4591 unsigned char op[16];
4592 int count;
a737bd4d 4593
921e5f0a 4594 if (!unwind.proc_start)
c921be7d 4595 as_bad (MISSING_FNSTART);
921e5f0a 4596
c19d1205
ZW
4597 expression (&exp);
4598 if (exp.X_op == O_constant
4599 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4600 {
c19d1205
ZW
4601 unwind.frame_size += exp.X_add_number;
4602 expression (&exp);
4603 }
4604 else
4605 exp.X_op = O_illegal;
a737bd4d 4606
c19d1205
ZW
4607 if (exp.X_op != O_constant)
4608 {
4609 as_bad (_("expected <offset>, <opcode>"));
4610 ignore_rest_of_line ();
4611 return;
4612 }
a737bd4d 4613
c19d1205 4614 count = 0;
a737bd4d 4615
c19d1205
ZW
4616 /* Parse the opcode. */
4617 for (;;)
4618 {
4619 if (count >= 16)
4620 {
4621 as_bad (_("unwind opcode too long"));
4622 ignore_rest_of_line ();
a737bd4d 4623 }
c19d1205 4624 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4625 {
c19d1205
ZW
4626 as_bad (_("invalid unwind opcode"));
4627 ignore_rest_of_line ();
4628 return;
a737bd4d 4629 }
c19d1205 4630 op[count++] = exp.X_add_number;
a737bd4d 4631
c19d1205
ZW
4632 /* Parse the next byte. */
4633 if (skip_past_comma (&input_line_pointer) == FAIL)
4634 break;
a737bd4d 4635
c19d1205
ZW
4636 expression (&exp);
4637 }
b99bd4ef 4638
c19d1205
ZW
4639 /* Add the opcode bytes in reverse order. */
4640 while (count--)
4641 add_unwind_opcode (op[count], 1);
b99bd4ef 4642
c19d1205 4643 demand_empty_rest_of_line ();
b99bd4ef 4644}
ee065d83
PB
4645
4646
4647/* Parse a .eabi_attribute directive. */
4648
4649static void
4650s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4651{
0420f52b 4652 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4653
4654 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4655 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4656}
4657
0855e32b
NS
4658/* Emit a tls fix for the symbol. */
4659
4660static void
4661s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4662{
4663 char *p;
4664 expressionS exp;
4665#ifdef md_flush_pending_output
4666 md_flush_pending_output ();
4667#endif
4668
4669#ifdef md_cons_align
4670 md_cons_align (4);
4671#endif
4672
4673 /* Since we're just labelling the code, there's no need to define a
4674 mapping symbol. */
4675 expression (&exp);
4676 p = obstack_next_free (&frchain_now->frch_obstack);
4677 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4678 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4679 : BFD_RELOC_ARM_TLS_DESCSEQ);
4680}
cdf9ccec 4681#endif /* OBJ_ELF */
0855e32b 4682
ee065d83 4683static void s_arm_arch (int);
7a1d4c38 4684static void s_arm_object_arch (int);
ee065d83
PB
4685static void s_arm_cpu (int);
4686static void s_arm_fpu (int);
69133863 4687static void s_arm_arch_extension (int);
b99bd4ef 4688
f0927246
NC
4689#ifdef TE_PE
4690
4691static void
5f4273c7 4692pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4693{
4694 expressionS exp;
4695
4696 do
4697 {
4698 expression (&exp);
4699 if (exp.X_op == O_symbol)
4700 exp.X_op = O_secrel;
4701
4702 emit_expr (&exp, 4);
4703 }
4704 while (*input_line_pointer++ == ',');
4705
4706 input_line_pointer--;
4707 demand_empty_rest_of_line ();
4708}
4709#endif /* TE_PE */
4710
c19d1205
ZW
4711/* This table describes all the machine specific pseudo-ops the assembler
4712 has to support. The fields are:
4713 pseudo-op name without dot
4714 function to call to execute this pseudo-op
4715 Integer arg to pass to the function. */
b99bd4ef 4716
c19d1205 4717const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4718{
c19d1205
ZW
4719 /* Never called because '.req' does not start a line. */
4720 { "req", s_req, 0 },
dcbf9037
JB
4721 /* Following two are likewise never called. */
4722 { "dn", s_dn, 0 },
4723 { "qn", s_qn, 0 },
c19d1205
ZW
4724 { "unreq", s_unreq, 0 },
4725 { "bss", s_bss, 0 },
db2ed2e0 4726 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4727 { "arm", s_arm, 0 },
4728 { "thumb", s_thumb, 0 },
4729 { "code", s_code, 0 },
4730 { "force_thumb", s_force_thumb, 0 },
4731 { "thumb_func", s_thumb_func, 0 },
4732 { "thumb_set", s_thumb_set, 0 },
4733 { "even", s_even, 0 },
4734 { "ltorg", s_ltorg, 0 },
4735 { "pool", s_ltorg, 0 },
4736 { "syntax", s_syntax, 0 },
8463be01
PB
4737 { "cpu", s_arm_cpu, 0 },
4738 { "arch", s_arm_arch, 0 },
7a1d4c38 4739 { "object_arch", s_arm_object_arch, 0 },
8463be01 4740 { "fpu", s_arm_fpu, 0 },
69133863 4741 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4742#ifdef OBJ_ELF
c921be7d
NC
4743 { "word", s_arm_elf_cons, 4 },
4744 { "long", s_arm_elf_cons, 4 },
4745 { "inst.n", s_arm_elf_inst, 2 },
4746 { "inst.w", s_arm_elf_inst, 4 },
4747 { "inst", s_arm_elf_inst, 0 },
4748 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4749 { "fnstart", s_arm_unwind_fnstart, 0 },
4750 { "fnend", s_arm_unwind_fnend, 0 },
4751 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4752 { "personality", s_arm_unwind_personality, 0 },
4753 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4754 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4755 { "save", s_arm_unwind_save, 0 },
fa073d69 4756 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4757 { "movsp", s_arm_unwind_movsp, 0 },
4758 { "pad", s_arm_unwind_pad, 0 },
4759 { "setfp", s_arm_unwind_setfp, 0 },
4760 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4761 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4762 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4763#else
4764 { "word", cons, 4},
f0927246
NC
4765
4766 /* These are used for dwarf. */
4767 {"2byte", cons, 2},
4768 {"4byte", cons, 4},
4769 {"8byte", cons, 8},
4770 /* These are used for dwarf2. */
68d20676 4771 { "file", dwarf2_directive_file, 0 },
f0927246
NC
4772 { "loc", dwarf2_directive_loc, 0 },
4773 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4774#endif
4775 { "extend", float_cons, 'x' },
4776 { "ldouble", float_cons, 'x' },
4777 { "packed", float_cons, 'p' },
f0927246
NC
4778#ifdef TE_PE
4779 {"secrel32", pe_directive_secrel, 0},
4780#endif
2e6976a8
DG
4781
4782 /* These are for compatibility with CodeComposer Studio. */
4783 {"ref", s_ccs_ref, 0},
4784 {"def", s_ccs_def, 0},
4785 {"asmfunc", s_ccs_asmfunc, 0},
4786 {"endasmfunc", s_ccs_endasmfunc, 0},
4787
c19d1205
ZW
4788 { 0, 0, 0 }
4789};
4790\f
4791/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4792
c19d1205
ZW
4793/* Generic immediate-value read function for use in insn parsing.
4794 STR points to the beginning of the immediate (the leading #);
4795 VAL receives the value; if the value is outside [MIN, MAX]
4796 issue an error. PREFIX_OPT is true if the immediate prefix is
4797 optional. */
b99bd4ef 4798
c19d1205
ZW
4799static int
4800parse_immediate (char **str, int *val, int min, int max,
4801 bfd_boolean prefix_opt)
4802{
4803 expressionS exp;
0198d5e6 4804
c19d1205
ZW
4805 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4806 if (exp.X_op != O_constant)
b99bd4ef 4807 {
c19d1205
ZW
4808 inst.error = _("constant expression required");
4809 return FAIL;
4810 }
b99bd4ef 4811
c19d1205
ZW
4812 if (exp.X_add_number < min || exp.X_add_number > max)
4813 {
4814 inst.error = _("immediate value out of range");
4815 return FAIL;
4816 }
b99bd4ef 4817
c19d1205
ZW
4818 *val = exp.X_add_number;
4819 return SUCCESS;
4820}
b99bd4ef 4821
5287ad62 4822/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4823 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4824 instructions. Puts the result directly in inst.operands[i]. */
4825
4826static int
8335d6aa
JW
4827parse_big_immediate (char **str, int i, expressionS *in_exp,
4828 bfd_boolean allow_symbol_p)
5287ad62
JB
4829{
4830 expressionS exp;
8335d6aa 4831 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4832 char *ptr = *str;
4833
8335d6aa 4834 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4835
8335d6aa 4836 if (exp_p->X_op == O_constant)
036dc3f7 4837 {
8335d6aa 4838 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4839 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4840 O_constant. We have to be careful not to break compilation for
4841 32-bit X_add_number, though. */
8335d6aa 4842 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4843 {
8335d6aa
JW
4844 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4845 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4846 & 0xffffffff);
036dc3f7
PB
4847 inst.operands[i].regisimm = 1;
4848 }
4849 }
8335d6aa
JW
4850 else if (exp_p->X_op == O_big
4851 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4852 {
4853 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4854
5287ad62 4855 /* Bignums have their least significant bits in
477330fc
RM
4856 generic_bignum[0]. Make sure we put 32 bits in imm and
4857 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4858 gas_assert (parts != 0);
95b75c01
NC
4859
4860 /* Make sure that the number is not too big.
4861 PR 11972: Bignums can now be sign-extended to the
4862 size of a .octa so check that the out of range bits
4863 are all zero or all one. */
8335d6aa 4864 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4865 {
4866 LITTLENUM_TYPE m = -1;
4867
4868 if (generic_bignum[parts * 2] != 0
4869 && generic_bignum[parts * 2] != m)
4870 return FAIL;
4871
8335d6aa 4872 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4873 if (generic_bignum[j] != generic_bignum[j-1])
4874 return FAIL;
4875 }
4876
5287ad62
JB
4877 inst.operands[i].imm = 0;
4878 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4879 inst.operands[i].imm |= generic_bignum[idx]
4880 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4881 inst.operands[i].reg = 0;
4882 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4883 inst.operands[i].reg |= generic_bignum[idx]
4884 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4885 inst.operands[i].regisimm = 1;
4886 }
8335d6aa 4887 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4888 return FAIL;
5f4273c7 4889
5287ad62
JB
4890 *str = ptr;
4891
4892 return SUCCESS;
4893}
4894
c19d1205
ZW
4895/* Returns the pseudo-register number of an FPA immediate constant,
4896 or FAIL if there isn't a valid constant here. */
b99bd4ef 4897
c19d1205
ZW
4898static int
4899parse_fpa_immediate (char ** str)
4900{
4901 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4902 char * save_in;
4903 expressionS exp;
4904 int i;
4905 int j;
b99bd4ef 4906
c19d1205
ZW
4907 /* First try and match exact strings, this is to guarantee
4908 that some formats will work even for cross assembly. */
b99bd4ef 4909
c19d1205
ZW
4910 for (i = 0; fp_const[i]; i++)
4911 {
4912 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4913 {
c19d1205 4914 char *start = *str;
b99bd4ef 4915
c19d1205
ZW
4916 *str += strlen (fp_const[i]);
4917 if (is_end_of_line[(unsigned char) **str])
4918 return i + 8;
4919 *str = start;
4920 }
4921 }
b99bd4ef 4922
c19d1205
ZW
4923 /* Just because we didn't get a match doesn't mean that the constant
4924 isn't valid, just that it is in a format that we don't
4925 automatically recognize. Try parsing it with the standard
4926 expression routines. */
b99bd4ef 4927
c19d1205 4928 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4929
c19d1205
ZW
4930 /* Look for a raw floating point number. */
4931 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4932 && is_end_of_line[(unsigned char) *save_in])
4933 {
4934 for (i = 0; i < NUM_FLOAT_VALS; i++)
4935 {
4936 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4937 {
c19d1205
ZW
4938 if (words[j] != fp_values[i][j])
4939 break;
b99bd4ef
NC
4940 }
4941
c19d1205 4942 if (j == MAX_LITTLENUMS)
b99bd4ef 4943 {
c19d1205
ZW
4944 *str = save_in;
4945 return i + 8;
b99bd4ef
NC
4946 }
4947 }
4948 }
b99bd4ef 4949
c19d1205
ZW
4950 /* Try and parse a more complex expression, this will probably fail
4951 unless the code uses a floating point prefix (eg "0f"). */
4952 save_in = input_line_pointer;
4953 input_line_pointer = *str;
4954 if (expression (&exp) == absolute_section
4955 && exp.X_op == O_big
4956 && exp.X_add_number < 0)
4957 {
4958 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4959 Ditto for 15. */
ba592044
AM
4960#define X_PRECISION 5
4961#define E_PRECISION 15L
4962 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4963 {
4964 for (i = 0; i < NUM_FLOAT_VALS; i++)
4965 {
4966 for (j = 0; j < MAX_LITTLENUMS; j++)
4967 {
4968 if (words[j] != fp_values[i][j])
4969 break;
4970 }
b99bd4ef 4971
c19d1205
ZW
4972 if (j == MAX_LITTLENUMS)
4973 {
4974 *str = input_line_pointer;
4975 input_line_pointer = save_in;
4976 return i + 8;
4977 }
4978 }
4979 }
b99bd4ef
NC
4980 }
4981
c19d1205
ZW
4982 *str = input_line_pointer;
4983 input_line_pointer = save_in;
4984 inst.error = _("invalid FPA immediate expression");
4985 return FAIL;
b99bd4ef
NC
4986}
4987
136da414
JB
4988/* Returns 1 if a number has "quarter-precision" float format
4989 0baBbbbbbc defgh000 00000000 00000000. */
4990
4991static int
4992is_quarter_float (unsigned imm)
4993{
4994 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4995 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4996}
4997
aacf0b33
KT
4998
4999/* Detect the presence of a floating point or integer zero constant,
5000 i.e. #0.0 or #0. */
5001
5002static bfd_boolean
5003parse_ifimm_zero (char **in)
5004{
5005 int error_code;
5006
5007 if (!is_immediate_prefix (**in))
3c6452ae
TP
5008 {
5009 /* In unified syntax, all prefixes are optional. */
5010 if (!unified_syntax)
5011 return FALSE;
5012 }
5013 else
5014 ++*in;
0900a05b
JW
5015
5016 /* Accept #0x0 as a synonym for #0. */
5017 if (strncmp (*in, "0x", 2) == 0)
5018 {
5019 int val;
5020 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5021 return FALSE;
5022 return TRUE;
5023 }
5024
aacf0b33
KT
5025 error_code = atof_generic (in, ".", EXP_CHARS,
5026 &generic_floating_point_number);
5027
5028 if (!error_code
5029 && generic_floating_point_number.sign == '+'
5030 && (generic_floating_point_number.low
5031 > generic_floating_point_number.leader))
5032 return TRUE;
5033
5034 return FALSE;
5035}
5036
136da414
JB
5037/* Parse an 8-bit "quarter-precision" floating point number of the form:
5038 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5039 The zero and minus-zero cases need special handling, since they can't be
5040 encoded in the "quarter-precision" float format, but can nonetheless be
5041 loaded as integer constants. */
136da414
JB
5042
5043static unsigned
5044parse_qfloat_immediate (char **ccp, int *immed)
5045{
5046 char *str = *ccp;
c96612cc 5047 char *fpnum;
136da414 5048 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5049 int found_fpchar = 0;
5f4273c7 5050
136da414 5051 skip_past_char (&str, '#');
5f4273c7 5052
c96612cc
JB
5053 /* We must not accidentally parse an integer as a floating-point number. Make
5054 sure that the value we parse is not an integer by checking for special
5055 characters '.' or 'e'.
5056 FIXME: This is a horrible hack, but doing better is tricky because type
5057 information isn't in a very usable state at parse time. */
5058 fpnum = str;
5059 skip_whitespace (fpnum);
5060
5061 if (strncmp (fpnum, "0x", 2) == 0)
5062 return FAIL;
5063 else
5064 {
5065 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5066 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5067 {
5068 found_fpchar = 1;
5069 break;
5070 }
c96612cc
JB
5071
5072 if (!found_fpchar)
477330fc 5073 return FAIL;
c96612cc 5074 }
5f4273c7 5075
136da414
JB
5076 if ((str = atof_ieee (str, 's', words)) != NULL)
5077 {
5078 unsigned fpword = 0;
5079 int i;
5f4273c7 5080
136da414
JB
5081 /* Our FP word must be 32 bits (single-precision FP). */
5082 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5083 {
5084 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5085 fpword |= words[i];
5086 }
5f4273c7 5087
c96612cc 5088 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5089 *immed = fpword;
136da414 5090 else
477330fc 5091 return FAIL;
136da414
JB
5092
5093 *ccp = str;
5f4273c7 5094
136da414
JB
5095 return SUCCESS;
5096 }
5f4273c7 5097
136da414
JB
5098 return FAIL;
5099}
5100
c19d1205
ZW
5101/* Shift operands. */
5102enum shift_kind
b99bd4ef 5103{
c19d1205
ZW
5104 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5105};
b99bd4ef 5106
c19d1205
ZW
5107struct asm_shift_name
5108{
5109 const char *name;
5110 enum shift_kind kind;
5111};
b99bd4ef 5112
c19d1205
ZW
5113/* Third argument to parse_shift. */
5114enum parse_shift_mode
5115{
5116 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5117 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5118 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5119 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5120 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5121};
b99bd4ef 5122
c19d1205
ZW
5123/* Parse a <shift> specifier on an ARM data processing instruction.
5124 This has three forms:
b99bd4ef 5125
c19d1205
ZW
5126 (LSL|LSR|ASL|ASR|ROR) Rs
5127 (LSL|LSR|ASL|ASR|ROR) #imm
5128 RRX
b99bd4ef 5129
c19d1205
ZW
5130 Note that ASL is assimilated to LSL in the instruction encoding, and
5131 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5132
c19d1205
ZW
5133static int
5134parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5135{
c19d1205
ZW
5136 const struct asm_shift_name *shift_name;
5137 enum shift_kind shift;
5138 char *s = *str;
5139 char *p = s;
5140 int reg;
b99bd4ef 5141
c19d1205
ZW
5142 for (p = *str; ISALPHA (*p); p++)
5143 ;
b99bd4ef 5144
c19d1205 5145 if (p == *str)
b99bd4ef 5146 {
c19d1205
ZW
5147 inst.error = _("shift expression expected");
5148 return FAIL;
b99bd4ef
NC
5149 }
5150
21d799b5 5151 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5152 p - *str);
c19d1205
ZW
5153
5154 if (shift_name == NULL)
b99bd4ef 5155 {
c19d1205
ZW
5156 inst.error = _("shift expression expected");
5157 return FAIL;
b99bd4ef
NC
5158 }
5159
c19d1205 5160 shift = shift_name->kind;
b99bd4ef 5161
c19d1205
ZW
5162 switch (mode)
5163 {
5164 case NO_SHIFT_RESTRICT:
5165 case SHIFT_IMMEDIATE: break;
b99bd4ef 5166
c19d1205
ZW
5167 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5168 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5169 {
5170 inst.error = _("'LSL' or 'ASR' required");
5171 return FAIL;
5172 }
5173 break;
b99bd4ef 5174
c19d1205
ZW
5175 case SHIFT_LSL_IMMEDIATE:
5176 if (shift != SHIFT_LSL)
5177 {
5178 inst.error = _("'LSL' required");
5179 return FAIL;
5180 }
5181 break;
b99bd4ef 5182
c19d1205
ZW
5183 case SHIFT_ASR_IMMEDIATE:
5184 if (shift != SHIFT_ASR)
5185 {
5186 inst.error = _("'ASR' required");
5187 return FAIL;
5188 }
5189 break;
b99bd4ef 5190
c19d1205
ZW
5191 default: abort ();
5192 }
b99bd4ef 5193
c19d1205
ZW
5194 if (shift != SHIFT_RRX)
5195 {
5196 /* Whitespace can appear here if the next thing is a bare digit. */
5197 skip_whitespace (p);
b99bd4ef 5198
c19d1205 5199 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5200 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5201 {
5202 inst.operands[i].imm = reg;
5203 inst.operands[i].immisreg = 1;
5204 }
5205 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5206 return FAIL;
5207 }
5208 inst.operands[i].shift_kind = shift;
5209 inst.operands[i].shifted = 1;
5210 *str = p;
5211 return SUCCESS;
b99bd4ef
NC
5212}
5213
c19d1205 5214/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5215
c19d1205
ZW
5216 #<immediate>
5217 #<immediate>, <rotate>
5218 <Rm>
5219 <Rm>, <shift>
b99bd4ef 5220
c19d1205
ZW
5221 where <shift> is defined by parse_shift above, and <rotate> is a
5222 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5223 is deferred to md_apply_fix. */
b99bd4ef 5224
c19d1205
ZW
5225static int
5226parse_shifter_operand (char **str, int i)
5227{
5228 int value;
91d6fa6a 5229 expressionS exp;
b99bd4ef 5230
dcbf9037 5231 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5232 {
5233 inst.operands[i].reg = value;
5234 inst.operands[i].isreg = 1;
b99bd4ef 5235
c19d1205
ZW
5236 /* parse_shift will override this if appropriate */
5237 inst.reloc.exp.X_op = O_constant;
5238 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5239
c19d1205
ZW
5240 if (skip_past_comma (str) == FAIL)
5241 return SUCCESS;
b99bd4ef 5242
c19d1205
ZW
5243 /* Shift operation on register. */
5244 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5245 }
5246
c19d1205
ZW
5247 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5248 return FAIL;
b99bd4ef 5249
c19d1205 5250 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5251 {
c19d1205 5252 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5253 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5254 return FAIL;
b99bd4ef 5255
91d6fa6a 5256 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5257 {
5258 inst.error = _("constant expression expected");
5259 return FAIL;
5260 }
b99bd4ef 5261
91d6fa6a 5262 value = exp.X_add_number;
c19d1205
ZW
5263 if (value < 0 || value > 30 || value % 2 != 0)
5264 {
5265 inst.error = _("invalid rotation");
5266 return FAIL;
5267 }
5268 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5269 {
5270 inst.error = _("invalid constant");
5271 return FAIL;
5272 }
09d92015 5273
a415b1cd
JB
5274 /* Encode as specified. */
5275 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5276 return SUCCESS;
09d92015
MM
5277 }
5278
c19d1205
ZW
5279 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5280 inst.reloc.pc_rel = 0;
5281 return SUCCESS;
09d92015
MM
5282}
5283
4962c51a
MS
5284/* Group relocation information. Each entry in the table contains the
5285 textual name of the relocation as may appear in assembler source
5286 and must end with a colon.
5287 Along with this textual name are the relocation codes to be used if
5288 the corresponding instruction is an ALU instruction (ADD or SUB only),
5289 an LDR, an LDRS, or an LDC. */
5290
5291struct group_reloc_table_entry
5292{
5293 const char *name;
5294 int alu_code;
5295 int ldr_code;
5296 int ldrs_code;
5297 int ldc_code;
5298};
5299
5300typedef enum
5301{
5302 /* Varieties of non-ALU group relocation. */
5303
5304 GROUP_LDR,
5305 GROUP_LDRS,
5306 GROUP_LDC
5307} group_reloc_type;
5308
5309static struct group_reloc_table_entry group_reloc_table[] =
5310 { /* Program counter relative: */
5311 { "pc_g0_nc",
5312 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5313 0, /* LDR */
5314 0, /* LDRS */
5315 0 }, /* LDC */
5316 { "pc_g0",
5317 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5318 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5319 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5320 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5321 { "pc_g1_nc",
5322 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5323 0, /* LDR */
5324 0, /* LDRS */
5325 0 }, /* LDC */
5326 { "pc_g1",
5327 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5328 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5329 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5330 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5331 { "pc_g2",
5332 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5333 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5334 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5335 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5336 /* Section base relative */
5337 { "sb_g0_nc",
5338 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5339 0, /* LDR */
5340 0, /* LDRS */
5341 0 }, /* LDC */
5342 { "sb_g0",
5343 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5344 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5345 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5346 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5347 { "sb_g1_nc",
5348 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5349 0, /* LDR */
5350 0, /* LDRS */
5351 0 }, /* LDC */
5352 { "sb_g1",
5353 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5354 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5355 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5356 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5357 { "sb_g2",
5358 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5359 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5360 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5361 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5362 /* Absolute thumb alu relocations. */
5363 { "lower0_7",
5364 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5365 0, /* LDR. */
5366 0, /* LDRS. */
5367 0 }, /* LDC. */
5368 { "lower8_15",
5369 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5370 0, /* LDR. */
5371 0, /* LDRS. */
5372 0 }, /* LDC. */
5373 { "upper0_7",
5374 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5375 0, /* LDR. */
5376 0, /* LDRS. */
5377 0 }, /* LDC. */
5378 { "upper8_15",
5379 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5380 0, /* LDR. */
5381 0, /* LDRS. */
5382 0 } }; /* LDC. */
4962c51a
MS
5383
5384/* Given the address of a pointer pointing to the textual name of a group
5385 relocation as may appear in assembler source, attempt to find its details
5386 in group_reloc_table. The pointer will be updated to the character after
5387 the trailing colon. On failure, FAIL will be returned; SUCCESS
5388 otherwise. On success, *entry will be updated to point at the relevant
5389 group_reloc_table entry. */
5390
5391static int
5392find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5393{
5394 unsigned int i;
5395 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5396 {
5397 int length = strlen (group_reloc_table[i].name);
5398
5f4273c7
NC
5399 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5400 && (*str)[length] == ':')
477330fc
RM
5401 {
5402 *out = &group_reloc_table[i];
5403 *str += (length + 1);
5404 return SUCCESS;
5405 }
4962c51a
MS
5406 }
5407
5408 return FAIL;
5409}
5410
5411/* Parse a <shifter_operand> for an ARM data processing instruction
5412 (as for parse_shifter_operand) where group relocations are allowed:
5413
5414 #<immediate>
5415 #<immediate>, <rotate>
5416 #:<group_reloc>:<expression>
5417 <Rm>
5418 <Rm>, <shift>
5419
5420 where <group_reloc> is one of the strings defined in group_reloc_table.
5421 The hashes are optional.
5422
5423 Everything else is as for parse_shifter_operand. */
5424
5425static parse_operand_result
5426parse_shifter_operand_group_reloc (char **str, int i)
5427{
5428 /* Determine if we have the sequence of characters #: or just :
5429 coming next. If we do, then we check for a group relocation.
5430 If we don't, punt the whole lot to parse_shifter_operand. */
5431
5432 if (((*str)[0] == '#' && (*str)[1] == ':')
5433 || (*str)[0] == ':')
5434 {
5435 struct group_reloc_table_entry *entry;
5436
5437 if ((*str)[0] == '#')
477330fc 5438 (*str) += 2;
4962c51a 5439 else
477330fc 5440 (*str)++;
4962c51a
MS
5441
5442 /* Try to parse a group relocation. Anything else is an error. */
5443 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5444 {
5445 inst.error = _("unknown group relocation");
5446 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5447 }
4962c51a
MS
5448
5449 /* We now have the group relocation table entry corresponding to
477330fc 5450 the name in the assembler source. Next, we parse the expression. */
4962c51a 5451 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5452 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5453
5454 /* Record the relocation type (always the ALU variant here). */
21d799b5 5455 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5456 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5457
5458 return PARSE_OPERAND_SUCCESS;
5459 }
5460 else
5461 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5462 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5463
5464 /* Never reached. */
5465}
5466
8e560766
MGD
5467/* Parse a Neon alignment expression. Information is written to
5468 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5469
8e560766
MGD
5470 align .imm = align << 8, .immisalign=1, .preind=0 */
5471static parse_operand_result
5472parse_neon_alignment (char **str, int i)
5473{
5474 char *p = *str;
5475 expressionS exp;
5476
5477 my_get_expression (&exp, &p, GE_NO_PREFIX);
5478
5479 if (exp.X_op != O_constant)
5480 {
5481 inst.error = _("alignment must be constant");
5482 return PARSE_OPERAND_FAIL;
5483 }
5484
5485 inst.operands[i].imm = exp.X_add_number << 8;
5486 inst.operands[i].immisalign = 1;
5487 /* Alignments are not pre-indexes. */
5488 inst.operands[i].preind = 0;
5489
5490 *str = p;
5491 return PARSE_OPERAND_SUCCESS;
5492}
5493
c19d1205
ZW
5494/* Parse all forms of an ARM address expression. Information is written
5495 to inst.operands[i] and/or inst.reloc.
09d92015 5496
c19d1205 5497 Preindexed addressing (.preind=1):
09d92015 5498
c19d1205
ZW
5499 [Rn, #offset] .reg=Rn .reloc.exp=offset
5500 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5501 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5502 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5503
c19d1205 5504 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5505
c19d1205 5506 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5507
c19d1205
ZW
5508 [Rn], #offset .reg=Rn .reloc.exp=offset
5509 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5510 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5511 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5512
c19d1205 5513 Unindexed addressing (.preind=0, .postind=0):
09d92015 5514
c19d1205 5515 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5516
c19d1205 5517 Other:
09d92015 5518
c19d1205
ZW
5519 [Rn]{!} shorthand for [Rn,#0]{!}
5520 =immediate .isreg=0 .reloc.exp=immediate
5521 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5522
c19d1205
ZW
5523 It is the caller's responsibility to check for addressing modes not
5524 supported by the instruction, and to set inst.reloc.type. */
5525
4962c51a
MS
5526static parse_operand_result
5527parse_address_main (char **str, int i, int group_relocations,
477330fc 5528 group_reloc_type group_type)
09d92015 5529{
c19d1205
ZW
5530 char *p = *str;
5531 int reg;
09d92015 5532
c19d1205 5533 if (skip_past_char (&p, '[') == FAIL)
09d92015 5534 {
c19d1205
ZW
5535 if (skip_past_char (&p, '=') == FAIL)
5536 {
974da60d 5537 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5538 inst.reloc.pc_rel = 1;
5539 inst.operands[i].reg = REG_PC;
5540 inst.operands[i].isreg = 1;
5541 inst.operands[i].preind = 1;
09d92015 5542
8335d6aa
JW
5543 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5544 return PARSE_OPERAND_FAIL;
5545 }
5546 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5547 /*allow_symbol_p=*/TRUE))
4962c51a 5548 return PARSE_OPERAND_FAIL;
09d92015 5549
c19d1205 5550 *str = p;
4962c51a 5551 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5552 }
5553
8ab8155f
NC
5554 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5555 skip_whitespace (p);
5556
dcbf9037 5557 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5558 {
c19d1205 5559 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5560 return PARSE_OPERAND_FAIL;
09d92015 5561 }
c19d1205
ZW
5562 inst.operands[i].reg = reg;
5563 inst.operands[i].isreg = 1;
09d92015 5564
c19d1205 5565 if (skip_past_comma (&p) == SUCCESS)
09d92015 5566 {
c19d1205 5567 inst.operands[i].preind = 1;
09d92015 5568
c19d1205
ZW
5569 if (*p == '+') p++;
5570 else if (*p == '-') p++, inst.operands[i].negative = 1;
5571
dcbf9037 5572 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5573 {
c19d1205
ZW
5574 inst.operands[i].imm = reg;
5575 inst.operands[i].immisreg = 1;
5576
5577 if (skip_past_comma (&p) == SUCCESS)
5578 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5579 return PARSE_OPERAND_FAIL;
c19d1205 5580 }
5287ad62 5581 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5582 {
5583 /* FIXME: '@' should be used here, but it's filtered out by generic
5584 code before we get to see it here. This may be subject to
5585 change. */
5586 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5587
8e560766
MGD
5588 if (result != PARSE_OPERAND_SUCCESS)
5589 return result;
5590 }
c19d1205
ZW
5591 else
5592 {
5593 if (inst.operands[i].negative)
5594 {
5595 inst.operands[i].negative = 0;
5596 p--;
5597 }
4962c51a 5598
5f4273c7
NC
5599 if (group_relocations
5600 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5601 {
5602 struct group_reloc_table_entry *entry;
5603
477330fc
RM
5604 /* Skip over the #: or : sequence. */
5605 if (*p == '#')
5606 p += 2;
5607 else
5608 p++;
4962c51a
MS
5609
5610 /* Try to parse a group relocation. Anything else is an
477330fc 5611 error. */
4962c51a
MS
5612 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5613 {
5614 inst.error = _("unknown group relocation");
5615 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5616 }
5617
5618 /* We now have the group relocation table entry corresponding to
5619 the name in the assembler source. Next, we parse the
477330fc 5620 expression. */
4962c51a
MS
5621 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5622 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5623
5624 /* Record the relocation type. */
477330fc
RM
5625 switch (group_type)
5626 {
5627 case GROUP_LDR:
5628 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5629 break;
4962c51a 5630
477330fc
RM
5631 case GROUP_LDRS:
5632 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5633 break;
4962c51a 5634
477330fc
RM
5635 case GROUP_LDC:
5636 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5637 break;
4962c51a 5638
477330fc
RM
5639 default:
5640 gas_assert (0);
5641 }
4962c51a 5642
477330fc 5643 if (inst.reloc.type == 0)
4962c51a
MS
5644 {
5645 inst.error = _("this group relocation is not allowed on this instruction");
5646 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5647 }
477330fc
RM
5648 }
5649 else
26d97720
NS
5650 {
5651 char *q = p;
0198d5e6 5652
26d97720
NS
5653 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5654 return PARSE_OPERAND_FAIL;
5655 /* If the offset is 0, find out if it's a +0 or -0. */
5656 if (inst.reloc.exp.X_op == O_constant
5657 && inst.reloc.exp.X_add_number == 0)
5658 {
5659 skip_whitespace (q);
5660 if (*q == '#')
5661 {
5662 q++;
5663 skip_whitespace (q);
5664 }
5665 if (*q == '-')
5666 inst.operands[i].negative = 1;
5667 }
5668 }
09d92015
MM
5669 }
5670 }
8e560766
MGD
5671 else if (skip_past_char (&p, ':') == SUCCESS)
5672 {
5673 /* FIXME: '@' should be used here, but it's filtered out by generic code
5674 before we get to see it here. This may be subject to change. */
5675 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5676
8e560766
MGD
5677 if (result != PARSE_OPERAND_SUCCESS)
5678 return result;
5679 }
09d92015 5680
c19d1205 5681 if (skip_past_char (&p, ']') == FAIL)
09d92015 5682 {
c19d1205 5683 inst.error = _("']' expected");
4962c51a 5684 return PARSE_OPERAND_FAIL;
09d92015
MM
5685 }
5686
c19d1205
ZW
5687 if (skip_past_char (&p, '!') == SUCCESS)
5688 inst.operands[i].writeback = 1;
09d92015 5689
c19d1205 5690 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5691 {
c19d1205
ZW
5692 if (skip_past_char (&p, '{') == SUCCESS)
5693 {
5694 /* [Rn], {expr} - unindexed, with option */
5695 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5696 0, 255, TRUE) == FAIL)
4962c51a 5697 return PARSE_OPERAND_FAIL;
09d92015 5698
c19d1205
ZW
5699 if (skip_past_char (&p, '}') == FAIL)
5700 {
5701 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5702 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5703 }
5704 if (inst.operands[i].preind)
5705 {
5706 inst.error = _("cannot combine index with option");
4962c51a 5707 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5708 }
5709 *str = p;
4962c51a 5710 return PARSE_OPERAND_SUCCESS;
09d92015 5711 }
c19d1205
ZW
5712 else
5713 {
5714 inst.operands[i].postind = 1;
5715 inst.operands[i].writeback = 1;
09d92015 5716
c19d1205
ZW
5717 if (inst.operands[i].preind)
5718 {
5719 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5720 return PARSE_OPERAND_FAIL;
c19d1205 5721 }
09d92015 5722
c19d1205
ZW
5723 if (*p == '+') p++;
5724 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5725
dcbf9037 5726 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5727 {
477330fc
RM
5728 /* We might be using the immediate for alignment already. If we
5729 are, OR the register number into the low-order bits. */
5730 if (inst.operands[i].immisalign)
5731 inst.operands[i].imm |= reg;
5732 else
5733 inst.operands[i].imm = reg;
c19d1205 5734 inst.operands[i].immisreg = 1;
a737bd4d 5735
c19d1205
ZW
5736 if (skip_past_comma (&p) == SUCCESS)
5737 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5738 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5739 }
5740 else
5741 {
26d97720 5742 char *q = p;
0198d5e6 5743
c19d1205
ZW
5744 if (inst.operands[i].negative)
5745 {
5746 inst.operands[i].negative = 0;
5747 p--;
5748 }
5749 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5750 return PARSE_OPERAND_FAIL;
26d97720
NS
5751 /* If the offset is 0, find out if it's a +0 or -0. */
5752 if (inst.reloc.exp.X_op == O_constant
5753 && inst.reloc.exp.X_add_number == 0)
5754 {
5755 skip_whitespace (q);
5756 if (*q == '#')
5757 {
5758 q++;
5759 skip_whitespace (q);
5760 }
5761 if (*q == '-')
5762 inst.operands[i].negative = 1;
5763 }
c19d1205
ZW
5764 }
5765 }
a737bd4d
NC
5766 }
5767
c19d1205
ZW
5768 /* If at this point neither .preind nor .postind is set, we have a
5769 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5770 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5771 {
5772 inst.operands[i].preind = 1;
5773 inst.reloc.exp.X_op = O_constant;
5774 inst.reloc.exp.X_add_number = 0;
5775 }
5776 *str = p;
4962c51a
MS
5777 return PARSE_OPERAND_SUCCESS;
5778}
5779
5780static int
5781parse_address (char **str, int i)
5782{
21d799b5 5783 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5784 ? SUCCESS : FAIL;
4962c51a
MS
5785}
5786
5787static parse_operand_result
5788parse_address_group_reloc (char **str, int i, group_reloc_type type)
5789{
5790 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5791}
5792
b6895b4f
PB
5793/* Parse an operand for a MOVW or MOVT instruction. */
5794static int
5795parse_half (char **str)
5796{
5797 char * p;
5f4273c7 5798
b6895b4f
PB
5799 p = *str;
5800 skip_past_char (&p, '#');
5f4273c7 5801 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5802 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5803 else if (strncasecmp (p, ":upper16:", 9) == 0)
5804 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5805
5806 if (inst.reloc.type != BFD_RELOC_UNUSED)
5807 {
5808 p += 9;
5f4273c7 5809 skip_whitespace (p);
b6895b4f
PB
5810 }
5811
5812 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5813 return FAIL;
5814
5815 if (inst.reloc.type == BFD_RELOC_UNUSED)
5816 {
5817 if (inst.reloc.exp.X_op != O_constant)
5818 {
5819 inst.error = _("constant expression expected");
5820 return FAIL;
5821 }
5822 if (inst.reloc.exp.X_add_number < 0
5823 || inst.reloc.exp.X_add_number > 0xffff)
5824 {
5825 inst.error = _("immediate value out of range");
5826 return FAIL;
5827 }
5828 }
5829 *str = p;
5830 return SUCCESS;
5831}
5832
c19d1205 5833/* Miscellaneous. */
a737bd4d 5834
c19d1205
ZW
5835/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5836 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5837static int
d2cd1205 5838parse_psr (char **str, bfd_boolean lhs)
09d92015 5839{
c19d1205
ZW
5840 char *p;
5841 unsigned long psr_field;
62b3e311
PB
5842 const struct asm_psr *psr;
5843 char *start;
d2cd1205 5844 bfd_boolean is_apsr = FALSE;
ac7f631b 5845 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5846
a4482bb6
NC
5847 /* PR gas/12698: If the user has specified -march=all then m_profile will
5848 be TRUE, but we want to ignore it in this case as we are building for any
5849 CPU type, including non-m variants. */
823d2571 5850 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5851 m_profile = FALSE;
5852
c19d1205
ZW
5853 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5854 feature for ease of use and backwards compatibility. */
5855 p = *str;
62b3e311 5856 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5857 {
5858 if (m_profile)
5859 goto unsupported_psr;
fa94de6b 5860
d2cd1205
JB
5861 psr_field = SPSR_BIT;
5862 }
5863 else if (strncasecmp (p, "CPSR", 4) == 0)
5864 {
5865 if (m_profile)
5866 goto unsupported_psr;
5867
5868 psr_field = 0;
5869 }
5870 else if (strncasecmp (p, "APSR", 4) == 0)
5871 {
5872 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5873 and ARMv7-R architecture CPUs. */
5874 is_apsr = TRUE;
5875 psr_field = 0;
5876 }
5877 else if (m_profile)
62b3e311
PB
5878 {
5879 start = p;
5880 do
5881 p++;
5882 while (ISALNUM (*p) || *p == '_');
5883
d2cd1205
JB
5884 if (strncasecmp (start, "iapsr", 5) == 0
5885 || strncasecmp (start, "eapsr", 5) == 0
5886 || strncasecmp (start, "xpsr", 4) == 0
5887 || strncasecmp (start, "psr", 3) == 0)
5888 p = start + strcspn (start, "rR") + 1;
5889
21d799b5 5890 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5891 p - start);
d2cd1205 5892
62b3e311
PB
5893 if (!psr)
5894 return FAIL;
09d92015 5895
d2cd1205
JB
5896 /* If APSR is being written, a bitfield may be specified. Note that
5897 APSR itself is handled above. */
5898 if (psr->field <= 3)
5899 {
5900 psr_field = psr->field;
5901 is_apsr = TRUE;
5902 goto check_suffix;
5903 }
5904
62b3e311 5905 *str = p;
d2cd1205
JB
5906 /* M-profile MSR instructions have the mask field set to "10", except
5907 *PSR variants which modify APSR, which may use a different mask (and
5908 have been handled already). Do that by setting the PSR_f field
5909 here. */
5910 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5911 }
d2cd1205
JB
5912 else
5913 goto unsupported_psr;
09d92015 5914
62b3e311 5915 p += 4;
d2cd1205 5916check_suffix:
c19d1205
ZW
5917 if (*p == '_')
5918 {
5919 /* A suffix follows. */
c19d1205
ZW
5920 p++;
5921 start = p;
a737bd4d 5922
c19d1205
ZW
5923 do
5924 p++;
5925 while (ISALNUM (*p) || *p == '_');
a737bd4d 5926
d2cd1205
JB
5927 if (is_apsr)
5928 {
5929 /* APSR uses a notation for bits, rather than fields. */
5930 unsigned int nzcvq_bits = 0;
5931 unsigned int g_bit = 0;
5932 char *bit;
fa94de6b 5933
d2cd1205
JB
5934 for (bit = start; bit != p; bit++)
5935 {
5936 switch (TOLOWER (*bit))
477330fc 5937 {
d2cd1205
JB
5938 case 'n':
5939 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5940 break;
5941
5942 case 'z':
5943 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5944 break;
5945
5946 case 'c':
5947 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5948 break;
5949
5950 case 'v':
5951 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5952 break;
fa94de6b 5953
d2cd1205
JB
5954 case 'q':
5955 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5956 break;
fa94de6b 5957
d2cd1205
JB
5958 case 'g':
5959 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5960 break;
fa94de6b 5961
d2cd1205
JB
5962 default:
5963 inst.error = _("unexpected bit specified after APSR");
5964 return FAIL;
5965 }
5966 }
fa94de6b 5967
d2cd1205
JB
5968 if (nzcvq_bits == 0x1f)
5969 psr_field |= PSR_f;
fa94de6b 5970
d2cd1205
JB
5971 if (g_bit == 0x1)
5972 {
5973 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5974 {
d2cd1205
JB
5975 inst.error = _("selected processor does not "
5976 "support DSP extension");
5977 return FAIL;
5978 }
5979
5980 psr_field |= PSR_s;
5981 }
fa94de6b 5982
d2cd1205
JB
5983 if ((nzcvq_bits & 0x20) != 0
5984 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5985 || (g_bit & 0x2) != 0)
5986 {
5987 inst.error = _("bad bitmask specified after APSR");
5988 return FAIL;
5989 }
5990 }
5991 else
477330fc 5992 {
d2cd1205 5993 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5994 p - start);
d2cd1205 5995 if (!psr)
477330fc 5996 goto error;
a737bd4d 5997
d2cd1205
JB
5998 psr_field |= psr->field;
5999 }
a737bd4d 6000 }
c19d1205 6001 else
a737bd4d 6002 {
c19d1205
ZW
6003 if (ISALNUM (*p))
6004 goto error; /* Garbage after "[CS]PSR". */
6005
d2cd1205 6006 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 6007 is deprecated, but allow it anyway. */
d2cd1205
JB
6008 if (is_apsr && lhs)
6009 {
6010 psr_field |= PSR_f;
6011 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6012 "deprecated"));
6013 }
6014 else if (!m_profile)
6015 /* These bits are never right for M-profile devices: don't set them
6016 (only code paths which read/write APSR reach here). */
6017 psr_field |= (PSR_c | PSR_f);
a737bd4d 6018 }
c19d1205
ZW
6019 *str = p;
6020 return psr_field;
a737bd4d 6021
d2cd1205
JB
6022 unsupported_psr:
6023 inst.error = _("selected processor does not support requested special "
6024 "purpose register");
6025 return FAIL;
6026
c19d1205
ZW
6027 error:
6028 inst.error = _("flag for {c}psr instruction expected");
6029 return FAIL;
a737bd4d
NC
6030}
6031
c19d1205
ZW
6032/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6033 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6034
c19d1205
ZW
6035static int
6036parse_cps_flags (char **str)
a737bd4d 6037{
c19d1205
ZW
6038 int val = 0;
6039 int saw_a_flag = 0;
6040 char *s = *str;
a737bd4d 6041
c19d1205
ZW
6042 for (;;)
6043 switch (*s++)
6044 {
6045 case '\0': case ',':
6046 goto done;
a737bd4d 6047
c19d1205
ZW
6048 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6049 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6050 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6051
c19d1205
ZW
6052 default:
6053 inst.error = _("unrecognized CPS flag");
6054 return FAIL;
6055 }
a737bd4d 6056
c19d1205
ZW
6057 done:
6058 if (saw_a_flag == 0)
a737bd4d 6059 {
c19d1205
ZW
6060 inst.error = _("missing CPS flags");
6061 return FAIL;
a737bd4d 6062 }
a737bd4d 6063
c19d1205
ZW
6064 *str = s - 1;
6065 return val;
a737bd4d
NC
6066}
6067
c19d1205
ZW
6068/* Parse an endian specifier ("BE" or "LE", case insensitive);
6069 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6070
6071static int
c19d1205 6072parse_endian_specifier (char **str)
a737bd4d 6073{
c19d1205
ZW
6074 int little_endian;
6075 char *s = *str;
a737bd4d 6076
c19d1205
ZW
6077 if (strncasecmp (s, "BE", 2))
6078 little_endian = 0;
6079 else if (strncasecmp (s, "LE", 2))
6080 little_endian = 1;
6081 else
a737bd4d 6082 {
c19d1205 6083 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6084 return FAIL;
6085 }
6086
c19d1205 6087 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6088 {
c19d1205 6089 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6090 return FAIL;
6091 }
6092
c19d1205
ZW
6093 *str = s + 2;
6094 return little_endian;
6095}
a737bd4d 6096
c19d1205
ZW
6097/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6098 value suitable for poking into the rotate field of an sxt or sxta
6099 instruction, or FAIL on error. */
6100
6101static int
6102parse_ror (char **str)
6103{
6104 int rot;
6105 char *s = *str;
6106
6107 if (strncasecmp (s, "ROR", 3) == 0)
6108 s += 3;
6109 else
a737bd4d 6110 {
c19d1205 6111 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6112 return FAIL;
6113 }
c19d1205
ZW
6114
6115 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6116 return FAIL;
6117
6118 switch (rot)
a737bd4d 6119 {
c19d1205
ZW
6120 case 0: *str = s; return 0x0;
6121 case 8: *str = s; return 0x1;
6122 case 16: *str = s; return 0x2;
6123 case 24: *str = s; return 0x3;
6124
6125 default:
6126 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6127 return FAIL;
6128 }
c19d1205 6129}
a737bd4d 6130
c19d1205
ZW
6131/* Parse a conditional code (from conds[] below). The value returned is in the
6132 range 0 .. 14, or FAIL. */
6133static int
6134parse_cond (char **str)
6135{
c462b453 6136 char *q;
c19d1205 6137 const struct asm_cond *c;
c462b453
PB
6138 int n;
6139 /* Condition codes are always 2 characters, so matching up to
6140 3 characters is sufficient. */
6141 char cond[3];
a737bd4d 6142
c462b453
PB
6143 q = *str;
6144 n = 0;
6145 while (ISALPHA (*q) && n < 3)
6146 {
e07e6e58 6147 cond[n] = TOLOWER (*q);
c462b453
PB
6148 q++;
6149 n++;
6150 }
a737bd4d 6151
21d799b5 6152 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6153 if (!c)
a737bd4d 6154 {
c19d1205 6155 inst.error = _("condition required");
a737bd4d
NC
6156 return FAIL;
6157 }
6158
c19d1205
ZW
6159 *str = q;
6160 return c->value;
6161}
6162
643afb90
MW
6163/* Record a use of the given feature. */
6164static void
6165record_feature_use (const arm_feature_set *feature)
6166{
6167 if (thumb_mode)
6168 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6169 else
6170 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6171}
6172
4d354d8b
TP
6173/* If the given feature is currently allowed, mark it as used and return TRUE.
6174 Return FALSE otherwise. */
e797f7e0
MGD
6175static bfd_boolean
6176mark_feature_used (const arm_feature_set *feature)
6177{
4d354d8b 6178 /* Ensure the option is currently allowed. */
e797f7e0
MGD
6179 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6180 return FALSE;
6181
4d354d8b 6182 /* Add the appropriate architecture feature for the barrier option used. */
643afb90 6183 record_feature_use (feature);
e797f7e0
MGD
6184
6185 return TRUE;
6186}
6187
62b3e311
PB
6188/* Parse an option for a barrier instruction. Returns the encoding for the
6189 option, or FAIL. */
6190static int
6191parse_barrier (char **str)
6192{
6193 char *p, *q;
6194 const struct asm_barrier_opt *o;
6195
6196 p = q = *str;
6197 while (ISALPHA (*q))
6198 q++;
6199
21d799b5 6200 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6201 q - p);
62b3e311
PB
6202 if (!o)
6203 return FAIL;
6204
e797f7e0
MGD
6205 if (!mark_feature_used (&o->arch))
6206 return FAIL;
6207
62b3e311
PB
6208 *str = q;
6209 return o->value;
6210}
6211
92e90b6e
PB
6212/* Parse the operands of a table branch instruction. Similar to a memory
6213 operand. */
6214static int
6215parse_tb (char **str)
6216{
6217 char * p = *str;
6218 int reg;
6219
6220 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6221 {
6222 inst.error = _("'[' expected");
6223 return FAIL;
6224 }
92e90b6e 6225
dcbf9037 6226 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6227 {
6228 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6229 return FAIL;
6230 }
6231 inst.operands[0].reg = reg;
6232
6233 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6234 {
6235 inst.error = _("',' expected");
6236 return FAIL;
6237 }
5f4273c7 6238
dcbf9037 6239 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6240 {
6241 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6242 return FAIL;
6243 }
6244 inst.operands[0].imm = reg;
6245
6246 if (skip_past_comma (&p) == SUCCESS)
6247 {
6248 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6249 return FAIL;
6250 if (inst.reloc.exp.X_add_number != 1)
6251 {
6252 inst.error = _("invalid shift");
6253 return FAIL;
6254 }
6255 inst.operands[0].shifted = 1;
6256 }
6257
6258 if (skip_past_char (&p, ']') == FAIL)
6259 {
6260 inst.error = _("']' expected");
6261 return FAIL;
6262 }
6263 *str = p;
6264 return SUCCESS;
6265}
6266
5287ad62
JB
6267/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6268 information on the types the operands can take and how they are encoded.
037e8744
JB
6269 Up to four operands may be read; this function handles setting the
6270 ".present" field for each read operand itself.
5287ad62
JB
6271 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6272 else returns FAIL. */
6273
6274static int
6275parse_neon_mov (char **str, int *which_operand)
6276{
6277 int i = *which_operand, val;
6278 enum arm_reg_type rtype;
6279 char *ptr = *str;
dcbf9037 6280 struct neon_type_el optype;
5f4273c7 6281
dcbf9037 6282 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6283 {
6284 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6285 inst.operands[i].reg = val;
6286 inst.operands[i].isscalar = 1;
dcbf9037 6287 inst.operands[i].vectype = optype;
5287ad62
JB
6288 inst.operands[i++].present = 1;
6289
6290 if (skip_past_comma (&ptr) == FAIL)
477330fc 6291 goto wanted_comma;
5f4273c7 6292
dcbf9037 6293 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6294 goto wanted_arm;
5f4273c7 6295
5287ad62
JB
6296 inst.operands[i].reg = val;
6297 inst.operands[i].isreg = 1;
6298 inst.operands[i].present = 1;
6299 }
037e8744 6300 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6301 != FAIL)
5287ad62
JB
6302 {
6303 /* Cases 0, 1, 2, 3, 5 (D only). */
6304 if (skip_past_comma (&ptr) == FAIL)
477330fc 6305 goto wanted_comma;
5f4273c7 6306
5287ad62
JB
6307 inst.operands[i].reg = val;
6308 inst.operands[i].isreg = 1;
6309 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6310 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6311 inst.operands[i].isvec = 1;
dcbf9037 6312 inst.operands[i].vectype = optype;
5287ad62
JB
6313 inst.operands[i++].present = 1;
6314
dcbf9037 6315 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6316 {
6317 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6318 Case 13: VMOV <Sd>, <Rm> */
6319 inst.operands[i].reg = val;
6320 inst.operands[i].isreg = 1;
6321 inst.operands[i].present = 1;
6322
6323 if (rtype == REG_TYPE_NQ)
6324 {
6325 first_error (_("can't use Neon quad register here"));
6326 return FAIL;
6327 }
6328 else if (rtype != REG_TYPE_VFS)
6329 {
6330 i++;
6331 if (skip_past_comma (&ptr) == FAIL)
6332 goto wanted_comma;
6333 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6334 goto wanted_arm;
6335 inst.operands[i].reg = val;
6336 inst.operands[i].isreg = 1;
6337 inst.operands[i].present = 1;
6338 }
6339 }
037e8744 6340 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6341 &optype)) != FAIL)
6342 {
6343 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6344 Case 1: VMOV<c><q> <Dd>, <Dm>
6345 Case 8: VMOV.F32 <Sd>, <Sm>
6346 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6347
6348 inst.operands[i].reg = val;
6349 inst.operands[i].isreg = 1;
6350 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6351 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6352 inst.operands[i].isvec = 1;
6353 inst.operands[i].vectype = optype;
6354 inst.operands[i].present = 1;
6355
6356 if (skip_past_comma (&ptr) == SUCCESS)
6357 {
6358 /* Case 15. */
6359 i++;
6360
6361 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6362 goto wanted_arm;
6363
6364 inst.operands[i].reg = val;
6365 inst.operands[i].isreg = 1;
6366 inst.operands[i++].present = 1;
6367
6368 if (skip_past_comma (&ptr) == FAIL)
6369 goto wanted_comma;
6370
6371 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6372 goto wanted_arm;
6373
6374 inst.operands[i].reg = val;
6375 inst.operands[i].isreg = 1;
6376 inst.operands[i].present = 1;
6377 }
6378 }
4641781c 6379 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6380 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6381 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6382 Case 10: VMOV.F32 <Sd>, #<imm>
6383 Case 11: VMOV.F64 <Dd>, #<imm> */
6384 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6385 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6386 == SUCCESS)
477330fc
RM
6387 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6388 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6389 ;
5287ad62 6390 else
477330fc
RM
6391 {
6392 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6393 return FAIL;
6394 }
5287ad62 6395 }
dcbf9037 6396 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6397 {
6398 /* Cases 6, 7. */
6399 inst.operands[i].reg = val;
6400 inst.operands[i].isreg = 1;
6401 inst.operands[i++].present = 1;
5f4273c7 6402
5287ad62 6403 if (skip_past_comma (&ptr) == FAIL)
477330fc 6404 goto wanted_comma;
5f4273c7 6405
dcbf9037 6406 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6407 {
6408 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6409 inst.operands[i].reg = val;
6410 inst.operands[i].isscalar = 1;
6411 inst.operands[i].present = 1;
6412 inst.operands[i].vectype = optype;
6413 }
dcbf9037 6414 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6415 {
6416 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6417 inst.operands[i].reg = val;
6418 inst.operands[i].isreg = 1;
6419 inst.operands[i++].present = 1;
6420
6421 if (skip_past_comma (&ptr) == FAIL)
6422 goto wanted_comma;
6423
6424 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6425 == FAIL)
6426 {
6427 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6428 return FAIL;
6429 }
6430
6431 inst.operands[i].reg = val;
6432 inst.operands[i].isreg = 1;
6433 inst.operands[i].isvec = 1;
6434 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6435 inst.operands[i].vectype = optype;
6436 inst.operands[i].present = 1;
6437
6438 if (rtype == REG_TYPE_VFS)
6439 {
6440 /* Case 14. */
6441 i++;
6442 if (skip_past_comma (&ptr) == FAIL)
6443 goto wanted_comma;
6444 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6445 &optype)) == FAIL)
6446 {
6447 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6448 return FAIL;
6449 }
6450 inst.operands[i].reg = val;
6451 inst.operands[i].isreg = 1;
6452 inst.operands[i].isvec = 1;
6453 inst.operands[i].issingle = 1;
6454 inst.operands[i].vectype = optype;
6455 inst.operands[i].present = 1;
6456 }
6457 }
037e8744 6458 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6459 != FAIL)
6460 {
6461 /* Case 13. */
6462 inst.operands[i].reg = val;
6463 inst.operands[i].isreg = 1;
6464 inst.operands[i].isvec = 1;
6465 inst.operands[i].issingle = 1;
6466 inst.operands[i].vectype = optype;
6467 inst.operands[i].present = 1;
6468 }
5287ad62
JB
6469 }
6470 else
6471 {
dcbf9037 6472 first_error (_("parse error"));
5287ad62
JB
6473 return FAIL;
6474 }
6475
6476 /* Successfully parsed the operands. Update args. */
6477 *which_operand = i;
6478 *str = ptr;
6479 return SUCCESS;
6480
5f4273c7 6481 wanted_comma:
dcbf9037 6482 first_error (_("expected comma"));
5287ad62 6483 return FAIL;
5f4273c7
NC
6484
6485 wanted_arm:
dcbf9037 6486 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6487 return FAIL;
5287ad62
JB
6488}
6489
5be8be5d
DG
6490/* Use this macro when the operand constraints are different
6491 for ARM and THUMB (e.g. ldrd). */
6492#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6493 ((arm_operand) | ((thumb_operand) << 16))
6494
c19d1205
ZW
6495/* Matcher codes for parse_operands. */
6496enum operand_parse_code
6497{
6498 OP_stop, /* end of line */
6499
6500 OP_RR, /* ARM register */
6501 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6502 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6503 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6504 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6505 optional trailing ! */
c19d1205
ZW
6506 OP_RRw, /* ARM register, not r15, optional trailing ! */
6507 OP_RCP, /* Coprocessor number */
6508 OP_RCN, /* Coprocessor register */
6509 OP_RF, /* FPA register */
6510 OP_RVS, /* VFP single precision register */
5287ad62
JB
6511 OP_RVD, /* VFP double precision register (0..15) */
6512 OP_RND, /* Neon double precision register (0..31) */
6513 OP_RNQ, /* Neon quad precision register */
037e8744 6514 OP_RVSD, /* VFP single or double precision register */
dec41383 6515 OP_RNSD, /* Neon single or double precision register */
5287ad62 6516 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6517 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6518 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6519 OP_RVC, /* VFP control register */
6520 OP_RMF, /* Maverick F register */
6521 OP_RMD, /* Maverick D register */
6522 OP_RMFX, /* Maverick FX register */
6523 OP_RMDX, /* Maverick DX register */
6524 OP_RMAX, /* Maverick AX register */
6525 OP_RMDS, /* Maverick DSPSC register */
6526 OP_RIWR, /* iWMMXt wR register */
6527 OP_RIWC, /* iWMMXt wC register */
6528 OP_RIWG, /* iWMMXt wCG register */
6529 OP_RXA, /* XScale accumulator register */
6530
6531 OP_REGLST, /* ARM register list */
6532 OP_VRSLST, /* VFP single-precision register list */
6533 OP_VRDLST, /* VFP double-precision register list */
037e8744 6534 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6535 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6536 OP_NSTRLST, /* Neon element/structure list */
6537
5287ad62 6538 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6539 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6540 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6541 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 6542 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 6543 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6544 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6545 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6546 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6547 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6548 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6549 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6550
6551 OP_I0, /* immediate zero */
c19d1205
ZW
6552 OP_I7, /* immediate value 0 .. 7 */
6553 OP_I15, /* 0 .. 15 */
6554 OP_I16, /* 1 .. 16 */
5287ad62 6555 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6556 OP_I31, /* 0 .. 31 */
6557 OP_I31w, /* 0 .. 31, optional trailing ! */
6558 OP_I32, /* 1 .. 32 */
5287ad62
JB
6559 OP_I32z, /* 0 .. 32 */
6560 OP_I63, /* 0 .. 63 */
c19d1205 6561 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6562 OP_I64, /* 1 .. 64 */
6563 OP_I64z, /* 0 .. 64 */
c19d1205 6564 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6565
6566 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6567 OP_I7b, /* 0 .. 7 */
6568 OP_I15b, /* 0 .. 15 */
6569 OP_I31b, /* 0 .. 31 */
6570
6571 OP_SH, /* shifter operand */
4962c51a 6572 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6573 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6574 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6575 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6576 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6577 OP_EXP, /* arbitrary expression */
6578 OP_EXPi, /* same, with optional immediate prefix */
6579 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6580 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
6581 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6582 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
6583
6584 OP_CPSF, /* CPS flags */
6585 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6586 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6587 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6588 OP_COND, /* conditional code */
92e90b6e 6589 OP_TB, /* Table branch. */
c19d1205 6590
037e8744
JB
6591 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6592
c19d1205 6593 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 6594 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
6595 OP_RR_EXi, /* ARM register or expression with imm prefix */
6596 OP_RF_IF, /* FPA register or immediate */
6597 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6598 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6599
6600 /* Optional operands. */
6601 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6602 OP_oI31b, /* 0 .. 31 */
5287ad62 6603 OP_oI32b, /* 1 .. 32 */
5f1af56b 6604 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6605 OP_oIffffb, /* 0 .. 65535 */
6606 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6607
6608 OP_oRR, /* ARM register */
6609 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6610 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6611 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6612 OP_oRND, /* Optional Neon double precision register */
6613 OP_oRNQ, /* Optional Neon quad precision register */
6614 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6615 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6616 OP_oSHll, /* LSL immediate */
6617 OP_oSHar, /* ASR immediate */
6618 OP_oSHllar, /* LSL or ASR immediate */
6619 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6620 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6621
5be8be5d
DG
6622 /* Some pre-defined mixed (ARM/THUMB) operands. */
6623 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6624 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6625 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6626
c19d1205
ZW
6627 OP_FIRST_OPTIONAL = OP_oI7b
6628};
a737bd4d 6629
c19d1205
ZW
6630/* Generic instruction operand parser. This does no encoding and no
6631 semantic validation; it merely squirrels values away in the inst
6632 structure. Returns SUCCESS or FAIL depending on whether the
6633 specified grammar matched. */
6634static int
5be8be5d 6635parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6636{
5be8be5d 6637 unsigned const int *upat = pattern;
c19d1205
ZW
6638 char *backtrack_pos = 0;
6639 const char *backtrack_error = 0;
99aad254 6640 int i, val = 0, backtrack_index = 0;
5287ad62 6641 enum arm_reg_type rtype;
4962c51a 6642 parse_operand_result result;
5be8be5d 6643 unsigned int op_parse_code;
c19d1205 6644
e07e6e58
NC
6645#define po_char_or_fail(chr) \
6646 do \
6647 { \
6648 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6649 goto bad_args; \
e07e6e58
NC
6650 } \
6651 while (0)
c19d1205 6652
e07e6e58
NC
6653#define po_reg_or_fail(regtype) \
6654 do \
dcbf9037 6655 { \
e07e6e58 6656 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6657 & inst.operands[i].vectype); \
e07e6e58 6658 if (val == FAIL) \
477330fc
RM
6659 { \
6660 first_error (_(reg_expected_msgs[regtype])); \
6661 goto failure; \
6662 } \
e07e6e58
NC
6663 inst.operands[i].reg = val; \
6664 inst.operands[i].isreg = 1; \
6665 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6666 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6667 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6668 || rtype == REG_TYPE_VFD \
6669 || rtype == REG_TYPE_NQ); \
dcbf9037 6670 } \
e07e6e58
NC
6671 while (0)
6672
6673#define po_reg_or_goto(regtype, label) \
6674 do \
6675 { \
6676 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6677 & inst.operands[i].vectype); \
6678 if (val == FAIL) \
6679 goto label; \
dcbf9037 6680 \
e07e6e58
NC
6681 inst.operands[i].reg = val; \
6682 inst.operands[i].isreg = 1; \
6683 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6684 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6685 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6686 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6687 || rtype == REG_TYPE_NQ); \
6688 } \
6689 while (0)
6690
6691#define po_imm_or_fail(min, max, popt) \
6692 do \
6693 { \
6694 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6695 goto failure; \
6696 inst.operands[i].imm = val; \
6697 } \
6698 while (0)
6699
6700#define po_scalar_or_goto(elsz, label) \
6701 do \
6702 { \
6703 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6704 if (val == FAIL) \
6705 goto label; \
6706 inst.operands[i].reg = val; \
6707 inst.operands[i].isscalar = 1; \
6708 } \
6709 while (0)
6710
6711#define po_misc_or_fail(expr) \
6712 do \
6713 { \
6714 if (expr) \
6715 goto failure; \
6716 } \
6717 while (0)
6718
6719#define po_misc_or_fail_no_backtrack(expr) \
6720 do \
6721 { \
6722 result = expr; \
6723 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6724 backtrack_pos = 0; \
6725 if (result != PARSE_OPERAND_SUCCESS) \
6726 goto failure; \
6727 } \
6728 while (0)
4962c51a 6729
52e7f43d
RE
6730#define po_barrier_or_imm(str) \
6731 do \
6732 { \
6733 val = parse_barrier (&str); \
ccb84d65
JB
6734 if (val == FAIL && ! ISALPHA (*str)) \
6735 goto immediate; \
6736 if (val == FAIL \
6737 /* ISB can only take SY as an option. */ \
6738 || ((inst.instruction & 0xf0) == 0x60 \
6739 && val != 0xf)) \
52e7f43d 6740 { \
ccb84d65
JB
6741 inst.error = _("invalid barrier type"); \
6742 backtrack_pos = 0; \
6743 goto failure; \
52e7f43d
RE
6744 } \
6745 } \
6746 while (0)
6747
c19d1205
ZW
6748 skip_whitespace (str);
6749
6750 for (i = 0; upat[i] != OP_stop; i++)
6751 {
5be8be5d
DG
6752 op_parse_code = upat[i];
6753 if (op_parse_code >= 1<<16)
6754 op_parse_code = thumb ? (op_parse_code >> 16)
6755 : (op_parse_code & ((1<<16)-1));
6756
6757 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6758 {
6759 /* Remember where we are in case we need to backtrack. */
9c2799c2 6760 gas_assert (!backtrack_pos);
c19d1205
ZW
6761 backtrack_pos = str;
6762 backtrack_error = inst.error;
6763 backtrack_index = i;
6764 }
6765
b6702015 6766 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6767 po_char_or_fail (',');
6768
5be8be5d 6769 switch (op_parse_code)
c19d1205
ZW
6770 {
6771 /* Registers */
6772 case OP_oRRnpc:
5be8be5d 6773 case OP_oRRnpcsp:
c19d1205 6774 case OP_RRnpc:
5be8be5d 6775 case OP_RRnpcsp:
c19d1205
ZW
6776 case OP_oRR:
6777 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6778 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6779 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6780 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6781 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6782 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6783 case OP_oRND:
5287ad62 6784 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6785 case OP_RVC:
6786 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6787 break;
6788 /* Also accept generic coprocessor regs for unknown registers. */
6789 coproc_reg:
6790 po_reg_or_fail (REG_TYPE_CN);
6791 break;
c19d1205
ZW
6792 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6793 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6794 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6795 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6796 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6797 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6798 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6799 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6800 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6801 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6802 case OP_oRNQ:
5287ad62 6803 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 6804 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
477330fc 6805 case OP_oRNDQ:
5287ad62 6806 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6807 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6808 case OP_oRNSDQ:
6809 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6810
6811 /* Neon scalar. Using an element size of 8 means that some invalid
6812 scalars are accepted here, so deal with those in later code. */
6813 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6814
6815 case OP_RNDQ_I0:
6816 {
6817 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6818 break;
6819 try_imm0:
6820 po_imm_or_fail (0, 0, TRUE);
6821 }
6822 break;
6823
6824 case OP_RVSD_I0:
6825 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6826 break;
6827
aacf0b33
KT
6828 case OP_RSVD_FI0:
6829 {
6830 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6831 break;
6832 try_ifimm0:
6833 if (parse_ifimm_zero (&str))
6834 inst.operands[i].imm = 0;
6835 else
6836 {
6837 inst.error
6838 = _("only floating point zero is allowed as immediate value");
6839 goto failure;
6840 }
6841 }
6842 break;
6843
477330fc
RM
6844 case OP_RR_RNSC:
6845 {
6846 po_scalar_or_goto (8, try_rr);
6847 break;
6848 try_rr:
6849 po_reg_or_fail (REG_TYPE_RN);
6850 }
6851 break;
6852
6853 case OP_RNSDQ_RNSC:
6854 {
6855 po_scalar_or_goto (8, try_nsdq);
6856 break;
6857 try_nsdq:
6858 po_reg_or_fail (REG_TYPE_NSDQ);
6859 }
6860 break;
6861
dec41383
JW
6862 case OP_RNSD_RNSC:
6863 {
6864 po_scalar_or_goto (8, try_s_scalar);
6865 break;
6866 try_s_scalar:
6867 po_scalar_or_goto (4, try_nsd);
6868 break;
6869 try_nsd:
6870 po_reg_or_fail (REG_TYPE_NSD);
6871 }
6872 break;
6873
477330fc
RM
6874 case OP_RNDQ_RNSC:
6875 {
6876 po_scalar_or_goto (8, try_ndq);
6877 break;
6878 try_ndq:
6879 po_reg_or_fail (REG_TYPE_NDQ);
6880 }
6881 break;
6882
6883 case OP_RND_RNSC:
6884 {
6885 po_scalar_or_goto (8, try_vfd);
6886 break;
6887 try_vfd:
6888 po_reg_or_fail (REG_TYPE_VFD);
6889 }
6890 break;
6891
6892 case OP_VMOV:
6893 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6894 not careful then bad things might happen. */
6895 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6896 break;
6897
6898 case OP_RNDQ_Ibig:
6899 {
6900 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6901 break;
6902 try_immbig:
6903 /* There's a possibility of getting a 64-bit immediate here, so
6904 we need special handling. */
8335d6aa
JW
6905 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6906 == FAIL)
477330fc
RM
6907 {
6908 inst.error = _("immediate value is out of range");
6909 goto failure;
6910 }
6911 }
6912 break;
6913
6914 case OP_RNDQ_I63b:
6915 {
6916 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6917 break;
6918 try_shimm:
6919 po_imm_or_fail (0, 63, TRUE);
6920 }
6921 break;
c19d1205
ZW
6922
6923 case OP_RRnpcb:
6924 po_char_or_fail ('[');
6925 po_reg_or_fail (REG_TYPE_RN);
6926 po_char_or_fail (']');
6927 break;
a737bd4d 6928
55881a11 6929 case OP_RRnpctw:
c19d1205 6930 case OP_RRw:
b6702015 6931 case OP_oRRw:
c19d1205
ZW
6932 po_reg_or_fail (REG_TYPE_RN);
6933 if (skip_past_char (&str, '!') == SUCCESS)
6934 inst.operands[i].writeback = 1;
6935 break;
6936
6937 /* Immediates */
6938 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6939 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6940 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6941 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6942 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6943 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6944 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6945 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6946 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6947 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6948 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6949 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6950
6951 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6952 case OP_oI7b:
6953 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6954 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6955 case OP_oI31b:
6956 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6957 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6958 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6959 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6960
6961 /* Immediate variants */
6962 case OP_oI255c:
6963 po_char_or_fail ('{');
6964 po_imm_or_fail (0, 255, TRUE);
6965 po_char_or_fail ('}');
6966 break;
6967
6968 case OP_I31w:
6969 /* The expression parser chokes on a trailing !, so we have
6970 to find it first and zap it. */
6971 {
6972 char *s = str;
6973 while (*s && *s != ',')
6974 s++;
6975 if (s[-1] == '!')
6976 {
6977 s[-1] = '\0';
6978 inst.operands[i].writeback = 1;
6979 }
6980 po_imm_or_fail (0, 31, TRUE);
6981 if (str == s - 1)
6982 str = s;
6983 }
6984 break;
6985
6986 /* Expressions */
6987 case OP_EXPi: EXPi:
6988 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6989 GE_OPT_PREFIX));
6990 break;
6991
6992 case OP_EXP:
6993 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6994 GE_NO_PREFIX));
6995 break;
6996
6997 case OP_EXPr: EXPr:
6998 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6999 GE_NO_PREFIX));
7000 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 7001 {
c19d1205
ZW
7002 val = parse_reloc (&str);
7003 if (val == -1)
7004 {
7005 inst.error = _("unrecognized relocation suffix");
7006 goto failure;
7007 }
7008 else if (val != BFD_RELOC_UNUSED)
7009 {
7010 inst.operands[i].imm = val;
7011 inst.operands[i].hasreloc = 1;
7012 }
a737bd4d 7013 }
c19d1205 7014 break;
a737bd4d 7015
b6895b4f
PB
7016 /* Operand for MOVW or MOVT. */
7017 case OP_HALF:
7018 po_misc_or_fail (parse_half (&str));
7019 break;
7020
e07e6e58 7021 /* Register or expression. */
c19d1205
ZW
7022 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7023 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7024
e07e6e58 7025 /* Register or immediate. */
c19d1205
ZW
7026 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7027 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7028
c19d1205
ZW
7029 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7030 IF:
7031 if (!is_immediate_prefix (*str))
7032 goto bad_args;
7033 str++;
7034 val = parse_fpa_immediate (&str);
7035 if (val == FAIL)
7036 goto failure;
7037 /* FPA immediates are encoded as registers 8-15.
7038 parse_fpa_immediate has already applied the offset. */
7039 inst.operands[i].reg = val;
7040 inst.operands[i].isreg = 1;
7041 break;
09d92015 7042
2d447fca
JM
7043 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7044 I32z: po_imm_or_fail (0, 32, FALSE); break;
7045
e07e6e58 7046 /* Two kinds of register. */
c19d1205
ZW
7047 case OP_RIWR_RIWC:
7048 {
7049 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7050 if (!rege
7051 || (rege->type != REG_TYPE_MMXWR
7052 && rege->type != REG_TYPE_MMXWC
7053 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7054 {
7055 inst.error = _("iWMMXt data or control register expected");
7056 goto failure;
7057 }
7058 inst.operands[i].reg = rege->number;
7059 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7060 }
7061 break;
09d92015 7062
41adaa5c
JM
7063 case OP_RIWC_RIWG:
7064 {
7065 struct reg_entry *rege = arm_reg_parse_multi (&str);
7066 if (!rege
7067 || (rege->type != REG_TYPE_MMXWC
7068 && rege->type != REG_TYPE_MMXWCG))
7069 {
7070 inst.error = _("iWMMXt control register expected");
7071 goto failure;
7072 }
7073 inst.operands[i].reg = rege->number;
7074 inst.operands[i].isreg = 1;
7075 }
7076 break;
7077
c19d1205
ZW
7078 /* Misc */
7079 case OP_CPSF: val = parse_cps_flags (&str); break;
7080 case OP_ENDI: val = parse_endian_specifier (&str); break;
7081 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7082 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7083 case OP_oBARRIER_I15:
7084 po_barrier_or_imm (str); break;
7085 immediate:
7086 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7087 goto failure;
52e7f43d 7088 break;
c19d1205 7089
fa94de6b 7090 case OP_wPSR:
d2cd1205 7091 case OP_rPSR:
90ec0d68
MGD
7092 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7093 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7094 {
7095 inst.error = _("Banked registers are not available with this "
7096 "architecture.");
7097 goto failure;
7098 }
7099 break;
d2cd1205
JB
7100 try_psr:
7101 val = parse_psr (&str, op_parse_code == OP_wPSR);
7102 break;
037e8744 7103
477330fc
RM
7104 case OP_APSR_RR:
7105 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7106 break;
7107 try_apsr:
7108 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7109 instruction). */
7110 if (strncasecmp (str, "APSR_", 5) == 0)
7111 {
7112 unsigned found = 0;
7113 str += 5;
7114 while (found < 15)
7115 switch (*str++)
7116 {
7117 case 'c': found = (found & 1) ? 16 : found | 1; break;
7118 case 'n': found = (found & 2) ? 16 : found | 2; break;
7119 case 'z': found = (found & 4) ? 16 : found | 4; break;
7120 case 'v': found = (found & 8) ? 16 : found | 8; break;
7121 default: found = 16;
7122 }
7123 if (found != 15)
7124 goto failure;
7125 inst.operands[i].isvec = 1;
f7c21dc7
NC
7126 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7127 inst.operands[i].reg = REG_PC;
477330fc
RM
7128 }
7129 else
7130 goto failure;
7131 break;
037e8744 7132
92e90b6e
PB
7133 case OP_TB:
7134 po_misc_or_fail (parse_tb (&str));
7135 break;
7136
e07e6e58 7137 /* Register lists. */
c19d1205
ZW
7138 case OP_REGLST:
7139 val = parse_reg_list (&str);
7140 if (*str == '^')
7141 {
5e0d7f77 7142 inst.operands[i].writeback = 1;
c19d1205
ZW
7143 str++;
7144 }
7145 break;
09d92015 7146
c19d1205 7147 case OP_VRSLST:
5287ad62 7148 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7149 break;
09d92015 7150
c19d1205 7151 case OP_VRDLST:
5287ad62 7152 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7153 break;
a737bd4d 7154
477330fc
RM
7155 case OP_VRSDLST:
7156 /* Allow Q registers too. */
7157 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7158 REGLIST_NEON_D);
7159 if (val == FAIL)
7160 {
7161 inst.error = NULL;
7162 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7163 REGLIST_VFP_S);
7164 inst.operands[i].issingle = 1;
7165 }
7166 break;
7167
7168 case OP_NRDLST:
7169 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7170 REGLIST_NEON_D);
7171 break;
5287ad62
JB
7172
7173 case OP_NSTRLST:
477330fc
RM
7174 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7175 &inst.operands[i].vectype);
7176 break;
5287ad62 7177
c19d1205
ZW
7178 /* Addressing modes */
7179 case OP_ADDR:
7180 po_misc_or_fail (parse_address (&str, i));
7181 break;
09d92015 7182
4962c51a
MS
7183 case OP_ADDRGLDR:
7184 po_misc_or_fail_no_backtrack (
477330fc 7185 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7186 break;
7187
7188 case OP_ADDRGLDRS:
7189 po_misc_or_fail_no_backtrack (
477330fc 7190 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7191 break;
7192
7193 case OP_ADDRGLDC:
7194 po_misc_or_fail_no_backtrack (
477330fc 7195 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7196 break;
7197
c19d1205
ZW
7198 case OP_SH:
7199 po_misc_or_fail (parse_shifter_operand (&str, i));
7200 break;
09d92015 7201
4962c51a
MS
7202 case OP_SHG:
7203 po_misc_or_fail_no_backtrack (
477330fc 7204 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7205 break;
7206
c19d1205
ZW
7207 case OP_oSHll:
7208 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7209 break;
09d92015 7210
c19d1205
ZW
7211 case OP_oSHar:
7212 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7213 break;
09d92015 7214
c19d1205
ZW
7215 case OP_oSHllar:
7216 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7217 break;
09d92015 7218
c19d1205 7219 default:
5be8be5d 7220 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7221 }
09d92015 7222
c19d1205
ZW
7223 /* Various value-based sanity checks and shared operations. We
7224 do not signal immediate failures for the register constraints;
7225 this allows a syntax error to take precedence. */
5be8be5d 7226 switch (op_parse_code)
c19d1205
ZW
7227 {
7228 case OP_oRRnpc:
7229 case OP_RRnpc:
7230 case OP_RRnpcb:
7231 case OP_RRw:
b6702015 7232 case OP_oRRw:
c19d1205
ZW
7233 case OP_RRnpc_I0:
7234 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7235 inst.error = BAD_PC;
7236 break;
09d92015 7237
5be8be5d
DG
7238 case OP_oRRnpcsp:
7239 case OP_RRnpcsp:
7240 if (inst.operands[i].isreg)
7241 {
7242 if (inst.operands[i].reg == REG_PC)
7243 inst.error = BAD_PC;
5c8ed6a4
JW
7244 else if (inst.operands[i].reg == REG_SP
7245 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7246 relaxed since ARMv8-A. */
7247 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7248 {
7249 gas_assert (thumb);
7250 inst.error = BAD_SP;
7251 }
5be8be5d
DG
7252 }
7253 break;
7254
55881a11 7255 case OP_RRnpctw:
fa94de6b
RM
7256 if (inst.operands[i].isreg
7257 && inst.operands[i].reg == REG_PC
55881a11
MGD
7258 && (inst.operands[i].writeback || thumb))
7259 inst.error = BAD_PC;
7260 break;
7261
c19d1205
ZW
7262 case OP_CPSF:
7263 case OP_ENDI:
7264 case OP_oROR:
d2cd1205
JB
7265 case OP_wPSR:
7266 case OP_rPSR:
c19d1205 7267 case OP_COND:
52e7f43d 7268 case OP_oBARRIER_I15:
c19d1205
ZW
7269 case OP_REGLST:
7270 case OP_VRSLST:
7271 case OP_VRDLST:
477330fc
RM
7272 case OP_VRSDLST:
7273 case OP_NRDLST:
7274 case OP_NSTRLST:
c19d1205
ZW
7275 if (val == FAIL)
7276 goto failure;
7277 inst.operands[i].imm = val;
7278 break;
a737bd4d 7279
c19d1205
ZW
7280 default:
7281 break;
7282 }
09d92015 7283
c19d1205
ZW
7284 /* If we get here, this operand was successfully parsed. */
7285 inst.operands[i].present = 1;
7286 continue;
09d92015 7287
c19d1205 7288 bad_args:
09d92015 7289 inst.error = BAD_ARGS;
c19d1205
ZW
7290
7291 failure:
7292 if (!backtrack_pos)
d252fdde
PB
7293 {
7294 /* The parse routine should already have set inst.error, but set a
5f4273c7 7295 default here just in case. */
d252fdde
PB
7296 if (!inst.error)
7297 inst.error = _("syntax error");
7298 return FAIL;
7299 }
c19d1205
ZW
7300
7301 /* Do not backtrack over a trailing optional argument that
7302 absorbed some text. We will only fail again, with the
7303 'garbage following instruction' error message, which is
7304 probably less helpful than the current one. */
7305 if (backtrack_index == i && backtrack_pos != str
7306 && upat[i+1] == OP_stop)
d252fdde
PB
7307 {
7308 if (!inst.error)
7309 inst.error = _("syntax error");
7310 return FAIL;
7311 }
c19d1205
ZW
7312
7313 /* Try again, skipping the optional argument at backtrack_pos. */
7314 str = backtrack_pos;
7315 inst.error = backtrack_error;
7316 inst.operands[backtrack_index].present = 0;
7317 i = backtrack_index;
7318 backtrack_pos = 0;
09d92015 7319 }
09d92015 7320
c19d1205
ZW
7321 /* Check that we have parsed all the arguments. */
7322 if (*str != '\0' && !inst.error)
7323 inst.error = _("garbage following instruction");
09d92015 7324
c19d1205 7325 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7326}
7327
c19d1205
ZW
7328#undef po_char_or_fail
7329#undef po_reg_or_fail
7330#undef po_reg_or_goto
7331#undef po_imm_or_fail
5287ad62 7332#undef po_scalar_or_fail
52e7f43d 7333#undef po_barrier_or_imm
e07e6e58 7334
c19d1205 7335/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7336#define constraint(expr, err) \
7337 do \
c19d1205 7338 { \
e07e6e58
NC
7339 if (expr) \
7340 { \
7341 inst.error = err; \
7342 return; \
7343 } \
c19d1205 7344 } \
e07e6e58 7345 while (0)
c19d1205 7346
fdfde340
JM
7347/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7348 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
7349 is the BadReg predicate in ARM's Thumb-2 documentation.
7350
7351 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7352 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7353#define reject_bad_reg(reg) \
7354 do \
7355 if (reg == REG_PC) \
7356 { \
7357 inst.error = BAD_PC; \
7358 return; \
7359 } \
7360 else if (reg == REG_SP \
7361 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7362 { \
7363 inst.error = BAD_SP; \
7364 return; \
7365 } \
fdfde340
JM
7366 while (0)
7367
94206790
MM
7368/* If REG is R13 (the stack pointer), warn that its use is
7369 deprecated. */
7370#define warn_deprecated_sp(reg) \
7371 do \
7372 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7373 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7374 while (0)
7375
c19d1205
ZW
7376/* Functions for operand encoding. ARM, then Thumb. */
7377
d840c081 7378#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7379
9db2f6b4
RL
7380/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7381
7382 The only binary encoding difference is the Coprocessor number. Coprocessor
7383 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 7384 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
7385 exists for Single-Precision operation. */
7386
7387static void
7388do_scalar_fp16_v82_encode (void)
7389{
7390 if (inst.cond != COND_ALWAYS)
7391 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7392 " the behaviour is UNPREDICTABLE"));
7393 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7394 _(BAD_FP16));
7395
7396 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7397 mark_feature_used (&arm_ext_fp16);
7398}
7399
c19d1205
ZW
7400/* If VAL can be encoded in the immediate field of an ARM instruction,
7401 return the encoded form. Otherwise, return FAIL. */
7402
7403static unsigned int
7404encode_arm_immediate (unsigned int val)
09d92015 7405{
c19d1205
ZW
7406 unsigned int a, i;
7407
4f1d6205
L
7408 if (val <= 0xff)
7409 return val;
7410
7411 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7412 if ((a = rotate_left (val, i)) <= 0xff)
7413 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7414
7415 return FAIL;
09d92015
MM
7416}
7417
c19d1205
ZW
7418/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7419 return the encoded form. Otherwise, return FAIL. */
7420static unsigned int
7421encode_thumb32_immediate (unsigned int val)
09d92015 7422{
c19d1205 7423 unsigned int a, i;
09d92015 7424
9c3c69f2 7425 if (val <= 0xff)
c19d1205 7426 return val;
a737bd4d 7427
9c3c69f2 7428 for (i = 1; i <= 24; i++)
09d92015 7429 {
9c3c69f2
PB
7430 a = val >> i;
7431 if ((val & ~(0xff << i)) == 0)
7432 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7433 }
a737bd4d 7434
c19d1205
ZW
7435 a = val & 0xff;
7436 if (val == ((a << 16) | a))
7437 return 0x100 | a;
7438 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7439 return 0x300 | a;
09d92015 7440
c19d1205
ZW
7441 a = val & 0xff00;
7442 if (val == ((a << 16) | a))
7443 return 0x200 | (a >> 8);
a737bd4d 7444
c19d1205 7445 return FAIL;
09d92015 7446}
5287ad62 7447/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7448
7449static void
5287ad62
JB
7450encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7451{
7452 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7453 && reg > 15)
7454 {
b1cc4aeb 7455 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7456 {
7457 if (thumb_mode)
7458 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7459 fpu_vfp_ext_d32);
7460 else
7461 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7462 fpu_vfp_ext_d32);
7463 }
5287ad62 7464 else
477330fc
RM
7465 {
7466 first_error (_("D register out of range for selected VFP version"));
7467 return;
7468 }
5287ad62
JB
7469 }
7470
c19d1205 7471 switch (pos)
09d92015 7472 {
c19d1205
ZW
7473 case VFP_REG_Sd:
7474 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7475 break;
7476
7477 case VFP_REG_Sn:
7478 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7479 break;
7480
7481 case VFP_REG_Sm:
7482 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7483 break;
7484
5287ad62
JB
7485 case VFP_REG_Dd:
7486 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7487 break;
5f4273c7 7488
5287ad62
JB
7489 case VFP_REG_Dn:
7490 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7491 break;
5f4273c7 7492
5287ad62
JB
7493 case VFP_REG_Dm:
7494 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7495 break;
7496
c19d1205
ZW
7497 default:
7498 abort ();
09d92015 7499 }
09d92015
MM
7500}
7501
c19d1205 7502/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7503 if any, is handled by md_apply_fix. */
09d92015 7504static void
c19d1205 7505encode_arm_shift (int i)
09d92015 7506{
008a97ef
RL
7507 /* register-shifted register. */
7508 if (inst.operands[i].immisreg)
7509 {
bf355b69
MR
7510 int op_index;
7511 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 7512 {
5689c942
RL
7513 /* Check the operand only when it's presented. In pre-UAL syntax,
7514 if the destination register is the same as the first operand, two
7515 register form of the instruction can be used. */
bf355b69
MR
7516 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7517 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
7518 as_warn (UNPRED_REG ("r15"));
7519 }
7520
7521 if (inst.operands[i].imm == REG_PC)
7522 as_warn (UNPRED_REG ("r15"));
7523 }
7524
c19d1205
ZW
7525 if (inst.operands[i].shift_kind == SHIFT_RRX)
7526 inst.instruction |= SHIFT_ROR << 5;
7527 else
09d92015 7528 {
c19d1205
ZW
7529 inst.instruction |= inst.operands[i].shift_kind << 5;
7530 if (inst.operands[i].immisreg)
7531 {
7532 inst.instruction |= SHIFT_BY_REG;
7533 inst.instruction |= inst.operands[i].imm << 8;
7534 }
7535 else
7536 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7537 }
c19d1205 7538}
09d92015 7539
c19d1205
ZW
7540static void
7541encode_arm_shifter_operand (int i)
7542{
7543 if (inst.operands[i].isreg)
09d92015 7544 {
c19d1205
ZW
7545 inst.instruction |= inst.operands[i].reg;
7546 encode_arm_shift (i);
09d92015 7547 }
c19d1205 7548 else
a415b1cd
JB
7549 {
7550 inst.instruction |= INST_IMMEDIATE;
7551 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7552 inst.instruction |= inst.operands[i].imm;
7553 }
09d92015
MM
7554}
7555
c19d1205 7556/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7557static void
c19d1205 7558encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7559{
2b2f5df9
NC
7560 /* PR 14260:
7561 Generate an error if the operand is not a register. */
7562 constraint (!inst.operands[i].isreg,
7563 _("Instruction does not support =N addresses"));
7564
c19d1205 7565 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7566
c19d1205 7567 if (inst.operands[i].preind)
09d92015 7568 {
c19d1205
ZW
7569 if (is_t)
7570 {
7571 inst.error = _("instruction does not accept preindexed addressing");
7572 return;
7573 }
7574 inst.instruction |= PRE_INDEX;
7575 if (inst.operands[i].writeback)
7576 inst.instruction |= WRITE_BACK;
09d92015 7577
c19d1205
ZW
7578 }
7579 else if (inst.operands[i].postind)
7580 {
9c2799c2 7581 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7582 if (is_t)
7583 inst.instruction |= WRITE_BACK;
7584 }
7585 else /* unindexed - only for coprocessor */
09d92015 7586 {
c19d1205 7587 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7588 return;
7589 }
7590
c19d1205
ZW
7591 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7592 && (((inst.instruction & 0x000f0000) >> 16)
7593 == ((inst.instruction & 0x0000f000) >> 12)))
7594 as_warn ((inst.instruction & LOAD_BIT)
7595 ? _("destination register same as write-back base")
7596 : _("source register same as write-back base"));
09d92015
MM
7597}
7598
c19d1205
ZW
7599/* inst.operands[i] was set up by parse_address. Encode it into an
7600 ARM-format mode 2 load or store instruction. If is_t is true,
7601 reject forms that cannot be used with a T instruction (i.e. not
7602 post-indexed). */
a737bd4d 7603static void
c19d1205 7604encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7605{
5be8be5d
DG
7606 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7607
c19d1205 7608 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7609
c19d1205 7610 if (inst.operands[i].immisreg)
09d92015 7611 {
5be8be5d
DG
7612 constraint ((inst.operands[i].imm == REG_PC
7613 || (is_pc && inst.operands[i].writeback)),
7614 BAD_PC_ADDRESSING);
c19d1205
ZW
7615 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7616 inst.instruction |= inst.operands[i].imm;
7617 if (!inst.operands[i].negative)
7618 inst.instruction |= INDEX_UP;
7619 if (inst.operands[i].shifted)
7620 {
7621 if (inst.operands[i].shift_kind == SHIFT_RRX)
7622 inst.instruction |= SHIFT_ROR << 5;
7623 else
7624 {
7625 inst.instruction |= inst.operands[i].shift_kind << 5;
7626 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7627 }
7628 }
09d92015 7629 }
c19d1205 7630 else /* immediate offset in inst.reloc */
09d92015 7631 {
5be8be5d
DG
7632 if (is_pc && !inst.reloc.pc_rel)
7633 {
7634 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7635
7636 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7637 cannot use PC in addressing.
7638 PC cannot be used in writeback addressing, either. */
7639 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7640 BAD_PC_ADDRESSING);
23a10334 7641
dc5ec521 7642 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7643 if (warn_on_deprecated
7644 && !is_load
7645 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7646 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7647 }
7648
c19d1205 7649 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7650 {
7651 /* Prefer + for zero encoded value. */
7652 if (!inst.operands[i].negative)
7653 inst.instruction |= INDEX_UP;
7654 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7655 }
09d92015 7656 }
09d92015
MM
7657}
7658
c19d1205
ZW
7659/* inst.operands[i] was set up by parse_address. Encode it into an
7660 ARM-format mode 3 load or store instruction. Reject forms that
7661 cannot be used with such instructions. If is_t is true, reject
7662 forms that cannot be used with a T instruction (i.e. not
7663 post-indexed). */
7664static void
7665encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7666{
c19d1205 7667 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7668 {
c19d1205
ZW
7669 inst.error = _("instruction does not accept scaled register index");
7670 return;
09d92015 7671 }
a737bd4d 7672
c19d1205 7673 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7674
c19d1205
ZW
7675 if (inst.operands[i].immisreg)
7676 {
5be8be5d 7677 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7678 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7679 BAD_PC_ADDRESSING);
eb9f3f00
JB
7680 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7681 BAD_PC_WRITEBACK);
c19d1205
ZW
7682 inst.instruction |= inst.operands[i].imm;
7683 if (!inst.operands[i].negative)
7684 inst.instruction |= INDEX_UP;
7685 }
7686 else /* immediate offset in inst.reloc */
7687 {
5be8be5d
DG
7688 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7689 && inst.operands[i].writeback),
7690 BAD_PC_WRITEBACK);
c19d1205
ZW
7691 inst.instruction |= HWOFFSET_IMM;
7692 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7693 {
7694 /* Prefer + for zero encoded value. */
7695 if (!inst.operands[i].negative)
7696 inst.instruction |= INDEX_UP;
7697
7698 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7699 }
c19d1205 7700 }
a737bd4d
NC
7701}
7702
8335d6aa
JW
7703/* Write immediate bits [7:0] to the following locations:
7704
7705 |28/24|23 19|18 16|15 4|3 0|
7706 | 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|
7707
7708 This function is used by VMOV/VMVN/VORR/VBIC. */
7709
7710static void
7711neon_write_immbits (unsigned immbits)
7712{
7713 inst.instruction |= immbits & 0xf;
7714 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7715 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7716}
7717
7718/* Invert low-order SIZE bits of XHI:XLO. */
7719
7720static void
7721neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7722{
7723 unsigned immlo = xlo ? *xlo : 0;
7724 unsigned immhi = xhi ? *xhi : 0;
7725
7726 switch (size)
7727 {
7728 case 8:
7729 immlo = (~immlo) & 0xff;
7730 break;
7731
7732 case 16:
7733 immlo = (~immlo) & 0xffff;
7734 break;
7735
7736 case 64:
7737 immhi = (~immhi) & 0xffffffff;
7738 /* fall through. */
7739
7740 case 32:
7741 immlo = (~immlo) & 0xffffffff;
7742 break;
7743
7744 default:
7745 abort ();
7746 }
7747
7748 if (xlo)
7749 *xlo = immlo;
7750
7751 if (xhi)
7752 *xhi = immhi;
7753}
7754
7755/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7756 A, B, C, D. */
09d92015 7757
c19d1205 7758static int
8335d6aa 7759neon_bits_same_in_bytes (unsigned imm)
09d92015 7760{
8335d6aa
JW
7761 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7762 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7763 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7764 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7765}
a737bd4d 7766
8335d6aa 7767/* For immediate of above form, return 0bABCD. */
09d92015 7768
8335d6aa
JW
7769static unsigned
7770neon_squash_bits (unsigned imm)
7771{
7772 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7773 | ((imm & 0x01000000) >> 21);
7774}
7775
7776/* Compress quarter-float representation to 0b...000 abcdefgh. */
7777
7778static unsigned
7779neon_qfloat_bits (unsigned imm)
7780{
7781 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7782}
7783
7784/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7785 the instruction. *OP is passed as the initial value of the op field, and
7786 may be set to a different value depending on the constant (i.e.
7787 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7788 MVN). If the immediate looks like a repeated pattern then also
7789 try smaller element sizes. */
7790
7791static int
7792neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7793 unsigned *immbits, int *op, int size,
7794 enum neon_el_type type)
7795{
7796 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7797 float. */
7798 if (type == NT_float && !float_p)
7799 return FAIL;
7800
7801 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7802 {
8335d6aa
JW
7803 if (size != 32 || *op == 1)
7804 return FAIL;
7805 *immbits = neon_qfloat_bits (immlo);
7806 return 0xf;
7807 }
7808
7809 if (size == 64)
7810 {
7811 if (neon_bits_same_in_bytes (immhi)
7812 && neon_bits_same_in_bytes (immlo))
c19d1205 7813 {
8335d6aa
JW
7814 if (*op == 1)
7815 return FAIL;
7816 *immbits = (neon_squash_bits (immhi) << 4)
7817 | neon_squash_bits (immlo);
7818 *op = 1;
7819 return 0xe;
c19d1205 7820 }
a737bd4d 7821
8335d6aa
JW
7822 if (immhi != immlo)
7823 return FAIL;
7824 }
a737bd4d 7825
8335d6aa 7826 if (size >= 32)
09d92015 7827 {
8335d6aa 7828 if (immlo == (immlo & 0x000000ff))
c19d1205 7829 {
8335d6aa
JW
7830 *immbits = immlo;
7831 return 0x0;
c19d1205 7832 }
8335d6aa 7833 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7834 {
8335d6aa
JW
7835 *immbits = immlo >> 8;
7836 return 0x2;
c19d1205 7837 }
8335d6aa
JW
7838 else if (immlo == (immlo & 0x00ff0000))
7839 {
7840 *immbits = immlo >> 16;
7841 return 0x4;
7842 }
7843 else if (immlo == (immlo & 0xff000000))
7844 {
7845 *immbits = immlo >> 24;
7846 return 0x6;
7847 }
7848 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7849 {
7850 *immbits = (immlo >> 8) & 0xff;
7851 return 0xc;
7852 }
7853 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7854 {
7855 *immbits = (immlo >> 16) & 0xff;
7856 return 0xd;
7857 }
7858
7859 if ((immlo & 0xffff) != (immlo >> 16))
7860 return FAIL;
7861 immlo &= 0xffff;
09d92015 7862 }
a737bd4d 7863
8335d6aa 7864 if (size >= 16)
4962c51a 7865 {
8335d6aa
JW
7866 if (immlo == (immlo & 0x000000ff))
7867 {
7868 *immbits = immlo;
7869 return 0x8;
7870 }
7871 else if (immlo == (immlo & 0x0000ff00))
7872 {
7873 *immbits = immlo >> 8;
7874 return 0xa;
7875 }
7876
7877 if ((immlo & 0xff) != (immlo >> 8))
7878 return FAIL;
7879 immlo &= 0xff;
4962c51a
MS
7880 }
7881
8335d6aa
JW
7882 if (immlo == (immlo & 0x000000ff))
7883 {
7884 /* Don't allow MVN with 8-bit immediate. */
7885 if (*op == 1)
7886 return FAIL;
7887 *immbits = immlo;
7888 return 0xe;
7889 }
26d97720 7890
8335d6aa 7891 return FAIL;
c19d1205 7892}
a737bd4d 7893
5fc177c8 7894#if defined BFD_HOST_64_BIT
ba592044
AM
7895/* Returns TRUE if double precision value V may be cast
7896 to single precision without loss of accuracy. */
7897
7898static bfd_boolean
5fc177c8 7899is_double_a_single (bfd_int64_t v)
ba592044 7900{
5fc177c8 7901 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7902 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7903
7904 return (exp == 0 || exp == 0x7FF
7905 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7906 && (mantissa & 0x1FFFFFFFl) == 0;
7907}
7908
3739860c 7909/* Returns a double precision value casted to single precision
ba592044
AM
7910 (ignoring the least significant bits in exponent and mantissa). */
7911
7912static int
5fc177c8 7913double_to_single (bfd_int64_t v)
ba592044
AM
7914{
7915 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7916 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7917 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7918
7919 if (exp == 0x7FF)
7920 exp = 0xFF;
7921 else
7922 {
7923 exp = exp - 1023 + 127;
7924 if (exp >= 0xFF)
7925 {
7926 /* Infinity. */
7927 exp = 0x7F;
7928 mantissa = 0;
7929 }
7930 else if (exp < 0)
7931 {
7932 /* No denormalized numbers. */
7933 exp = 0;
7934 mantissa = 0;
7935 }
7936 }
7937 mantissa >>= 29;
7938 return (sign << 31) | (exp << 23) | mantissa;
7939}
5fc177c8 7940#endif /* BFD_HOST_64_BIT */
ba592044 7941
8335d6aa
JW
7942enum lit_type
7943{
7944 CONST_THUMB,
7945 CONST_ARM,
7946 CONST_VEC
7947};
7948
ba592044
AM
7949static void do_vfp_nsyn_opcode (const char *);
7950
c19d1205
ZW
7951/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7952 Determine whether it can be performed with a move instruction; if
7953 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7954 return TRUE; if it can't, convert inst.instruction to a literal-pool
7955 load and return FALSE. If this is not a valid thing to do in the
7956 current context, set inst.error and return TRUE.
a737bd4d 7957
c19d1205
ZW
7958 inst.operands[i] describes the destination register. */
7959
c921be7d 7960static bfd_boolean
8335d6aa 7961move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7962{
53365c0d 7963 unsigned long tbit;
8335d6aa
JW
7964 bfd_boolean thumb_p = (t == CONST_THUMB);
7965 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7966
7967 if (thumb_p)
7968 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7969 else
7970 tbit = LOAD_BIT;
7971
7972 if ((inst.instruction & tbit) == 0)
09d92015 7973 {
c19d1205 7974 inst.error = _("invalid pseudo operation");
c921be7d 7975 return TRUE;
09d92015 7976 }
ba592044 7977
8335d6aa
JW
7978 if (inst.reloc.exp.X_op != O_constant
7979 && inst.reloc.exp.X_op != O_symbol
7980 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7981 {
7982 inst.error = _("constant expression expected");
c921be7d 7983 return TRUE;
09d92015 7984 }
ba592044
AM
7985
7986 if (inst.reloc.exp.X_op == O_constant
7987 || inst.reloc.exp.X_op == O_big)
8335d6aa 7988 {
5fc177c8
NC
7989#if defined BFD_HOST_64_BIT
7990 bfd_int64_t v;
7991#else
ba592044 7992 offsetT v;
5fc177c8 7993#endif
ba592044 7994 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7995 {
ba592044
AM
7996 LITTLENUM_TYPE w[X_PRECISION];
7997 LITTLENUM_TYPE * l;
7998
7999 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 8000 {
ba592044
AM
8001 gen_to_words (w, X_PRECISION, E_PRECISION);
8002 l = w;
8003 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 8004 }
ba592044
AM
8005 else
8006 l = generic_bignum;
3739860c 8007
5fc177c8
NC
8008#if defined BFD_HOST_64_BIT
8009 v =
8010 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8011 << LITTLENUM_NUMBER_OF_BITS)
8012 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8013 << LITTLENUM_NUMBER_OF_BITS)
8014 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8015 << LITTLENUM_NUMBER_OF_BITS)
8016 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8017#else
ba592044
AM
8018 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8019 | (l[0] & LITTLENUM_MASK);
5fc177c8 8020#endif
8335d6aa 8021 }
ba592044
AM
8022 else
8023 v = inst.reloc.exp.X_add_number;
8024
8025 if (!inst.operands[i].issingle)
8335d6aa 8026 {
12569877 8027 if (thumb_p)
8335d6aa 8028 {
53445554
TP
8029 /* LDR should not use lead in a flag-setting instruction being
8030 chosen so we do not check whether movs can be used. */
12569877 8031
53445554 8032 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8033 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8034 && inst.operands[i].reg != 13
8035 && inst.operands[i].reg != 15)
12569877 8036 {
fc289b0a
TP
8037 /* Check if on thumb2 it can be done with a mov.w, mvn or
8038 movw instruction. */
12569877
AM
8039 unsigned int newimm;
8040 bfd_boolean isNegated;
8041
8042 newimm = encode_thumb32_immediate (v);
8043 if (newimm != (unsigned int) FAIL)
8044 isNegated = FALSE;
8045 else
8046 {
582cfe03 8047 newimm = encode_thumb32_immediate (~v);
12569877
AM
8048 if (newimm != (unsigned int) FAIL)
8049 isNegated = TRUE;
8050 }
8051
fc289b0a
TP
8052 /* The number can be loaded with a mov.w or mvn
8053 instruction. */
ff8646ee
TP
8054 if (newimm != (unsigned int) FAIL
8055 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8056 {
fc289b0a 8057 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8058 | (inst.operands[i].reg << 8));
fc289b0a 8059 /* Change to MOVN. */
582cfe03 8060 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8061 inst.instruction |= (newimm & 0x800) << 15;
8062 inst.instruction |= (newimm & 0x700) << 4;
8063 inst.instruction |= (newimm & 0x0ff);
8064 return TRUE;
8065 }
fc289b0a 8066 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8067 else if ((v & ~0xFFFF) == 0
8068 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8069 {
582cfe03 8070 int imm = v & 0xFFFF;
12569877 8071
582cfe03 8072 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8073 inst.instruction |= (inst.operands[i].reg << 8);
8074 inst.instruction |= (imm & 0xf000) << 4;
8075 inst.instruction |= (imm & 0x0800) << 15;
8076 inst.instruction |= (imm & 0x0700) << 4;
8077 inst.instruction |= (imm & 0x00ff);
8078 return TRUE;
8079 }
8080 }
8335d6aa 8081 }
12569877 8082 else if (arm_p)
ba592044
AM
8083 {
8084 int value = encode_arm_immediate (v);
12569877 8085
ba592044
AM
8086 if (value != FAIL)
8087 {
8088 /* This can be done with a mov instruction. */
8089 inst.instruction &= LITERAL_MASK;
8090 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8091 inst.instruction |= value & 0xfff;
8092 return TRUE;
8093 }
8335d6aa 8094
ba592044
AM
8095 value = encode_arm_immediate (~ v);
8096 if (value != FAIL)
8097 {
8098 /* This can be done with a mvn instruction. */
8099 inst.instruction &= LITERAL_MASK;
8100 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8101 inst.instruction |= value & 0xfff;
8102 return TRUE;
8103 }
8104 }
934c2632 8105 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8106 {
ba592044
AM
8107 int op = 0;
8108 unsigned immbits = 0;
8109 unsigned immlo = inst.operands[1].imm;
8110 unsigned immhi = inst.operands[1].regisimm
8111 ? inst.operands[1].reg
8112 : inst.reloc.exp.X_unsigned
8113 ? 0
8114 : ((bfd_int64_t)((int) immlo)) >> 32;
8115 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8116 &op, 64, NT_invtype);
8117
8118 if (cmode == FAIL)
8119 {
8120 neon_invert_size (&immlo, &immhi, 64);
8121 op = !op;
8122 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8123 &op, 64, NT_invtype);
8124 }
8125
8126 if (cmode != FAIL)
8127 {
8128 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8129 | (1 << 23)
8130 | (cmode << 8)
8131 | (op << 5)
8132 | (1 << 4);
8133
8134 /* Fill other bits in vmov encoding for both thumb and arm. */
8135 if (thumb_mode)
eff0bc54 8136 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8137 else
eff0bc54 8138 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8139 neon_write_immbits (immbits);
8140 return TRUE;
8141 }
8335d6aa
JW
8142 }
8143 }
8335d6aa 8144
ba592044
AM
8145 if (t == CONST_VEC)
8146 {
8147 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8148 if (inst.operands[i].issingle
8149 && is_quarter_float (inst.operands[1].imm)
8150 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8151 {
ba592044
AM
8152 inst.operands[1].imm =
8153 neon_qfloat_bits (v);
8154 do_vfp_nsyn_opcode ("fconsts");
8155 return TRUE;
8335d6aa 8156 }
5fc177c8
NC
8157
8158 /* If our host does not support a 64-bit type then we cannot perform
8159 the following optimization. This mean that there will be a
8160 discrepancy between the output produced by an assembler built for
8161 a 32-bit-only host and the output produced from a 64-bit host, but
8162 this cannot be helped. */
8163#if defined BFD_HOST_64_BIT
ba592044
AM
8164 else if (!inst.operands[1].issingle
8165 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8166 {
ba592044
AM
8167 if (is_double_a_single (v)
8168 && is_quarter_float (double_to_single (v)))
8169 {
8170 inst.operands[1].imm =
8171 neon_qfloat_bits (double_to_single (v));
8172 do_vfp_nsyn_opcode ("fconstd");
8173 return TRUE;
8174 }
8335d6aa 8175 }
5fc177c8 8176#endif
8335d6aa
JW
8177 }
8178 }
8179
8180 if (add_to_lit_pool ((!inst.operands[i].isvec
8181 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8182 return TRUE;
8183
8184 inst.operands[1].reg = REG_PC;
8185 inst.operands[1].isreg = 1;
8186 inst.operands[1].preind = 1;
8187 inst.reloc.pc_rel = 1;
8188 inst.reloc.type = (thumb_p
8189 ? BFD_RELOC_ARM_THUMB_OFFSET
8190 : (mode_3
8191 ? BFD_RELOC_ARM_HWLITERAL
8192 : BFD_RELOC_ARM_LITERAL));
8193 return FALSE;
8194}
8195
8196/* inst.operands[i] was set up by parse_address. Encode it into an
8197 ARM-format instruction. Reject all forms which cannot be encoded
8198 into a coprocessor load/store instruction. If wb_ok is false,
8199 reject use of writeback; if unind_ok is false, reject use of
8200 unindexed addressing. If reloc_override is not 0, use it instead
8201 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8202 (in which case it is preserved). */
8203
8204static int
8205encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8206{
8207 if (!inst.operands[i].isreg)
8208 {
99b2a2dd
NC
8209 /* PR 18256 */
8210 if (! inst.operands[0].isvec)
8211 {
8212 inst.error = _("invalid co-processor operand");
8213 return FAIL;
8214 }
8335d6aa
JW
8215 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8216 return SUCCESS;
8217 }
8218
8219 inst.instruction |= inst.operands[i].reg << 16;
8220
8221 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8222
8223 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8224 {
8225 gas_assert (!inst.operands[i].writeback);
8226 if (!unind_ok)
8227 {
8228 inst.error = _("instruction does not support unindexed addressing");
8229 return FAIL;
8230 }
8231 inst.instruction |= inst.operands[i].imm;
8232 inst.instruction |= INDEX_UP;
8233 return SUCCESS;
8234 }
8235
8236 if (inst.operands[i].preind)
8237 inst.instruction |= PRE_INDEX;
8238
8239 if (inst.operands[i].writeback)
09d92015 8240 {
8335d6aa 8241 if (inst.operands[i].reg == REG_PC)
c19d1205 8242 {
8335d6aa
JW
8243 inst.error = _("pc may not be used with write-back");
8244 return FAIL;
c19d1205 8245 }
8335d6aa 8246 if (!wb_ok)
c19d1205 8247 {
8335d6aa
JW
8248 inst.error = _("instruction does not support writeback");
8249 return FAIL;
c19d1205 8250 }
8335d6aa 8251 inst.instruction |= WRITE_BACK;
09d92015
MM
8252 }
8253
8335d6aa
JW
8254 if (reloc_override)
8255 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8256 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8257 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8258 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8259 {
8335d6aa
JW
8260 if (thumb_mode)
8261 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8262 else
8263 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8264 }
8335d6aa
JW
8265
8266 /* Prefer + for zero encoded value. */
8267 if (!inst.operands[i].negative)
8268 inst.instruction |= INDEX_UP;
8269
8270 return SUCCESS;
09d92015
MM
8271}
8272
5f4273c7 8273/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8274 First some generics; their names are taken from the conventional
8275 bit positions for register arguments in ARM format instructions. */
09d92015 8276
a737bd4d 8277static void
c19d1205 8278do_noargs (void)
09d92015 8279{
c19d1205 8280}
a737bd4d 8281
c19d1205
ZW
8282static void
8283do_rd (void)
8284{
8285 inst.instruction |= inst.operands[0].reg << 12;
8286}
a737bd4d 8287
16a1fa25
TP
8288static void
8289do_rn (void)
8290{
8291 inst.instruction |= inst.operands[0].reg << 16;
8292}
8293
c19d1205
ZW
8294static void
8295do_rd_rm (void)
8296{
8297 inst.instruction |= inst.operands[0].reg << 12;
8298 inst.instruction |= inst.operands[1].reg;
8299}
09d92015 8300
9eb6c0f1
MGD
8301static void
8302do_rm_rn (void)
8303{
8304 inst.instruction |= inst.operands[0].reg;
8305 inst.instruction |= inst.operands[1].reg << 16;
8306}
8307
c19d1205
ZW
8308static void
8309do_rd_rn (void)
8310{
8311 inst.instruction |= inst.operands[0].reg << 12;
8312 inst.instruction |= inst.operands[1].reg << 16;
8313}
a737bd4d 8314
c19d1205
ZW
8315static void
8316do_rn_rd (void)
8317{
8318 inst.instruction |= inst.operands[0].reg << 16;
8319 inst.instruction |= inst.operands[1].reg << 12;
8320}
09d92015 8321
4ed7ed8d
TP
8322static void
8323do_tt (void)
8324{
8325 inst.instruction |= inst.operands[0].reg << 8;
8326 inst.instruction |= inst.operands[1].reg << 16;
8327}
8328
59d09be6
MGD
8329static bfd_boolean
8330check_obsolete (const arm_feature_set *feature, const char *msg)
8331{
8332 if (ARM_CPU_IS_ANY (cpu_variant))
8333 {
5c3696f8 8334 as_tsktsk ("%s", msg);
59d09be6
MGD
8335 return TRUE;
8336 }
8337 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8338 {
8339 as_bad ("%s", msg);
8340 return TRUE;
8341 }
8342
8343 return FALSE;
8344}
8345
c19d1205
ZW
8346static void
8347do_rd_rm_rn (void)
8348{
9a64e435 8349 unsigned Rn = inst.operands[2].reg;
708587a4 8350 /* Enforce restrictions on SWP instruction. */
9a64e435 8351 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8352 {
8353 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8354 _("Rn must not overlap other operands"));
8355
59d09be6
MGD
8356 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8357 */
8358 if (!check_obsolete (&arm_ext_v8,
8359 _("swp{b} use is obsoleted for ARMv8 and later"))
8360 && warn_on_deprecated
8361 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8362 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8363 }
59d09be6 8364
c19d1205
ZW
8365 inst.instruction |= inst.operands[0].reg << 12;
8366 inst.instruction |= inst.operands[1].reg;
9a64e435 8367 inst.instruction |= Rn << 16;
c19d1205 8368}
09d92015 8369
c19d1205
ZW
8370static void
8371do_rd_rn_rm (void)
8372{
8373 inst.instruction |= inst.operands[0].reg << 12;
8374 inst.instruction |= inst.operands[1].reg << 16;
8375 inst.instruction |= inst.operands[2].reg;
8376}
a737bd4d 8377
c19d1205
ZW
8378static void
8379do_rm_rd_rn (void)
8380{
5be8be5d
DG
8381 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8382 constraint (((inst.reloc.exp.X_op != O_constant
8383 && inst.reloc.exp.X_op != O_illegal)
8384 || inst.reloc.exp.X_add_number != 0),
8385 BAD_ADDR_MODE);
c19d1205
ZW
8386 inst.instruction |= inst.operands[0].reg;
8387 inst.instruction |= inst.operands[1].reg << 12;
8388 inst.instruction |= inst.operands[2].reg << 16;
8389}
09d92015 8390
c19d1205
ZW
8391static void
8392do_imm0 (void)
8393{
8394 inst.instruction |= inst.operands[0].imm;
8395}
09d92015 8396
c19d1205
ZW
8397static void
8398do_rd_cpaddr (void)
8399{
8400 inst.instruction |= inst.operands[0].reg << 12;
8401 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8402}
a737bd4d 8403
c19d1205
ZW
8404/* ARM instructions, in alphabetical order by function name (except
8405 that wrapper functions appear immediately after the function they
8406 wrap). */
09d92015 8407
c19d1205
ZW
8408/* This is a pseudo-op of the form "adr rd, label" to be converted
8409 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8410
8411static void
c19d1205 8412do_adr (void)
09d92015 8413{
c19d1205 8414 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8415
c19d1205
ZW
8416 /* Frag hacking will turn this into a sub instruction if the offset turns
8417 out to be negative. */
8418 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8419 inst.reloc.pc_rel = 1;
2fc8bdac 8420 inst.reloc.exp.X_add_number -= 8;
52a86f84 8421
fc6141f0
NC
8422 if (support_interwork
8423 && inst.reloc.exp.X_op == O_symbol
52a86f84
NC
8424 && inst.reloc.exp.X_add_symbol != NULL
8425 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8426 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
fc6141f0 8427 inst.reloc.exp.X_add_number |= 1;
c19d1205 8428}
b99bd4ef 8429
c19d1205
ZW
8430/* This is a pseudo-op of the form "adrl rd, label" to be converted
8431 into a relative address of the form:
8432 add rd, pc, #low(label-.-8)"
8433 add rd, rd, #high(label-.-8)" */
b99bd4ef 8434
c19d1205
ZW
8435static void
8436do_adrl (void)
8437{
8438 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8439
c19d1205
ZW
8440 /* Frag hacking will turn this into a sub instruction if the offset turns
8441 out to be negative. */
8442 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8443 inst.reloc.pc_rel = 1;
8444 inst.size = INSN_SIZE * 2;
2fc8bdac 8445 inst.reloc.exp.X_add_number -= 8;
52a86f84 8446
fc6141f0
NC
8447 if (support_interwork
8448 && inst.reloc.exp.X_op == O_symbol
52a86f84
NC
8449 && inst.reloc.exp.X_add_symbol != NULL
8450 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8451 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
fc6141f0 8452 inst.reloc.exp.X_add_number |= 1;
b99bd4ef
NC
8453}
8454
b99bd4ef 8455static void
c19d1205 8456do_arit (void)
b99bd4ef 8457{
a9f02af8
MG
8458 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8459 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8460 THUMB1_RELOC_ONLY);
c19d1205
ZW
8461 if (!inst.operands[1].present)
8462 inst.operands[1].reg = inst.operands[0].reg;
8463 inst.instruction |= inst.operands[0].reg << 12;
8464 inst.instruction |= inst.operands[1].reg << 16;
8465 encode_arm_shifter_operand (2);
8466}
b99bd4ef 8467
62b3e311
PB
8468static void
8469do_barrier (void)
8470{
8471 if (inst.operands[0].present)
ccb84d65 8472 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8473 else
8474 inst.instruction |= 0xf;
8475}
8476
c19d1205
ZW
8477static void
8478do_bfc (void)
8479{
8480 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8481 constraint (msb > 32, _("bit-field extends past end of register"));
8482 /* The instruction encoding stores the LSB and MSB,
8483 not the LSB and width. */
8484 inst.instruction |= inst.operands[0].reg << 12;
8485 inst.instruction |= inst.operands[1].imm << 7;
8486 inst.instruction |= (msb - 1) << 16;
8487}
b99bd4ef 8488
c19d1205
ZW
8489static void
8490do_bfi (void)
8491{
8492 unsigned int msb;
b99bd4ef 8493
c19d1205
ZW
8494 /* #0 in second position is alternative syntax for bfc, which is
8495 the same instruction but with REG_PC in the Rm field. */
8496 if (!inst.operands[1].isreg)
8497 inst.operands[1].reg = REG_PC;
b99bd4ef 8498
c19d1205
ZW
8499 msb = inst.operands[2].imm + inst.operands[3].imm;
8500 constraint (msb > 32, _("bit-field extends past end of register"));
8501 /* The instruction encoding stores the LSB and MSB,
8502 not the LSB and width. */
8503 inst.instruction |= inst.operands[0].reg << 12;
8504 inst.instruction |= inst.operands[1].reg;
8505 inst.instruction |= inst.operands[2].imm << 7;
8506 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8507}
8508
b99bd4ef 8509static void
c19d1205 8510do_bfx (void)
b99bd4ef 8511{
c19d1205
ZW
8512 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8513 _("bit-field extends past end of register"));
8514 inst.instruction |= inst.operands[0].reg << 12;
8515 inst.instruction |= inst.operands[1].reg;
8516 inst.instruction |= inst.operands[2].imm << 7;
8517 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8518}
09d92015 8519
c19d1205
ZW
8520/* ARM V5 breakpoint instruction (argument parse)
8521 BKPT <16 bit unsigned immediate>
8522 Instruction is not conditional.
8523 The bit pattern given in insns[] has the COND_ALWAYS condition,
8524 and it is an error if the caller tried to override that. */
b99bd4ef 8525
c19d1205
ZW
8526static void
8527do_bkpt (void)
8528{
8529 /* Top 12 of 16 bits to bits 19:8. */
8530 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8531
c19d1205
ZW
8532 /* Bottom 4 of 16 bits to bits 3:0. */
8533 inst.instruction |= inst.operands[0].imm & 0xf;
8534}
09d92015 8535
c19d1205
ZW
8536static void
8537encode_branch (int default_reloc)
8538{
8539 if (inst.operands[0].hasreloc)
8540 {
0855e32b
NS
8541 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8542 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8543 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8544 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8545 ? BFD_RELOC_ARM_PLT32
8546 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8547 }
b99bd4ef 8548 else
9ae92b05 8549 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8550 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8551}
8552
b99bd4ef 8553static void
c19d1205 8554do_branch (void)
b99bd4ef 8555{
39b41c9c
PB
8556#ifdef OBJ_ELF
8557 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8558 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8559 else
8560#endif
8561 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8562}
8563
8564static void
8565do_bl (void)
8566{
8567#ifdef OBJ_ELF
8568 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8569 {
8570 if (inst.cond == COND_ALWAYS)
8571 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8572 else
8573 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8574 }
8575 else
8576#endif
8577 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8578}
b99bd4ef 8579
c19d1205
ZW
8580/* ARM V5 branch-link-exchange instruction (argument parse)
8581 BLX <target_addr> ie BLX(1)
8582 BLX{<condition>} <Rm> ie BLX(2)
8583 Unfortunately, there are two different opcodes for this mnemonic.
8584 So, the insns[].value is not used, and the code here zaps values
8585 into inst.instruction.
8586 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8587
c19d1205
ZW
8588static void
8589do_blx (void)
8590{
8591 if (inst.operands[0].isreg)
b99bd4ef 8592 {
c19d1205
ZW
8593 /* Arg is a register; the opcode provided by insns[] is correct.
8594 It is not illegal to do "blx pc", just useless. */
8595 if (inst.operands[0].reg == REG_PC)
8596 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8597
c19d1205
ZW
8598 inst.instruction |= inst.operands[0].reg;
8599 }
8600 else
b99bd4ef 8601 {
c19d1205 8602 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8603 conditionally, and the opcode must be adjusted.
8604 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8605 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8606 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8607 inst.instruction = 0xfa000000;
267bf995 8608 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8609 }
c19d1205
ZW
8610}
8611
8612static void
8613do_bx (void)
8614{
845b51d6
PB
8615 bfd_boolean want_reloc;
8616
c19d1205
ZW
8617 if (inst.operands[0].reg == REG_PC)
8618 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8619
c19d1205 8620 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8621 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8622 it is for ARMv4t or earlier. */
8623 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
4d354d8b
TP
8624 if (!ARM_FEATURE_ZERO (selected_object_arch)
8625 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
845b51d6
PB
8626 want_reloc = TRUE;
8627
5ad34203 8628#ifdef OBJ_ELF
845b51d6 8629 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8630#endif
584206db 8631 want_reloc = FALSE;
845b51d6
PB
8632
8633 if (want_reloc)
8634 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8635}
8636
c19d1205
ZW
8637
8638/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8639
8640static void
c19d1205 8641do_bxj (void)
a737bd4d 8642{
c19d1205
ZW
8643 if (inst.operands[0].reg == REG_PC)
8644 as_tsktsk (_("use of r15 in bxj is not really useful"));
8645
8646 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8647}
8648
c19d1205
ZW
8649/* Co-processor data operation:
8650 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8651 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8652static void
8653do_cdp (void)
8654{
8655 inst.instruction |= inst.operands[0].reg << 8;
8656 inst.instruction |= inst.operands[1].imm << 20;
8657 inst.instruction |= inst.operands[2].reg << 12;
8658 inst.instruction |= inst.operands[3].reg << 16;
8659 inst.instruction |= inst.operands[4].reg;
8660 inst.instruction |= inst.operands[5].imm << 5;
8661}
a737bd4d
NC
8662
8663static void
c19d1205 8664do_cmp (void)
a737bd4d 8665{
c19d1205
ZW
8666 inst.instruction |= inst.operands[0].reg << 16;
8667 encode_arm_shifter_operand (1);
a737bd4d
NC
8668}
8669
c19d1205
ZW
8670/* Transfer between coprocessor and ARM registers.
8671 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8672 MRC2
8673 MCR{cond}
8674 MCR2
8675
8676 No special properties. */
09d92015 8677
dcbd0d71
MGD
8678struct deprecated_coproc_regs_s
8679{
8680 unsigned cp;
8681 int opc1;
8682 unsigned crn;
8683 unsigned crm;
8684 int opc2;
8685 arm_feature_set deprecated;
8686 arm_feature_set obsoleted;
8687 const char *dep_msg;
8688 const char *obs_msg;
8689};
8690
8691#define DEPR_ACCESS_V8 \
8692 N_("This coprocessor register access is deprecated in ARMv8")
8693
8694/* Table of all deprecated coprocessor registers. */
8695static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8696{
8697 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8698 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8699 DEPR_ACCESS_V8, NULL},
8700 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8701 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8702 DEPR_ACCESS_V8, NULL},
8703 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8704 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8705 DEPR_ACCESS_V8, NULL},
8706 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8707 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8708 DEPR_ACCESS_V8, NULL},
8709 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8710 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8711 DEPR_ACCESS_V8, NULL},
8712};
8713
8714#undef DEPR_ACCESS_V8
8715
8716static const size_t deprecated_coproc_reg_count =
8717 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8718
09d92015 8719static void
c19d1205 8720do_co_reg (void)
09d92015 8721{
fdfde340 8722 unsigned Rd;
dcbd0d71 8723 size_t i;
fdfde340
JM
8724
8725 Rd = inst.operands[2].reg;
8726 if (thumb_mode)
8727 {
8728 if (inst.instruction == 0xee000010
8729 || inst.instruction == 0xfe000010)
8730 /* MCR, MCR2 */
8731 reject_bad_reg (Rd);
5c8ed6a4 8732 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
8733 /* MRC, MRC2 */
8734 constraint (Rd == REG_SP, BAD_SP);
8735 }
8736 else
8737 {
8738 /* MCR */
8739 if (inst.instruction == 0xe000010)
8740 constraint (Rd == REG_PC, BAD_PC);
8741 }
8742
dcbd0d71
MGD
8743 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8744 {
8745 const struct deprecated_coproc_regs_s *r =
8746 deprecated_coproc_regs + i;
8747
8748 if (inst.operands[0].reg == r->cp
8749 && inst.operands[1].imm == r->opc1
8750 && inst.operands[3].reg == r->crn
8751 && inst.operands[4].reg == r->crm
8752 && inst.operands[5].imm == r->opc2)
8753 {
b10bf8c5 8754 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8755 && warn_on_deprecated
dcbd0d71 8756 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8757 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8758 }
8759 }
fdfde340 8760
c19d1205
ZW
8761 inst.instruction |= inst.operands[0].reg << 8;
8762 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8763 inst.instruction |= Rd << 12;
c19d1205
ZW
8764 inst.instruction |= inst.operands[3].reg << 16;
8765 inst.instruction |= inst.operands[4].reg;
8766 inst.instruction |= inst.operands[5].imm << 5;
8767}
09d92015 8768
c19d1205
ZW
8769/* Transfer between coprocessor register and pair of ARM registers.
8770 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8771 MCRR2
8772 MRRC{cond}
8773 MRRC2
b99bd4ef 8774
c19d1205 8775 Two XScale instructions are special cases of these:
09d92015 8776
c19d1205
ZW
8777 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8778 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8779
5f4273c7 8780 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8781
c19d1205
ZW
8782static void
8783do_co_reg2c (void)
8784{
fdfde340
JM
8785 unsigned Rd, Rn;
8786
8787 Rd = inst.operands[2].reg;
8788 Rn = inst.operands[3].reg;
8789
8790 if (thumb_mode)
8791 {
8792 reject_bad_reg (Rd);
8793 reject_bad_reg (Rn);
8794 }
8795 else
8796 {
8797 constraint (Rd == REG_PC, BAD_PC);
8798 constraint (Rn == REG_PC, BAD_PC);
8799 }
8800
873f10f0
TC
8801 /* Only check the MRRC{2} variants. */
8802 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8803 {
8804 /* If Rd == Rn, error that the operation is
8805 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8806 constraint (Rd == Rn, BAD_OVERLAP);
8807 }
8808
c19d1205
ZW
8809 inst.instruction |= inst.operands[0].reg << 8;
8810 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8811 inst.instruction |= Rd << 12;
8812 inst.instruction |= Rn << 16;
c19d1205 8813 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8814}
8815
c19d1205
ZW
8816static void
8817do_cpsi (void)
8818{
8819 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8820 if (inst.operands[1].present)
8821 {
8822 inst.instruction |= CPSI_MMOD;
8823 inst.instruction |= inst.operands[1].imm;
8824 }
c19d1205 8825}
b99bd4ef 8826
62b3e311
PB
8827static void
8828do_dbg (void)
8829{
8830 inst.instruction |= inst.operands[0].imm;
8831}
8832
eea54501
MGD
8833static void
8834do_div (void)
8835{
8836 unsigned Rd, Rn, Rm;
8837
8838 Rd = inst.operands[0].reg;
8839 Rn = (inst.operands[1].present
8840 ? inst.operands[1].reg : Rd);
8841 Rm = inst.operands[2].reg;
8842
8843 constraint ((Rd == REG_PC), BAD_PC);
8844 constraint ((Rn == REG_PC), BAD_PC);
8845 constraint ((Rm == REG_PC), BAD_PC);
8846
8847 inst.instruction |= Rd << 16;
8848 inst.instruction |= Rn << 0;
8849 inst.instruction |= Rm << 8;
8850}
8851
b99bd4ef 8852static void
c19d1205 8853do_it (void)
b99bd4ef 8854{
c19d1205 8855 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8856 process it to do the validation as if in
8857 thumb mode, just in case the code gets
8858 assembled for thumb using the unified syntax. */
8859
c19d1205 8860 inst.size = 0;
e07e6e58
NC
8861 if (unified_syntax)
8862 {
8863 set_it_insn_type (IT_INSN);
8864 now_it.mask = (inst.instruction & 0xf) | 0x10;
8865 now_it.cc = inst.operands[0].imm;
8866 }
09d92015 8867}
b99bd4ef 8868
6530b175
NC
8869/* If there is only one register in the register list,
8870 then return its register number. Otherwise return -1. */
8871static int
8872only_one_reg_in_list (int range)
8873{
8874 int i = ffs (range) - 1;
8875 return (i > 15 || range != (1 << i)) ? -1 : i;
8876}
8877
09d92015 8878static void
6530b175 8879encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8880{
c19d1205
ZW
8881 int base_reg = inst.operands[0].reg;
8882 int range = inst.operands[1].imm;
6530b175 8883 int one_reg;
ea6ef066 8884
c19d1205
ZW
8885 inst.instruction |= base_reg << 16;
8886 inst.instruction |= range;
ea6ef066 8887
c19d1205
ZW
8888 if (inst.operands[1].writeback)
8889 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8890
c19d1205 8891 if (inst.operands[0].writeback)
ea6ef066 8892 {
c19d1205
ZW
8893 inst.instruction |= WRITE_BACK;
8894 /* Check for unpredictable uses of writeback. */
8895 if (inst.instruction & LOAD_BIT)
09d92015 8896 {
c19d1205
ZW
8897 /* Not allowed in LDM type 2. */
8898 if ((inst.instruction & LDM_TYPE_2_OR_3)
8899 && ((range & (1 << REG_PC)) == 0))
8900 as_warn (_("writeback of base register is UNPREDICTABLE"));
8901 /* Only allowed if base reg not in list for other types. */
8902 else if (range & (1 << base_reg))
8903 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8904 }
8905 else /* STM. */
8906 {
8907 /* Not allowed for type 2. */
8908 if (inst.instruction & LDM_TYPE_2_OR_3)
8909 as_warn (_("writeback of base register is UNPREDICTABLE"));
8910 /* Only allowed if base reg not in list, or first in list. */
8911 else if ((range & (1 << base_reg))
8912 && (range & ((1 << base_reg) - 1)))
8913 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8914 }
ea6ef066 8915 }
6530b175
NC
8916
8917 /* If PUSH/POP has only one register, then use the A2 encoding. */
8918 one_reg = only_one_reg_in_list (range);
8919 if (from_push_pop_mnem && one_reg >= 0)
8920 {
8921 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8922
4f588891
NC
8923 if (is_push && one_reg == 13 /* SP */)
8924 /* PR 22483: The A2 encoding cannot be used when
8925 pushing the stack pointer as this is UNPREDICTABLE. */
8926 return;
8927
6530b175
NC
8928 inst.instruction &= A_COND_MASK;
8929 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8930 inst.instruction |= one_reg << 12;
8931 }
8932}
8933
8934static void
8935do_ldmstm (void)
8936{
8937 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8938}
8939
c19d1205
ZW
8940/* ARMv5TE load-consecutive (argument parse)
8941 Mode is like LDRH.
8942
8943 LDRccD R, mode
8944 STRccD R, mode. */
8945
a737bd4d 8946static void
c19d1205 8947do_ldrd (void)
a737bd4d 8948{
c19d1205 8949 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8950 _("first transfer register must be even"));
c19d1205
ZW
8951 constraint (inst.operands[1].present
8952 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8953 _("can only transfer two consecutive registers"));
c19d1205
ZW
8954 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8955 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8956
c19d1205
ZW
8957 if (!inst.operands[1].present)
8958 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8959
c56791bb
RE
8960 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8961 register and the first register written; we have to diagnose
8962 overlap between the base and the second register written here. */
ea6ef066 8963
c56791bb
RE
8964 if (inst.operands[2].reg == inst.operands[1].reg
8965 && (inst.operands[2].writeback || inst.operands[2].postind))
8966 as_warn (_("base register written back, and overlaps "
8967 "second transfer register"));
b05fe5cf 8968
c56791bb
RE
8969 if (!(inst.instruction & V4_STR_BIT))
8970 {
c19d1205 8971 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8972 destination (even if not write-back). */
8973 if (inst.operands[2].immisreg
8974 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8975 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8976 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8977 }
c19d1205
ZW
8978 inst.instruction |= inst.operands[0].reg << 12;
8979 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8980}
8981
8982static void
c19d1205 8983do_ldrex (void)
b05fe5cf 8984{
c19d1205
ZW
8985 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8986 || inst.operands[1].postind || inst.operands[1].writeback
8987 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8988 || inst.operands[1].negative
8989 /* This can arise if the programmer has written
8990 strex rN, rM, foo
8991 or if they have mistakenly used a register name as the last
8992 operand, eg:
8993 strex rN, rM, rX
8994 It is very difficult to distinguish between these two cases
8995 because "rX" might actually be a label. ie the register
8996 name has been occluded by a symbol of the same name. So we
8997 just generate a general 'bad addressing mode' type error
8998 message and leave it up to the programmer to discover the
8999 true cause and fix their mistake. */
9000 || (inst.operands[1].reg == REG_PC),
9001 BAD_ADDR_MODE);
b05fe5cf 9002
c19d1205
ZW
9003 constraint (inst.reloc.exp.X_op != O_constant
9004 || inst.reloc.exp.X_add_number != 0,
9005 _("offset must be zero in ARM encoding"));
b05fe5cf 9006
5be8be5d
DG
9007 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9008
c19d1205
ZW
9009 inst.instruction |= inst.operands[0].reg << 12;
9010 inst.instruction |= inst.operands[1].reg << 16;
9011 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
9012}
9013
9014static void
c19d1205 9015do_ldrexd (void)
b05fe5cf 9016{
c19d1205
ZW
9017 constraint (inst.operands[0].reg % 2 != 0,
9018 _("even register required"));
9019 constraint (inst.operands[1].present
9020 && inst.operands[1].reg != inst.operands[0].reg + 1,
9021 _("can only load two consecutive registers"));
9022 /* If op 1 were present and equal to PC, this function wouldn't
9023 have been called in the first place. */
9024 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9025
c19d1205
ZW
9026 inst.instruction |= inst.operands[0].reg << 12;
9027 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9028}
9029
1be5fd2e
NC
9030/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9031 which is not a multiple of four is UNPREDICTABLE. */
9032static void
9033check_ldr_r15_aligned (void)
9034{
9035 constraint (!(inst.operands[1].immisreg)
9036 && (inst.operands[0].reg == REG_PC
9037 && inst.operands[1].reg == REG_PC
9038 && (inst.reloc.exp.X_add_number & 0x3)),
de194d85 9039 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9040}
9041
b05fe5cf 9042static void
c19d1205 9043do_ldst (void)
b05fe5cf 9044{
c19d1205
ZW
9045 inst.instruction |= inst.operands[0].reg << 12;
9046 if (!inst.operands[1].isreg)
8335d6aa 9047 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9048 return;
c19d1205 9049 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9050 check_ldr_r15_aligned ();
b05fe5cf
ZW
9051}
9052
9053static void
c19d1205 9054do_ldstt (void)
b05fe5cf 9055{
c19d1205
ZW
9056 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9057 reject [Rn,...]. */
9058 if (inst.operands[1].preind)
b05fe5cf 9059 {
bd3ba5d1
NC
9060 constraint (inst.reloc.exp.X_op != O_constant
9061 || inst.reloc.exp.X_add_number != 0,
c19d1205 9062 _("this instruction requires a post-indexed address"));
b05fe5cf 9063
c19d1205
ZW
9064 inst.operands[1].preind = 0;
9065 inst.operands[1].postind = 1;
9066 inst.operands[1].writeback = 1;
b05fe5cf 9067 }
c19d1205
ZW
9068 inst.instruction |= inst.operands[0].reg << 12;
9069 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9070}
b05fe5cf 9071
c19d1205 9072/* Halfword and signed-byte load/store operations. */
b05fe5cf 9073
c19d1205
ZW
9074static void
9075do_ldstv4 (void)
9076{
ff4a8d2b 9077 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9078 inst.instruction |= inst.operands[0].reg << 12;
9079 if (!inst.operands[1].isreg)
8335d6aa 9080 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9081 return;
c19d1205 9082 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9083}
9084
9085static void
c19d1205 9086do_ldsttv4 (void)
b05fe5cf 9087{
c19d1205
ZW
9088 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9089 reject [Rn,...]. */
9090 if (inst.operands[1].preind)
b05fe5cf 9091 {
bd3ba5d1
NC
9092 constraint (inst.reloc.exp.X_op != O_constant
9093 || inst.reloc.exp.X_add_number != 0,
c19d1205 9094 _("this instruction requires a post-indexed address"));
b05fe5cf 9095
c19d1205
ZW
9096 inst.operands[1].preind = 0;
9097 inst.operands[1].postind = 1;
9098 inst.operands[1].writeback = 1;
b05fe5cf 9099 }
c19d1205
ZW
9100 inst.instruction |= inst.operands[0].reg << 12;
9101 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9102}
b05fe5cf 9103
c19d1205
ZW
9104/* Co-processor register load/store.
9105 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9106static void
9107do_lstc (void)
9108{
9109 inst.instruction |= inst.operands[0].reg << 8;
9110 inst.instruction |= inst.operands[1].reg << 12;
9111 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9112}
9113
b05fe5cf 9114static void
c19d1205 9115do_mlas (void)
b05fe5cf 9116{
8fb9d7b9 9117 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9118 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9119 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9120 && !(inst.instruction & 0x00400000))
8fb9d7b9 9121 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9122
c19d1205
ZW
9123 inst.instruction |= inst.operands[0].reg << 16;
9124 inst.instruction |= inst.operands[1].reg;
9125 inst.instruction |= inst.operands[2].reg << 8;
9126 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9127}
b05fe5cf 9128
c19d1205
ZW
9129static void
9130do_mov (void)
9131{
a9f02af8
MG
9132 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9133 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9134 THUMB1_RELOC_ONLY);
c19d1205
ZW
9135 inst.instruction |= inst.operands[0].reg << 12;
9136 encode_arm_shifter_operand (1);
9137}
b05fe5cf 9138
c19d1205
ZW
9139/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9140static void
9141do_mov16 (void)
9142{
b6895b4f
PB
9143 bfd_vma imm;
9144 bfd_boolean top;
9145
9146 top = (inst.instruction & 0x00400000) != 0;
9147 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
33eaf5de 9148 _(":lower16: not allowed in this instruction"));
b6895b4f 9149 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
33eaf5de 9150 _(":upper16: not allowed in this instruction"));
c19d1205 9151 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9152 if (inst.reloc.type == BFD_RELOC_UNUSED)
9153 {
9154 imm = inst.reloc.exp.X_add_number;
9155 /* The value is in two pieces: 0:11, 16:19. */
9156 inst.instruction |= (imm & 0x00000fff);
9157 inst.instruction |= (imm & 0x0000f000) << 4;
9158 }
b05fe5cf 9159}
b99bd4ef 9160
037e8744
JB
9161static int
9162do_vfp_nsyn_mrs (void)
9163{
9164 if (inst.operands[0].isvec)
9165 {
9166 if (inst.operands[1].reg != 1)
477330fc 9167 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9168 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9169 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9170 do_vfp_nsyn_opcode ("fmstat");
9171 }
9172 else if (inst.operands[1].isvec)
9173 do_vfp_nsyn_opcode ("fmrx");
9174 else
9175 return FAIL;
5f4273c7 9176
037e8744
JB
9177 return SUCCESS;
9178}
9179
9180static int
9181do_vfp_nsyn_msr (void)
9182{
9183 if (inst.operands[0].isvec)
9184 do_vfp_nsyn_opcode ("fmxr");
9185 else
9186 return FAIL;
9187
9188 return SUCCESS;
9189}
9190
f7c21dc7
NC
9191static void
9192do_vmrs (void)
9193{
9194 unsigned Rt = inst.operands[0].reg;
fa94de6b 9195
16d02dc9 9196 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9197 {
9198 inst.error = BAD_SP;
9199 return;
9200 }
9201
40c7d507
RR
9202 /* MVFR2 is only valid at ARMv8-A. */
9203 if (inst.operands[1].reg == 5)
9204 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9205 _(BAD_FPU));
9206
f7c21dc7 9207 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9208 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9209 {
9210 inst.error = BAD_PC;
9211 return;
9212 }
9213
16d02dc9
JB
9214 /* If we get through parsing the register name, we just insert the number
9215 generated into the instruction without further validation. */
9216 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9217 inst.instruction |= (Rt << 12);
9218}
9219
9220static void
9221do_vmsr (void)
9222{
9223 unsigned Rt = inst.operands[1].reg;
fa94de6b 9224
f7c21dc7
NC
9225 if (thumb_mode)
9226 reject_bad_reg (Rt);
9227 else if (Rt == REG_PC)
9228 {
9229 inst.error = BAD_PC;
9230 return;
9231 }
9232
40c7d507
RR
9233 /* MVFR2 is only valid for ARMv8-A. */
9234 if (inst.operands[0].reg == 5)
9235 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9236 _(BAD_FPU));
9237
16d02dc9
JB
9238 /* If we get through parsing the register name, we just insert the number
9239 generated into the instruction without further validation. */
9240 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9241 inst.instruction |= (Rt << 12);
9242}
9243
b99bd4ef 9244static void
c19d1205 9245do_mrs (void)
b99bd4ef 9246{
90ec0d68
MGD
9247 unsigned br;
9248
037e8744
JB
9249 if (do_vfp_nsyn_mrs () == SUCCESS)
9250 return;
9251
ff4a8d2b 9252 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9253 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9254
9255 if (inst.operands[1].isreg)
9256 {
9257 br = inst.operands[1].reg;
806ab1c0 9258 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
90ec0d68
MGD
9259 as_bad (_("bad register for mrs"));
9260 }
9261 else
9262 {
9263 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9264 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9265 != (PSR_c|PSR_f),
d2cd1205 9266 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9267 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9268 }
9269
9270 inst.instruction |= br;
c19d1205 9271}
b99bd4ef 9272
c19d1205
ZW
9273/* Two possible forms:
9274 "{C|S}PSR_<field>, Rm",
9275 "{C|S}PSR_f, #expression". */
b99bd4ef 9276
c19d1205
ZW
9277static void
9278do_msr (void)
9279{
037e8744
JB
9280 if (do_vfp_nsyn_msr () == SUCCESS)
9281 return;
9282
c19d1205
ZW
9283 inst.instruction |= inst.operands[0].imm;
9284 if (inst.operands[1].isreg)
9285 inst.instruction |= inst.operands[1].reg;
9286 else
b99bd4ef 9287 {
c19d1205
ZW
9288 inst.instruction |= INST_IMMEDIATE;
9289 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9290 inst.reloc.pc_rel = 0;
b99bd4ef 9291 }
b99bd4ef
NC
9292}
9293
c19d1205
ZW
9294static void
9295do_mul (void)
a737bd4d 9296{
ff4a8d2b
NC
9297 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9298
c19d1205
ZW
9299 if (!inst.operands[2].present)
9300 inst.operands[2].reg = inst.operands[0].reg;
9301 inst.instruction |= inst.operands[0].reg << 16;
9302 inst.instruction |= inst.operands[1].reg;
9303 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9304
8fb9d7b9
MS
9305 if (inst.operands[0].reg == inst.operands[1].reg
9306 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9307 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9308}
9309
c19d1205
ZW
9310/* Long Multiply Parser
9311 UMULL RdLo, RdHi, Rm, Rs
9312 SMULL RdLo, RdHi, Rm, Rs
9313 UMLAL RdLo, RdHi, Rm, Rs
9314 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9315
9316static void
c19d1205 9317do_mull (void)
b99bd4ef 9318{
c19d1205
ZW
9319 inst.instruction |= inst.operands[0].reg << 12;
9320 inst.instruction |= inst.operands[1].reg << 16;
9321 inst.instruction |= inst.operands[2].reg;
9322 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9323
682b27ad
PB
9324 /* rdhi and rdlo must be different. */
9325 if (inst.operands[0].reg == inst.operands[1].reg)
9326 as_tsktsk (_("rdhi and rdlo must be different"));
9327
9328 /* rdhi, rdlo and rm must all be different before armv6. */
9329 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9330 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9331 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9332 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9333}
b99bd4ef 9334
c19d1205
ZW
9335static void
9336do_nop (void)
9337{
e7495e45
NS
9338 if (inst.operands[0].present
9339 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9340 {
9341 /* Architectural NOP hints are CPSR sets with no bits selected. */
9342 inst.instruction &= 0xf0000000;
e7495e45
NS
9343 inst.instruction |= 0x0320f000;
9344 if (inst.operands[0].present)
9345 inst.instruction |= inst.operands[0].imm;
c19d1205 9346 }
b99bd4ef
NC
9347}
9348
c19d1205
ZW
9349/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9350 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9351 Condition defaults to COND_ALWAYS.
9352 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9353
9354static void
c19d1205 9355do_pkhbt (void)
b99bd4ef 9356{
c19d1205
ZW
9357 inst.instruction |= inst.operands[0].reg << 12;
9358 inst.instruction |= inst.operands[1].reg << 16;
9359 inst.instruction |= inst.operands[2].reg;
9360 if (inst.operands[3].present)
9361 encode_arm_shift (3);
9362}
b99bd4ef 9363
c19d1205 9364/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9365
c19d1205
ZW
9366static void
9367do_pkhtb (void)
9368{
9369 if (!inst.operands[3].present)
b99bd4ef 9370 {
c19d1205
ZW
9371 /* If the shift specifier is omitted, turn the instruction
9372 into pkhbt rd, rm, rn. */
9373 inst.instruction &= 0xfff00010;
9374 inst.instruction |= inst.operands[0].reg << 12;
9375 inst.instruction |= inst.operands[1].reg;
9376 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9377 }
9378 else
9379 {
c19d1205
ZW
9380 inst.instruction |= inst.operands[0].reg << 12;
9381 inst.instruction |= inst.operands[1].reg << 16;
9382 inst.instruction |= inst.operands[2].reg;
9383 encode_arm_shift (3);
b99bd4ef
NC
9384 }
9385}
9386
c19d1205 9387/* ARMv5TE: Preload-Cache
60e5ef9f 9388 MP Extensions: Preload for write
c19d1205 9389
60e5ef9f 9390 PLD(W) <addr_mode>
c19d1205
ZW
9391
9392 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9393
9394static void
c19d1205 9395do_pld (void)
b99bd4ef 9396{
c19d1205
ZW
9397 constraint (!inst.operands[0].isreg,
9398 _("'[' expected after PLD mnemonic"));
9399 constraint (inst.operands[0].postind,
9400 _("post-indexed expression used in preload instruction"));
9401 constraint (inst.operands[0].writeback,
9402 _("writeback used in preload instruction"));
9403 constraint (!inst.operands[0].preind,
9404 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9405 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9406}
b99bd4ef 9407
62b3e311
PB
9408/* ARMv7: PLI <addr_mode> */
9409static void
9410do_pli (void)
9411{
9412 constraint (!inst.operands[0].isreg,
9413 _("'[' expected after PLI mnemonic"));
9414 constraint (inst.operands[0].postind,
9415 _("post-indexed expression used in preload instruction"));
9416 constraint (inst.operands[0].writeback,
9417 _("writeback used in preload instruction"));
9418 constraint (!inst.operands[0].preind,
9419 _("unindexed addressing used in preload instruction"));
9420 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9421 inst.instruction &= ~PRE_INDEX;
9422}
9423
c19d1205
ZW
9424static void
9425do_push_pop (void)
9426{
5e0d7f77
MP
9427 constraint (inst.operands[0].writeback,
9428 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9429 inst.operands[1] = inst.operands[0];
9430 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9431 inst.operands[0].isreg = 1;
9432 inst.operands[0].writeback = 1;
9433 inst.operands[0].reg = REG_SP;
6530b175 9434 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9435}
b99bd4ef 9436
c19d1205
ZW
9437/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9438 word at the specified address and the following word
9439 respectively.
9440 Unconditionally executed.
9441 Error if Rn is R15. */
b99bd4ef 9442
c19d1205
ZW
9443static void
9444do_rfe (void)
9445{
9446 inst.instruction |= inst.operands[0].reg << 16;
9447 if (inst.operands[0].writeback)
9448 inst.instruction |= WRITE_BACK;
9449}
b99bd4ef 9450
c19d1205 9451/* ARM V6 ssat (argument parse). */
b99bd4ef 9452
c19d1205
ZW
9453static void
9454do_ssat (void)
9455{
9456 inst.instruction |= inst.operands[0].reg << 12;
9457 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9458 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9459
c19d1205
ZW
9460 if (inst.operands[3].present)
9461 encode_arm_shift (3);
b99bd4ef
NC
9462}
9463
c19d1205 9464/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9465
9466static void
c19d1205 9467do_usat (void)
b99bd4ef 9468{
c19d1205
ZW
9469 inst.instruction |= inst.operands[0].reg << 12;
9470 inst.instruction |= inst.operands[1].imm << 16;
9471 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9472
c19d1205
ZW
9473 if (inst.operands[3].present)
9474 encode_arm_shift (3);
b99bd4ef
NC
9475}
9476
c19d1205 9477/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9478
9479static void
c19d1205 9480do_ssat16 (void)
09d92015 9481{
c19d1205
ZW
9482 inst.instruction |= inst.operands[0].reg << 12;
9483 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9484 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9485}
9486
c19d1205
ZW
9487static void
9488do_usat16 (void)
a737bd4d 9489{
c19d1205
ZW
9490 inst.instruction |= inst.operands[0].reg << 12;
9491 inst.instruction |= inst.operands[1].imm << 16;
9492 inst.instruction |= inst.operands[2].reg;
9493}
a737bd4d 9494
c19d1205
ZW
9495/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9496 preserving the other bits.
a737bd4d 9497
c19d1205
ZW
9498 setend <endian_specifier>, where <endian_specifier> is either
9499 BE or LE. */
a737bd4d 9500
c19d1205
ZW
9501static void
9502do_setend (void)
9503{
12e37cbc
MGD
9504 if (warn_on_deprecated
9505 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9506 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9507
c19d1205
ZW
9508 if (inst.operands[0].imm)
9509 inst.instruction |= 0x200;
a737bd4d
NC
9510}
9511
9512static void
c19d1205 9513do_shift (void)
a737bd4d 9514{
c19d1205
ZW
9515 unsigned int Rm = (inst.operands[1].present
9516 ? inst.operands[1].reg
9517 : inst.operands[0].reg);
a737bd4d 9518
c19d1205
ZW
9519 inst.instruction |= inst.operands[0].reg << 12;
9520 inst.instruction |= Rm;
9521 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9522 {
c19d1205
ZW
9523 inst.instruction |= inst.operands[2].reg << 8;
9524 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9525 /* PR 12854: Error on extraneous shifts. */
9526 constraint (inst.operands[2].shifted,
9527 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9528 }
9529 else
c19d1205 9530 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9531}
9532
09d92015 9533static void
3eb17e6b 9534do_smc (void)
09d92015 9535{
3eb17e6b 9536 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9537 inst.reloc.pc_rel = 0;
09d92015
MM
9538}
9539
90ec0d68
MGD
9540static void
9541do_hvc (void)
9542{
9543 inst.reloc.type = BFD_RELOC_ARM_HVC;
9544 inst.reloc.pc_rel = 0;
9545}
9546
09d92015 9547static void
c19d1205 9548do_swi (void)
09d92015 9549{
c19d1205
ZW
9550 inst.reloc.type = BFD_RELOC_ARM_SWI;
9551 inst.reloc.pc_rel = 0;
09d92015
MM
9552}
9553
ddfded2f
MW
9554static void
9555do_setpan (void)
9556{
9557 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9558 _("selected processor does not support SETPAN instruction"));
9559
9560 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9561}
9562
9563static void
9564do_t_setpan (void)
9565{
9566 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9567 _("selected processor does not support SETPAN instruction"));
9568
9569 inst.instruction |= (inst.operands[0].imm << 3);
9570}
9571
c19d1205
ZW
9572/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9573 SMLAxy{cond} Rd,Rm,Rs,Rn
9574 SMLAWy{cond} Rd,Rm,Rs,Rn
9575 Error if any register is R15. */
e16bb312 9576
c19d1205
ZW
9577static void
9578do_smla (void)
e16bb312 9579{
c19d1205
ZW
9580 inst.instruction |= inst.operands[0].reg << 16;
9581 inst.instruction |= inst.operands[1].reg;
9582 inst.instruction |= inst.operands[2].reg << 8;
9583 inst.instruction |= inst.operands[3].reg << 12;
9584}
a737bd4d 9585
c19d1205
ZW
9586/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9587 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9588 Error if any register is R15.
9589 Warning if Rdlo == Rdhi. */
a737bd4d 9590
c19d1205
ZW
9591static void
9592do_smlal (void)
9593{
9594 inst.instruction |= inst.operands[0].reg << 12;
9595 inst.instruction |= inst.operands[1].reg << 16;
9596 inst.instruction |= inst.operands[2].reg;
9597 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9598
c19d1205
ZW
9599 if (inst.operands[0].reg == inst.operands[1].reg)
9600 as_tsktsk (_("rdhi and rdlo must be different"));
9601}
a737bd4d 9602
c19d1205
ZW
9603/* ARM V5E (El Segundo) signed-multiply (argument parse)
9604 SMULxy{cond} Rd,Rm,Rs
9605 Error if any register is R15. */
a737bd4d 9606
c19d1205
ZW
9607static void
9608do_smul (void)
9609{
9610 inst.instruction |= inst.operands[0].reg << 16;
9611 inst.instruction |= inst.operands[1].reg;
9612 inst.instruction |= inst.operands[2].reg << 8;
9613}
a737bd4d 9614
b6702015
PB
9615/* ARM V6 srs (argument parse). The variable fields in the encoding are
9616 the same for both ARM and Thumb-2. */
a737bd4d 9617
c19d1205
ZW
9618static void
9619do_srs (void)
9620{
b6702015
PB
9621 int reg;
9622
9623 if (inst.operands[0].present)
9624 {
9625 reg = inst.operands[0].reg;
fdfde340 9626 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9627 }
9628 else
fdfde340 9629 reg = REG_SP;
b6702015
PB
9630
9631 inst.instruction |= reg << 16;
9632 inst.instruction |= inst.operands[1].imm;
9633 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9634 inst.instruction |= WRITE_BACK;
9635}
a737bd4d 9636
c19d1205 9637/* ARM V6 strex (argument parse). */
a737bd4d 9638
c19d1205
ZW
9639static void
9640do_strex (void)
9641{
9642 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9643 || inst.operands[2].postind || inst.operands[2].writeback
9644 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9645 || inst.operands[2].negative
9646 /* See comment in do_ldrex(). */
9647 || (inst.operands[2].reg == REG_PC),
9648 BAD_ADDR_MODE);
a737bd4d 9649
c19d1205
ZW
9650 constraint (inst.operands[0].reg == inst.operands[1].reg
9651 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9652
c19d1205
ZW
9653 constraint (inst.reloc.exp.X_op != O_constant
9654 || inst.reloc.exp.X_add_number != 0,
9655 _("offset must be zero in ARM encoding"));
a737bd4d 9656
c19d1205
ZW
9657 inst.instruction |= inst.operands[0].reg << 12;
9658 inst.instruction |= inst.operands[1].reg;
9659 inst.instruction |= inst.operands[2].reg << 16;
9660 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9661}
9662
877807f8
NC
9663static void
9664do_t_strexbh (void)
9665{
9666 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9667 || inst.operands[2].postind || inst.operands[2].writeback
9668 || inst.operands[2].immisreg || inst.operands[2].shifted
9669 || inst.operands[2].negative,
9670 BAD_ADDR_MODE);
9671
9672 constraint (inst.operands[0].reg == inst.operands[1].reg
9673 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9674
9675 do_rm_rd_rn ();
9676}
9677
e16bb312 9678static void
c19d1205 9679do_strexd (void)
e16bb312 9680{
c19d1205
ZW
9681 constraint (inst.operands[1].reg % 2 != 0,
9682 _("even register required"));
9683 constraint (inst.operands[2].present
9684 && inst.operands[2].reg != inst.operands[1].reg + 1,
9685 _("can only store two consecutive registers"));
9686 /* If op 2 were present and equal to PC, this function wouldn't
9687 have been called in the first place. */
9688 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9689
c19d1205
ZW
9690 constraint (inst.operands[0].reg == inst.operands[1].reg
9691 || inst.operands[0].reg == inst.operands[1].reg + 1
9692 || inst.operands[0].reg == inst.operands[3].reg,
9693 BAD_OVERLAP);
e16bb312 9694
c19d1205
ZW
9695 inst.instruction |= inst.operands[0].reg << 12;
9696 inst.instruction |= inst.operands[1].reg;
9697 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9698}
9699
9eb6c0f1
MGD
9700/* ARM V8 STRL. */
9701static void
4b8c8c02 9702do_stlex (void)
9eb6c0f1
MGD
9703{
9704 constraint (inst.operands[0].reg == inst.operands[1].reg
9705 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9706
9707 do_rd_rm_rn ();
9708}
9709
9710static void
4b8c8c02 9711do_t_stlex (void)
9eb6c0f1
MGD
9712{
9713 constraint (inst.operands[0].reg == inst.operands[1].reg
9714 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9715
9716 do_rm_rd_rn ();
9717}
9718
c19d1205
ZW
9719/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9720 extends it to 32-bits, and adds the result to a value in another
9721 register. You can specify a rotation by 0, 8, 16, or 24 bits
9722 before extracting the 16-bit value.
9723 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9724 Condition defaults to COND_ALWAYS.
9725 Error if any register uses R15. */
9726
e16bb312 9727static void
c19d1205 9728do_sxtah (void)
e16bb312 9729{
c19d1205
ZW
9730 inst.instruction |= inst.operands[0].reg << 12;
9731 inst.instruction |= inst.operands[1].reg << 16;
9732 inst.instruction |= inst.operands[2].reg;
9733 inst.instruction |= inst.operands[3].imm << 10;
9734}
e16bb312 9735
c19d1205 9736/* ARM V6 SXTH.
e16bb312 9737
c19d1205
ZW
9738 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9739 Condition defaults to COND_ALWAYS.
9740 Error if any register uses R15. */
e16bb312
NC
9741
9742static void
c19d1205 9743do_sxth (void)
e16bb312 9744{
c19d1205
ZW
9745 inst.instruction |= inst.operands[0].reg << 12;
9746 inst.instruction |= inst.operands[1].reg;
9747 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9748}
c19d1205
ZW
9749\f
9750/* VFP instructions. In a logical order: SP variant first, monad
9751 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9752
9753static void
c19d1205 9754do_vfp_sp_monadic (void)
e16bb312 9755{
5287ad62
JB
9756 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9757 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9758}
9759
9760static void
c19d1205 9761do_vfp_sp_dyadic (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_Sn);
9765 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9766}
9767
9768static void
c19d1205 9769do_vfp_sp_compare_z (void)
e16bb312 9770{
5287ad62 9771 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9772}
9773
9774static void
c19d1205 9775do_vfp_dp_sp_cvt (void)
e16bb312 9776{
5287ad62
JB
9777 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9778 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9779}
9780
9781static void
c19d1205 9782do_vfp_sp_dp_cvt (void)
e16bb312 9783{
5287ad62
JB
9784 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9785 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9786}
9787
9788static void
c19d1205 9789do_vfp_reg_from_sp (void)
e16bb312 9790{
c19d1205 9791 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9792 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9793}
9794
9795static void
c19d1205 9796do_vfp_reg2_from_sp2 (void)
e16bb312 9797{
c19d1205
ZW
9798 constraint (inst.operands[2].imm != 2,
9799 _("only two consecutive VFP SP registers allowed here"));
9800 inst.instruction |= inst.operands[0].reg << 12;
9801 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9802 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9803}
9804
9805static void
c19d1205 9806do_vfp_sp_from_reg (void)
e16bb312 9807{
5287ad62 9808 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9809 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9810}
9811
9812static void
c19d1205 9813do_vfp_sp2_from_reg2 (void)
e16bb312 9814{
c19d1205
ZW
9815 constraint (inst.operands[0].imm != 2,
9816 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9817 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9818 inst.instruction |= inst.operands[1].reg << 12;
9819 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9820}
9821
9822static void
c19d1205 9823do_vfp_sp_ldst (void)
e16bb312 9824{
5287ad62 9825 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9826 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9827}
9828
9829static void
c19d1205 9830do_vfp_dp_ldst (void)
e16bb312 9831{
5287ad62 9832 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9833 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9834}
9835
c19d1205 9836
e16bb312 9837static void
c19d1205 9838vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9839{
c19d1205
ZW
9840 if (inst.operands[0].writeback)
9841 inst.instruction |= WRITE_BACK;
9842 else
9843 constraint (ldstm_type != VFP_LDSTMIA,
9844 _("this addressing mode requires base-register writeback"));
9845 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9846 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9847 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9848}
9849
9850static void
c19d1205 9851vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9852{
c19d1205 9853 int count;
e16bb312 9854
c19d1205
ZW
9855 if (inst.operands[0].writeback)
9856 inst.instruction |= WRITE_BACK;
9857 else
9858 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9859 _("this addressing mode requires base-register writeback"));
e16bb312 9860
c19d1205 9861 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9862 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9863
c19d1205
ZW
9864 count = inst.operands[1].imm << 1;
9865 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9866 count += 1;
e16bb312 9867
c19d1205 9868 inst.instruction |= count;
e16bb312
NC
9869}
9870
9871static void
c19d1205 9872do_vfp_sp_ldstmia (void)
e16bb312 9873{
c19d1205 9874 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9875}
9876
9877static void
c19d1205 9878do_vfp_sp_ldstmdb (void)
e16bb312 9879{
c19d1205 9880 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9881}
9882
9883static void
c19d1205 9884do_vfp_dp_ldstmia (void)
e16bb312 9885{
c19d1205 9886 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9887}
9888
9889static void
c19d1205 9890do_vfp_dp_ldstmdb (void)
e16bb312 9891{
c19d1205 9892 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9893}
9894
9895static void
c19d1205 9896do_vfp_xp_ldstmia (void)
e16bb312 9897{
c19d1205
ZW
9898 vfp_dp_ldstm (VFP_LDSTMIAX);
9899}
e16bb312 9900
c19d1205
ZW
9901static void
9902do_vfp_xp_ldstmdb (void)
9903{
9904 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9905}
5287ad62
JB
9906
9907static void
9908do_vfp_dp_rd_rm (void)
9909{
9910 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9911 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9912}
9913
9914static void
9915do_vfp_dp_rn_rd (void)
9916{
9917 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9918 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9919}
9920
9921static void
9922do_vfp_dp_rd_rn (void)
9923{
9924 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9925 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9926}
9927
9928static void
9929do_vfp_dp_rd_rn_rm (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 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9934}
9935
9936static void
9937do_vfp_dp_rd (void)
9938{
9939 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9940}
9941
9942static void
9943do_vfp_dp_rm_rd_rn (void)
9944{
9945 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9946 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9947 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9948}
9949
9950/* VFPv3 instructions. */
9951static void
9952do_vfp_sp_const (void)
9953{
9954 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9955 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9956 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9957}
9958
9959static void
9960do_vfp_dp_const (void)
9961{
9962 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9963 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9964 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9965}
9966
9967static void
9968vfp_conv (int srcsize)
9969{
5f1af56b
MGD
9970 int immbits = srcsize - inst.operands[1].imm;
9971
fa94de6b
RM
9972 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9973 {
5f1af56b 9974 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9975 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9976 inst.error = _("immediate value out of range, expected range [0, 16]");
9977 return;
9978 }
fa94de6b 9979 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9980 {
9981 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9982 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9983 inst.error = _("immediate value out of range, expected range [1, 32]");
9984 return;
9985 }
9986
5287ad62
JB
9987 inst.instruction |= (immbits & 1) << 5;
9988 inst.instruction |= (immbits >> 1);
9989}
9990
9991static void
9992do_vfp_sp_conv_16 (void)
9993{
9994 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9995 vfp_conv (16);
9996}
9997
9998static void
9999do_vfp_dp_conv_16 (void)
10000{
10001 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10002 vfp_conv (16);
10003}
10004
10005static void
10006do_vfp_sp_conv_32 (void)
10007{
10008 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10009 vfp_conv (32);
10010}
10011
10012static void
10013do_vfp_dp_conv_32 (void)
10014{
10015 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10016 vfp_conv (32);
10017}
c19d1205
ZW
10018\f
10019/* FPA instructions. Also in a logical order. */
e16bb312 10020
c19d1205
ZW
10021static void
10022do_fpa_cmp (void)
10023{
10024 inst.instruction |= inst.operands[0].reg << 16;
10025 inst.instruction |= inst.operands[1].reg;
10026}
b99bd4ef
NC
10027
10028static void
c19d1205 10029do_fpa_ldmstm (void)
b99bd4ef 10030{
c19d1205
ZW
10031 inst.instruction |= inst.operands[0].reg << 12;
10032 switch (inst.operands[1].imm)
10033 {
10034 case 1: inst.instruction |= CP_T_X; break;
10035 case 2: inst.instruction |= CP_T_Y; break;
10036 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10037 case 4: break;
10038 default: abort ();
10039 }
b99bd4ef 10040
c19d1205
ZW
10041 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10042 {
10043 /* The instruction specified "ea" or "fd", so we can only accept
10044 [Rn]{!}. The instruction does not really support stacking or
10045 unstacking, so we have to emulate these by setting appropriate
10046 bits and offsets. */
10047 constraint (inst.reloc.exp.X_op != O_constant
10048 || inst.reloc.exp.X_add_number != 0,
10049 _("this instruction does not support indexing"));
b99bd4ef 10050
c19d1205
ZW
10051 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
10052 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 10053
c19d1205
ZW
10054 if (!(inst.instruction & INDEX_UP))
10055 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 10056
c19d1205
ZW
10057 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10058 {
10059 inst.operands[2].preind = 0;
10060 inst.operands[2].postind = 1;
10061 }
10062 }
b99bd4ef 10063
c19d1205 10064 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 10065}
c19d1205
ZW
10066\f
10067/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 10068
c19d1205
ZW
10069static void
10070do_iwmmxt_tandorc (void)
10071{
10072 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10073}
b99bd4ef 10074
c19d1205
ZW
10075static void
10076do_iwmmxt_textrc (void)
10077{
10078 inst.instruction |= inst.operands[0].reg << 12;
10079 inst.instruction |= inst.operands[1].imm;
10080}
b99bd4ef
NC
10081
10082static void
c19d1205 10083do_iwmmxt_textrm (void)
b99bd4ef 10084{
c19d1205
ZW
10085 inst.instruction |= inst.operands[0].reg << 12;
10086 inst.instruction |= inst.operands[1].reg << 16;
10087 inst.instruction |= inst.operands[2].imm;
10088}
b99bd4ef 10089
c19d1205
ZW
10090static void
10091do_iwmmxt_tinsr (void)
10092{
10093 inst.instruction |= inst.operands[0].reg << 16;
10094 inst.instruction |= inst.operands[1].reg << 12;
10095 inst.instruction |= inst.operands[2].imm;
10096}
b99bd4ef 10097
c19d1205
ZW
10098static void
10099do_iwmmxt_tmia (void)
10100{
10101 inst.instruction |= inst.operands[0].reg << 5;
10102 inst.instruction |= inst.operands[1].reg;
10103 inst.instruction |= inst.operands[2].reg << 12;
10104}
b99bd4ef 10105
c19d1205
ZW
10106static void
10107do_iwmmxt_waligni (void)
10108{
10109 inst.instruction |= inst.operands[0].reg << 12;
10110 inst.instruction |= inst.operands[1].reg << 16;
10111 inst.instruction |= inst.operands[2].reg;
10112 inst.instruction |= inst.operands[3].imm << 20;
10113}
b99bd4ef 10114
2d447fca
JM
10115static void
10116do_iwmmxt_wmerge (void)
10117{
10118 inst.instruction |= inst.operands[0].reg << 12;
10119 inst.instruction |= inst.operands[1].reg << 16;
10120 inst.instruction |= inst.operands[2].reg;
10121 inst.instruction |= inst.operands[3].imm << 21;
10122}
10123
c19d1205
ZW
10124static void
10125do_iwmmxt_wmov (void)
10126{
10127 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10128 inst.instruction |= inst.operands[0].reg << 12;
10129 inst.instruction |= inst.operands[1].reg << 16;
10130 inst.instruction |= inst.operands[1].reg;
10131}
b99bd4ef 10132
c19d1205
ZW
10133static void
10134do_iwmmxt_wldstbh (void)
10135{
8f06b2d8 10136 int reloc;
c19d1205 10137 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10138 if (thumb_mode)
10139 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10140 else
10141 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10142 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10143}
10144
c19d1205
ZW
10145static void
10146do_iwmmxt_wldstw (void)
10147{
10148 /* RIWR_RIWC clears .isreg for a control register. */
10149 if (!inst.operands[0].isreg)
10150 {
10151 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10152 inst.instruction |= 0xf0000000;
10153 }
b99bd4ef 10154
c19d1205
ZW
10155 inst.instruction |= inst.operands[0].reg << 12;
10156 encode_arm_cp_address (1, TRUE, TRUE, 0);
10157}
b99bd4ef
NC
10158
10159static void
c19d1205 10160do_iwmmxt_wldstd (void)
b99bd4ef 10161{
c19d1205 10162 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10163 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10164 && inst.operands[1].immisreg)
10165 {
10166 inst.instruction &= ~0x1a000ff;
eff0bc54 10167 inst.instruction |= (0xfU << 28);
2d447fca
JM
10168 if (inst.operands[1].preind)
10169 inst.instruction |= PRE_INDEX;
10170 if (!inst.operands[1].negative)
10171 inst.instruction |= INDEX_UP;
10172 if (inst.operands[1].writeback)
10173 inst.instruction |= WRITE_BACK;
10174 inst.instruction |= inst.operands[1].reg << 16;
10175 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10176 inst.instruction |= inst.operands[1].imm;
10177 }
10178 else
10179 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10180}
b99bd4ef 10181
c19d1205
ZW
10182static void
10183do_iwmmxt_wshufh (void)
10184{
10185 inst.instruction |= inst.operands[0].reg << 12;
10186 inst.instruction |= inst.operands[1].reg << 16;
10187 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10188 inst.instruction |= (inst.operands[2].imm & 0x0f);
10189}
b99bd4ef 10190
c19d1205
ZW
10191static void
10192do_iwmmxt_wzero (void)
10193{
10194 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10195 inst.instruction |= inst.operands[0].reg;
10196 inst.instruction |= inst.operands[0].reg << 12;
10197 inst.instruction |= inst.operands[0].reg << 16;
10198}
2d447fca
JM
10199
10200static void
10201do_iwmmxt_wrwrwr_or_imm5 (void)
10202{
10203 if (inst.operands[2].isreg)
10204 do_rd_rn_rm ();
10205 else {
10206 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10207 _("immediate operand requires iWMMXt2"));
10208 do_rd_rn ();
10209 if (inst.operands[2].imm == 0)
10210 {
10211 switch ((inst.instruction >> 20) & 0xf)
10212 {
10213 case 4:
10214 case 5:
10215 case 6:
5f4273c7 10216 case 7:
2d447fca
JM
10217 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10218 inst.operands[2].imm = 16;
10219 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10220 break;
10221 case 8:
10222 case 9:
10223 case 10:
10224 case 11:
10225 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10226 inst.operands[2].imm = 32;
10227 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10228 break;
10229 case 12:
10230 case 13:
10231 case 14:
10232 case 15:
10233 {
10234 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10235 unsigned long wrn;
10236 wrn = (inst.instruction >> 16) & 0xf;
10237 inst.instruction &= 0xff0fff0f;
10238 inst.instruction |= wrn;
10239 /* Bail out here; the instruction is now assembled. */
10240 return;
10241 }
10242 }
10243 }
10244 /* Map 32 -> 0, etc. */
10245 inst.operands[2].imm &= 0x1f;
eff0bc54 10246 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10247 }
10248}
c19d1205
ZW
10249\f
10250/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10251 operations first, then control, shift, and load/store. */
b99bd4ef 10252
c19d1205 10253/* Insns like "foo X,Y,Z". */
b99bd4ef 10254
c19d1205
ZW
10255static void
10256do_mav_triple (void)
10257{
10258 inst.instruction |= inst.operands[0].reg << 16;
10259 inst.instruction |= inst.operands[1].reg;
10260 inst.instruction |= inst.operands[2].reg << 12;
10261}
b99bd4ef 10262
c19d1205
ZW
10263/* Insns like "foo W,X,Y,Z".
10264 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10265
c19d1205
ZW
10266static void
10267do_mav_quad (void)
10268{
10269 inst.instruction |= inst.operands[0].reg << 5;
10270 inst.instruction |= inst.operands[1].reg << 12;
10271 inst.instruction |= inst.operands[2].reg << 16;
10272 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10273}
10274
c19d1205
ZW
10275/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10276static void
10277do_mav_dspsc (void)
a737bd4d 10278{
c19d1205
ZW
10279 inst.instruction |= inst.operands[1].reg << 12;
10280}
a737bd4d 10281
c19d1205
ZW
10282/* Maverick shift immediate instructions.
10283 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10284 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10285
c19d1205
ZW
10286static void
10287do_mav_shift (void)
10288{
10289 int imm = inst.operands[2].imm;
a737bd4d 10290
c19d1205
ZW
10291 inst.instruction |= inst.operands[0].reg << 12;
10292 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10293
c19d1205
ZW
10294 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10295 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10296 Bit 4 should be 0. */
10297 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10298
c19d1205
ZW
10299 inst.instruction |= imm;
10300}
10301\f
10302/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10303
c19d1205
ZW
10304/* Xscale multiply-accumulate (argument parse)
10305 MIAcc acc0,Rm,Rs
10306 MIAPHcc acc0,Rm,Rs
10307 MIAxycc acc0,Rm,Rs. */
a737bd4d 10308
c19d1205
ZW
10309static void
10310do_xsc_mia (void)
10311{
10312 inst.instruction |= inst.operands[1].reg;
10313 inst.instruction |= inst.operands[2].reg << 12;
10314}
a737bd4d 10315
c19d1205 10316/* Xscale move-accumulator-register (argument parse)
a737bd4d 10317
c19d1205 10318 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10319
c19d1205
ZW
10320static void
10321do_xsc_mar (void)
10322{
10323 inst.instruction |= inst.operands[1].reg << 12;
10324 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10325}
10326
c19d1205 10327/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10328
c19d1205 10329 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10330
10331static void
c19d1205 10332do_xsc_mra (void)
b99bd4ef 10333{
c19d1205
ZW
10334 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10335 inst.instruction |= inst.operands[0].reg << 12;
10336 inst.instruction |= inst.operands[1].reg << 16;
10337}
10338\f
10339/* Encoding functions relevant only to Thumb. */
b99bd4ef 10340
c19d1205
ZW
10341/* inst.operands[i] is a shifted-register operand; encode
10342 it into inst.instruction in the format used by Thumb32. */
10343
10344static void
10345encode_thumb32_shifted_operand (int i)
10346{
10347 unsigned int value = inst.reloc.exp.X_add_number;
10348 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10349
9c3c69f2
PB
10350 constraint (inst.operands[i].immisreg,
10351 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10352 inst.instruction |= inst.operands[i].reg;
10353 if (shift == SHIFT_RRX)
10354 inst.instruction |= SHIFT_ROR << 4;
10355 else
b99bd4ef 10356 {
c19d1205
ZW
10357 constraint (inst.reloc.exp.X_op != O_constant,
10358 _("expression too complex"));
10359
10360 constraint (value > 32
10361 || (value == 32 && (shift == SHIFT_LSL
10362 || shift == SHIFT_ROR)),
10363 _("shift expression is too large"));
10364
10365 if (value == 0)
10366 shift = SHIFT_LSL;
10367 else if (value == 32)
10368 value = 0;
10369
10370 inst.instruction |= shift << 4;
10371 inst.instruction |= (value & 0x1c) << 10;
10372 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10373 }
c19d1205 10374}
b99bd4ef 10375
b99bd4ef 10376
c19d1205
ZW
10377/* inst.operands[i] was set up by parse_address. Encode it into a
10378 Thumb32 format load or store instruction. Reject forms that cannot
10379 be used with such instructions. If is_t is true, reject forms that
10380 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10381 that cannot be used with a D instruction. If it is a store insn,
10382 reject PC in Rn. */
b99bd4ef 10383
c19d1205
ZW
10384static void
10385encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10386{
5be8be5d 10387 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10388
10389 constraint (!inst.operands[i].isreg,
53365c0d 10390 _("Instruction does not support =N addresses"));
b99bd4ef 10391
c19d1205
ZW
10392 inst.instruction |= inst.operands[i].reg << 16;
10393 if (inst.operands[i].immisreg)
b99bd4ef 10394 {
5be8be5d 10395 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10396 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10397 constraint (inst.operands[i].negative,
10398 _("Thumb does not support negative register indexing"));
10399 constraint (inst.operands[i].postind,
10400 _("Thumb does not support register post-indexing"));
10401 constraint (inst.operands[i].writeback,
10402 _("Thumb does not support register indexing with writeback"));
10403 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10404 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10405
f40d1643 10406 inst.instruction |= inst.operands[i].imm;
c19d1205 10407 if (inst.operands[i].shifted)
b99bd4ef 10408 {
c19d1205
ZW
10409 constraint (inst.reloc.exp.X_op != O_constant,
10410 _("expression too complex"));
9c3c69f2
PB
10411 constraint (inst.reloc.exp.X_add_number < 0
10412 || inst.reloc.exp.X_add_number > 3,
c19d1205 10413 _("shift out of range"));
9c3c69f2 10414 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10415 }
10416 inst.reloc.type = BFD_RELOC_UNUSED;
10417 }
10418 else if (inst.operands[i].preind)
10419 {
5be8be5d 10420 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10421 constraint (is_t && inst.operands[i].writeback,
c19d1205 10422 _("cannot use writeback with this instruction"));
4755303e
WN
10423 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10424 BAD_PC_ADDRESSING);
c19d1205
ZW
10425
10426 if (is_d)
10427 {
10428 inst.instruction |= 0x01000000;
10429 if (inst.operands[i].writeback)
10430 inst.instruction |= 0x00200000;
b99bd4ef 10431 }
c19d1205 10432 else
b99bd4ef 10433 {
c19d1205
ZW
10434 inst.instruction |= 0x00000c00;
10435 if (inst.operands[i].writeback)
10436 inst.instruction |= 0x00000100;
b99bd4ef 10437 }
c19d1205 10438 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10439 }
c19d1205 10440 else if (inst.operands[i].postind)
b99bd4ef 10441 {
9c2799c2 10442 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10443 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10444 constraint (is_t, _("cannot use post-indexing with this instruction"));
10445
10446 if (is_d)
10447 inst.instruction |= 0x00200000;
10448 else
10449 inst.instruction |= 0x00000900;
10450 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10451 }
10452 else /* unindexed - only for coprocessor */
10453 inst.error = _("instruction does not accept unindexed addressing");
10454}
10455
10456/* Table of Thumb instructions which exist in both 16- and 32-bit
10457 encodings (the latter only in post-V6T2 cores). The index is the
10458 value used in the insns table below. When there is more than one
10459 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10460 holds variant (1).
10461 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10462#define T16_32_TAB \
21d799b5
NC
10463 X(_adc, 4140, eb400000), \
10464 X(_adcs, 4140, eb500000), \
10465 X(_add, 1c00, eb000000), \
10466 X(_adds, 1c00, eb100000), \
10467 X(_addi, 0000, f1000000), \
10468 X(_addis, 0000, f1100000), \
10469 X(_add_pc,000f, f20f0000), \
10470 X(_add_sp,000d, f10d0000), \
10471 X(_adr, 000f, f20f0000), \
10472 X(_and, 4000, ea000000), \
10473 X(_ands, 4000, ea100000), \
10474 X(_asr, 1000, fa40f000), \
10475 X(_asrs, 1000, fa50f000), \
10476 X(_b, e000, f000b000), \
10477 X(_bcond, d000, f0008000), \
10478 X(_bic, 4380, ea200000), \
10479 X(_bics, 4380, ea300000), \
10480 X(_cmn, 42c0, eb100f00), \
10481 X(_cmp, 2800, ebb00f00), \
10482 X(_cpsie, b660, f3af8400), \
10483 X(_cpsid, b670, f3af8600), \
10484 X(_cpy, 4600, ea4f0000), \
10485 X(_dec_sp,80dd, f1ad0d00), \
10486 X(_eor, 4040, ea800000), \
10487 X(_eors, 4040, ea900000), \
10488 X(_inc_sp,00dd, f10d0d00), \
10489 X(_ldmia, c800, e8900000), \
10490 X(_ldr, 6800, f8500000), \
10491 X(_ldrb, 7800, f8100000), \
10492 X(_ldrh, 8800, f8300000), \
10493 X(_ldrsb, 5600, f9100000), \
10494 X(_ldrsh, 5e00, f9300000), \
10495 X(_ldr_pc,4800, f85f0000), \
10496 X(_ldr_pc2,4800, f85f0000), \
10497 X(_ldr_sp,9800, f85d0000), \
10498 X(_lsl, 0000, fa00f000), \
10499 X(_lsls, 0000, fa10f000), \
10500 X(_lsr, 0800, fa20f000), \
10501 X(_lsrs, 0800, fa30f000), \
10502 X(_mov, 2000, ea4f0000), \
10503 X(_movs, 2000, ea5f0000), \
10504 X(_mul, 4340, fb00f000), \
10505 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10506 X(_mvn, 43c0, ea6f0000), \
10507 X(_mvns, 43c0, ea7f0000), \
10508 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10509 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10510 X(_orr, 4300, ea400000), \
10511 X(_orrs, 4300, ea500000), \
10512 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10513 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10514 X(_rev, ba00, fa90f080), \
10515 X(_rev16, ba40, fa90f090), \
10516 X(_revsh, bac0, fa90f0b0), \
10517 X(_ror, 41c0, fa60f000), \
10518 X(_rors, 41c0, fa70f000), \
10519 X(_sbc, 4180, eb600000), \
10520 X(_sbcs, 4180, eb700000), \
10521 X(_stmia, c000, e8800000), \
10522 X(_str, 6000, f8400000), \
10523 X(_strb, 7000, f8000000), \
10524 X(_strh, 8000, f8200000), \
10525 X(_str_sp,9000, f84d0000), \
10526 X(_sub, 1e00, eba00000), \
10527 X(_subs, 1e00, ebb00000), \
10528 X(_subi, 8000, f1a00000), \
10529 X(_subis, 8000, f1b00000), \
10530 X(_sxtb, b240, fa4ff080), \
10531 X(_sxth, b200, fa0ff080), \
10532 X(_tst, 4200, ea100f00), \
10533 X(_uxtb, b2c0, fa5ff080), \
10534 X(_uxth, b280, fa1ff080), \
10535 X(_nop, bf00, f3af8000), \
10536 X(_yield, bf10, f3af8001), \
10537 X(_wfe, bf20, f3af8002), \
10538 X(_wfi, bf30, f3af8003), \
53c4b28b 10539 X(_sev, bf40, f3af8004), \
74db7efb
NC
10540 X(_sevl, bf50, f3af8005), \
10541 X(_udf, de00, f7f0a000)
c19d1205
ZW
10542
10543/* To catch errors in encoding functions, the codes are all offset by
10544 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10545 as 16-bit instructions. */
21d799b5 10546#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10547enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10548#undef X
10549
10550#define X(a,b,c) 0x##b
10551static const unsigned short thumb_op16[] = { T16_32_TAB };
10552#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10553#undef X
10554
10555#define X(a,b,c) 0x##c
10556static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10557#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10558#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10559#undef X
10560#undef T16_32_TAB
10561
10562/* Thumb instruction encoders, in alphabetical order. */
10563
92e90b6e 10564/* ADDW or SUBW. */
c921be7d 10565
92e90b6e
PB
10566static void
10567do_t_add_sub_w (void)
10568{
10569 int Rd, Rn;
10570
10571 Rd = inst.operands[0].reg;
10572 Rn = inst.operands[1].reg;
10573
539d4391
NC
10574 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10575 is the SP-{plus,minus}-immediate form of the instruction. */
10576 if (Rn == REG_SP)
10577 constraint (Rd == REG_PC, BAD_PC);
10578 else
10579 reject_bad_reg (Rd);
fdfde340 10580
92e90b6e
PB
10581 inst.instruction |= (Rn << 16) | (Rd << 8);
10582 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10583}
10584
c19d1205 10585/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 10586 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
10587
10588static void
10589do_t_add_sub (void)
10590{
10591 int Rd, Rs, Rn;
10592
10593 Rd = inst.operands[0].reg;
10594 Rs = (inst.operands[1].present
10595 ? inst.operands[1].reg /* Rd, Rs, foo */
10596 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10597
e07e6e58
NC
10598 if (Rd == REG_PC)
10599 set_it_insn_type_last ();
10600
c19d1205
ZW
10601 if (unified_syntax)
10602 {
0110f2b8
PB
10603 bfd_boolean flags;
10604 bfd_boolean narrow;
10605 int opcode;
10606
10607 flags = (inst.instruction == T_MNEM_adds
10608 || inst.instruction == T_MNEM_subs);
10609 if (flags)
e07e6e58 10610 narrow = !in_it_block ();
0110f2b8 10611 else
e07e6e58 10612 narrow = in_it_block ();
c19d1205 10613 if (!inst.operands[2].isreg)
b99bd4ef 10614 {
16805f35
PB
10615 int add;
10616
5c8ed6a4
JW
10617 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10618 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 10619
16805f35
PB
10620 add = (inst.instruction == T_MNEM_add
10621 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10622 opcode = 0;
10623 if (inst.size_req != 4)
10624 {
0110f2b8 10625 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10626 appropriate. */
0110f2b8
PB
10627 if (Rd == REG_SP && Rs == REG_SP && !flags)
10628 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10629 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10630 opcode = T_MNEM_add_sp;
10631 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10632 opcode = T_MNEM_add_pc;
10633 else if (Rd <= 7 && Rs <= 7 && narrow)
10634 {
10635 if (flags)
10636 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10637 else
10638 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10639 }
10640 if (opcode)
10641 {
10642 inst.instruction = THUMB_OP16(opcode);
10643 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10644 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10645 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10646 {
10647 if (inst.size_req == 2)
10648 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10649 else
10650 inst.relax = opcode;
10651 }
0110f2b8
PB
10652 }
10653 else
10654 constraint (inst.size_req == 2, BAD_HIREG);
10655 }
10656 if (inst.size_req == 4
10657 || (inst.size_req != 2 && !opcode))
10658 {
a9f02af8
MG
10659 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10660 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10661 THUMB1_RELOC_ONLY);
efd81785
PB
10662 if (Rd == REG_PC)
10663 {
fdfde340 10664 constraint (add, BAD_PC);
efd81785
PB
10665 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10666 _("only SUBS PC, LR, #const allowed"));
10667 constraint (inst.reloc.exp.X_op != O_constant,
10668 _("expression too complex"));
10669 constraint (inst.reloc.exp.X_add_number < 0
10670 || inst.reloc.exp.X_add_number > 0xff,
10671 _("immediate value out of range"));
10672 inst.instruction = T2_SUBS_PC_LR
10673 | inst.reloc.exp.X_add_number;
10674 inst.reloc.type = BFD_RELOC_UNUSED;
10675 return;
10676 }
10677 else if (Rs == REG_PC)
16805f35
PB
10678 {
10679 /* Always use addw/subw. */
10680 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10681 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10682 }
10683 else
10684 {
10685 inst.instruction = THUMB_OP32 (inst.instruction);
10686 inst.instruction = (inst.instruction & 0xe1ffffff)
10687 | 0x10000000;
10688 if (flags)
10689 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10690 else
10691 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10692 }
dc4503c6
PB
10693 inst.instruction |= Rd << 8;
10694 inst.instruction |= Rs << 16;
0110f2b8 10695 }
b99bd4ef 10696 }
c19d1205
ZW
10697 else
10698 {
5f4cb198
NC
10699 unsigned int value = inst.reloc.exp.X_add_number;
10700 unsigned int shift = inst.operands[2].shift_kind;
10701
c19d1205
ZW
10702 Rn = inst.operands[2].reg;
10703 /* See if we can do this with a 16-bit instruction. */
10704 if (!inst.operands[2].shifted && inst.size_req != 4)
10705 {
e27ec89e
PB
10706 if (Rd > 7 || Rs > 7 || Rn > 7)
10707 narrow = FALSE;
10708
10709 if (narrow)
c19d1205 10710 {
e27ec89e
PB
10711 inst.instruction = ((inst.instruction == T_MNEM_adds
10712 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10713 ? T_OPCODE_ADD_R3
10714 : T_OPCODE_SUB_R3);
10715 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10716 return;
10717 }
b99bd4ef 10718
7e806470 10719 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10720 {
7e806470
PB
10721 /* Thumb-1 cores (except v6-M) require at least one high
10722 register in a narrow non flag setting add. */
10723 if (Rd > 7 || Rn > 7
10724 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10725 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10726 {
7e806470
PB
10727 if (Rd == Rn)
10728 {
10729 Rn = Rs;
10730 Rs = Rd;
10731 }
c19d1205
ZW
10732 inst.instruction = T_OPCODE_ADD_HI;
10733 inst.instruction |= (Rd & 8) << 4;
10734 inst.instruction |= (Rd & 7);
10735 inst.instruction |= Rn << 3;
10736 return;
10737 }
c19d1205
ZW
10738 }
10739 }
c921be7d 10740
fdfde340 10741 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
10742 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10743 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
10744 constraint (Rs == REG_PC, BAD_PC);
10745 reject_bad_reg (Rn);
10746
c19d1205
ZW
10747 /* If we get here, it can't be done in 16 bits. */
10748 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10749 _("shift must be constant"));
10750 inst.instruction = THUMB_OP32 (inst.instruction);
10751 inst.instruction |= Rd << 8;
10752 inst.instruction |= Rs << 16;
5f4cb198
NC
10753 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10754 _("shift value over 3 not allowed in thumb mode"));
10755 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10756 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10757 encode_thumb32_shifted_operand (2);
10758 }
10759 }
10760 else
10761 {
10762 constraint (inst.instruction == T_MNEM_adds
10763 || inst.instruction == T_MNEM_subs,
10764 BAD_THUMB32);
b99bd4ef 10765
c19d1205 10766 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10767 {
c19d1205
ZW
10768 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10769 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10770 BAD_HIREG);
10771
10772 inst.instruction = (inst.instruction == T_MNEM_add
10773 ? 0x0000 : 0x8000);
10774 inst.instruction |= (Rd << 4) | Rs;
10775 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10776 return;
10777 }
10778
c19d1205
ZW
10779 Rn = inst.operands[2].reg;
10780 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10781
c19d1205
ZW
10782 /* We now have Rd, Rs, and Rn set to registers. */
10783 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10784 {
c19d1205
ZW
10785 /* Can't do this for SUB. */
10786 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10787 inst.instruction = T_OPCODE_ADD_HI;
10788 inst.instruction |= (Rd & 8) << 4;
10789 inst.instruction |= (Rd & 7);
10790 if (Rs == Rd)
10791 inst.instruction |= Rn << 3;
10792 else if (Rn == Rd)
10793 inst.instruction |= Rs << 3;
10794 else
10795 constraint (1, _("dest must overlap one source register"));
10796 }
10797 else
10798 {
10799 inst.instruction = (inst.instruction == T_MNEM_add
10800 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10801 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10802 }
b99bd4ef 10803 }
b99bd4ef
NC
10804}
10805
c19d1205
ZW
10806static void
10807do_t_adr (void)
10808{
fdfde340
JM
10809 unsigned Rd;
10810
10811 Rd = inst.operands[0].reg;
10812 reject_bad_reg (Rd);
10813
10814 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10815 {
10816 /* Defer to section relaxation. */
10817 inst.relax = inst.instruction;
10818 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10819 inst.instruction |= Rd << 4;
0110f2b8
PB
10820 }
10821 else if (unified_syntax && inst.size_req != 2)
e9f89963 10822 {
0110f2b8 10823 /* Generate a 32-bit opcode. */
e9f89963 10824 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10825 inst.instruction |= Rd << 8;
e9f89963
PB
10826 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10827 inst.reloc.pc_rel = 1;
10828 }
10829 else
10830 {
0110f2b8 10831 /* Generate a 16-bit opcode. */
e9f89963
PB
10832 inst.instruction = THUMB_OP16 (inst.instruction);
10833 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10834 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10835 inst.reloc.pc_rel = 1;
fdfde340 10836 inst.instruction |= Rd << 4;
e9f89963 10837 }
52a86f84
NC
10838
10839 if (inst.reloc.exp.X_op == O_symbol
10840 && inst.reloc.exp.X_add_symbol != NULL
10841 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10842 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10843 inst.reloc.exp.X_add_number += 1;
c19d1205 10844}
b99bd4ef 10845
c19d1205
ZW
10846/* Arithmetic instructions for which there is just one 16-bit
10847 instruction encoding, and it allows only two low registers.
10848 For maximal compatibility with ARM syntax, we allow three register
10849 operands even when Thumb-32 instructions are not available, as long
10850 as the first two are identical. For instance, both "sbc r0,r1" and
10851 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10852static void
c19d1205 10853do_t_arit3 (void)
b99bd4ef 10854{
c19d1205 10855 int Rd, Rs, Rn;
b99bd4ef 10856
c19d1205
ZW
10857 Rd = inst.operands[0].reg;
10858 Rs = (inst.operands[1].present
10859 ? inst.operands[1].reg /* Rd, Rs, foo */
10860 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10861 Rn = inst.operands[2].reg;
b99bd4ef 10862
fdfde340
JM
10863 reject_bad_reg (Rd);
10864 reject_bad_reg (Rs);
10865 if (inst.operands[2].isreg)
10866 reject_bad_reg (Rn);
10867
c19d1205 10868 if (unified_syntax)
b99bd4ef 10869 {
c19d1205
ZW
10870 if (!inst.operands[2].isreg)
10871 {
10872 /* For an immediate, we always generate a 32-bit opcode;
10873 section relaxation will shrink it later if possible. */
10874 inst.instruction = THUMB_OP32 (inst.instruction);
10875 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10876 inst.instruction |= Rd << 8;
10877 inst.instruction |= Rs << 16;
10878 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10879 }
10880 else
10881 {
e27ec89e
PB
10882 bfd_boolean narrow;
10883
c19d1205 10884 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10885 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10886 narrow = !in_it_block ();
e27ec89e 10887 else
e07e6e58 10888 narrow = in_it_block ();
e27ec89e
PB
10889
10890 if (Rd > 7 || Rn > 7 || Rs > 7)
10891 narrow = FALSE;
10892 if (inst.operands[2].shifted)
10893 narrow = FALSE;
10894 if (inst.size_req == 4)
10895 narrow = FALSE;
10896
10897 if (narrow
c19d1205
ZW
10898 && Rd == Rs)
10899 {
10900 inst.instruction = THUMB_OP16 (inst.instruction);
10901 inst.instruction |= Rd;
10902 inst.instruction |= Rn << 3;
10903 return;
10904 }
b99bd4ef 10905
c19d1205
ZW
10906 /* If we get here, it can't be done in 16 bits. */
10907 constraint (inst.operands[2].shifted
10908 && inst.operands[2].immisreg,
10909 _("shift must be constant"));
10910 inst.instruction = THUMB_OP32 (inst.instruction);
10911 inst.instruction |= Rd << 8;
10912 inst.instruction |= Rs << 16;
10913 encode_thumb32_shifted_operand (2);
10914 }
a737bd4d 10915 }
c19d1205 10916 else
b99bd4ef 10917 {
c19d1205
ZW
10918 /* On its face this is a lie - the instruction does set the
10919 flags. However, the only supported mnemonic in this mode
10920 says it doesn't. */
10921 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10922
c19d1205
ZW
10923 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10924 _("unshifted register required"));
10925 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10926 constraint (Rd != Rs,
10927 _("dest and source1 must be the same register"));
a737bd4d 10928
c19d1205
ZW
10929 inst.instruction = THUMB_OP16 (inst.instruction);
10930 inst.instruction |= Rd;
10931 inst.instruction |= Rn << 3;
b99bd4ef 10932 }
a737bd4d 10933}
b99bd4ef 10934
c19d1205
ZW
10935/* Similarly, but for instructions where the arithmetic operation is
10936 commutative, so we can allow either of them to be different from
10937 the destination operand in a 16-bit instruction. For instance, all
10938 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10939 accepted. */
10940static void
10941do_t_arit3c (void)
a737bd4d 10942{
c19d1205 10943 int Rd, Rs, Rn;
b99bd4ef 10944
c19d1205
ZW
10945 Rd = inst.operands[0].reg;
10946 Rs = (inst.operands[1].present
10947 ? inst.operands[1].reg /* Rd, Rs, foo */
10948 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10949 Rn = inst.operands[2].reg;
c921be7d 10950
fdfde340
JM
10951 reject_bad_reg (Rd);
10952 reject_bad_reg (Rs);
10953 if (inst.operands[2].isreg)
10954 reject_bad_reg (Rn);
a737bd4d 10955
c19d1205 10956 if (unified_syntax)
a737bd4d 10957 {
c19d1205 10958 if (!inst.operands[2].isreg)
b99bd4ef 10959 {
c19d1205
ZW
10960 /* For an immediate, we always generate a 32-bit opcode;
10961 section relaxation will shrink it later if possible. */
10962 inst.instruction = THUMB_OP32 (inst.instruction);
10963 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10964 inst.instruction |= Rd << 8;
10965 inst.instruction |= Rs << 16;
10966 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10967 }
c19d1205 10968 else
a737bd4d 10969 {
e27ec89e
PB
10970 bfd_boolean narrow;
10971
c19d1205 10972 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10973 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10974 narrow = !in_it_block ();
e27ec89e 10975 else
e07e6e58 10976 narrow = in_it_block ();
e27ec89e
PB
10977
10978 if (Rd > 7 || Rn > 7 || Rs > 7)
10979 narrow = FALSE;
10980 if (inst.operands[2].shifted)
10981 narrow = FALSE;
10982 if (inst.size_req == 4)
10983 narrow = FALSE;
10984
10985 if (narrow)
a737bd4d 10986 {
c19d1205 10987 if (Rd == Rs)
a737bd4d 10988 {
c19d1205
ZW
10989 inst.instruction = THUMB_OP16 (inst.instruction);
10990 inst.instruction |= Rd;
10991 inst.instruction |= Rn << 3;
10992 return;
a737bd4d 10993 }
c19d1205 10994 if (Rd == Rn)
a737bd4d 10995 {
c19d1205
ZW
10996 inst.instruction = THUMB_OP16 (inst.instruction);
10997 inst.instruction |= Rd;
10998 inst.instruction |= Rs << 3;
10999 return;
a737bd4d
NC
11000 }
11001 }
c19d1205
ZW
11002
11003 /* If we get here, it can't be done in 16 bits. */
11004 constraint (inst.operands[2].shifted
11005 && inst.operands[2].immisreg,
11006 _("shift must be constant"));
11007 inst.instruction = THUMB_OP32 (inst.instruction);
11008 inst.instruction |= Rd << 8;
11009 inst.instruction |= Rs << 16;
11010 encode_thumb32_shifted_operand (2);
a737bd4d 11011 }
b99bd4ef 11012 }
c19d1205
ZW
11013 else
11014 {
11015 /* On its face this is a lie - the instruction does set the
11016 flags. However, the only supported mnemonic in this mode
11017 says it doesn't. */
11018 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11019
c19d1205
ZW
11020 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11021 _("unshifted register required"));
11022 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11023
11024 inst.instruction = THUMB_OP16 (inst.instruction);
11025 inst.instruction |= Rd;
11026
11027 if (Rd == Rs)
11028 inst.instruction |= Rn << 3;
11029 else if (Rd == Rn)
11030 inst.instruction |= Rs << 3;
11031 else
11032 constraint (1, _("dest must overlap one source register"));
11033 }
a737bd4d
NC
11034}
11035
c19d1205
ZW
11036static void
11037do_t_bfc (void)
a737bd4d 11038{
fdfde340 11039 unsigned Rd;
c19d1205
ZW
11040 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11041 constraint (msb > 32, _("bit-field extends past end of register"));
11042 /* The instruction encoding stores the LSB and MSB,
11043 not the LSB and width. */
fdfde340
JM
11044 Rd = inst.operands[0].reg;
11045 reject_bad_reg (Rd);
11046 inst.instruction |= Rd << 8;
c19d1205
ZW
11047 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11048 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11049 inst.instruction |= msb - 1;
b99bd4ef
NC
11050}
11051
c19d1205
ZW
11052static void
11053do_t_bfi (void)
b99bd4ef 11054{
fdfde340 11055 int Rd, Rn;
c19d1205 11056 unsigned int msb;
b99bd4ef 11057
fdfde340
JM
11058 Rd = inst.operands[0].reg;
11059 reject_bad_reg (Rd);
11060
c19d1205
ZW
11061 /* #0 in second position is alternative syntax for bfc, which is
11062 the same instruction but with REG_PC in the Rm field. */
11063 if (!inst.operands[1].isreg)
fdfde340
JM
11064 Rn = REG_PC;
11065 else
11066 {
11067 Rn = inst.operands[1].reg;
11068 reject_bad_reg (Rn);
11069 }
b99bd4ef 11070
c19d1205
ZW
11071 msb = inst.operands[2].imm + inst.operands[3].imm;
11072 constraint (msb > 32, _("bit-field extends past end of register"));
11073 /* The instruction encoding stores the LSB and MSB,
11074 not the LSB and width. */
fdfde340
JM
11075 inst.instruction |= Rd << 8;
11076 inst.instruction |= Rn << 16;
c19d1205
ZW
11077 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11078 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11079 inst.instruction |= msb - 1;
b99bd4ef
NC
11080}
11081
c19d1205
ZW
11082static void
11083do_t_bfx (void)
b99bd4ef 11084{
fdfde340
JM
11085 unsigned Rd, Rn;
11086
11087 Rd = inst.operands[0].reg;
11088 Rn = inst.operands[1].reg;
11089
11090 reject_bad_reg (Rd);
11091 reject_bad_reg (Rn);
11092
c19d1205
ZW
11093 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11094 _("bit-field extends past end of register"));
fdfde340
JM
11095 inst.instruction |= Rd << 8;
11096 inst.instruction |= Rn << 16;
c19d1205
ZW
11097 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11098 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11099 inst.instruction |= inst.operands[3].imm - 1;
11100}
b99bd4ef 11101
c19d1205
ZW
11102/* ARM V5 Thumb BLX (argument parse)
11103 BLX <target_addr> which is BLX(1)
11104 BLX <Rm> which is BLX(2)
11105 Unfortunately, there are two different opcodes for this mnemonic.
11106 So, the insns[].value is not used, and the code here zaps values
11107 into inst.instruction.
b99bd4ef 11108
c19d1205
ZW
11109 ??? How to take advantage of the additional two bits of displacement
11110 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11111
c19d1205
ZW
11112static void
11113do_t_blx (void)
11114{
e07e6e58
NC
11115 set_it_insn_type_last ();
11116
c19d1205 11117 if (inst.operands[0].isreg)
fdfde340
JM
11118 {
11119 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11120 /* We have a register, so this is BLX(2). */
11121 inst.instruction |= inst.operands[0].reg << 3;
11122 }
b99bd4ef
NC
11123 else
11124 {
c19d1205 11125 /* No register. This must be BLX(1). */
2fc8bdac 11126 inst.instruction = 0xf000e800;
0855e32b 11127 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11128 }
11129}
11130
c19d1205
ZW
11131static void
11132do_t_branch (void)
b99bd4ef 11133{
0110f2b8 11134 int opcode;
dfa9f0d5 11135 int cond;
2fe88214 11136 bfd_reloc_code_real_type reloc;
dfa9f0d5 11137
e07e6e58
NC
11138 cond = inst.cond;
11139 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11140
11141 if (in_it_block ())
dfa9f0d5
PB
11142 {
11143 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11144 branches. */
dfa9f0d5 11145 cond = COND_ALWAYS;
dfa9f0d5
PB
11146 }
11147 else
11148 cond = inst.cond;
11149
11150 if (cond != COND_ALWAYS)
0110f2b8
PB
11151 opcode = T_MNEM_bcond;
11152 else
11153 opcode = inst.instruction;
11154
12d6b0b7
RS
11155 if (unified_syntax
11156 && (inst.size_req == 4
10960bfb
PB
11157 || (inst.size_req != 2
11158 && (inst.operands[0].hasreloc
11159 || inst.reloc.exp.X_op == O_constant))))
c19d1205 11160 {
0110f2b8 11161 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11162 if (cond == COND_ALWAYS)
9ae92b05 11163 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11164 else
11165 {
ff8646ee
TP
11166 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11167 _("selected architecture does not support "
11168 "wide conditional branch instruction"));
11169
9c2799c2 11170 gas_assert (cond != 0xF);
dfa9f0d5 11171 inst.instruction |= cond << 22;
9ae92b05 11172 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11173 }
11174 }
b99bd4ef
NC
11175 else
11176 {
0110f2b8 11177 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11178 if (cond == COND_ALWAYS)
9ae92b05 11179 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11180 else
b99bd4ef 11181 {
dfa9f0d5 11182 inst.instruction |= cond << 8;
9ae92b05 11183 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11184 }
0110f2b8
PB
11185 /* Allow section relaxation. */
11186 if (unified_syntax && inst.size_req != 2)
11187 inst.relax = opcode;
b99bd4ef 11188 }
9ae92b05 11189 inst.reloc.type = reloc;
c19d1205 11190 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11191}
11192
8884b720 11193/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11194 between the two is the maximum immediate allowed - which is passed in
8884b720 11195 RANGE. */
b99bd4ef 11196static void
8884b720 11197do_t_bkpt_hlt1 (int range)
b99bd4ef 11198{
dfa9f0d5
PB
11199 constraint (inst.cond != COND_ALWAYS,
11200 _("instruction is always unconditional"));
c19d1205 11201 if (inst.operands[0].present)
b99bd4ef 11202 {
8884b720 11203 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11204 _("immediate value out of range"));
11205 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11206 }
8884b720
MGD
11207
11208 set_it_insn_type (NEUTRAL_IT_INSN);
11209}
11210
11211static void
11212do_t_hlt (void)
11213{
11214 do_t_bkpt_hlt1 (63);
11215}
11216
11217static void
11218do_t_bkpt (void)
11219{
11220 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11221}
11222
11223static void
c19d1205 11224do_t_branch23 (void)
b99bd4ef 11225{
e07e6e58 11226 set_it_insn_type_last ();
0855e32b 11227 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11228
0855e32b
NS
11229 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11230 this file. We used to simply ignore the PLT reloc type here --
11231 the branch encoding is now needed to deal with TLSCALL relocs.
11232 So if we see a PLT reloc now, put it back to how it used to be to
11233 keep the preexisting behaviour. */
11234 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11235 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11236
4343666d 11237#if defined(OBJ_COFF)
c19d1205
ZW
11238 /* If the destination of the branch is a defined symbol which does not have
11239 the THUMB_FUNC attribute, then we must be calling a function which has
11240 the (interfacearm) attribute. We look for the Thumb entry point to that
11241 function and change the branch to refer to that function instead. */
11242 if ( inst.reloc.exp.X_op == O_symbol
11243 && inst.reloc.exp.X_add_symbol != NULL
11244 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11245 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11246 inst.reloc.exp.X_add_symbol =
11247 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11248#endif
90e4755a
RE
11249}
11250
11251static void
c19d1205 11252do_t_bx (void)
90e4755a 11253{
e07e6e58 11254 set_it_insn_type_last ();
c19d1205
ZW
11255 inst.instruction |= inst.operands[0].reg << 3;
11256 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11257 should cause the alignment to be checked once it is known. This is
11258 because BX PC only works if the instruction is word aligned. */
11259}
90e4755a 11260
c19d1205
ZW
11261static void
11262do_t_bxj (void)
11263{
fdfde340 11264 int Rm;
90e4755a 11265
e07e6e58 11266 set_it_insn_type_last ();
fdfde340
JM
11267 Rm = inst.operands[0].reg;
11268 reject_bad_reg (Rm);
11269 inst.instruction |= Rm << 16;
90e4755a
RE
11270}
11271
11272static void
c19d1205 11273do_t_clz (void)
90e4755a 11274{
fdfde340
JM
11275 unsigned Rd;
11276 unsigned Rm;
11277
11278 Rd = inst.operands[0].reg;
11279 Rm = inst.operands[1].reg;
11280
11281 reject_bad_reg (Rd);
11282 reject_bad_reg (Rm);
11283
11284 inst.instruction |= Rd << 8;
11285 inst.instruction |= Rm << 16;
11286 inst.instruction |= Rm;
c19d1205 11287}
90e4755a 11288
91d8b670
JG
11289static void
11290do_t_csdb (void)
11291{
11292 set_it_insn_type (OUTSIDE_IT_INSN);
11293}
11294
dfa9f0d5
PB
11295static void
11296do_t_cps (void)
11297{
e07e6e58 11298 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11299 inst.instruction |= inst.operands[0].imm;
11300}
11301
c19d1205
ZW
11302static void
11303do_t_cpsi (void)
11304{
e07e6e58 11305 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11306 if (unified_syntax
62b3e311
PB
11307 && (inst.operands[1].present || inst.size_req == 4)
11308 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11309 {
c19d1205
ZW
11310 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11311 inst.instruction = 0xf3af8000;
11312 inst.instruction |= imod << 9;
11313 inst.instruction |= inst.operands[0].imm << 5;
11314 if (inst.operands[1].present)
11315 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11316 }
c19d1205 11317 else
90e4755a 11318 {
62b3e311
PB
11319 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11320 && (inst.operands[0].imm & 4),
11321 _("selected processor does not support 'A' form "
11322 "of this instruction"));
11323 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11324 _("Thumb does not support the 2-argument "
11325 "form of this instruction"));
11326 inst.instruction |= inst.operands[0].imm;
90e4755a 11327 }
90e4755a
RE
11328}
11329
c19d1205
ZW
11330/* THUMB CPY instruction (argument parse). */
11331
90e4755a 11332static void
c19d1205 11333do_t_cpy (void)
90e4755a 11334{
c19d1205 11335 if (inst.size_req == 4)
90e4755a 11336 {
c19d1205
ZW
11337 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11338 inst.instruction |= inst.operands[0].reg << 8;
11339 inst.instruction |= inst.operands[1].reg;
90e4755a 11340 }
c19d1205 11341 else
90e4755a 11342 {
c19d1205
ZW
11343 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11344 inst.instruction |= (inst.operands[0].reg & 0x7);
11345 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11346 }
90e4755a
RE
11347}
11348
90e4755a 11349static void
25fe350b 11350do_t_cbz (void)
90e4755a 11351{
e07e6e58 11352 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11353 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11354 inst.instruction |= inst.operands[0].reg;
11355 inst.reloc.pc_rel = 1;
11356 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11357}
90e4755a 11358
62b3e311
PB
11359static void
11360do_t_dbg (void)
11361{
11362 inst.instruction |= inst.operands[0].imm;
11363}
11364
11365static void
11366do_t_div (void)
11367{
fdfde340
JM
11368 unsigned Rd, Rn, Rm;
11369
11370 Rd = inst.operands[0].reg;
11371 Rn = (inst.operands[1].present
11372 ? inst.operands[1].reg : Rd);
11373 Rm = inst.operands[2].reg;
11374
11375 reject_bad_reg (Rd);
11376 reject_bad_reg (Rn);
11377 reject_bad_reg (Rm);
11378
11379 inst.instruction |= Rd << 8;
11380 inst.instruction |= Rn << 16;
11381 inst.instruction |= Rm;
62b3e311
PB
11382}
11383
c19d1205
ZW
11384static void
11385do_t_hint (void)
11386{
11387 if (unified_syntax && inst.size_req == 4)
11388 inst.instruction = THUMB_OP32 (inst.instruction);
11389 else
11390 inst.instruction = THUMB_OP16 (inst.instruction);
11391}
90e4755a 11392
c19d1205
ZW
11393static void
11394do_t_it (void)
11395{
11396 unsigned int cond = inst.operands[0].imm;
e27ec89e 11397
e07e6e58
NC
11398 set_it_insn_type (IT_INSN);
11399 now_it.mask = (inst.instruction & 0xf) | 0x10;
11400 now_it.cc = cond;
5a01bb1d 11401 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11402
11403 /* If the condition is a negative condition, invert the mask. */
c19d1205 11404 if ((cond & 0x1) == 0x0)
90e4755a 11405 {
c19d1205 11406 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11407
c19d1205 11408 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11409 {
11410 /* No conversion needed. */
11411 now_it.block_length = 1;
11412 }
c19d1205 11413 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11414 {
11415 mask ^= 0x8;
11416 now_it.block_length = 2;
11417 }
e27ec89e 11418 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11419 {
11420 mask ^= 0xC;
11421 now_it.block_length = 3;
11422 }
c19d1205 11423 else
5a01bb1d
MGD
11424 {
11425 mask ^= 0xE;
11426 now_it.block_length = 4;
11427 }
90e4755a 11428
e27ec89e
PB
11429 inst.instruction &= 0xfff0;
11430 inst.instruction |= mask;
c19d1205 11431 }
90e4755a 11432
c19d1205
ZW
11433 inst.instruction |= cond << 4;
11434}
90e4755a 11435
3c707909
PB
11436/* Helper function used for both push/pop and ldm/stm. */
11437static void
11438encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11439{
11440 bfd_boolean load;
11441
11442 load = (inst.instruction & (1 << 20)) != 0;
11443
11444 if (mask & (1 << 13))
11445 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11446
11447 if ((mask & (1 << base)) != 0
11448 && writeback)
11449 inst.error = _("having the base register in the register list when "
11450 "using write back is UNPREDICTABLE");
11451
3c707909
PB
11452 if (load)
11453 {
e07e6e58 11454 if (mask & (1 << 15))
477330fc
RM
11455 {
11456 if (mask & (1 << 14))
11457 inst.error = _("LR and PC should not both be in register list");
11458 else
11459 set_it_insn_type_last ();
11460 }
3c707909
PB
11461 }
11462 else
11463 {
11464 if (mask & (1 << 15))
11465 inst.error = _("PC not allowed in register list");
3c707909
PB
11466 }
11467
11468 if ((mask & (mask - 1)) == 0)
11469 {
11470 /* Single register transfers implemented as str/ldr. */
11471 if (writeback)
11472 {
11473 if (inst.instruction & (1 << 23))
11474 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11475 else
11476 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11477 }
11478 else
11479 {
11480 if (inst.instruction & (1 << 23))
11481 inst.instruction = 0x00800000; /* ia -> [base] */
11482 else
11483 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11484 }
11485
11486 inst.instruction |= 0xf8400000;
11487 if (load)
11488 inst.instruction |= 0x00100000;
11489
5f4273c7 11490 mask = ffs (mask) - 1;
3c707909
PB
11491 mask <<= 12;
11492 }
11493 else if (writeback)
11494 inst.instruction |= WRITE_BACK;
11495
11496 inst.instruction |= mask;
11497 inst.instruction |= base << 16;
11498}
11499
c19d1205
ZW
11500static void
11501do_t_ldmstm (void)
11502{
11503 /* This really doesn't seem worth it. */
11504 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11505 _("expression too complex"));
11506 constraint (inst.operands[1].writeback,
11507 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11508
c19d1205
ZW
11509 if (unified_syntax)
11510 {
3c707909
PB
11511 bfd_boolean narrow;
11512 unsigned mask;
11513
11514 narrow = FALSE;
c19d1205
ZW
11515 /* See if we can use a 16-bit instruction. */
11516 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11517 && inst.size_req != 4
3c707909 11518 && !(inst.operands[1].imm & ~0xff))
90e4755a 11519 {
3c707909 11520 mask = 1 << inst.operands[0].reg;
90e4755a 11521
eab4f823 11522 if (inst.operands[0].reg <= 7)
90e4755a 11523 {
3c707909 11524 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11525 ? inst.operands[0].writeback
11526 : (inst.operands[0].writeback
11527 == !(inst.operands[1].imm & mask)))
477330fc 11528 {
eab4f823
MGD
11529 if (inst.instruction == T_MNEM_stmia
11530 && (inst.operands[1].imm & mask)
11531 && (inst.operands[1].imm & (mask - 1)))
11532 as_warn (_("value stored for r%d is UNKNOWN"),
11533 inst.operands[0].reg);
3c707909 11534
eab4f823
MGD
11535 inst.instruction = THUMB_OP16 (inst.instruction);
11536 inst.instruction |= inst.operands[0].reg << 8;
11537 inst.instruction |= inst.operands[1].imm;
11538 narrow = TRUE;
11539 }
11540 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11541 {
11542 /* This means 1 register in reg list one of 3 situations:
11543 1. Instruction is stmia, but without writeback.
11544 2. lmdia without writeback, but with Rn not in
477330fc 11545 reglist.
eab4f823
MGD
11546 3. ldmia with writeback, but with Rn in reglist.
11547 Case 3 is UNPREDICTABLE behaviour, so we handle
11548 case 1 and 2 which can be converted into a 16-bit
11549 str or ldr. The SP cases are handled below. */
11550 unsigned long opcode;
11551 /* First, record an error for Case 3. */
11552 if (inst.operands[1].imm & mask
11553 && inst.operands[0].writeback)
fa94de6b 11554 inst.error =
eab4f823
MGD
11555 _("having the base register in the register list when "
11556 "using write back is UNPREDICTABLE");
fa94de6b
RM
11557
11558 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11559 : T_MNEM_ldr);
11560 inst.instruction = THUMB_OP16 (opcode);
11561 inst.instruction |= inst.operands[0].reg << 3;
11562 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11563 narrow = TRUE;
11564 }
90e4755a 11565 }
eab4f823 11566 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11567 {
eab4f823
MGD
11568 if (inst.operands[0].writeback)
11569 {
fa94de6b 11570 inst.instruction =
eab4f823 11571 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11572 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11573 inst.instruction |= inst.operands[1].imm;
477330fc 11574 narrow = TRUE;
eab4f823
MGD
11575 }
11576 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11577 {
fa94de6b 11578 inst.instruction =
eab4f823 11579 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11580 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11581 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11582 narrow = TRUE;
eab4f823 11583 }
90e4755a 11584 }
3c707909
PB
11585 }
11586
11587 if (!narrow)
11588 {
c19d1205
ZW
11589 if (inst.instruction < 0xffff)
11590 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11591
5f4273c7
NC
11592 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11593 inst.operands[0].writeback);
90e4755a
RE
11594 }
11595 }
c19d1205 11596 else
90e4755a 11597 {
c19d1205
ZW
11598 constraint (inst.operands[0].reg > 7
11599 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11600 constraint (inst.instruction != T_MNEM_ldmia
11601 && inst.instruction != T_MNEM_stmia,
11602 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11603 if (inst.instruction == T_MNEM_stmia)
f03698e6 11604 {
c19d1205
ZW
11605 if (!inst.operands[0].writeback)
11606 as_warn (_("this instruction will write back the base register"));
11607 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11608 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11609 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11610 inst.operands[0].reg);
f03698e6 11611 }
c19d1205 11612 else
90e4755a 11613 {
c19d1205
ZW
11614 if (!inst.operands[0].writeback
11615 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11616 as_warn (_("this instruction will write back the base register"));
11617 else if (inst.operands[0].writeback
11618 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11619 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11620 }
11621
c19d1205
ZW
11622 inst.instruction = THUMB_OP16 (inst.instruction);
11623 inst.instruction |= inst.operands[0].reg << 8;
11624 inst.instruction |= inst.operands[1].imm;
11625 }
11626}
e28cd48c 11627
c19d1205
ZW
11628static void
11629do_t_ldrex (void)
11630{
11631 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11632 || inst.operands[1].postind || inst.operands[1].writeback
11633 || inst.operands[1].immisreg || inst.operands[1].shifted
11634 || inst.operands[1].negative,
01cfc07f 11635 BAD_ADDR_MODE);
e28cd48c 11636
5be8be5d
DG
11637 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11638
c19d1205
ZW
11639 inst.instruction |= inst.operands[0].reg << 12;
11640 inst.instruction |= inst.operands[1].reg << 16;
11641 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11642}
e28cd48c 11643
c19d1205
ZW
11644static void
11645do_t_ldrexd (void)
11646{
11647 if (!inst.operands[1].present)
1cac9012 11648 {
c19d1205
ZW
11649 constraint (inst.operands[0].reg == REG_LR,
11650 _("r14 not allowed as first register "
11651 "when second register is omitted"));
11652 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11653 }
c19d1205
ZW
11654 constraint (inst.operands[0].reg == inst.operands[1].reg,
11655 BAD_OVERLAP);
b99bd4ef 11656
c19d1205
ZW
11657 inst.instruction |= inst.operands[0].reg << 12;
11658 inst.instruction |= inst.operands[1].reg << 8;
11659 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11660}
11661
11662static void
c19d1205 11663do_t_ldst (void)
b99bd4ef 11664{
0110f2b8
PB
11665 unsigned long opcode;
11666 int Rn;
11667
e07e6e58
NC
11668 if (inst.operands[0].isreg
11669 && !inst.operands[0].preind
11670 && inst.operands[0].reg == REG_PC)
11671 set_it_insn_type_last ();
11672
0110f2b8 11673 opcode = inst.instruction;
c19d1205 11674 if (unified_syntax)
b99bd4ef 11675 {
53365c0d
PB
11676 if (!inst.operands[1].isreg)
11677 {
11678 if (opcode <= 0xffff)
11679 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11680 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11681 return;
11682 }
0110f2b8
PB
11683 if (inst.operands[1].isreg
11684 && !inst.operands[1].writeback
c19d1205
ZW
11685 && !inst.operands[1].shifted && !inst.operands[1].postind
11686 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11687 && opcode <= 0xffff
11688 && inst.size_req != 4)
c19d1205 11689 {
0110f2b8
PB
11690 /* Insn may have a 16-bit form. */
11691 Rn = inst.operands[1].reg;
11692 if (inst.operands[1].immisreg)
11693 {
11694 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11695 /* [Rn, Rik] */
0110f2b8
PB
11696 if (Rn <= 7 && inst.operands[1].imm <= 7)
11697 goto op16;
5be8be5d
DG
11698 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11699 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11700 }
11701 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11702 && opcode != T_MNEM_ldrsb)
11703 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11704 || (Rn == REG_SP && opcode == T_MNEM_str))
11705 {
11706 /* [Rn, #const] */
11707 if (Rn > 7)
11708 {
11709 if (Rn == REG_PC)
11710 {
11711 if (inst.reloc.pc_rel)
11712 opcode = T_MNEM_ldr_pc2;
11713 else
11714 opcode = T_MNEM_ldr_pc;
11715 }
11716 else
11717 {
11718 if (opcode == T_MNEM_ldr)
11719 opcode = T_MNEM_ldr_sp;
11720 else
11721 opcode = T_MNEM_str_sp;
11722 }
11723 inst.instruction = inst.operands[0].reg << 8;
11724 }
11725 else
11726 {
11727 inst.instruction = inst.operands[0].reg;
11728 inst.instruction |= inst.operands[1].reg << 3;
11729 }
11730 inst.instruction |= THUMB_OP16 (opcode);
11731 if (inst.size_req == 2)
11732 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11733 else
11734 inst.relax = opcode;
11735 return;
11736 }
c19d1205 11737 }
0110f2b8 11738 /* Definitely a 32-bit variant. */
5be8be5d 11739
8d67f500
NC
11740 /* Warning for Erratum 752419. */
11741 if (opcode == T_MNEM_ldr
11742 && inst.operands[0].reg == REG_SP
11743 && inst.operands[1].writeback == 1
11744 && !inst.operands[1].immisreg)
11745 {
11746 if (no_cpu_selected ()
11747 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11748 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11749 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11750 as_warn (_("This instruction may be unpredictable "
11751 "if executed on M-profile cores "
11752 "with interrupts enabled."));
11753 }
11754
5be8be5d 11755 /* Do some validations regarding addressing modes. */
1be5fd2e 11756 if (inst.operands[1].immisreg)
5be8be5d
DG
11757 reject_bad_reg (inst.operands[1].imm);
11758
1be5fd2e
NC
11759 constraint (inst.operands[1].writeback == 1
11760 && inst.operands[0].reg == inst.operands[1].reg,
11761 BAD_OVERLAP);
11762
0110f2b8 11763 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11764 inst.instruction |= inst.operands[0].reg << 12;
11765 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11766 check_ldr_r15_aligned ();
b99bd4ef
NC
11767 return;
11768 }
11769
c19d1205
ZW
11770 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11771
11772 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11773 {
c19d1205
ZW
11774 /* Only [Rn,Rm] is acceptable. */
11775 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11776 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11777 || inst.operands[1].postind || inst.operands[1].shifted
11778 || inst.operands[1].negative,
11779 _("Thumb does not support this addressing mode"));
11780 inst.instruction = THUMB_OP16 (inst.instruction);
11781 goto op16;
b99bd4ef 11782 }
5f4273c7 11783
c19d1205
ZW
11784 inst.instruction = THUMB_OP16 (inst.instruction);
11785 if (!inst.operands[1].isreg)
8335d6aa 11786 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11787 return;
b99bd4ef 11788
c19d1205
ZW
11789 constraint (!inst.operands[1].preind
11790 || inst.operands[1].shifted
11791 || inst.operands[1].writeback,
11792 _("Thumb does not support this addressing mode"));
11793 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11794 {
c19d1205
ZW
11795 constraint (inst.instruction & 0x0600,
11796 _("byte or halfword not valid for base register"));
11797 constraint (inst.operands[1].reg == REG_PC
11798 && !(inst.instruction & THUMB_LOAD_BIT),
11799 _("r15 based store not allowed"));
11800 constraint (inst.operands[1].immisreg,
11801 _("invalid base register for register offset"));
b99bd4ef 11802
c19d1205
ZW
11803 if (inst.operands[1].reg == REG_PC)
11804 inst.instruction = T_OPCODE_LDR_PC;
11805 else if (inst.instruction & THUMB_LOAD_BIT)
11806 inst.instruction = T_OPCODE_LDR_SP;
11807 else
11808 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11809
c19d1205
ZW
11810 inst.instruction |= inst.operands[0].reg << 8;
11811 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11812 return;
11813 }
90e4755a 11814
c19d1205
ZW
11815 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11816 if (!inst.operands[1].immisreg)
11817 {
11818 /* Immediate offset. */
11819 inst.instruction |= inst.operands[0].reg;
11820 inst.instruction |= inst.operands[1].reg << 3;
11821 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11822 return;
11823 }
90e4755a 11824
c19d1205
ZW
11825 /* Register offset. */
11826 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11827 constraint (inst.operands[1].negative,
11828 _("Thumb does not support this addressing mode"));
90e4755a 11829
c19d1205
ZW
11830 op16:
11831 switch (inst.instruction)
11832 {
11833 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11834 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11835 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11836 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11837 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11838 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11839 case 0x5600 /* ldrsb */:
11840 case 0x5e00 /* ldrsh */: break;
11841 default: abort ();
11842 }
90e4755a 11843
c19d1205
ZW
11844 inst.instruction |= inst.operands[0].reg;
11845 inst.instruction |= inst.operands[1].reg << 3;
11846 inst.instruction |= inst.operands[1].imm << 6;
11847}
90e4755a 11848
c19d1205
ZW
11849static void
11850do_t_ldstd (void)
11851{
11852 if (!inst.operands[1].present)
b99bd4ef 11853 {
c19d1205
ZW
11854 inst.operands[1].reg = inst.operands[0].reg + 1;
11855 constraint (inst.operands[0].reg == REG_LR,
11856 _("r14 not allowed here"));
bd340a04 11857 constraint (inst.operands[0].reg == REG_R12,
477330fc 11858 _("r12 not allowed here"));
b99bd4ef 11859 }
bd340a04
MGD
11860
11861 if (inst.operands[2].writeback
11862 && (inst.operands[0].reg == inst.operands[2].reg
11863 || inst.operands[1].reg == inst.operands[2].reg))
11864 as_warn (_("base register written back, and overlaps "
477330fc 11865 "one of transfer registers"));
bd340a04 11866
c19d1205
ZW
11867 inst.instruction |= inst.operands[0].reg << 12;
11868 inst.instruction |= inst.operands[1].reg << 8;
11869 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11870}
11871
c19d1205
ZW
11872static void
11873do_t_ldstt (void)
11874{
11875 inst.instruction |= inst.operands[0].reg << 12;
11876 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11877}
a737bd4d 11878
b99bd4ef 11879static void
c19d1205 11880do_t_mla (void)
b99bd4ef 11881{
fdfde340 11882 unsigned Rd, Rn, Rm, Ra;
c921be7d 11883
fdfde340
JM
11884 Rd = inst.operands[0].reg;
11885 Rn = inst.operands[1].reg;
11886 Rm = inst.operands[2].reg;
11887 Ra = inst.operands[3].reg;
11888
11889 reject_bad_reg (Rd);
11890 reject_bad_reg (Rn);
11891 reject_bad_reg (Rm);
11892 reject_bad_reg (Ra);
11893
11894 inst.instruction |= Rd << 8;
11895 inst.instruction |= Rn << 16;
11896 inst.instruction |= Rm;
11897 inst.instruction |= Ra << 12;
c19d1205 11898}
b99bd4ef 11899
c19d1205
ZW
11900static void
11901do_t_mlal (void)
11902{
fdfde340
JM
11903 unsigned RdLo, RdHi, Rn, Rm;
11904
11905 RdLo = inst.operands[0].reg;
11906 RdHi = inst.operands[1].reg;
11907 Rn = inst.operands[2].reg;
11908 Rm = inst.operands[3].reg;
11909
11910 reject_bad_reg (RdLo);
11911 reject_bad_reg (RdHi);
11912 reject_bad_reg (Rn);
11913 reject_bad_reg (Rm);
11914
11915 inst.instruction |= RdLo << 12;
11916 inst.instruction |= RdHi << 8;
11917 inst.instruction |= Rn << 16;
11918 inst.instruction |= Rm;
c19d1205 11919}
b99bd4ef 11920
c19d1205
ZW
11921static void
11922do_t_mov_cmp (void)
11923{
fdfde340
JM
11924 unsigned Rn, Rm;
11925
11926 Rn = inst.operands[0].reg;
11927 Rm = inst.operands[1].reg;
11928
e07e6e58
NC
11929 if (Rn == REG_PC)
11930 set_it_insn_type_last ();
11931
c19d1205 11932 if (unified_syntax)
b99bd4ef 11933 {
c19d1205
ZW
11934 int r0off = (inst.instruction == T_MNEM_mov
11935 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11936 unsigned long opcode;
3d388997
PB
11937 bfd_boolean narrow;
11938 bfd_boolean low_regs;
11939
fdfde340 11940 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11941 opcode = inst.instruction;
e07e6e58 11942 if (in_it_block ())
0110f2b8 11943 narrow = opcode != T_MNEM_movs;
3d388997 11944 else
0110f2b8 11945 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11946 if (inst.size_req == 4
11947 || inst.operands[1].shifted)
11948 narrow = FALSE;
11949
efd81785
PB
11950 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11951 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11952 && !inst.operands[1].shifted
fdfde340
JM
11953 && Rn == REG_PC
11954 && Rm == REG_LR)
efd81785
PB
11955 {
11956 inst.instruction = T2_SUBS_PC_LR;
11957 return;
11958 }
11959
fdfde340
JM
11960 if (opcode == T_MNEM_cmp)
11961 {
11962 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11963 if (narrow)
11964 {
11965 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11966 but valid. */
11967 warn_deprecated_sp (Rm);
11968 /* R15 was documented as a valid choice for Rm in ARMv6,
11969 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11970 tools reject R15, so we do too. */
11971 constraint (Rm == REG_PC, BAD_PC);
11972 }
11973 else
11974 reject_bad_reg (Rm);
fdfde340
JM
11975 }
11976 else if (opcode == T_MNEM_mov
11977 || opcode == T_MNEM_movs)
11978 {
11979 if (inst.operands[1].isreg)
11980 {
11981 if (opcode == T_MNEM_movs)
11982 {
11983 reject_bad_reg (Rn);
11984 reject_bad_reg (Rm);
11985 }
76fa04a4
MGD
11986 else if (narrow)
11987 {
11988 /* This is mov.n. */
11989 if ((Rn == REG_SP || Rn == REG_PC)
11990 && (Rm == REG_SP || Rm == REG_PC))
11991 {
5c3696f8 11992 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11993 "deprecated when r%u is the destination "
11994 "register."), Rm, Rn);
11995 }
11996 }
11997 else
11998 {
11999 /* This is mov.w. */
12000 constraint (Rn == REG_PC, BAD_PC);
12001 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
12002 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12003 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 12004 }
fdfde340
JM
12005 }
12006 else
12007 reject_bad_reg (Rn);
12008 }
12009
c19d1205
ZW
12010 if (!inst.operands[1].isreg)
12011 {
0110f2b8 12012 /* Immediate operand. */
e07e6e58 12013 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
12014 narrow = 0;
12015 if (low_regs && narrow)
12016 {
12017 inst.instruction = THUMB_OP16 (opcode);
fdfde340 12018 inst.instruction |= Rn << 8;
a9f02af8
MG
12019 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12020 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 12021 {
a9f02af8 12022 if (inst.size_req == 2)
72d98d16 12023 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
12024 else
12025 inst.relax = opcode;
72d98d16 12026 }
0110f2b8
PB
12027 }
12028 else
12029 {
a9f02af8
MG
12030 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12031 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
12032 THUMB1_RELOC_ONLY);
12033
0110f2b8
PB
12034 inst.instruction = THUMB_OP32 (inst.instruction);
12035 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12036 inst.instruction |= Rn << r0off;
0110f2b8
PB
12037 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12038 }
c19d1205 12039 }
728ca7c9
PB
12040 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12041 && (inst.instruction == T_MNEM_mov
12042 || inst.instruction == T_MNEM_movs))
12043 {
12044 /* Register shifts are encoded as separate shift instructions. */
12045 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
12046
e07e6e58 12047 if (in_it_block ())
728ca7c9
PB
12048 narrow = !flags;
12049 else
12050 narrow = flags;
12051
12052 if (inst.size_req == 4)
12053 narrow = FALSE;
12054
12055 if (!low_regs || inst.operands[1].imm > 7)
12056 narrow = FALSE;
12057
fdfde340 12058 if (Rn != Rm)
728ca7c9
PB
12059 narrow = FALSE;
12060
12061 switch (inst.operands[1].shift_kind)
12062 {
12063 case SHIFT_LSL:
12064 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12065 break;
12066 case SHIFT_ASR:
12067 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12068 break;
12069 case SHIFT_LSR:
12070 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12071 break;
12072 case SHIFT_ROR:
12073 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12074 break;
12075 default:
5f4273c7 12076 abort ();
728ca7c9
PB
12077 }
12078
12079 inst.instruction = opcode;
12080 if (narrow)
12081 {
fdfde340 12082 inst.instruction |= Rn;
728ca7c9
PB
12083 inst.instruction |= inst.operands[1].imm << 3;
12084 }
12085 else
12086 {
12087 if (flags)
12088 inst.instruction |= CONDS_BIT;
12089
fdfde340
JM
12090 inst.instruction |= Rn << 8;
12091 inst.instruction |= Rm << 16;
728ca7c9
PB
12092 inst.instruction |= inst.operands[1].imm;
12093 }
12094 }
3d388997 12095 else if (!narrow)
c19d1205 12096 {
728ca7c9
PB
12097 /* Some mov with immediate shift have narrow variants.
12098 Register shifts are handled above. */
12099 if (low_regs && inst.operands[1].shifted
12100 && (inst.instruction == T_MNEM_mov
12101 || inst.instruction == T_MNEM_movs))
12102 {
e07e6e58 12103 if (in_it_block ())
728ca7c9
PB
12104 narrow = (inst.instruction == T_MNEM_mov);
12105 else
12106 narrow = (inst.instruction == T_MNEM_movs);
12107 }
12108
12109 if (narrow)
12110 {
12111 switch (inst.operands[1].shift_kind)
12112 {
12113 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12114 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12115 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12116 default: narrow = FALSE; break;
12117 }
12118 }
12119
12120 if (narrow)
12121 {
fdfde340
JM
12122 inst.instruction |= Rn;
12123 inst.instruction |= Rm << 3;
728ca7c9
PB
12124 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12125 }
12126 else
12127 {
12128 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12129 inst.instruction |= Rn << r0off;
728ca7c9
PB
12130 encode_thumb32_shifted_operand (1);
12131 }
c19d1205
ZW
12132 }
12133 else
12134 switch (inst.instruction)
12135 {
12136 case T_MNEM_mov:
837b3435 12137 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12138 results. Don't allow this. */
12139 if (low_regs)
12140 {
12141 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12142 "MOV Rd, Rs with two low registers is not "
12143 "permitted on this architecture");
fa94de6b 12144 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12145 arm_ext_v6);
12146 }
12147
c19d1205 12148 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12149 inst.instruction |= (Rn & 0x8) << 4;
12150 inst.instruction |= (Rn & 0x7);
12151 inst.instruction |= Rm << 3;
c19d1205 12152 break;
b99bd4ef 12153
c19d1205
ZW
12154 case T_MNEM_movs:
12155 /* We know we have low registers at this point.
941a8a52
MGD
12156 Generate LSLS Rd, Rs, #0. */
12157 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12158 inst.instruction |= Rn;
12159 inst.instruction |= Rm << 3;
c19d1205
ZW
12160 break;
12161
12162 case T_MNEM_cmp:
3d388997 12163 if (low_regs)
c19d1205
ZW
12164 {
12165 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12166 inst.instruction |= Rn;
12167 inst.instruction |= Rm << 3;
c19d1205
ZW
12168 }
12169 else
12170 {
12171 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12172 inst.instruction |= (Rn & 0x8) << 4;
12173 inst.instruction |= (Rn & 0x7);
12174 inst.instruction |= Rm << 3;
c19d1205
ZW
12175 }
12176 break;
12177 }
b99bd4ef
NC
12178 return;
12179 }
12180
c19d1205 12181 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12182
12183 /* PR 10443: Do not silently ignore shifted operands. */
12184 constraint (inst.operands[1].shifted,
12185 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12186
c19d1205 12187 if (inst.operands[1].isreg)
b99bd4ef 12188 {
fdfde340 12189 if (Rn < 8 && Rm < 8)
b99bd4ef 12190 {
c19d1205
ZW
12191 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12192 since a MOV instruction produces unpredictable results. */
12193 if (inst.instruction == T_OPCODE_MOV_I8)
12194 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12195 else
c19d1205 12196 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12197
fdfde340
JM
12198 inst.instruction |= Rn;
12199 inst.instruction |= Rm << 3;
b99bd4ef
NC
12200 }
12201 else
12202 {
c19d1205
ZW
12203 if (inst.instruction == T_OPCODE_MOV_I8)
12204 inst.instruction = T_OPCODE_MOV_HR;
12205 else
12206 inst.instruction = T_OPCODE_CMP_HR;
12207 do_t_cpy ();
b99bd4ef
NC
12208 }
12209 }
c19d1205 12210 else
b99bd4ef 12211 {
fdfde340 12212 constraint (Rn > 7,
c19d1205 12213 _("only lo regs allowed with immediate"));
fdfde340 12214 inst.instruction |= Rn << 8;
c19d1205
ZW
12215 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12216 }
12217}
b99bd4ef 12218
c19d1205
ZW
12219static void
12220do_t_mov16 (void)
12221{
fdfde340 12222 unsigned Rd;
b6895b4f
PB
12223 bfd_vma imm;
12224 bfd_boolean top;
12225
12226 top = (inst.instruction & 0x00800000) != 0;
12227 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12228 {
33eaf5de 12229 constraint (top, _(":lower16: not allowed in this instruction"));
b6895b4f
PB
12230 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12231 }
12232 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12233 {
33eaf5de 12234 constraint (!top, _(":upper16: not allowed in this instruction"));
b6895b4f
PB
12235 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12236 }
12237
fdfde340
JM
12238 Rd = inst.operands[0].reg;
12239 reject_bad_reg (Rd);
12240
12241 inst.instruction |= Rd << 8;
b6895b4f
PB
12242 if (inst.reloc.type == BFD_RELOC_UNUSED)
12243 {
12244 imm = inst.reloc.exp.X_add_number;
12245 inst.instruction |= (imm & 0xf000) << 4;
12246 inst.instruction |= (imm & 0x0800) << 15;
12247 inst.instruction |= (imm & 0x0700) << 4;
12248 inst.instruction |= (imm & 0x00ff);
12249 }
c19d1205 12250}
b99bd4ef 12251
c19d1205
ZW
12252static void
12253do_t_mvn_tst (void)
12254{
fdfde340 12255 unsigned Rn, Rm;
c921be7d 12256
fdfde340
JM
12257 Rn = inst.operands[0].reg;
12258 Rm = inst.operands[1].reg;
12259
12260 if (inst.instruction == T_MNEM_cmp
12261 || inst.instruction == T_MNEM_cmn)
12262 constraint (Rn == REG_PC, BAD_PC);
12263 else
12264 reject_bad_reg (Rn);
12265 reject_bad_reg (Rm);
12266
c19d1205
ZW
12267 if (unified_syntax)
12268 {
12269 int r0off = (inst.instruction == T_MNEM_mvn
12270 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12271 bfd_boolean narrow;
12272
12273 if (inst.size_req == 4
12274 || inst.instruction > 0xffff
12275 || inst.operands[1].shifted
fdfde340 12276 || Rn > 7 || Rm > 7)
3d388997 12277 narrow = FALSE;
fe8b4cc3
KT
12278 else if (inst.instruction == T_MNEM_cmn
12279 || inst.instruction == T_MNEM_tst)
3d388997
PB
12280 narrow = TRUE;
12281 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12282 narrow = !in_it_block ();
3d388997 12283 else
e07e6e58 12284 narrow = in_it_block ();
3d388997 12285
c19d1205 12286 if (!inst.operands[1].isreg)
b99bd4ef 12287 {
c19d1205
ZW
12288 /* For an immediate, we always generate a 32-bit opcode;
12289 section relaxation will shrink it later if possible. */
12290 if (inst.instruction < 0xffff)
12291 inst.instruction = THUMB_OP32 (inst.instruction);
12292 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12293 inst.instruction |= Rn << r0off;
c19d1205 12294 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12295 }
c19d1205 12296 else
b99bd4ef 12297 {
c19d1205 12298 /* See if we can do this with a 16-bit instruction. */
3d388997 12299 if (narrow)
b99bd4ef 12300 {
c19d1205 12301 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12302 inst.instruction |= Rn;
12303 inst.instruction |= Rm << 3;
b99bd4ef 12304 }
c19d1205 12305 else
b99bd4ef 12306 {
c19d1205
ZW
12307 constraint (inst.operands[1].shifted
12308 && inst.operands[1].immisreg,
12309 _("shift must be constant"));
12310 if (inst.instruction < 0xffff)
12311 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12312 inst.instruction |= Rn << r0off;
c19d1205 12313 encode_thumb32_shifted_operand (1);
b99bd4ef 12314 }
b99bd4ef
NC
12315 }
12316 }
12317 else
12318 {
c19d1205
ZW
12319 constraint (inst.instruction > 0xffff
12320 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12321 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12322 _("unshifted register required"));
fdfde340 12323 constraint (Rn > 7 || Rm > 7,
c19d1205 12324 BAD_HIREG);
b99bd4ef 12325
c19d1205 12326 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12327 inst.instruction |= Rn;
12328 inst.instruction |= Rm << 3;
b99bd4ef 12329 }
b99bd4ef
NC
12330}
12331
b05fe5cf 12332static void
c19d1205 12333do_t_mrs (void)
b05fe5cf 12334{
fdfde340 12335 unsigned Rd;
037e8744
JB
12336
12337 if (do_vfp_nsyn_mrs () == SUCCESS)
12338 return;
12339
90ec0d68
MGD
12340 Rd = inst.operands[0].reg;
12341 reject_bad_reg (Rd);
12342 inst.instruction |= Rd << 8;
12343
12344 if (inst.operands[1].isreg)
62b3e311 12345 {
90ec0d68
MGD
12346 unsigned br = inst.operands[1].reg;
12347 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12348 as_bad (_("bad register for mrs"));
12349
12350 inst.instruction |= br & (0xf << 16);
12351 inst.instruction |= (br & 0x300) >> 4;
12352 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12353 }
12354 else
12355 {
90ec0d68 12356 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12357
d2cd1205 12358 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12359 {
12360 /* PR gas/12698: The constraint is only applied for m_profile.
12361 If the user has specified -march=all, we want to ignore it as
12362 we are building for any CPU type, including non-m variants. */
823d2571
TG
12363 bfd_boolean m_profile =
12364 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12365 constraint ((flags != 0) && m_profile, _("selected processor does "
12366 "not support requested special purpose register"));
12367 }
90ec0d68 12368 else
d2cd1205
JB
12369 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12370 devices). */
12371 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12372 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12373
90ec0d68
MGD
12374 inst.instruction |= (flags & SPSR_BIT) >> 2;
12375 inst.instruction |= inst.operands[1].imm & 0xff;
12376 inst.instruction |= 0xf0000;
12377 }
c19d1205 12378}
b05fe5cf 12379
c19d1205
ZW
12380static void
12381do_t_msr (void)
12382{
62b3e311 12383 int flags;
fdfde340 12384 unsigned Rn;
62b3e311 12385
037e8744
JB
12386 if (do_vfp_nsyn_msr () == SUCCESS)
12387 return;
12388
c19d1205
ZW
12389 constraint (!inst.operands[1].isreg,
12390 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12391
12392 if (inst.operands[0].isreg)
12393 flags = (int)(inst.operands[0].reg);
12394 else
12395 flags = inst.operands[0].imm;
12396
d2cd1205 12397 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12398 {
d2cd1205
JB
12399 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12400
1a43faaf 12401 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12402 If the user has specified -march=all, we want to ignore it as
12403 we are building for any CPU type, including non-m variants. */
823d2571
TG
12404 bfd_boolean m_profile =
12405 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12406 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12407 && (bits & ~(PSR_s | PSR_f)) != 0)
12408 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12409 && bits != PSR_f)) && m_profile,
12410 _("selected processor does not support requested special "
12411 "purpose register"));
62b3e311
PB
12412 }
12413 else
d2cd1205
JB
12414 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12415 "requested special purpose register"));
c921be7d 12416
fdfde340
JM
12417 Rn = inst.operands[1].reg;
12418 reject_bad_reg (Rn);
12419
62b3e311 12420 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12421 inst.instruction |= (flags & 0xf0000) >> 8;
12422 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12423 inst.instruction |= (flags & 0xff);
fdfde340 12424 inst.instruction |= Rn << 16;
c19d1205 12425}
b05fe5cf 12426
c19d1205
ZW
12427static void
12428do_t_mul (void)
12429{
17828f45 12430 bfd_boolean narrow;
fdfde340 12431 unsigned Rd, Rn, Rm;
17828f45 12432
c19d1205
ZW
12433 if (!inst.operands[2].present)
12434 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12435
fdfde340
JM
12436 Rd = inst.operands[0].reg;
12437 Rn = inst.operands[1].reg;
12438 Rm = inst.operands[2].reg;
12439
17828f45 12440 if (unified_syntax)
b05fe5cf 12441 {
17828f45 12442 if (inst.size_req == 4
fdfde340
JM
12443 || (Rd != Rn
12444 && Rd != Rm)
12445 || Rn > 7
12446 || Rm > 7)
17828f45
JM
12447 narrow = FALSE;
12448 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12449 narrow = !in_it_block ();
17828f45 12450 else
e07e6e58 12451 narrow = in_it_block ();
b05fe5cf 12452 }
c19d1205 12453 else
b05fe5cf 12454 {
17828f45 12455 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12456 constraint (Rn > 7 || Rm > 7,
c19d1205 12457 BAD_HIREG);
17828f45
JM
12458 narrow = TRUE;
12459 }
b05fe5cf 12460
17828f45
JM
12461 if (narrow)
12462 {
12463 /* 16-bit MULS/Conditional MUL. */
c19d1205 12464 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12465 inst.instruction |= Rd;
b05fe5cf 12466
fdfde340
JM
12467 if (Rd == Rn)
12468 inst.instruction |= Rm << 3;
12469 else if (Rd == Rm)
12470 inst.instruction |= Rn << 3;
c19d1205
ZW
12471 else
12472 constraint (1, _("dest must overlap one source register"));
12473 }
17828f45
JM
12474 else
12475 {
e07e6e58
NC
12476 constraint (inst.instruction != T_MNEM_mul,
12477 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12478 /* 32-bit MUL. */
12479 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12480 inst.instruction |= Rd << 8;
12481 inst.instruction |= Rn << 16;
12482 inst.instruction |= Rm << 0;
12483
12484 reject_bad_reg (Rd);
12485 reject_bad_reg (Rn);
12486 reject_bad_reg (Rm);
17828f45 12487 }
c19d1205 12488}
b05fe5cf 12489
c19d1205
ZW
12490static void
12491do_t_mull (void)
12492{
fdfde340 12493 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12494
fdfde340
JM
12495 RdLo = inst.operands[0].reg;
12496 RdHi = inst.operands[1].reg;
12497 Rn = inst.operands[2].reg;
12498 Rm = inst.operands[3].reg;
12499
12500 reject_bad_reg (RdLo);
12501 reject_bad_reg (RdHi);
12502 reject_bad_reg (Rn);
12503 reject_bad_reg (Rm);
12504
12505 inst.instruction |= RdLo << 12;
12506 inst.instruction |= RdHi << 8;
12507 inst.instruction |= Rn << 16;
12508 inst.instruction |= Rm;
12509
12510 if (RdLo == RdHi)
c19d1205
ZW
12511 as_tsktsk (_("rdhi and rdlo must be different"));
12512}
b05fe5cf 12513
c19d1205
ZW
12514static void
12515do_t_nop (void)
12516{
e07e6e58
NC
12517 set_it_insn_type (NEUTRAL_IT_INSN);
12518
c19d1205
ZW
12519 if (unified_syntax)
12520 {
12521 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12522 {
c19d1205
ZW
12523 inst.instruction = THUMB_OP32 (inst.instruction);
12524 inst.instruction |= inst.operands[0].imm;
12525 }
12526 else
12527 {
bc2d1808
NC
12528 /* PR9722: Check for Thumb2 availability before
12529 generating a thumb2 nop instruction. */
afa62d5e 12530 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12531 {
12532 inst.instruction = THUMB_OP16 (inst.instruction);
12533 inst.instruction |= inst.operands[0].imm << 4;
12534 }
12535 else
12536 inst.instruction = 0x46c0;
c19d1205
ZW
12537 }
12538 }
12539 else
12540 {
12541 constraint (inst.operands[0].present,
12542 _("Thumb does not support NOP with hints"));
12543 inst.instruction = 0x46c0;
12544 }
12545}
b05fe5cf 12546
c19d1205
ZW
12547static void
12548do_t_neg (void)
12549{
12550 if (unified_syntax)
12551 {
3d388997
PB
12552 bfd_boolean narrow;
12553
12554 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12555 narrow = !in_it_block ();
3d388997 12556 else
e07e6e58 12557 narrow = in_it_block ();
3d388997
PB
12558 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12559 narrow = FALSE;
12560 if (inst.size_req == 4)
12561 narrow = FALSE;
12562
12563 if (!narrow)
c19d1205
ZW
12564 {
12565 inst.instruction = THUMB_OP32 (inst.instruction);
12566 inst.instruction |= inst.operands[0].reg << 8;
12567 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12568 }
12569 else
12570 {
c19d1205
ZW
12571 inst.instruction = THUMB_OP16 (inst.instruction);
12572 inst.instruction |= inst.operands[0].reg;
12573 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12574 }
12575 }
12576 else
12577 {
c19d1205
ZW
12578 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12579 BAD_HIREG);
12580 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12581
12582 inst.instruction = THUMB_OP16 (inst.instruction);
12583 inst.instruction |= inst.operands[0].reg;
12584 inst.instruction |= inst.operands[1].reg << 3;
12585 }
12586}
12587
1c444d06
JM
12588static void
12589do_t_orn (void)
12590{
12591 unsigned Rd, Rn;
12592
12593 Rd = inst.operands[0].reg;
12594 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12595
fdfde340
JM
12596 reject_bad_reg (Rd);
12597 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12598 reject_bad_reg (Rn);
12599
1c444d06
JM
12600 inst.instruction |= Rd << 8;
12601 inst.instruction |= Rn << 16;
12602
12603 if (!inst.operands[2].isreg)
12604 {
12605 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12606 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12607 }
12608 else
12609 {
12610 unsigned Rm;
12611
12612 Rm = inst.operands[2].reg;
fdfde340 12613 reject_bad_reg (Rm);
1c444d06
JM
12614
12615 constraint (inst.operands[2].shifted
12616 && inst.operands[2].immisreg,
12617 _("shift must be constant"));
12618 encode_thumb32_shifted_operand (2);
12619 }
12620}
12621
c19d1205
ZW
12622static void
12623do_t_pkhbt (void)
12624{
fdfde340
JM
12625 unsigned Rd, Rn, Rm;
12626
12627 Rd = inst.operands[0].reg;
12628 Rn = inst.operands[1].reg;
12629 Rm = inst.operands[2].reg;
12630
12631 reject_bad_reg (Rd);
12632 reject_bad_reg (Rn);
12633 reject_bad_reg (Rm);
12634
12635 inst.instruction |= Rd << 8;
12636 inst.instruction |= Rn << 16;
12637 inst.instruction |= Rm;
c19d1205
ZW
12638 if (inst.operands[3].present)
12639 {
12640 unsigned int val = inst.reloc.exp.X_add_number;
12641 constraint (inst.reloc.exp.X_op != O_constant,
12642 _("expression too complex"));
12643 inst.instruction |= (val & 0x1c) << 10;
12644 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12645 }
c19d1205 12646}
b05fe5cf 12647
c19d1205
ZW
12648static void
12649do_t_pkhtb (void)
12650{
12651 if (!inst.operands[3].present)
1ef52f49
NC
12652 {
12653 unsigned Rtmp;
12654
12655 inst.instruction &= ~0x00000020;
12656
12657 /* PR 10168. Swap the Rm and Rn registers. */
12658 Rtmp = inst.operands[1].reg;
12659 inst.operands[1].reg = inst.operands[2].reg;
12660 inst.operands[2].reg = Rtmp;
12661 }
c19d1205 12662 do_t_pkhbt ();
b05fe5cf
ZW
12663}
12664
c19d1205
ZW
12665static void
12666do_t_pld (void)
12667{
fdfde340
JM
12668 if (inst.operands[0].immisreg)
12669 reject_bad_reg (inst.operands[0].imm);
12670
c19d1205
ZW
12671 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12672}
b05fe5cf 12673
c19d1205
ZW
12674static void
12675do_t_push_pop (void)
b99bd4ef 12676{
e9f89963 12677 unsigned mask;
5f4273c7 12678
c19d1205
ZW
12679 constraint (inst.operands[0].writeback,
12680 _("push/pop do not support {reglist}^"));
12681 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12682 _("expression too complex"));
b99bd4ef 12683
e9f89963 12684 mask = inst.operands[0].imm;
d3bfe16e 12685 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12686 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12687 else if (inst.size_req != 4
c6025a80 12688 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12689 ? REG_LR : REG_PC)))
b99bd4ef 12690 {
c19d1205
ZW
12691 inst.instruction = THUMB_OP16 (inst.instruction);
12692 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12693 inst.instruction |= mask & 0xff;
c19d1205
ZW
12694 }
12695 else if (unified_syntax)
12696 {
3c707909 12697 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12698 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12699 }
12700 else
12701 {
12702 inst.error = _("invalid register list to push/pop instruction");
12703 return;
12704 }
c19d1205 12705}
b99bd4ef 12706
c19d1205
ZW
12707static void
12708do_t_rbit (void)
12709{
fdfde340
JM
12710 unsigned Rd, Rm;
12711
12712 Rd = inst.operands[0].reg;
12713 Rm = inst.operands[1].reg;
12714
12715 reject_bad_reg (Rd);
12716 reject_bad_reg (Rm);
12717
12718 inst.instruction |= Rd << 8;
12719 inst.instruction |= Rm << 16;
12720 inst.instruction |= Rm;
c19d1205 12721}
b99bd4ef 12722
c19d1205
ZW
12723static void
12724do_t_rev (void)
12725{
fdfde340
JM
12726 unsigned Rd, Rm;
12727
12728 Rd = inst.operands[0].reg;
12729 Rm = inst.operands[1].reg;
12730
12731 reject_bad_reg (Rd);
12732 reject_bad_reg (Rm);
12733
12734 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12735 && inst.size_req != 4)
12736 {
12737 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12738 inst.instruction |= Rd;
12739 inst.instruction |= Rm << 3;
c19d1205
ZW
12740 }
12741 else if (unified_syntax)
12742 {
12743 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12744 inst.instruction |= Rd << 8;
12745 inst.instruction |= Rm << 16;
12746 inst.instruction |= Rm;
c19d1205
ZW
12747 }
12748 else
12749 inst.error = BAD_HIREG;
12750}
b99bd4ef 12751
1c444d06
JM
12752static void
12753do_t_rrx (void)
12754{
12755 unsigned Rd, Rm;
12756
12757 Rd = inst.operands[0].reg;
12758 Rm = inst.operands[1].reg;
12759
fdfde340
JM
12760 reject_bad_reg (Rd);
12761 reject_bad_reg (Rm);
c921be7d 12762
1c444d06
JM
12763 inst.instruction |= Rd << 8;
12764 inst.instruction |= Rm;
12765}
12766
c19d1205
ZW
12767static void
12768do_t_rsb (void)
12769{
fdfde340 12770 unsigned Rd, Rs;
b99bd4ef 12771
c19d1205
ZW
12772 Rd = inst.operands[0].reg;
12773 Rs = (inst.operands[1].present
12774 ? inst.operands[1].reg /* Rd, Rs, foo */
12775 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12776
fdfde340
JM
12777 reject_bad_reg (Rd);
12778 reject_bad_reg (Rs);
12779 if (inst.operands[2].isreg)
12780 reject_bad_reg (inst.operands[2].reg);
12781
c19d1205
ZW
12782 inst.instruction |= Rd << 8;
12783 inst.instruction |= Rs << 16;
12784 if (!inst.operands[2].isreg)
12785 {
026d3abb
PB
12786 bfd_boolean narrow;
12787
12788 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12789 narrow = !in_it_block ();
026d3abb 12790 else
e07e6e58 12791 narrow = in_it_block ();
026d3abb
PB
12792
12793 if (Rd > 7 || Rs > 7)
12794 narrow = FALSE;
12795
12796 if (inst.size_req == 4 || !unified_syntax)
12797 narrow = FALSE;
12798
12799 if (inst.reloc.exp.X_op != O_constant
12800 || inst.reloc.exp.X_add_number != 0)
12801 narrow = FALSE;
12802
12803 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12804 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12805 if (narrow)
12806 {
12807 inst.reloc.type = BFD_RELOC_UNUSED;
12808 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12809 inst.instruction |= Rs << 3;
12810 inst.instruction |= Rd;
12811 }
12812 else
12813 {
12814 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12815 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12816 }
c19d1205
ZW
12817 }
12818 else
12819 encode_thumb32_shifted_operand (2);
12820}
b99bd4ef 12821
c19d1205
ZW
12822static void
12823do_t_setend (void)
12824{
12e37cbc
MGD
12825 if (warn_on_deprecated
12826 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12827 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12828
e07e6e58 12829 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12830 if (inst.operands[0].imm)
12831 inst.instruction |= 0x8;
12832}
b99bd4ef 12833
c19d1205
ZW
12834static void
12835do_t_shift (void)
12836{
12837 if (!inst.operands[1].present)
12838 inst.operands[1].reg = inst.operands[0].reg;
12839
12840 if (unified_syntax)
12841 {
3d388997
PB
12842 bfd_boolean narrow;
12843 int shift_kind;
12844
12845 switch (inst.instruction)
12846 {
12847 case T_MNEM_asr:
12848 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12849 case T_MNEM_lsl:
12850 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12851 case T_MNEM_lsr:
12852 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12853 case T_MNEM_ror:
12854 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12855 default: abort ();
12856 }
12857
12858 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12859 narrow = !in_it_block ();
3d388997 12860 else
e07e6e58 12861 narrow = in_it_block ();
3d388997
PB
12862 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12863 narrow = FALSE;
12864 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12865 narrow = FALSE;
12866 if (inst.operands[2].isreg
12867 && (inst.operands[1].reg != inst.operands[0].reg
12868 || inst.operands[2].reg > 7))
12869 narrow = FALSE;
12870 if (inst.size_req == 4)
12871 narrow = FALSE;
12872
fdfde340
JM
12873 reject_bad_reg (inst.operands[0].reg);
12874 reject_bad_reg (inst.operands[1].reg);
c921be7d 12875
3d388997 12876 if (!narrow)
c19d1205
ZW
12877 {
12878 if (inst.operands[2].isreg)
b99bd4ef 12879 {
fdfde340 12880 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12881 inst.instruction = THUMB_OP32 (inst.instruction);
12882 inst.instruction |= inst.operands[0].reg << 8;
12883 inst.instruction |= inst.operands[1].reg << 16;
12884 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12885
12886 /* PR 12854: Error on extraneous shifts. */
12887 constraint (inst.operands[2].shifted,
12888 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12889 }
12890 else
12891 {
12892 inst.operands[1].shifted = 1;
3d388997 12893 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12894 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12895 ? T_MNEM_movs : T_MNEM_mov);
12896 inst.instruction |= inst.operands[0].reg << 8;
12897 encode_thumb32_shifted_operand (1);
12898 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12899 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12900 }
12901 }
12902 else
12903 {
c19d1205 12904 if (inst.operands[2].isreg)
b99bd4ef 12905 {
3d388997 12906 switch (shift_kind)
b99bd4ef 12907 {
3d388997
PB
12908 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12909 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12910 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12911 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12912 default: abort ();
b99bd4ef 12913 }
5f4273c7 12914
c19d1205
ZW
12915 inst.instruction |= inst.operands[0].reg;
12916 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12917
12918 /* PR 12854: Error on extraneous shifts. */
12919 constraint (inst.operands[2].shifted,
12920 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12921 }
12922 else
12923 {
3d388997 12924 switch (shift_kind)
b99bd4ef 12925 {
3d388997
PB
12926 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12927 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12928 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12929 default: abort ();
b99bd4ef 12930 }
c19d1205
ZW
12931 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12932 inst.instruction |= inst.operands[0].reg;
12933 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12934 }
12935 }
c19d1205
ZW
12936 }
12937 else
12938 {
12939 constraint (inst.operands[0].reg > 7
12940 || inst.operands[1].reg > 7, BAD_HIREG);
12941 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12942
c19d1205
ZW
12943 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12944 {
12945 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12946 constraint (inst.operands[0].reg != inst.operands[1].reg,
12947 _("source1 and dest must be same register"));
b99bd4ef 12948
c19d1205
ZW
12949 switch (inst.instruction)
12950 {
12951 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12952 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12953 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12954 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12955 default: abort ();
12956 }
5f4273c7 12957
c19d1205
ZW
12958 inst.instruction |= inst.operands[0].reg;
12959 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12960
12961 /* PR 12854: Error on extraneous shifts. */
12962 constraint (inst.operands[2].shifted,
12963 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12964 }
12965 else
b99bd4ef 12966 {
c19d1205
ZW
12967 switch (inst.instruction)
12968 {
12969 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12970 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12971 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12972 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12973 default: abort ();
12974 }
12975 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12976 inst.instruction |= inst.operands[0].reg;
12977 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12978 }
12979 }
b99bd4ef
NC
12980}
12981
12982static void
c19d1205 12983do_t_simd (void)
b99bd4ef 12984{
fdfde340
JM
12985 unsigned Rd, Rn, Rm;
12986
12987 Rd = inst.operands[0].reg;
12988 Rn = inst.operands[1].reg;
12989 Rm = inst.operands[2].reg;
12990
12991 reject_bad_reg (Rd);
12992 reject_bad_reg (Rn);
12993 reject_bad_reg (Rm);
12994
12995 inst.instruction |= Rd << 8;
12996 inst.instruction |= Rn << 16;
12997 inst.instruction |= Rm;
c19d1205 12998}
b99bd4ef 12999
03ee1b7f
NC
13000static void
13001do_t_simd2 (void)
13002{
13003 unsigned Rd, Rn, Rm;
13004
13005 Rd = inst.operands[0].reg;
13006 Rm = inst.operands[1].reg;
13007 Rn = inst.operands[2].reg;
13008
13009 reject_bad_reg (Rd);
13010 reject_bad_reg (Rn);
13011 reject_bad_reg (Rm);
13012
13013 inst.instruction |= Rd << 8;
13014 inst.instruction |= Rn << 16;
13015 inst.instruction |= Rm;
13016}
13017
c19d1205 13018static void
3eb17e6b 13019do_t_smc (void)
c19d1205
ZW
13020{
13021 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
13022 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
13023 _("SMC is not permitted on this architecture"));
c19d1205
ZW
13024 constraint (inst.reloc.exp.X_op != O_constant,
13025 _("expression too complex"));
13026 inst.reloc.type = BFD_RELOC_UNUSED;
13027 inst.instruction |= (value & 0xf000) >> 12;
13028 inst.instruction |= (value & 0x0ff0);
13029 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
13030 /* PR gas/15623: SMC instructions must be last in an IT block. */
13031 set_it_insn_type_last ();
c19d1205 13032}
b99bd4ef 13033
90ec0d68
MGD
13034static void
13035do_t_hvc (void)
13036{
13037 unsigned int value = inst.reloc.exp.X_add_number;
13038
13039 inst.reloc.type = BFD_RELOC_UNUSED;
13040 inst.instruction |= (value & 0x0fff);
13041 inst.instruction |= (value & 0xf000) << 4;
13042}
13043
c19d1205 13044static void
3a21c15a 13045do_t_ssat_usat (int bias)
c19d1205 13046{
fdfde340
JM
13047 unsigned Rd, Rn;
13048
13049 Rd = inst.operands[0].reg;
13050 Rn = inst.operands[2].reg;
13051
13052 reject_bad_reg (Rd);
13053 reject_bad_reg (Rn);
13054
13055 inst.instruction |= Rd << 8;
3a21c15a 13056 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 13057 inst.instruction |= Rn << 16;
b99bd4ef 13058
c19d1205 13059 if (inst.operands[3].present)
b99bd4ef 13060 {
3a21c15a
NC
13061 offsetT shift_amount = inst.reloc.exp.X_add_number;
13062
13063 inst.reloc.type = BFD_RELOC_UNUSED;
13064
c19d1205
ZW
13065 constraint (inst.reloc.exp.X_op != O_constant,
13066 _("expression too complex"));
b99bd4ef 13067
3a21c15a 13068 if (shift_amount != 0)
6189168b 13069 {
3a21c15a
NC
13070 constraint (shift_amount > 31,
13071 _("shift expression is too large"));
13072
c19d1205 13073 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
13074 inst.instruction |= 0x00200000; /* sh bit. */
13075
13076 inst.instruction |= (shift_amount & 0x1c) << 10;
13077 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
13078 }
13079 }
b99bd4ef 13080}
c921be7d 13081
3a21c15a
NC
13082static void
13083do_t_ssat (void)
13084{
13085 do_t_ssat_usat (1);
13086}
b99bd4ef 13087
0dd132b6 13088static void
c19d1205 13089do_t_ssat16 (void)
0dd132b6 13090{
fdfde340
JM
13091 unsigned Rd, Rn;
13092
13093 Rd = inst.operands[0].reg;
13094 Rn = inst.operands[2].reg;
13095
13096 reject_bad_reg (Rd);
13097 reject_bad_reg (Rn);
13098
13099 inst.instruction |= Rd << 8;
c19d1205 13100 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 13101 inst.instruction |= Rn << 16;
c19d1205 13102}
0dd132b6 13103
c19d1205
ZW
13104static void
13105do_t_strex (void)
13106{
13107 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13108 || inst.operands[2].postind || inst.operands[2].writeback
13109 || inst.operands[2].immisreg || inst.operands[2].shifted
13110 || inst.operands[2].negative,
01cfc07f 13111 BAD_ADDR_MODE);
0dd132b6 13112
5be8be5d
DG
13113 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13114
c19d1205
ZW
13115 inst.instruction |= inst.operands[0].reg << 8;
13116 inst.instruction |= inst.operands[1].reg << 12;
13117 inst.instruction |= inst.operands[2].reg << 16;
13118 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13119}
13120
b99bd4ef 13121static void
c19d1205 13122do_t_strexd (void)
b99bd4ef 13123{
c19d1205
ZW
13124 if (!inst.operands[2].present)
13125 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13126
c19d1205
ZW
13127 constraint (inst.operands[0].reg == inst.operands[1].reg
13128 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13129 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13130 BAD_OVERLAP);
b99bd4ef 13131
c19d1205
ZW
13132 inst.instruction |= inst.operands[0].reg;
13133 inst.instruction |= inst.operands[1].reg << 12;
13134 inst.instruction |= inst.operands[2].reg << 8;
13135 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13136}
13137
13138static void
c19d1205 13139do_t_sxtah (void)
b99bd4ef 13140{
fdfde340
JM
13141 unsigned Rd, Rn, Rm;
13142
13143 Rd = inst.operands[0].reg;
13144 Rn = inst.operands[1].reg;
13145 Rm = inst.operands[2].reg;
13146
13147 reject_bad_reg (Rd);
13148 reject_bad_reg (Rn);
13149 reject_bad_reg (Rm);
13150
13151 inst.instruction |= Rd << 8;
13152 inst.instruction |= Rn << 16;
13153 inst.instruction |= Rm;
c19d1205
ZW
13154 inst.instruction |= inst.operands[3].imm << 4;
13155}
b99bd4ef 13156
c19d1205
ZW
13157static void
13158do_t_sxth (void)
13159{
fdfde340
JM
13160 unsigned Rd, Rm;
13161
13162 Rd = inst.operands[0].reg;
13163 Rm = inst.operands[1].reg;
13164
13165 reject_bad_reg (Rd);
13166 reject_bad_reg (Rm);
c921be7d
NC
13167
13168 if (inst.instruction <= 0xffff
13169 && inst.size_req != 4
fdfde340 13170 && Rd <= 7 && Rm <= 7
c19d1205 13171 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13172 {
c19d1205 13173 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13174 inst.instruction |= Rd;
13175 inst.instruction |= Rm << 3;
b99bd4ef 13176 }
c19d1205 13177 else if (unified_syntax)
b99bd4ef 13178 {
c19d1205
ZW
13179 if (inst.instruction <= 0xffff)
13180 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13181 inst.instruction |= Rd << 8;
13182 inst.instruction |= Rm;
c19d1205 13183 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13184 }
c19d1205 13185 else
b99bd4ef 13186 {
c19d1205
ZW
13187 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13188 _("Thumb encoding does not support rotation"));
13189 constraint (1, BAD_HIREG);
b99bd4ef 13190 }
c19d1205 13191}
b99bd4ef 13192
c19d1205
ZW
13193static void
13194do_t_swi (void)
13195{
13196 inst.reloc.type = BFD_RELOC_ARM_SWI;
13197}
b99bd4ef 13198
92e90b6e
PB
13199static void
13200do_t_tb (void)
13201{
fdfde340 13202 unsigned Rn, Rm;
92e90b6e
PB
13203 int half;
13204
13205 half = (inst.instruction & 0x10) != 0;
e07e6e58 13206 set_it_insn_type_last ();
dfa9f0d5
PB
13207 constraint (inst.operands[0].immisreg,
13208 _("instruction requires register index"));
fdfde340
JM
13209
13210 Rn = inst.operands[0].reg;
13211 Rm = inst.operands[0].imm;
c921be7d 13212
5c8ed6a4
JW
13213 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13214 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
13215 reject_bad_reg (Rm);
13216
92e90b6e
PB
13217 constraint (!half && inst.operands[0].shifted,
13218 _("instruction does not allow shifted index"));
fdfde340 13219 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13220}
13221
74db7efb
NC
13222static void
13223do_t_udf (void)
13224{
13225 if (!inst.operands[0].present)
13226 inst.operands[0].imm = 0;
13227
13228 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13229 {
13230 constraint (inst.size_req == 2,
13231 _("immediate value out of range"));
13232 inst.instruction = THUMB_OP32 (inst.instruction);
13233 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13234 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13235 }
13236 else
13237 {
13238 inst.instruction = THUMB_OP16 (inst.instruction);
13239 inst.instruction |= inst.operands[0].imm;
13240 }
13241
13242 set_it_insn_type (NEUTRAL_IT_INSN);
13243}
13244
13245
c19d1205
ZW
13246static void
13247do_t_usat (void)
13248{
3a21c15a 13249 do_t_ssat_usat (0);
b99bd4ef
NC
13250}
13251
13252static void
c19d1205 13253do_t_usat16 (void)
b99bd4ef 13254{
fdfde340
JM
13255 unsigned Rd, Rn;
13256
13257 Rd = inst.operands[0].reg;
13258 Rn = inst.operands[2].reg;
13259
13260 reject_bad_reg (Rd);
13261 reject_bad_reg (Rn);
13262
13263 inst.instruction |= Rd << 8;
c19d1205 13264 inst.instruction |= inst.operands[1].imm;
fdfde340 13265 inst.instruction |= Rn << 16;
b99bd4ef 13266}
c19d1205 13267
5287ad62 13268/* Neon instruction encoder helpers. */
5f4273c7 13269
5287ad62 13270/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13271
5287ad62
JB
13272/* An "invalid" code for the following tables. */
13273#define N_INV -1u
13274
13275struct neon_tab_entry
b99bd4ef 13276{
5287ad62
JB
13277 unsigned integer;
13278 unsigned float_or_poly;
13279 unsigned scalar_or_imm;
13280};
5f4273c7 13281
5287ad62
JB
13282/* Map overloaded Neon opcodes to their respective encodings. */
13283#define NEON_ENC_TAB \
13284 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13285 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13286 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13287 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13288 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13289 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13290 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13291 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13292 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13293 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13294 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13295 /* Register variants of the following two instructions are encoded as
e07e6e58 13296 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13297 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13298 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13299 X(vfma, N_INV, 0x0000c10, N_INV), \
13300 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13301 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13302 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13303 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13304 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13305 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13306 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13307 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13308 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13309 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13310 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13311 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13312 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13313 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13314 X(vshl, 0x0000400, N_INV, 0x0800510), \
13315 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13316 X(vand, 0x0000110, N_INV, 0x0800030), \
13317 X(vbic, 0x0100110, N_INV, 0x0800030), \
13318 X(veor, 0x1000110, N_INV, N_INV), \
13319 X(vorn, 0x0300110, N_INV, 0x0800010), \
13320 X(vorr, 0x0200110, N_INV, 0x0800010), \
13321 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13322 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13323 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13324 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13325 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13326 X(vst1, 0x0000000, 0x0800000, N_INV), \
13327 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13328 X(vst2, 0x0000100, 0x0800100, N_INV), \
13329 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13330 X(vst3, 0x0000200, 0x0800200, N_INV), \
13331 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13332 X(vst4, 0x0000300, 0x0800300, N_INV), \
13333 X(vmovn, 0x1b20200, N_INV, N_INV), \
13334 X(vtrn, 0x1b20080, N_INV, N_INV), \
13335 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13336 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13337 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13338 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13339 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13340 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13341 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13342 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13343 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13344 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13345 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13346 X(vseleq, 0xe000a00, N_INV, N_INV), \
13347 X(vselvs, 0xe100a00, N_INV, N_INV), \
13348 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13349 X(vselgt, 0xe300a00, N_INV, N_INV), \
13350 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13351 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13352 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13353 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13354 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13355 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13356 X(sha3op, 0x2000c00, N_INV, N_INV), \
13357 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13358 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13359
13360enum neon_opc
13361{
13362#define X(OPC,I,F,S) N_MNEM_##OPC
13363NEON_ENC_TAB
13364#undef X
13365};
b99bd4ef 13366
5287ad62
JB
13367static const struct neon_tab_entry neon_enc_tab[] =
13368{
13369#define X(OPC,I,F,S) { (I), (F), (S) }
13370NEON_ENC_TAB
13371#undef X
13372};
b99bd4ef 13373
88714cb8
DG
13374/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13375#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13376#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13377#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13378#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13379#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13380#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13381#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13382#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13383#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13384#define NEON_ENC_SINGLE_(X) \
037e8744 13385 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13386#define NEON_ENC_DOUBLE_(X) \
037e8744 13387 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13388#define NEON_ENC_FPV8_(X) \
13389 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13390
88714cb8
DG
13391#define NEON_ENCODE(type, inst) \
13392 do \
13393 { \
13394 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13395 inst.is_neon = 1; \
13396 } \
13397 while (0)
13398
13399#define check_neon_suffixes \
13400 do \
13401 { \
13402 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13403 { \
13404 as_bad (_("invalid neon suffix for non neon instruction")); \
13405 return; \
13406 } \
13407 } \
13408 while (0)
13409
037e8744
JB
13410/* Define shapes for instruction operands. The following mnemonic characters
13411 are used in this table:
5287ad62 13412
037e8744 13413 F - VFP S<n> register
5287ad62
JB
13414 D - Neon D<n> register
13415 Q - Neon Q<n> register
13416 I - Immediate
13417 S - Scalar
13418 R - ARM register
13419 L - D<n> register list
5f4273c7 13420
037e8744
JB
13421 This table is used to generate various data:
13422 - enumerations of the form NS_DDR to be used as arguments to
13423 neon_select_shape.
13424 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13425 - a table used to drive neon_select_shape. */
b99bd4ef 13426
037e8744
JB
13427#define NEON_SHAPE_DEF \
13428 X(3, (D, D, D), DOUBLE), \
13429 X(3, (Q, Q, Q), QUAD), \
13430 X(3, (D, D, I), DOUBLE), \
13431 X(3, (Q, Q, I), QUAD), \
13432 X(3, (D, D, S), DOUBLE), \
13433 X(3, (Q, Q, S), QUAD), \
13434 X(2, (D, D), DOUBLE), \
13435 X(2, (Q, Q), QUAD), \
13436 X(2, (D, S), DOUBLE), \
13437 X(2, (Q, S), QUAD), \
13438 X(2, (D, R), DOUBLE), \
13439 X(2, (Q, R), QUAD), \
13440 X(2, (D, I), DOUBLE), \
13441 X(2, (Q, I), QUAD), \
13442 X(3, (D, L, D), DOUBLE), \
13443 X(2, (D, Q), MIXED), \
13444 X(2, (Q, D), MIXED), \
13445 X(3, (D, Q, I), MIXED), \
13446 X(3, (Q, D, I), MIXED), \
13447 X(3, (Q, D, D), MIXED), \
13448 X(3, (D, Q, Q), MIXED), \
13449 X(3, (Q, Q, D), MIXED), \
13450 X(3, (Q, D, S), MIXED), \
13451 X(3, (D, Q, S), MIXED), \
13452 X(4, (D, D, D, I), DOUBLE), \
13453 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
13454 X(4, (D, D, S, I), DOUBLE), \
13455 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
13456 X(2, (F, F), SINGLE), \
13457 X(3, (F, F, F), SINGLE), \
13458 X(2, (F, I), SINGLE), \
13459 X(2, (F, D), MIXED), \
13460 X(2, (D, F), MIXED), \
13461 X(3, (F, F, I), MIXED), \
13462 X(4, (R, R, F, F), SINGLE), \
13463 X(4, (F, F, R, R), SINGLE), \
13464 X(3, (D, R, R), DOUBLE), \
13465 X(3, (R, R, D), DOUBLE), \
13466 X(2, (S, R), SINGLE), \
13467 X(2, (R, S), SINGLE), \
13468 X(2, (F, R), SINGLE), \
d54af2d0
RL
13469 X(2, (R, F), SINGLE), \
13470/* Half float shape supported so far. */\
13471 X (2, (H, D), MIXED), \
13472 X (2, (D, H), MIXED), \
13473 X (2, (H, F), MIXED), \
13474 X (2, (F, H), MIXED), \
13475 X (2, (H, H), HALF), \
13476 X (2, (H, R), HALF), \
13477 X (2, (R, H), HALF), \
13478 X (2, (H, I), HALF), \
13479 X (3, (H, H, H), HALF), \
13480 X (3, (H, F, I), MIXED), \
dec41383
JW
13481 X (3, (F, H, I), MIXED), \
13482 X (3, (D, H, H), MIXED), \
13483 X (3, (D, H, S), MIXED)
037e8744
JB
13484
13485#define S2(A,B) NS_##A##B
13486#define S3(A,B,C) NS_##A##B##C
13487#define S4(A,B,C,D) NS_##A##B##C##D
13488
13489#define X(N, L, C) S##N L
13490
5287ad62
JB
13491enum neon_shape
13492{
037e8744
JB
13493 NEON_SHAPE_DEF,
13494 NS_NULL
5287ad62 13495};
b99bd4ef 13496
037e8744
JB
13497#undef X
13498#undef S2
13499#undef S3
13500#undef S4
13501
13502enum neon_shape_class
13503{
d54af2d0 13504 SC_HALF,
037e8744
JB
13505 SC_SINGLE,
13506 SC_DOUBLE,
13507 SC_QUAD,
13508 SC_MIXED
13509};
13510
13511#define X(N, L, C) SC_##C
13512
13513static enum neon_shape_class neon_shape_class[] =
13514{
13515 NEON_SHAPE_DEF
13516};
13517
13518#undef X
13519
13520enum neon_shape_el
13521{
d54af2d0 13522 SE_H,
037e8744
JB
13523 SE_F,
13524 SE_D,
13525 SE_Q,
13526 SE_I,
13527 SE_S,
13528 SE_R,
13529 SE_L
13530};
13531
13532/* Register widths of above. */
13533static unsigned neon_shape_el_size[] =
13534{
d54af2d0 13535 16,
037e8744
JB
13536 32,
13537 64,
13538 128,
13539 0,
13540 32,
13541 32,
13542 0
13543};
13544
13545struct neon_shape_info
13546{
13547 unsigned els;
13548 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13549};
13550
13551#define S2(A,B) { SE_##A, SE_##B }
13552#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13553#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13554
13555#define X(N, L, C) { N, S##N L }
13556
13557static struct neon_shape_info neon_shape_tab[] =
13558{
13559 NEON_SHAPE_DEF
13560};
13561
13562#undef X
13563#undef S2
13564#undef S3
13565#undef S4
13566
5287ad62
JB
13567/* Bit masks used in type checking given instructions.
13568 'N_EQK' means the type must be the same as (or based on in some way) the key
13569 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13570 set, various other bits can be set as well in order to modify the meaning of
13571 the type constraint. */
13572
13573enum neon_type_mask
13574{
8e79c3df
CM
13575 N_S8 = 0x0000001,
13576 N_S16 = 0x0000002,
13577 N_S32 = 0x0000004,
13578 N_S64 = 0x0000008,
13579 N_U8 = 0x0000010,
13580 N_U16 = 0x0000020,
13581 N_U32 = 0x0000040,
13582 N_U64 = 0x0000080,
13583 N_I8 = 0x0000100,
13584 N_I16 = 0x0000200,
13585 N_I32 = 0x0000400,
13586 N_I64 = 0x0000800,
13587 N_8 = 0x0001000,
13588 N_16 = 0x0002000,
13589 N_32 = 0x0004000,
13590 N_64 = 0x0008000,
13591 N_P8 = 0x0010000,
13592 N_P16 = 0x0020000,
13593 N_F16 = 0x0040000,
13594 N_F32 = 0x0080000,
13595 N_F64 = 0x0100000,
4f51b4bd 13596 N_P64 = 0x0200000,
c921be7d
NC
13597 N_KEY = 0x1000000, /* Key element (main type specifier). */
13598 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13599 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13600 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13601 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13602 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13603 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13604 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13605 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13606 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13607 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13608 N_UTYP = 0,
4f51b4bd 13609 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13610};
13611
dcbf9037
JB
13612#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13613
5287ad62
JB
13614#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13615#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13616#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13617#define N_S_32 (N_S8 | N_S16 | N_S32)
13618#define N_F_16_32 (N_F16 | N_F32)
13619#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13620#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13621#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13622#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13623
13624/* Pass this as the first type argument to neon_check_type to ignore types
13625 altogether. */
13626#define N_IGNORE_TYPE (N_KEY | N_EQK)
13627
037e8744
JB
13628/* Select a "shape" for the current instruction (describing register types or
13629 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13630 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13631 function of operand parsing, so this function doesn't need to be called.
13632 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13633
13634static enum neon_shape
037e8744 13635neon_select_shape (enum neon_shape shape, ...)
5287ad62 13636{
037e8744
JB
13637 va_list ap;
13638 enum neon_shape first_shape = shape;
5287ad62
JB
13639
13640 /* Fix missing optional operands. FIXME: we don't know at this point how
13641 many arguments we should have, so this makes the assumption that we have
13642 > 1. This is true of all current Neon opcodes, I think, but may not be
13643 true in the future. */
13644 if (!inst.operands[1].present)
13645 inst.operands[1] = inst.operands[0];
13646
037e8744 13647 va_start (ap, shape);
5f4273c7 13648
21d799b5 13649 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13650 {
13651 unsigned j;
13652 int matches = 1;
13653
13654 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13655 {
13656 if (!inst.operands[j].present)
13657 {
13658 matches = 0;
13659 break;
13660 }
13661
13662 switch (neon_shape_tab[shape].el[j])
13663 {
d54af2d0
RL
13664 /* If a .f16, .16, .u16, .s16 type specifier is given over
13665 a VFP single precision register operand, it's essentially
13666 means only half of the register is used.
13667
13668 If the type specifier is given after the mnemonics, the
13669 information is stored in inst.vectype. If the type specifier
13670 is given after register operand, the information is stored
13671 in inst.operands[].vectype.
13672
13673 When there is only one type specifier, and all the register
13674 operands are the same type of hardware register, the type
13675 specifier applies to all register operands.
13676
13677 If no type specifier is given, the shape is inferred from
13678 operand information.
13679
13680 for example:
13681 vadd.f16 s0, s1, s2: NS_HHH
13682 vabs.f16 s0, s1: NS_HH
13683 vmov.f16 s0, r1: NS_HR
13684 vmov.f16 r0, s1: NS_RH
13685 vcvt.f16 r0, s1: NS_RH
13686 vcvt.f16.s32 s2, s2, #29: NS_HFI
13687 vcvt.f16.s32 s2, s2: NS_HF
13688 */
13689 case SE_H:
13690 if (!(inst.operands[j].isreg
13691 && inst.operands[j].isvec
13692 && inst.operands[j].issingle
13693 && !inst.operands[j].isquad
13694 && ((inst.vectype.elems == 1
13695 && inst.vectype.el[0].size == 16)
13696 || (inst.vectype.elems > 1
13697 && inst.vectype.el[j].size == 16)
13698 || (inst.vectype.elems == 0
13699 && inst.operands[j].vectype.type != NT_invtype
13700 && inst.operands[j].vectype.size == 16))))
13701 matches = 0;
13702 break;
13703
477330fc
RM
13704 case SE_F:
13705 if (!(inst.operands[j].isreg
13706 && inst.operands[j].isvec
13707 && inst.operands[j].issingle
d54af2d0
RL
13708 && !inst.operands[j].isquad
13709 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13710 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13711 || (inst.vectype.elems == 0
13712 && (inst.operands[j].vectype.size == 32
13713 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13714 matches = 0;
13715 break;
13716
13717 case SE_D:
13718 if (!(inst.operands[j].isreg
13719 && inst.operands[j].isvec
13720 && !inst.operands[j].isquad
13721 && !inst.operands[j].issingle))
13722 matches = 0;
13723 break;
13724
13725 case SE_R:
13726 if (!(inst.operands[j].isreg
13727 && !inst.operands[j].isvec))
13728 matches = 0;
13729 break;
13730
13731 case SE_Q:
13732 if (!(inst.operands[j].isreg
13733 && inst.operands[j].isvec
13734 && inst.operands[j].isquad
13735 && !inst.operands[j].issingle))
13736 matches = 0;
13737 break;
13738
13739 case SE_I:
13740 if (!(!inst.operands[j].isreg
13741 && !inst.operands[j].isscalar))
13742 matches = 0;
13743 break;
13744
13745 case SE_S:
13746 if (!(!inst.operands[j].isreg
13747 && inst.operands[j].isscalar))
13748 matches = 0;
13749 break;
13750
13751 case SE_L:
13752 break;
13753 }
3fde54a2
JZ
13754 if (!matches)
13755 break;
477330fc 13756 }
ad6cec43
MGD
13757 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13758 /* We've matched all the entries in the shape table, and we don't
13759 have any left over operands which have not been matched. */
477330fc 13760 break;
037e8744 13761 }
5f4273c7 13762
037e8744 13763 va_end (ap);
5287ad62 13764
037e8744
JB
13765 if (shape == NS_NULL && first_shape != NS_NULL)
13766 first_error (_("invalid instruction shape"));
5287ad62 13767
037e8744
JB
13768 return shape;
13769}
5287ad62 13770
037e8744
JB
13771/* True if SHAPE is predominantly a quadword operation (most of the time, this
13772 means the Q bit should be set). */
13773
13774static int
13775neon_quad (enum neon_shape shape)
13776{
13777 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13778}
037e8744 13779
5287ad62
JB
13780static void
13781neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13782 unsigned *g_size)
5287ad62
JB
13783{
13784 /* Allow modification to be made to types which are constrained to be
13785 based on the key element, based on bits set alongside N_EQK. */
13786 if ((typebits & N_EQK) != 0)
13787 {
13788 if ((typebits & N_HLF) != 0)
13789 *g_size /= 2;
13790 else if ((typebits & N_DBL) != 0)
13791 *g_size *= 2;
13792 if ((typebits & N_SGN) != 0)
13793 *g_type = NT_signed;
13794 else if ((typebits & N_UNS) != 0)
477330fc 13795 *g_type = NT_unsigned;
5287ad62 13796 else if ((typebits & N_INT) != 0)
477330fc 13797 *g_type = NT_integer;
5287ad62 13798 else if ((typebits & N_FLT) != 0)
477330fc 13799 *g_type = NT_float;
dcbf9037 13800 else if ((typebits & N_SIZ) != 0)
477330fc 13801 *g_type = NT_untyped;
5287ad62
JB
13802 }
13803}
5f4273c7 13804
5287ad62
JB
13805/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13806 operand type, i.e. the single type specified in a Neon instruction when it
13807 is the only one given. */
13808
13809static struct neon_type_el
13810neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13811{
13812 struct neon_type_el dest = *key;
5f4273c7 13813
9c2799c2 13814 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13815
5287ad62
JB
13816 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13817
13818 return dest;
13819}
13820
13821/* Convert Neon type and size into compact bitmask representation. */
13822
13823static enum neon_type_mask
13824type_chk_of_el_type (enum neon_el_type type, unsigned size)
13825{
13826 switch (type)
13827 {
13828 case NT_untyped:
13829 switch (size)
477330fc
RM
13830 {
13831 case 8: return N_8;
13832 case 16: return N_16;
13833 case 32: return N_32;
13834 case 64: return N_64;
13835 default: ;
13836 }
5287ad62
JB
13837 break;
13838
13839 case NT_integer:
13840 switch (size)
477330fc
RM
13841 {
13842 case 8: return N_I8;
13843 case 16: return N_I16;
13844 case 32: return N_I32;
13845 case 64: return N_I64;
13846 default: ;
13847 }
5287ad62
JB
13848 break;
13849
13850 case NT_float:
037e8744 13851 switch (size)
477330fc 13852 {
8e79c3df 13853 case 16: return N_F16;
477330fc
RM
13854 case 32: return N_F32;
13855 case 64: return N_F64;
13856 default: ;
13857 }
5287ad62
JB
13858 break;
13859
13860 case NT_poly:
13861 switch (size)
477330fc
RM
13862 {
13863 case 8: return N_P8;
13864 case 16: return N_P16;
4f51b4bd 13865 case 64: return N_P64;
477330fc
RM
13866 default: ;
13867 }
5287ad62
JB
13868 break;
13869
13870 case NT_signed:
13871 switch (size)
477330fc
RM
13872 {
13873 case 8: return N_S8;
13874 case 16: return N_S16;
13875 case 32: return N_S32;
13876 case 64: return N_S64;
13877 default: ;
13878 }
5287ad62
JB
13879 break;
13880
13881 case NT_unsigned:
13882 switch (size)
477330fc
RM
13883 {
13884 case 8: return N_U8;
13885 case 16: return N_U16;
13886 case 32: return N_U32;
13887 case 64: return N_U64;
13888 default: ;
13889 }
5287ad62
JB
13890 break;
13891
13892 default: ;
13893 }
5f4273c7 13894
5287ad62
JB
13895 return N_UTYP;
13896}
13897
13898/* Convert compact Neon bitmask type representation to a type and size. Only
13899 handles the case where a single bit is set in the mask. */
13900
dcbf9037 13901static int
5287ad62 13902el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13903 enum neon_type_mask mask)
5287ad62 13904{
dcbf9037
JB
13905 if ((mask & N_EQK) != 0)
13906 return FAIL;
13907
5287ad62
JB
13908 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13909 *size = 8;
c70a8987 13910 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13911 *size = 16;
dcbf9037 13912 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13913 *size = 32;
4f51b4bd 13914 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13915 *size = 64;
dcbf9037
JB
13916 else
13917 return FAIL;
13918
5287ad62
JB
13919 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13920 *type = NT_signed;
dcbf9037 13921 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13922 *type = NT_unsigned;
dcbf9037 13923 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13924 *type = NT_integer;
dcbf9037 13925 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13926 *type = NT_untyped;
4f51b4bd 13927 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13928 *type = NT_poly;
d54af2d0 13929 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13930 *type = NT_float;
dcbf9037
JB
13931 else
13932 return FAIL;
5f4273c7 13933
dcbf9037 13934 return SUCCESS;
5287ad62
JB
13935}
13936
13937/* Modify a bitmask of allowed types. This is only needed for type
13938 relaxation. */
13939
13940static unsigned
13941modify_types_allowed (unsigned allowed, unsigned mods)
13942{
13943 unsigned size;
13944 enum neon_el_type type;
13945 unsigned destmask;
13946 int i;
5f4273c7 13947
5287ad62 13948 destmask = 0;
5f4273c7 13949
5287ad62
JB
13950 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13951 {
21d799b5 13952 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13953 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13954 {
13955 neon_modify_type_size (mods, &type, &size);
13956 destmask |= type_chk_of_el_type (type, size);
13957 }
5287ad62 13958 }
5f4273c7 13959
5287ad62
JB
13960 return destmask;
13961}
13962
13963/* Check type and return type classification.
13964 The manual states (paraphrase): If one datatype is given, it indicates the
13965 type given in:
13966 - the second operand, if there is one
13967 - the operand, if there is no second operand
13968 - the result, if there are no operands.
13969 This isn't quite good enough though, so we use a concept of a "key" datatype
13970 which is set on a per-instruction basis, which is the one which matters when
13971 only one data type is written.
13972 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13973 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13974
13975static struct neon_type_el
13976neon_check_type (unsigned els, enum neon_shape ns, ...)
13977{
13978 va_list ap;
13979 unsigned i, pass, key_el = 0;
13980 unsigned types[NEON_MAX_TYPE_ELS];
13981 enum neon_el_type k_type = NT_invtype;
13982 unsigned k_size = -1u;
13983 struct neon_type_el badtype = {NT_invtype, -1};
13984 unsigned key_allowed = 0;
13985
13986 /* Optional registers in Neon instructions are always (not) in operand 1.
13987 Fill in the missing operand here, if it was omitted. */
13988 if (els > 1 && !inst.operands[1].present)
13989 inst.operands[1] = inst.operands[0];
13990
13991 /* Suck up all the varargs. */
13992 va_start (ap, ns);
13993 for (i = 0; i < els; i++)
13994 {
13995 unsigned thisarg = va_arg (ap, unsigned);
13996 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13997 {
13998 va_end (ap);
13999 return badtype;
14000 }
5287ad62
JB
14001 types[i] = thisarg;
14002 if ((thisarg & N_KEY) != 0)
477330fc 14003 key_el = i;
5287ad62
JB
14004 }
14005 va_end (ap);
14006
dcbf9037
JB
14007 if (inst.vectype.elems > 0)
14008 for (i = 0; i < els; i++)
14009 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
14010 {
14011 first_error (_("types specified in both the mnemonic and operands"));
14012 return badtype;
14013 }
dcbf9037 14014
5287ad62
JB
14015 /* Duplicate inst.vectype elements here as necessary.
14016 FIXME: No idea if this is exactly the same as the ARM assembler,
14017 particularly when an insn takes one register and one non-register
14018 operand. */
14019 if (inst.vectype.elems == 1 && els > 1)
14020 {
14021 unsigned j;
14022 inst.vectype.elems = els;
14023 inst.vectype.el[key_el] = inst.vectype.el[0];
14024 for (j = 0; j < els; j++)
477330fc
RM
14025 if (j != key_el)
14026 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14027 types[j]);
dcbf9037
JB
14028 }
14029 else if (inst.vectype.elems == 0 && els > 0)
14030 {
14031 unsigned j;
14032 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
14033 after each operand. We allow some flexibility here; as long as the
14034 "key" operand has a type, we can infer the others. */
dcbf9037 14035 for (j = 0; j < els; j++)
477330fc
RM
14036 if (inst.operands[j].vectype.type != NT_invtype)
14037 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
14038
14039 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
14040 {
14041 for (j = 0; j < els; j++)
14042 if (inst.operands[j].vectype.type == NT_invtype)
14043 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14044 types[j]);
14045 }
dcbf9037 14046 else
477330fc
RM
14047 {
14048 first_error (_("operand types can't be inferred"));
14049 return badtype;
14050 }
5287ad62
JB
14051 }
14052 else if (inst.vectype.elems != els)
14053 {
dcbf9037 14054 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
14055 return badtype;
14056 }
14057
14058 for (pass = 0; pass < 2; pass++)
14059 {
14060 for (i = 0; i < els; i++)
477330fc
RM
14061 {
14062 unsigned thisarg = types[i];
14063 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
14064 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
14065 enum neon_el_type g_type = inst.vectype.el[i].type;
14066 unsigned g_size = inst.vectype.el[i].size;
14067
14068 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 14069 integer types if sign-specific variants are unavailable. */
477330fc 14070 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
14071 && (types_allowed & N_SU_ALL) == 0)
14072 g_type = NT_integer;
14073
477330fc 14074 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
14075 them. Some instructions only care about signs for some element
14076 sizes, so handle that properly. */
477330fc 14077 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
14078 && ((g_size == 8 && (types_allowed & N_8) != 0)
14079 || (g_size == 16 && (types_allowed & N_16) != 0)
14080 || (g_size == 32 && (types_allowed & N_32) != 0)
14081 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
14082 g_type = NT_untyped;
14083
477330fc
RM
14084 if (pass == 0)
14085 {
14086 if ((thisarg & N_KEY) != 0)
14087 {
14088 k_type = g_type;
14089 k_size = g_size;
14090 key_allowed = thisarg & ~N_KEY;
cc933301
JW
14091
14092 /* Check architecture constraint on FP16 extension. */
14093 if (k_size == 16
14094 && k_type == NT_float
14095 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14096 {
14097 inst.error = _(BAD_FP16);
14098 return badtype;
14099 }
477330fc
RM
14100 }
14101 }
14102 else
14103 {
14104 if ((thisarg & N_VFP) != 0)
14105 {
14106 enum neon_shape_el regshape;
14107 unsigned regwidth, match;
99b253c5
NC
14108
14109 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14110 if (ns == NS_NULL)
14111 {
14112 first_error (_("invalid instruction shape"));
14113 return badtype;
14114 }
477330fc
RM
14115 regshape = neon_shape_tab[ns].el[i];
14116 regwidth = neon_shape_el_size[regshape];
14117
14118 /* In VFP mode, operands must match register widths. If we
14119 have a key operand, use its width, else use the width of
14120 the current operand. */
14121 if (k_size != -1u)
14122 match = k_size;
14123 else
14124 match = g_size;
14125
9db2f6b4
RL
14126 /* FP16 will use a single precision register. */
14127 if (regwidth == 32 && match == 16)
14128 {
14129 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14130 match = regwidth;
14131 else
14132 {
14133 inst.error = _(BAD_FP16);
14134 return badtype;
14135 }
14136 }
14137
477330fc
RM
14138 if (regwidth != match)
14139 {
14140 first_error (_("operand size must match register width"));
14141 return badtype;
14142 }
14143 }
14144
14145 if ((thisarg & N_EQK) == 0)
14146 {
14147 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14148
14149 if ((given_type & types_allowed) == 0)
14150 {
14151 first_error (_("bad type in Neon instruction"));
14152 return badtype;
14153 }
14154 }
14155 else
14156 {
14157 enum neon_el_type mod_k_type = k_type;
14158 unsigned mod_k_size = k_size;
14159 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14160 if (g_type != mod_k_type || g_size != mod_k_size)
14161 {
14162 first_error (_("inconsistent types in Neon instruction"));
14163 return badtype;
14164 }
14165 }
14166 }
14167 }
5287ad62
JB
14168 }
14169
14170 return inst.vectype.el[key_el];
14171}
14172
037e8744 14173/* Neon-style VFP instruction forwarding. */
5287ad62 14174
037e8744
JB
14175/* Thumb VFP instructions have 0xE in the condition field. */
14176
14177static void
14178do_vfp_cond_or_thumb (void)
5287ad62 14179{
88714cb8
DG
14180 inst.is_neon = 1;
14181
5287ad62 14182 if (thumb_mode)
037e8744 14183 inst.instruction |= 0xe0000000;
5287ad62 14184 else
037e8744 14185 inst.instruction |= inst.cond << 28;
5287ad62
JB
14186}
14187
037e8744
JB
14188/* Look up and encode a simple mnemonic, for use as a helper function for the
14189 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14190 etc. It is assumed that operand parsing has already been done, and that the
14191 operands are in the form expected by the given opcode (this isn't necessarily
14192 the same as the form in which they were parsed, hence some massaging must
14193 take place before this function is called).
14194 Checks current arch version against that in the looked-up opcode. */
5287ad62 14195
037e8744
JB
14196static void
14197do_vfp_nsyn_opcode (const char *opname)
5287ad62 14198{
037e8744 14199 const struct asm_opcode *opcode;
5f4273c7 14200
21d799b5 14201 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14202
037e8744
JB
14203 if (!opcode)
14204 abort ();
5287ad62 14205
037e8744 14206 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14207 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14208 _(BAD_FPU));
5287ad62 14209
88714cb8
DG
14210 inst.is_neon = 1;
14211
037e8744
JB
14212 if (thumb_mode)
14213 {
14214 inst.instruction = opcode->tvalue;
14215 opcode->tencode ();
14216 }
14217 else
14218 {
14219 inst.instruction = (inst.cond << 28) | opcode->avalue;
14220 opcode->aencode ();
14221 }
14222}
5287ad62
JB
14223
14224static void
037e8744 14225do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14226{
037e8744
JB
14227 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14228
9db2f6b4 14229 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14230 {
14231 if (is_add)
477330fc 14232 do_vfp_nsyn_opcode ("fadds");
037e8744 14233 else
477330fc 14234 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14235
14236 /* ARMv8.2 fp16 instruction. */
14237 if (rs == NS_HHH)
14238 do_scalar_fp16_v82_encode ();
037e8744
JB
14239 }
14240 else
14241 {
14242 if (is_add)
477330fc 14243 do_vfp_nsyn_opcode ("faddd");
037e8744 14244 else
477330fc 14245 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14246 }
14247}
14248
14249/* Check operand types to see if this is a VFP instruction, and if so call
14250 PFN (). */
14251
14252static int
14253try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14254{
14255 enum neon_shape rs;
14256 struct neon_type_el et;
14257
14258 switch (args)
14259 {
14260 case 2:
9db2f6b4
RL
14261 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14262 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14263 break;
5f4273c7 14264
037e8744 14265 case 3:
9db2f6b4
RL
14266 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14267 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14268 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14269 break;
14270
14271 default:
14272 abort ();
14273 }
14274
14275 if (et.type != NT_invtype)
14276 {
14277 pfn (rs);
14278 return SUCCESS;
14279 }
037e8744 14280
99b253c5 14281 inst.error = NULL;
037e8744
JB
14282 return FAIL;
14283}
14284
14285static void
14286do_vfp_nsyn_mla_mls (enum neon_shape rs)
14287{
14288 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14289
9db2f6b4 14290 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14291 {
14292 if (is_mla)
477330fc 14293 do_vfp_nsyn_opcode ("fmacs");
037e8744 14294 else
477330fc 14295 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14296
14297 /* ARMv8.2 fp16 instruction. */
14298 if (rs == NS_HHH)
14299 do_scalar_fp16_v82_encode ();
037e8744
JB
14300 }
14301 else
14302 {
14303 if (is_mla)
477330fc 14304 do_vfp_nsyn_opcode ("fmacd");
037e8744 14305 else
477330fc 14306 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14307 }
14308}
14309
62f3b8c8
PB
14310static void
14311do_vfp_nsyn_fma_fms (enum neon_shape rs)
14312{
14313 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14314
9db2f6b4 14315 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14316 {
14317 if (is_fma)
477330fc 14318 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14319 else
477330fc 14320 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14321
14322 /* ARMv8.2 fp16 instruction. */
14323 if (rs == NS_HHH)
14324 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14325 }
14326 else
14327 {
14328 if (is_fma)
477330fc 14329 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14330 else
477330fc 14331 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14332 }
14333}
14334
037e8744
JB
14335static void
14336do_vfp_nsyn_mul (enum neon_shape rs)
14337{
9db2f6b4
RL
14338 if (rs == NS_FFF || rs == NS_HHH)
14339 {
14340 do_vfp_nsyn_opcode ("fmuls");
14341
14342 /* ARMv8.2 fp16 instruction. */
14343 if (rs == NS_HHH)
14344 do_scalar_fp16_v82_encode ();
14345 }
037e8744
JB
14346 else
14347 do_vfp_nsyn_opcode ("fmuld");
14348}
14349
14350static void
14351do_vfp_nsyn_abs_neg (enum neon_shape rs)
14352{
14353 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14354 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14355
9db2f6b4 14356 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14357 {
14358 if (is_neg)
477330fc 14359 do_vfp_nsyn_opcode ("fnegs");
037e8744 14360 else
477330fc 14361 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14362
14363 /* ARMv8.2 fp16 instruction. */
14364 if (rs == NS_HH)
14365 do_scalar_fp16_v82_encode ();
037e8744
JB
14366 }
14367 else
14368 {
14369 if (is_neg)
477330fc 14370 do_vfp_nsyn_opcode ("fnegd");
037e8744 14371 else
477330fc 14372 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14373 }
14374}
14375
14376/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14377 insns belong to Neon, and are handled elsewhere. */
14378
14379static void
14380do_vfp_nsyn_ldm_stm (int is_dbmode)
14381{
14382 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14383 if (is_ldm)
14384 {
14385 if (is_dbmode)
477330fc 14386 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14387 else
477330fc 14388 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14389 }
14390 else
14391 {
14392 if (is_dbmode)
477330fc 14393 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14394 else
477330fc 14395 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14396 }
14397}
14398
037e8744
JB
14399static void
14400do_vfp_nsyn_sqrt (void)
14401{
9db2f6b4
RL
14402 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14403 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14404
9db2f6b4
RL
14405 if (rs == NS_FF || rs == NS_HH)
14406 {
14407 do_vfp_nsyn_opcode ("fsqrts");
14408
14409 /* ARMv8.2 fp16 instruction. */
14410 if (rs == NS_HH)
14411 do_scalar_fp16_v82_encode ();
14412 }
037e8744
JB
14413 else
14414 do_vfp_nsyn_opcode ("fsqrtd");
14415}
14416
14417static void
14418do_vfp_nsyn_div (void)
14419{
9db2f6b4 14420 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14421 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14422 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14423
9db2f6b4
RL
14424 if (rs == NS_FFF || rs == NS_HHH)
14425 {
14426 do_vfp_nsyn_opcode ("fdivs");
14427
14428 /* ARMv8.2 fp16 instruction. */
14429 if (rs == NS_HHH)
14430 do_scalar_fp16_v82_encode ();
14431 }
037e8744
JB
14432 else
14433 do_vfp_nsyn_opcode ("fdivd");
14434}
14435
14436static void
14437do_vfp_nsyn_nmul (void)
14438{
9db2f6b4 14439 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14440 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14441 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14442
9db2f6b4 14443 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14444 {
88714cb8 14445 NEON_ENCODE (SINGLE, inst);
037e8744 14446 do_vfp_sp_dyadic ();
9db2f6b4
RL
14447
14448 /* ARMv8.2 fp16 instruction. */
14449 if (rs == NS_HHH)
14450 do_scalar_fp16_v82_encode ();
037e8744
JB
14451 }
14452 else
14453 {
88714cb8 14454 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14455 do_vfp_dp_rd_rn_rm ();
14456 }
14457 do_vfp_cond_or_thumb ();
9db2f6b4 14458
037e8744
JB
14459}
14460
14461static void
14462do_vfp_nsyn_cmp (void)
14463{
9db2f6b4 14464 enum neon_shape rs;
037e8744
JB
14465 if (inst.operands[1].isreg)
14466 {
9db2f6b4
RL
14467 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14468 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14469
9db2f6b4 14470 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14471 {
14472 NEON_ENCODE (SINGLE, inst);
14473 do_vfp_sp_monadic ();
14474 }
037e8744 14475 else
477330fc
RM
14476 {
14477 NEON_ENCODE (DOUBLE, inst);
14478 do_vfp_dp_rd_rm ();
14479 }
037e8744
JB
14480 }
14481 else
14482 {
9db2f6b4
RL
14483 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14484 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14485
14486 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14487 {
14488 case N_MNEM_vcmp:
14489 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14490 break;
14491 case N_MNEM_vcmpe:
14492 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14493 break;
14494 default:
14495 abort ();
14496 }
5f4273c7 14497
9db2f6b4 14498 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14499 {
14500 NEON_ENCODE (SINGLE, inst);
14501 do_vfp_sp_compare_z ();
14502 }
037e8744 14503 else
477330fc
RM
14504 {
14505 NEON_ENCODE (DOUBLE, inst);
14506 do_vfp_dp_rd ();
14507 }
037e8744
JB
14508 }
14509 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14510
14511 /* ARMv8.2 fp16 instruction. */
14512 if (rs == NS_HI || rs == NS_HH)
14513 do_scalar_fp16_v82_encode ();
037e8744
JB
14514}
14515
14516static void
14517nsyn_insert_sp (void)
14518{
14519 inst.operands[1] = inst.operands[0];
14520 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14521 inst.operands[0].reg = REG_SP;
037e8744
JB
14522 inst.operands[0].isreg = 1;
14523 inst.operands[0].writeback = 1;
14524 inst.operands[0].present = 1;
14525}
14526
14527static void
14528do_vfp_nsyn_push (void)
14529{
14530 nsyn_insert_sp ();
b126985e
NC
14531
14532 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14533 _("register list must contain at least 1 and at most 16 "
14534 "registers"));
14535
037e8744
JB
14536 if (inst.operands[1].issingle)
14537 do_vfp_nsyn_opcode ("fstmdbs");
14538 else
14539 do_vfp_nsyn_opcode ("fstmdbd");
14540}
14541
14542static void
14543do_vfp_nsyn_pop (void)
14544{
14545 nsyn_insert_sp ();
b126985e
NC
14546
14547 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14548 _("register list must contain at least 1 and at most 16 "
14549 "registers"));
14550
037e8744 14551 if (inst.operands[1].issingle)
22b5b651 14552 do_vfp_nsyn_opcode ("fldmias");
037e8744 14553 else
22b5b651 14554 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14555}
14556
14557/* Fix up Neon data-processing instructions, ORing in the correct bits for
14558 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14559
88714cb8
DG
14560static void
14561neon_dp_fixup (struct arm_it* insn)
037e8744 14562{
88714cb8
DG
14563 unsigned int i = insn->instruction;
14564 insn->is_neon = 1;
14565
037e8744
JB
14566 if (thumb_mode)
14567 {
14568 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14569 if (i & (1 << 24))
477330fc 14570 i |= 1 << 28;
5f4273c7 14571
037e8744 14572 i &= ~(1 << 24);
5f4273c7 14573
037e8744
JB
14574 i |= 0xef000000;
14575 }
14576 else
14577 i |= 0xf2000000;
5f4273c7 14578
88714cb8 14579 insn->instruction = i;
037e8744
JB
14580}
14581
14582/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14583 (0, 1, 2, 3). */
14584
14585static unsigned
14586neon_logbits (unsigned x)
14587{
14588 return ffs (x) - 4;
14589}
14590
14591#define LOW4(R) ((R) & 0xf)
14592#define HI1(R) (((R) >> 4) & 1)
14593
14594/* Encode insns with bit pattern:
14595
14596 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14597 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14598
037e8744
JB
14599 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14600 different meaning for some instruction. */
14601
14602static void
14603neon_three_same (int isquad, int ubit, int size)
14604{
14605 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14606 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14607 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14608 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14609 inst.instruction |= LOW4 (inst.operands[2].reg);
14610 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14611 inst.instruction |= (isquad != 0) << 6;
14612 inst.instruction |= (ubit != 0) << 24;
14613 if (size != -1)
14614 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14615
88714cb8 14616 neon_dp_fixup (&inst);
037e8744
JB
14617}
14618
14619/* Encode instructions of the form:
14620
14621 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14622 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14623
14624 Don't write size if SIZE == -1. */
14625
14626static void
14627neon_two_same (int qbit, int ubit, int size)
14628{
14629 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14630 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14631 inst.instruction |= LOW4 (inst.operands[1].reg);
14632 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14633 inst.instruction |= (qbit != 0) << 6;
14634 inst.instruction |= (ubit != 0) << 24;
14635
14636 if (size != -1)
14637 inst.instruction |= neon_logbits (size) << 18;
14638
88714cb8 14639 neon_dp_fixup (&inst);
5287ad62
JB
14640}
14641
14642/* Neon instruction encoders, in approximate order of appearance. */
14643
14644static void
14645do_neon_dyadic_i_su (void)
14646{
037e8744 14647 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14648 struct neon_type_el et = neon_check_type (3, rs,
14649 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14650 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14651}
14652
14653static void
14654do_neon_dyadic_i64_su (void)
14655{
037e8744 14656 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14657 struct neon_type_el et = neon_check_type (3, rs,
14658 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14659 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14660}
14661
14662static void
14663neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14664 unsigned immbits)
5287ad62
JB
14665{
14666 unsigned size = et.size >> 3;
14667 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14668 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14669 inst.instruction |= LOW4 (inst.operands[1].reg);
14670 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14671 inst.instruction |= (isquad != 0) << 6;
14672 inst.instruction |= immbits << 16;
14673 inst.instruction |= (size >> 3) << 7;
14674 inst.instruction |= (size & 0x7) << 19;
14675 if (write_ubit)
14676 inst.instruction |= (uval != 0) << 24;
14677
88714cb8 14678 neon_dp_fixup (&inst);
5287ad62
JB
14679}
14680
14681static void
14682do_neon_shl_imm (void)
14683{
14684 if (!inst.operands[2].isreg)
14685 {
037e8744 14686 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14687 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14688 int imm = inst.operands[2].imm;
14689
14690 constraint (imm < 0 || (unsigned)imm >= et.size,
14691 _("immediate out of range for shift"));
88714cb8 14692 NEON_ENCODE (IMMED, inst);
cb3b1e65 14693 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14694 }
14695 else
14696 {
037e8744 14697 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14698 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14699 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14700 unsigned int tmp;
14701
14702 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14703 vshl.xx Dd, Dm, Dn
14704 whereas other 3-register operations encoded by neon_three_same have
14705 syntax like:
14706 vadd.xx Dd, Dn, Dm
14707 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14708 here. */
627907b7
JB
14709 tmp = inst.operands[2].reg;
14710 inst.operands[2].reg = inst.operands[1].reg;
14711 inst.operands[1].reg = tmp;
88714cb8 14712 NEON_ENCODE (INTEGER, inst);
037e8744 14713 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14714 }
14715}
14716
14717static void
14718do_neon_qshl_imm (void)
14719{
14720 if (!inst.operands[2].isreg)
14721 {
037e8744 14722 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14723 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14724 int imm = inst.operands[2].imm;
627907b7 14725
cb3b1e65
JB
14726 constraint (imm < 0 || (unsigned)imm >= et.size,
14727 _("immediate out of range for shift"));
88714cb8 14728 NEON_ENCODE (IMMED, inst);
cb3b1e65 14729 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14730 }
14731 else
14732 {
037e8744 14733 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14734 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14735 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14736 unsigned int tmp;
14737
14738 /* See note in do_neon_shl_imm. */
14739 tmp = inst.operands[2].reg;
14740 inst.operands[2].reg = inst.operands[1].reg;
14741 inst.operands[1].reg = tmp;
88714cb8 14742 NEON_ENCODE (INTEGER, inst);
037e8744 14743 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14744 }
14745}
14746
627907b7
JB
14747static void
14748do_neon_rshl (void)
14749{
14750 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14751 struct neon_type_el et = neon_check_type (3, rs,
14752 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14753 unsigned int tmp;
14754
14755 tmp = inst.operands[2].reg;
14756 inst.operands[2].reg = inst.operands[1].reg;
14757 inst.operands[1].reg = tmp;
14758 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14759}
14760
5287ad62
JB
14761static int
14762neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14763{
036dc3f7
PB
14764 /* Handle .I8 pseudo-instructions. */
14765 if (size == 8)
5287ad62 14766 {
5287ad62 14767 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14768 FIXME is this the intended semantics? There doesn't seem much point in
14769 accepting .I8 if so. */
5287ad62
JB
14770 immediate |= immediate << 8;
14771 size = 16;
036dc3f7
PB
14772 }
14773
14774 if (size >= 32)
14775 {
14776 if (immediate == (immediate & 0x000000ff))
14777 {
14778 *immbits = immediate;
14779 return 0x1;
14780 }
14781 else if (immediate == (immediate & 0x0000ff00))
14782 {
14783 *immbits = immediate >> 8;
14784 return 0x3;
14785 }
14786 else if (immediate == (immediate & 0x00ff0000))
14787 {
14788 *immbits = immediate >> 16;
14789 return 0x5;
14790 }
14791 else if (immediate == (immediate & 0xff000000))
14792 {
14793 *immbits = immediate >> 24;
14794 return 0x7;
14795 }
14796 if ((immediate & 0xffff) != (immediate >> 16))
14797 goto bad_immediate;
14798 immediate &= 0xffff;
5287ad62
JB
14799 }
14800
14801 if (immediate == (immediate & 0x000000ff))
14802 {
14803 *immbits = immediate;
036dc3f7 14804 return 0x9;
5287ad62
JB
14805 }
14806 else if (immediate == (immediate & 0x0000ff00))
14807 {
14808 *immbits = immediate >> 8;
036dc3f7 14809 return 0xb;
5287ad62
JB
14810 }
14811
14812 bad_immediate:
dcbf9037 14813 first_error (_("immediate value out of range"));
5287ad62
JB
14814 return FAIL;
14815}
14816
5287ad62
JB
14817static void
14818do_neon_logic (void)
14819{
14820 if (inst.operands[2].present && inst.operands[2].isreg)
14821 {
037e8744 14822 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14823 neon_check_type (3, rs, N_IGNORE_TYPE);
14824 /* U bit and size field were set as part of the bitmask. */
88714cb8 14825 NEON_ENCODE (INTEGER, inst);
037e8744 14826 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14827 }
14828 else
14829 {
4316f0d2
DG
14830 const int three_ops_form = (inst.operands[2].present
14831 && !inst.operands[2].isreg);
14832 const int immoperand = (three_ops_form ? 2 : 1);
14833 enum neon_shape rs = (three_ops_form
14834 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14835 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14836 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14837 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14838 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14839 unsigned immbits;
14840 int cmode;
5f4273c7 14841
5287ad62 14842 if (et.type == NT_invtype)
477330fc 14843 return;
5f4273c7 14844
4316f0d2
DG
14845 if (three_ops_form)
14846 constraint (inst.operands[0].reg != inst.operands[1].reg,
14847 _("first and second operands shall be the same register"));
14848
88714cb8 14849 NEON_ENCODE (IMMED, inst);
5287ad62 14850
4316f0d2 14851 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14852 if (et.size == 64)
14853 {
14854 /* .i64 is a pseudo-op, so the immediate must be a repeating
14855 pattern. */
4316f0d2
DG
14856 if (immbits != (inst.operands[immoperand].regisimm ?
14857 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14858 {
14859 /* Set immbits to an invalid constant. */
14860 immbits = 0xdeadbeef;
14861 }
14862 }
14863
5287ad62 14864 switch (opcode)
477330fc
RM
14865 {
14866 case N_MNEM_vbic:
14867 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14868 break;
14869
14870 case N_MNEM_vorr:
14871 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14872 break;
14873
14874 case N_MNEM_vand:
14875 /* Pseudo-instruction for VBIC. */
14876 neon_invert_size (&immbits, 0, et.size);
14877 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14878 break;
14879
14880 case N_MNEM_vorn:
14881 /* Pseudo-instruction for VORR. */
14882 neon_invert_size (&immbits, 0, et.size);
14883 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14884 break;
14885
14886 default:
14887 abort ();
14888 }
5287ad62
JB
14889
14890 if (cmode == FAIL)
477330fc 14891 return;
5287ad62 14892
037e8744 14893 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14894 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14895 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14896 inst.instruction |= cmode << 8;
14897 neon_write_immbits (immbits);
5f4273c7 14898
88714cb8 14899 neon_dp_fixup (&inst);
5287ad62
JB
14900 }
14901}
14902
14903static void
14904do_neon_bitfield (void)
14905{
037e8744 14906 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14907 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14908 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14909}
14910
14911static void
dcbf9037 14912neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14913 unsigned destbits)
5287ad62 14914{
037e8744 14915 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14916 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14917 types | N_KEY);
5287ad62
JB
14918 if (et.type == NT_float)
14919 {
88714cb8 14920 NEON_ENCODE (FLOAT, inst);
cc933301 14921 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14922 }
14923 else
14924 {
88714cb8 14925 NEON_ENCODE (INTEGER, inst);
037e8744 14926 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14927 }
14928}
14929
14930static void
14931do_neon_dyadic_if_su (void)
14932{
dcbf9037 14933 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14934}
14935
14936static void
14937do_neon_dyadic_if_su_d (void)
14938{
14939 /* This version only allow D registers, but that constraint is enforced during
14940 operand parsing so we don't need to do anything extra here. */
dcbf9037 14941 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14942}
14943
5287ad62
JB
14944static void
14945do_neon_dyadic_if_i_d (void)
14946{
428e3f1f
PB
14947 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14948 affected if we specify unsigned args. */
14949 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14950}
14951
037e8744
JB
14952enum vfp_or_neon_is_neon_bits
14953{
14954 NEON_CHECK_CC = 1,
73924fbc
MGD
14955 NEON_CHECK_ARCH = 2,
14956 NEON_CHECK_ARCH8 = 4
037e8744
JB
14957};
14958
14959/* Call this function if an instruction which may have belonged to the VFP or
14960 Neon instruction sets, but turned out to be a Neon instruction (due to the
14961 operand types involved, etc.). We have to check and/or fix-up a couple of
14962 things:
14963
14964 - Make sure the user hasn't attempted to make a Neon instruction
14965 conditional.
14966 - Alter the value in the condition code field if necessary.
14967 - Make sure that the arch supports Neon instructions.
14968
14969 Which of these operations take place depends on bits from enum
14970 vfp_or_neon_is_neon_bits.
14971
14972 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14973 current instruction's condition is COND_ALWAYS, the condition field is
14974 changed to inst.uncond_value. This is necessary because instructions shared
14975 between VFP and Neon may be conditional for the VFP variants only, and the
14976 unconditional Neon version must have, e.g., 0xF in the condition field. */
14977
14978static int
14979vfp_or_neon_is_neon (unsigned check)
14980{
14981 /* Conditions are always legal in Thumb mode (IT blocks). */
14982 if (!thumb_mode && (check & NEON_CHECK_CC))
14983 {
14984 if (inst.cond != COND_ALWAYS)
477330fc
RM
14985 {
14986 first_error (_(BAD_COND));
14987 return FAIL;
14988 }
037e8744 14989 if (inst.uncond_value != -1)
477330fc 14990 inst.instruction |= inst.uncond_value << 28;
037e8744 14991 }
5f4273c7 14992
037e8744 14993 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14994 && !mark_feature_used (&fpu_neon_ext_v1))
14995 {
14996 first_error (_(BAD_FPU));
14997 return FAIL;
14998 }
14999
15000 if ((check & NEON_CHECK_ARCH8)
15001 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
15002 {
15003 first_error (_(BAD_FPU));
15004 return FAIL;
15005 }
5f4273c7 15006
037e8744
JB
15007 return SUCCESS;
15008}
15009
5287ad62
JB
15010static void
15011do_neon_addsub_if_i (void)
15012{
037e8744
JB
15013 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
15014 return;
15015
15016 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15017 return;
15018
5287ad62
JB
15019 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15020 affected if we specify unsigned args. */
dcbf9037 15021 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
15022}
15023
15024/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
15025 result to be:
15026 V<op> A,B (A is operand 0, B is operand 2)
15027 to mean:
15028 V<op> A,B,A
15029 not:
15030 V<op> A,B,B
15031 so handle that case specially. */
15032
15033static void
15034neon_exchange_operands (void)
15035{
5287ad62
JB
15036 if (inst.operands[1].present)
15037 {
e1fa0163
NC
15038 void *scratch = xmalloc (sizeof (inst.operands[0]));
15039
5287ad62
JB
15040 /* Swap operands[1] and operands[2]. */
15041 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
15042 inst.operands[1] = inst.operands[2];
15043 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 15044 free (scratch);
5287ad62
JB
15045 }
15046 else
15047 {
15048 inst.operands[1] = inst.operands[2];
15049 inst.operands[2] = inst.operands[0];
15050 }
15051}
15052
15053static void
15054neon_compare (unsigned regtypes, unsigned immtypes, int invert)
15055{
15056 if (inst.operands[2].isreg)
15057 {
15058 if (invert)
477330fc 15059 neon_exchange_operands ();
dcbf9037 15060 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
15061 }
15062 else
15063 {
037e8744 15064 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 15065 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15066 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 15067
88714cb8 15068 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15069 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15070 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15071 inst.instruction |= LOW4 (inst.operands[1].reg);
15072 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15073 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15074 inst.instruction |= (et.type == NT_float) << 10;
15075 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15076
88714cb8 15077 neon_dp_fixup (&inst);
5287ad62
JB
15078 }
15079}
15080
15081static void
15082do_neon_cmp (void)
15083{
cc933301 15084 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
15085}
15086
15087static void
15088do_neon_cmp_inv (void)
15089{
cc933301 15090 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
15091}
15092
15093static void
15094do_neon_ceq (void)
15095{
15096 neon_compare (N_IF_32, N_IF_32, FALSE);
15097}
15098
15099/* For multiply instructions, we have the possibility of 16-bit or 32-bit
15100 scalars, which are encoded in 5 bits, M : Rm.
15101 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15102 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
15103 index in M.
15104
15105 Dot Product instructions are similar to multiply instructions except elsize
15106 should always be 32.
15107
15108 This function translates SCALAR, which is GAS's internal encoding of indexed
15109 scalar register, to raw encoding. There is also register and index range
15110 check based on ELSIZE. */
5287ad62
JB
15111
15112static unsigned
15113neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15114{
dcbf9037
JB
15115 unsigned regno = NEON_SCALAR_REG (scalar);
15116 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
15117
15118 switch (elsize)
15119 {
15120 case 16:
15121 if (regno > 7 || elno > 3)
477330fc 15122 goto bad_scalar;
5287ad62 15123 return regno | (elno << 3);
5f4273c7 15124
5287ad62
JB
15125 case 32:
15126 if (regno > 15 || elno > 1)
477330fc 15127 goto bad_scalar;
5287ad62
JB
15128 return regno | (elno << 4);
15129
15130 default:
15131 bad_scalar:
dcbf9037 15132 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15133 }
15134
15135 return 0;
15136}
15137
15138/* Encode multiply / multiply-accumulate scalar instructions. */
15139
15140static void
15141neon_mul_mac (struct neon_type_el et, int ubit)
15142{
dcbf9037
JB
15143 unsigned scalar;
15144
15145 /* Give a more helpful error message if we have an invalid type. */
15146 if (et.type == NT_invtype)
15147 return;
5f4273c7 15148
dcbf9037 15149 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15150 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15151 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15152 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15153 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15154 inst.instruction |= LOW4 (scalar);
15155 inst.instruction |= HI1 (scalar) << 5;
15156 inst.instruction |= (et.type == NT_float) << 8;
15157 inst.instruction |= neon_logbits (et.size) << 20;
15158 inst.instruction |= (ubit != 0) << 24;
15159
88714cb8 15160 neon_dp_fixup (&inst);
5287ad62
JB
15161}
15162
15163static void
15164do_neon_mac_maybe_scalar (void)
15165{
037e8744
JB
15166 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15167 return;
15168
15169 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15170 return;
15171
5287ad62
JB
15172 if (inst.operands[2].isscalar)
15173 {
037e8744 15174 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15175 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15176 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15177 NEON_ENCODE (SCALAR, inst);
037e8744 15178 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15179 }
15180 else
428e3f1f
PB
15181 {
15182 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15183 affected if we specify unsigned args. */
15184 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15185 }
5287ad62
JB
15186}
15187
62f3b8c8
PB
15188static void
15189do_neon_fmac (void)
15190{
15191 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15192 return;
15193
15194 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15195 return;
15196
15197 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15198}
15199
5287ad62
JB
15200static void
15201do_neon_tst (void)
15202{
037e8744 15203 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15204 struct neon_type_el et = neon_check_type (3, rs,
15205 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15206 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15207}
15208
15209/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15210 same types as the MAC equivalents. The polynomial type for this instruction
15211 is encoded the same as the integer type. */
15212
15213static void
15214do_neon_mul (void)
15215{
037e8744
JB
15216 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15217 return;
15218
15219 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15220 return;
15221
5287ad62
JB
15222 if (inst.operands[2].isscalar)
15223 do_neon_mac_maybe_scalar ();
15224 else
cc933301 15225 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15226}
15227
15228static void
15229do_neon_qdmulh (void)
15230{
15231 if (inst.operands[2].isscalar)
15232 {
037e8744 15233 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15234 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15235 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15236 NEON_ENCODE (SCALAR, inst);
037e8744 15237 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15238 }
15239 else
15240 {
037e8744 15241 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15242 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15243 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15244 NEON_ENCODE (INTEGER, inst);
5287ad62 15245 /* The U bit (rounding) comes from bit mask. */
037e8744 15246 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15247 }
15248}
15249
643afb90
MW
15250static void
15251do_neon_qrdmlah (void)
15252{
15253 /* Check we're on the correct architecture. */
15254 if (!mark_feature_used (&fpu_neon_ext_armv8))
15255 inst.error =
15256 _("instruction form not available on this architecture.");
15257 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15258 {
15259 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15260 record_feature_use (&fpu_neon_ext_v8_1);
15261 }
15262
15263 if (inst.operands[2].isscalar)
15264 {
15265 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15266 struct neon_type_el et = neon_check_type (3, rs,
15267 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15268 NEON_ENCODE (SCALAR, inst);
15269 neon_mul_mac (et, neon_quad (rs));
15270 }
15271 else
15272 {
15273 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15274 struct neon_type_el et = neon_check_type (3, rs,
15275 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15276 NEON_ENCODE (INTEGER, inst);
15277 /* The U bit (rounding) comes from bit mask. */
15278 neon_three_same (neon_quad (rs), 0, et.size);
15279 }
15280}
15281
5287ad62
JB
15282static void
15283do_neon_fcmp_absolute (void)
15284{
037e8744 15285 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15286 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15287 N_F_16_32 | N_KEY);
5287ad62 15288 /* Size field comes from bit mask. */
cc933301 15289 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15290}
15291
15292static void
15293do_neon_fcmp_absolute_inv (void)
15294{
15295 neon_exchange_operands ();
15296 do_neon_fcmp_absolute ();
15297}
15298
15299static void
15300do_neon_step (void)
15301{
037e8744 15302 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15303 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15304 N_F_16_32 | N_KEY);
15305 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15306}
15307
15308static void
15309do_neon_abs_neg (void)
15310{
037e8744
JB
15311 enum neon_shape rs;
15312 struct neon_type_el et;
5f4273c7 15313
037e8744
JB
15314 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15315 return;
15316
15317 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15318 return;
15319
15320 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15321 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15322
5287ad62
JB
15323 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15324 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15325 inst.instruction |= LOW4 (inst.operands[1].reg);
15326 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15327 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15328 inst.instruction |= (et.type == NT_float) << 10;
15329 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15330
88714cb8 15331 neon_dp_fixup (&inst);
5287ad62
JB
15332}
15333
15334static void
15335do_neon_sli (void)
15336{
037e8744 15337 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15338 struct neon_type_el et = neon_check_type (2, rs,
15339 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15340 int imm = inst.operands[2].imm;
15341 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15342 _("immediate out of range for insert"));
037e8744 15343 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15344}
15345
15346static void
15347do_neon_sri (void)
15348{
037e8744 15349 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15350 struct neon_type_el et = neon_check_type (2, rs,
15351 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15352 int imm = inst.operands[2].imm;
15353 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15354 _("immediate out of range for insert"));
037e8744 15355 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15356}
15357
15358static void
15359do_neon_qshlu_imm (void)
15360{
037e8744 15361 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15362 struct neon_type_el et = neon_check_type (2, rs,
15363 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15364 int imm = inst.operands[2].imm;
15365 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15366 _("immediate out of range for shift"));
5287ad62
JB
15367 /* Only encodes the 'U present' variant of the instruction.
15368 In this case, signed types have OP (bit 8) set to 0.
15369 Unsigned types have OP set to 1. */
15370 inst.instruction |= (et.type == NT_unsigned) << 8;
15371 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15372 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15373}
15374
15375static void
15376do_neon_qmovn (void)
15377{
15378 struct neon_type_el et = neon_check_type (2, NS_DQ,
15379 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15380 /* Saturating move where operands can be signed or unsigned, and the
15381 destination has the same signedness. */
88714cb8 15382 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15383 if (et.type == NT_unsigned)
15384 inst.instruction |= 0xc0;
15385 else
15386 inst.instruction |= 0x80;
15387 neon_two_same (0, 1, et.size / 2);
15388}
15389
15390static void
15391do_neon_qmovun (void)
15392{
15393 struct neon_type_el et = neon_check_type (2, NS_DQ,
15394 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15395 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15396 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15397 neon_two_same (0, 1, et.size / 2);
15398}
15399
15400static void
15401do_neon_rshift_sat_narrow (void)
15402{
15403 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15404 or unsigned. If operands are unsigned, results must also be unsigned. */
15405 struct neon_type_el et = neon_check_type (2, NS_DQI,
15406 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15407 int imm = inst.operands[2].imm;
15408 /* This gets the bounds check, size encoding and immediate bits calculation
15409 right. */
15410 et.size /= 2;
5f4273c7 15411
5287ad62
JB
15412 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15413 VQMOVN.I<size> <Dd>, <Qm>. */
15414 if (imm == 0)
15415 {
15416 inst.operands[2].present = 0;
15417 inst.instruction = N_MNEM_vqmovn;
15418 do_neon_qmovn ();
15419 return;
15420 }
5f4273c7 15421
5287ad62 15422 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15423 _("immediate out of range"));
5287ad62
JB
15424 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15425}
15426
15427static void
15428do_neon_rshift_sat_narrow_u (void)
15429{
15430 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15431 or unsigned. If operands are unsigned, results must also be unsigned. */
15432 struct neon_type_el et = neon_check_type (2, NS_DQI,
15433 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15434 int imm = inst.operands[2].imm;
15435 /* This gets the bounds check, size encoding and immediate bits calculation
15436 right. */
15437 et.size /= 2;
15438
15439 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15440 VQMOVUN.I<size> <Dd>, <Qm>. */
15441 if (imm == 0)
15442 {
15443 inst.operands[2].present = 0;
15444 inst.instruction = N_MNEM_vqmovun;
15445 do_neon_qmovun ();
15446 return;
15447 }
15448
15449 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15450 _("immediate out of range"));
5287ad62
JB
15451 /* FIXME: The manual is kind of unclear about what value U should have in
15452 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15453 must be 1. */
15454 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15455}
15456
15457static void
15458do_neon_movn (void)
15459{
15460 struct neon_type_el et = neon_check_type (2, NS_DQ,
15461 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15462 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15463 neon_two_same (0, 1, et.size / 2);
15464}
15465
15466static void
15467do_neon_rshift_narrow (void)
15468{
15469 struct neon_type_el et = neon_check_type (2, NS_DQI,
15470 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15471 int imm = inst.operands[2].imm;
15472 /* This gets the bounds check, size encoding and immediate bits calculation
15473 right. */
15474 et.size /= 2;
5f4273c7 15475
5287ad62
JB
15476 /* If immediate is zero then we are a pseudo-instruction for
15477 VMOVN.I<size> <Dd>, <Qm> */
15478 if (imm == 0)
15479 {
15480 inst.operands[2].present = 0;
15481 inst.instruction = N_MNEM_vmovn;
15482 do_neon_movn ();
15483 return;
15484 }
5f4273c7 15485
5287ad62 15486 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15487 _("immediate out of range for narrowing operation"));
5287ad62
JB
15488 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15489}
15490
15491static void
15492do_neon_shll (void)
15493{
15494 /* FIXME: Type checking when lengthening. */
15495 struct neon_type_el et = neon_check_type (2, NS_QDI,
15496 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15497 unsigned imm = inst.operands[2].imm;
15498
15499 if (imm == et.size)
15500 {
15501 /* Maximum shift variant. */
88714cb8 15502 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15503 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15504 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15505 inst.instruction |= LOW4 (inst.operands[1].reg);
15506 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15507 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15508
88714cb8 15509 neon_dp_fixup (&inst);
5287ad62
JB
15510 }
15511 else
15512 {
15513 /* A more-specific type check for non-max versions. */
15514 et = neon_check_type (2, NS_QDI,
477330fc 15515 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15516 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15517 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15518 }
15519}
15520
037e8744 15521/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15522 the current instruction is. */
15523
6b9a8b67
MGD
15524#define CVT_FLAVOUR_VAR \
15525 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15526 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15527 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15528 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15529 /* Half-precision conversions. */ \
cc933301
JW
15530 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15531 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15532 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15533 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15534 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15535 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15536 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15537 Compared with single/double precision variants, only the co-processor \
15538 field is different, so the encoding flow is reused here. */ \
15539 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15540 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15541 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15542 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15543 /* VFP instructions. */ \
15544 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15545 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15546 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15547 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15548 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15549 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15550 /* VFP instructions with bitshift. */ \
15551 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15552 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15553 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15554 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15555 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15556 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15557 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15558 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15559
15560#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15561 neon_cvt_flavour_##C,
15562
15563/* The different types of conversions we can do. */
15564enum neon_cvt_flavour
15565{
15566 CVT_FLAVOUR_VAR
15567 neon_cvt_flavour_invalid,
15568 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15569};
15570
15571#undef CVT_VAR
15572
15573static enum neon_cvt_flavour
15574get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15575{
6b9a8b67
MGD
15576#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15577 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15578 if (et.type != NT_invtype) \
15579 { \
15580 inst.error = NULL; \
15581 return (neon_cvt_flavour_##C); \
5287ad62 15582 }
6b9a8b67 15583
5287ad62 15584 struct neon_type_el et;
037e8744 15585 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15586 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15587 /* The instruction versions which take an immediate take one register
15588 argument, which is extended to the width of the full register. Thus the
15589 "source" and "destination" registers must have the same width. Hack that
15590 here by making the size equal to the key (wider, in this case) operand. */
15591 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15592
6b9a8b67
MGD
15593 CVT_FLAVOUR_VAR;
15594
15595 return neon_cvt_flavour_invalid;
5287ad62
JB
15596#undef CVT_VAR
15597}
15598
7e8e6784
MGD
15599enum neon_cvt_mode
15600{
15601 neon_cvt_mode_a,
15602 neon_cvt_mode_n,
15603 neon_cvt_mode_p,
15604 neon_cvt_mode_m,
15605 neon_cvt_mode_z,
30bdf752
MGD
15606 neon_cvt_mode_x,
15607 neon_cvt_mode_r
7e8e6784
MGD
15608};
15609
037e8744
JB
15610/* Neon-syntax VFP conversions. */
15611
5287ad62 15612static void
6b9a8b67 15613do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15614{
037e8744 15615 const char *opname = 0;
5f4273c7 15616
d54af2d0
RL
15617 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15618 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15619 {
037e8744
JB
15620 /* Conversions with immediate bitshift. */
15621 const char *enc[] =
477330fc 15622 {
6b9a8b67
MGD
15623#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15624 CVT_FLAVOUR_VAR
15625 NULL
15626#undef CVT_VAR
477330fc 15627 };
037e8744 15628
6b9a8b67 15629 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15630 {
15631 opname = enc[flavour];
15632 constraint (inst.operands[0].reg != inst.operands[1].reg,
15633 _("operands 0 and 1 must be the same register"));
15634 inst.operands[1] = inst.operands[2];
15635 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15636 }
5287ad62
JB
15637 }
15638 else
15639 {
037e8744
JB
15640 /* Conversions without bitshift. */
15641 const char *enc[] =
477330fc 15642 {
6b9a8b67
MGD
15643#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15644 CVT_FLAVOUR_VAR
15645 NULL
15646#undef CVT_VAR
477330fc 15647 };
037e8744 15648
6b9a8b67 15649 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15650 opname = enc[flavour];
037e8744
JB
15651 }
15652
15653 if (opname)
15654 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15655
15656 /* ARMv8.2 fp16 VCVT instruction. */
15657 if (flavour == neon_cvt_flavour_s32_f16
15658 || flavour == neon_cvt_flavour_u32_f16
15659 || flavour == neon_cvt_flavour_f16_u32
15660 || flavour == neon_cvt_flavour_f16_s32)
15661 do_scalar_fp16_v82_encode ();
037e8744
JB
15662}
15663
15664static void
15665do_vfp_nsyn_cvtz (void)
15666{
d54af2d0 15667 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15668 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15669 const char *enc[] =
15670 {
6b9a8b67
MGD
15671#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15672 CVT_FLAVOUR_VAR
15673 NULL
15674#undef CVT_VAR
037e8744
JB
15675 };
15676
6b9a8b67 15677 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15678 do_vfp_nsyn_opcode (enc[flavour]);
15679}
f31fef98 15680
037e8744 15681static void
bacebabc 15682do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15683 enum neon_cvt_mode mode)
15684{
15685 int sz, op;
15686 int rm;
15687
a715796b
TG
15688 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15689 D register operands. */
15690 if (flavour == neon_cvt_flavour_s32_f64
15691 || flavour == neon_cvt_flavour_u32_f64)
15692 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15693 _(BAD_FPU));
15694
9db2f6b4
RL
15695 if (flavour == neon_cvt_flavour_s32_f16
15696 || flavour == neon_cvt_flavour_u32_f16)
15697 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15698 _(BAD_FP16));
15699
7e8e6784
MGD
15700 set_it_insn_type (OUTSIDE_IT_INSN);
15701
15702 switch (flavour)
15703 {
15704 case neon_cvt_flavour_s32_f64:
15705 sz = 1;
827f64ff 15706 op = 1;
7e8e6784
MGD
15707 break;
15708 case neon_cvt_flavour_s32_f32:
15709 sz = 0;
15710 op = 1;
15711 break;
9db2f6b4
RL
15712 case neon_cvt_flavour_s32_f16:
15713 sz = 0;
15714 op = 1;
15715 break;
7e8e6784
MGD
15716 case neon_cvt_flavour_u32_f64:
15717 sz = 1;
15718 op = 0;
15719 break;
15720 case neon_cvt_flavour_u32_f32:
15721 sz = 0;
15722 op = 0;
15723 break;
9db2f6b4
RL
15724 case neon_cvt_flavour_u32_f16:
15725 sz = 0;
15726 op = 0;
15727 break;
7e8e6784
MGD
15728 default:
15729 first_error (_("invalid instruction shape"));
15730 return;
15731 }
15732
15733 switch (mode)
15734 {
15735 case neon_cvt_mode_a: rm = 0; break;
15736 case neon_cvt_mode_n: rm = 1; break;
15737 case neon_cvt_mode_p: rm = 2; break;
15738 case neon_cvt_mode_m: rm = 3; break;
15739 default: first_error (_("invalid rounding mode")); return;
15740 }
15741
15742 NEON_ENCODE (FPV8, inst);
15743 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15744 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15745 inst.instruction |= sz << 8;
9db2f6b4
RL
15746
15747 /* ARMv8.2 fp16 VCVT instruction. */
15748 if (flavour == neon_cvt_flavour_s32_f16
15749 ||flavour == neon_cvt_flavour_u32_f16)
15750 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15751 inst.instruction |= op << 7;
15752 inst.instruction |= rm << 16;
15753 inst.instruction |= 0xf0000000;
15754 inst.is_neon = TRUE;
15755}
15756
15757static void
15758do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15759{
15760 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15761 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15762 NS_FH, NS_HF, NS_FHI, NS_HFI,
15763 NS_NULL);
6b9a8b67 15764 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15765
cc933301
JW
15766 if (flavour == neon_cvt_flavour_invalid)
15767 return;
15768
e3e535bc 15769 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15770 if (mode == neon_cvt_mode_z
e3e535bc 15771 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15772 && (flavour == neon_cvt_flavour_s16_f16
15773 || flavour == neon_cvt_flavour_u16_f16
15774 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15775 || flavour == neon_cvt_flavour_u32_f32
15776 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15777 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15778 && (rs == NS_FD || rs == NS_FF))
15779 {
15780 do_vfp_nsyn_cvtz ();
15781 return;
15782 }
15783
9db2f6b4
RL
15784 /* ARMv8.2 fp16 VCVT conversions. */
15785 if (mode == neon_cvt_mode_z
15786 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15787 && (flavour == neon_cvt_flavour_s32_f16
15788 || flavour == neon_cvt_flavour_u32_f16)
15789 && (rs == NS_FH))
15790 {
15791 do_vfp_nsyn_cvtz ();
15792 do_scalar_fp16_v82_encode ();
15793 return;
15794 }
15795
037e8744 15796 /* VFP rather than Neon conversions. */
6b9a8b67 15797 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15798 {
7e8e6784
MGD
15799 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15800 do_vfp_nsyn_cvt (rs, flavour);
15801 else
15802 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15803
037e8744
JB
15804 return;
15805 }
15806
15807 switch (rs)
15808 {
15809 case NS_DDI:
15810 case NS_QQI:
15811 {
477330fc 15812 unsigned immbits;
cc933301
JW
15813 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15814 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15815
477330fc
RM
15816 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15817 return;
037e8744 15818
477330fc
RM
15819 /* Fixed-point conversion with #0 immediate is encoded as an
15820 integer conversion. */
15821 if (inst.operands[2].present && inst.operands[2].imm == 0)
15822 goto int_encode;
477330fc
RM
15823 NEON_ENCODE (IMMED, inst);
15824 if (flavour != neon_cvt_flavour_invalid)
15825 inst.instruction |= enctab[flavour];
15826 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15827 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15828 inst.instruction |= LOW4 (inst.operands[1].reg);
15829 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15830 inst.instruction |= neon_quad (rs) << 6;
15831 inst.instruction |= 1 << 21;
cc933301
JW
15832 if (flavour < neon_cvt_flavour_s16_f16)
15833 {
15834 inst.instruction |= 1 << 21;
15835 immbits = 32 - inst.operands[2].imm;
15836 inst.instruction |= immbits << 16;
15837 }
15838 else
15839 {
15840 inst.instruction |= 3 << 20;
15841 immbits = 16 - inst.operands[2].imm;
15842 inst.instruction |= immbits << 16;
15843 inst.instruction &= ~(1 << 9);
15844 }
477330fc
RM
15845
15846 neon_dp_fixup (&inst);
037e8744
JB
15847 }
15848 break;
15849
15850 case NS_DD:
15851 case NS_QQ:
7e8e6784
MGD
15852 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15853 {
15854 NEON_ENCODE (FLOAT, inst);
15855 set_it_insn_type (OUTSIDE_IT_INSN);
15856
15857 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15858 return;
15859
15860 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15861 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15862 inst.instruction |= LOW4 (inst.operands[1].reg);
15863 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15864 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15865 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15866 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15867 inst.instruction |= mode << 8;
cc933301
JW
15868 if (flavour == neon_cvt_flavour_u16_f16
15869 || flavour == neon_cvt_flavour_s16_f16)
15870 /* Mask off the original size bits and reencode them. */
15871 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15872
7e8e6784
MGD
15873 if (thumb_mode)
15874 inst.instruction |= 0xfc000000;
15875 else
15876 inst.instruction |= 0xf0000000;
15877 }
15878 else
15879 {
037e8744 15880 int_encode:
7e8e6784 15881 {
cc933301
JW
15882 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15883 0x100, 0x180, 0x0, 0x080};
037e8744 15884
7e8e6784 15885 NEON_ENCODE (INTEGER, inst);
037e8744 15886
7e8e6784
MGD
15887 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15888 return;
037e8744 15889
7e8e6784
MGD
15890 if (flavour != neon_cvt_flavour_invalid)
15891 inst.instruction |= enctab[flavour];
037e8744 15892
7e8e6784
MGD
15893 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15894 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15895 inst.instruction |= LOW4 (inst.operands[1].reg);
15896 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15897 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15898 if (flavour >= neon_cvt_flavour_s16_f16
15899 && flavour <= neon_cvt_flavour_f16_u16)
15900 /* Half precision. */
15901 inst.instruction |= 1 << 18;
15902 else
15903 inst.instruction |= 2 << 18;
037e8744 15904
7e8e6784
MGD
15905 neon_dp_fixup (&inst);
15906 }
15907 }
15908 break;
037e8744 15909
8e79c3df
CM
15910 /* Half-precision conversions for Advanced SIMD -- neon. */
15911 case NS_QD:
15912 case NS_DQ:
15913
15914 if ((rs == NS_DQ)
15915 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15916 {
15917 as_bad (_("operand size must match register width"));
15918 break;
15919 }
15920
15921 if ((rs == NS_QD)
15922 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15923 {
15924 as_bad (_("operand size must match register width"));
15925 break;
15926 }
15927
15928 if (rs == NS_DQ)
477330fc 15929 inst.instruction = 0x3b60600;
8e79c3df
CM
15930 else
15931 inst.instruction = 0x3b60700;
15932
15933 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15934 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15935 inst.instruction |= LOW4 (inst.operands[1].reg);
15936 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15937 neon_dp_fixup (&inst);
8e79c3df
CM
15938 break;
15939
037e8744
JB
15940 default:
15941 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15942 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15943 do_vfp_nsyn_cvt (rs, flavour);
15944 else
15945 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15946 }
5287ad62
JB
15947}
15948
e3e535bc
NC
15949static void
15950do_neon_cvtr (void)
15951{
7e8e6784 15952 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15953}
15954
15955static void
15956do_neon_cvt (void)
15957{
7e8e6784
MGD
15958 do_neon_cvt_1 (neon_cvt_mode_z);
15959}
15960
15961static void
15962do_neon_cvta (void)
15963{
15964 do_neon_cvt_1 (neon_cvt_mode_a);
15965}
15966
15967static void
15968do_neon_cvtn (void)
15969{
15970 do_neon_cvt_1 (neon_cvt_mode_n);
15971}
15972
15973static void
15974do_neon_cvtp (void)
15975{
15976 do_neon_cvt_1 (neon_cvt_mode_p);
15977}
15978
15979static void
15980do_neon_cvtm (void)
15981{
15982 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15983}
15984
8e79c3df 15985static void
c70a8987 15986do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15987{
c70a8987
MGD
15988 if (is_double)
15989 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15990
c70a8987
MGD
15991 encode_arm_vfp_reg (inst.operands[0].reg,
15992 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15993 encode_arm_vfp_reg (inst.operands[1].reg,
15994 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15995 inst.instruction |= to ? 0x10000 : 0;
15996 inst.instruction |= t ? 0x80 : 0;
15997 inst.instruction |= is_double ? 0x100 : 0;
15998 do_vfp_cond_or_thumb ();
15999}
8e79c3df 16000
c70a8987
MGD
16001static void
16002do_neon_cvttb_1 (bfd_boolean t)
16003{
d54af2d0
RL
16004 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
16005 NS_DF, NS_DH, NS_NULL);
8e79c3df 16006
c70a8987
MGD
16007 if (rs == NS_NULL)
16008 return;
16009 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
16010 {
16011 inst.error = NULL;
16012 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
16013 }
16014 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
16015 {
16016 inst.error = NULL;
16017 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
16018 }
16019 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
16020 {
a715796b
TG
16021 /* The VCVTB and VCVTT instructions with D-register operands
16022 don't work for SP only targets. */
16023 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16024 _(BAD_FPU));
16025
c70a8987
MGD
16026 inst.error = NULL;
16027 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
16028 }
16029 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
16030 {
a715796b
TG
16031 /* The VCVTB and VCVTT instructions with D-register operands
16032 don't work for SP only targets. */
16033 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16034 _(BAD_FPU));
16035
c70a8987
MGD
16036 inst.error = NULL;
16037 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
16038 }
16039 else
16040 return;
16041}
16042
16043static void
16044do_neon_cvtb (void)
16045{
16046 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
16047}
16048
16049
16050static void
16051do_neon_cvtt (void)
16052{
c70a8987 16053 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
16054}
16055
5287ad62
JB
16056static void
16057neon_move_immediate (void)
16058{
037e8744
JB
16059 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
16060 struct neon_type_el et = neon_check_type (2, rs,
16061 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 16062 unsigned immlo, immhi = 0, immbits;
c96612cc 16063 int op, cmode, float_p;
5287ad62 16064
037e8744 16065 constraint (et.type == NT_invtype,
477330fc 16066 _("operand size must be specified for immediate VMOV"));
037e8744 16067
5287ad62
JB
16068 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
16069 op = (inst.instruction & (1 << 5)) != 0;
16070
16071 immlo = inst.operands[1].imm;
16072 if (inst.operands[1].regisimm)
16073 immhi = inst.operands[1].reg;
16074
16075 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 16076 _("immediate has bits set outside the operand size"));
5287ad62 16077
c96612cc
JB
16078 float_p = inst.operands[1].immisfloat;
16079
16080 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 16081 et.size, et.type)) == FAIL)
5287ad62
JB
16082 {
16083 /* Invert relevant bits only. */
16084 neon_invert_size (&immlo, &immhi, et.size);
16085 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
16086 with one or the other; those cases are caught by
16087 neon_cmode_for_move_imm. */
5287ad62 16088 op = !op;
c96612cc
JB
16089 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16090 &op, et.size, et.type)) == FAIL)
477330fc
RM
16091 {
16092 first_error (_("immediate out of range"));
16093 return;
16094 }
5287ad62
JB
16095 }
16096
16097 inst.instruction &= ~(1 << 5);
16098 inst.instruction |= op << 5;
16099
16100 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16101 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 16102 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16103 inst.instruction |= cmode << 8;
16104
16105 neon_write_immbits (immbits);
16106}
16107
16108static void
16109do_neon_mvn (void)
16110{
16111 if (inst.operands[1].isreg)
16112 {
037e8744 16113 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16114
88714cb8 16115 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16116 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16117 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16118 inst.instruction |= LOW4 (inst.operands[1].reg);
16119 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16120 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16121 }
16122 else
16123 {
88714cb8 16124 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16125 neon_move_immediate ();
16126 }
16127
88714cb8 16128 neon_dp_fixup (&inst);
5287ad62
JB
16129}
16130
16131/* Encode instructions of form:
16132
16133 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16134 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16135
16136static void
16137neon_mixed_length (struct neon_type_el et, unsigned size)
16138{
16139 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16140 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16141 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16142 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16143 inst.instruction |= LOW4 (inst.operands[2].reg);
16144 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16145 inst.instruction |= (et.type == NT_unsigned) << 24;
16146 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16147
88714cb8 16148 neon_dp_fixup (&inst);
5287ad62
JB
16149}
16150
16151static void
16152do_neon_dyadic_long (void)
16153{
16154 /* FIXME: Type checking for lengthening op. */
16155 struct neon_type_el et = neon_check_type (3, NS_QDD,
16156 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16157 neon_mixed_length (et, et.size);
16158}
16159
16160static void
16161do_neon_abal (void)
16162{
16163 struct neon_type_el et = neon_check_type (3, NS_QDD,
16164 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16165 neon_mixed_length (et, et.size);
16166}
16167
16168static void
16169neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16170{
16171 if (inst.operands[2].isscalar)
16172 {
dcbf9037 16173 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16174 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16175 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16176 neon_mul_mac (et, et.type == NT_unsigned);
16177 }
16178 else
16179 {
16180 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16181 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16182 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16183 neon_mixed_length (et, et.size);
16184 }
16185}
16186
16187static void
16188do_neon_mac_maybe_scalar_long (void)
16189{
16190 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16191}
16192
dec41383
JW
16193/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
16194 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
16195
16196static unsigned
16197neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
16198{
16199 unsigned regno = NEON_SCALAR_REG (scalar);
16200 unsigned elno = NEON_SCALAR_INDEX (scalar);
16201
16202 if (quad_p)
16203 {
16204 if (regno > 7 || elno > 3)
16205 goto bad_scalar;
16206
16207 return ((regno & 0x7)
16208 | ((elno & 0x1) << 3)
16209 | (((elno >> 1) & 0x1) << 5));
16210 }
16211 else
16212 {
16213 if (regno > 15 || elno > 1)
16214 goto bad_scalar;
16215
16216 return (((regno & 0x1) << 5)
16217 | ((regno >> 1) & 0x7)
16218 | ((elno & 0x1) << 3));
16219 }
16220
16221bad_scalar:
16222 first_error (_("scalar out of range for multiply instruction"));
16223 return 0;
16224}
16225
16226static void
16227do_neon_fmac_maybe_scalar_long (int subtype)
16228{
16229 enum neon_shape rs;
16230 int high8;
16231 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
16232 field (bits[21:20]) has different meaning. For scalar index variant, it's
16233 used to differentiate add and subtract, otherwise it's with fixed value
16234 0x2. */
16235 int size = -1;
16236
16237 if (inst.cond != COND_ALWAYS)
16238 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
16239 "behaviour is UNPREDICTABLE"));
16240
01f48020 16241 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
dec41383
JW
16242 _(BAD_FP16));
16243
16244 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
16245 _(BAD_FPU));
16246
16247 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
16248 be a scalar index register. */
16249 if (inst.operands[2].isscalar)
16250 {
16251 high8 = 0xfe000000;
16252 if (subtype)
16253 size = 16;
16254 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
16255 }
16256 else
16257 {
16258 high8 = 0xfc000000;
16259 size = 32;
16260 if (subtype)
16261 inst.instruction |= (0x1 << 23);
16262 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
16263 }
16264
16265 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
16266
16267 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
16268 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
16269 so we simply pass -1 as size. */
16270 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
16271 neon_three_same (quad_p, 0, size);
16272
16273 /* Undo neon_dp_fixup. Redo the high eight bits. */
16274 inst.instruction &= 0x00ffffff;
16275 inst.instruction |= high8;
16276
16277#define LOW1(R) ((R) & 0x1)
16278#define HI4(R) (((R) >> 1) & 0xf)
16279 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
16280 whether the instruction is in Q form and whether Vm is a scalar indexed
16281 operand. */
16282 if (inst.operands[2].isscalar)
16283 {
16284 unsigned rm
16285 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
16286 inst.instruction &= 0xffffffd0;
16287 inst.instruction |= rm;
16288
16289 if (!quad_p)
16290 {
16291 /* Redo Rn as well. */
16292 inst.instruction &= 0xfff0ff7f;
16293 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16294 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16295 }
16296 }
16297 else if (!quad_p)
16298 {
16299 /* Redo Rn and Rm. */
16300 inst.instruction &= 0xfff0ff50;
16301 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16302 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16303 inst.instruction |= HI4 (inst.operands[2].reg);
16304 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
16305 }
16306}
16307
16308static void
16309do_neon_vfmal (void)
16310{
16311 return do_neon_fmac_maybe_scalar_long (0);
16312}
16313
16314static void
16315do_neon_vfmsl (void)
16316{
16317 return do_neon_fmac_maybe_scalar_long (1);
16318}
16319
5287ad62
JB
16320static void
16321do_neon_dyadic_wide (void)
16322{
16323 struct neon_type_el et = neon_check_type (3, NS_QQD,
16324 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16325 neon_mixed_length (et, et.size);
16326}
16327
16328static void
16329do_neon_dyadic_narrow (void)
16330{
16331 struct neon_type_el et = neon_check_type (3, NS_QDD,
16332 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16333 /* Operand sign is unimportant, and the U bit is part of the opcode,
16334 so force the operand type to integer. */
16335 et.type = NT_integer;
5287ad62
JB
16336 neon_mixed_length (et, et.size / 2);
16337}
16338
16339static void
16340do_neon_mul_sat_scalar_long (void)
16341{
16342 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16343}
16344
16345static void
16346do_neon_vmull (void)
16347{
16348 if (inst.operands[2].isscalar)
16349 do_neon_mac_maybe_scalar_long ();
16350 else
16351 {
16352 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16353 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16354
5287ad62 16355 if (et.type == NT_poly)
477330fc 16356 NEON_ENCODE (POLY, inst);
5287ad62 16357 else
477330fc 16358 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16359
16360 /* For polynomial encoding the U bit must be zero, and the size must
16361 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16362 obviously, as 0b10). */
16363 if (et.size == 64)
16364 {
16365 /* Check we're on the correct architecture. */
16366 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16367 inst.error =
16368 _("Instruction form not available on this architecture.");
16369
16370 et.size = 32;
16371 }
16372
5287ad62
JB
16373 neon_mixed_length (et, et.size);
16374 }
16375}
16376
16377static void
16378do_neon_ext (void)
16379{
037e8744 16380 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16381 struct neon_type_el et = neon_check_type (3, rs,
16382 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16383 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16384
16385 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16386 _("shift out of range"));
5287ad62
JB
16387 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16388 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16389 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16390 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16391 inst.instruction |= LOW4 (inst.operands[2].reg);
16392 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16393 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16394 inst.instruction |= imm << 8;
5f4273c7 16395
88714cb8 16396 neon_dp_fixup (&inst);
5287ad62
JB
16397}
16398
16399static void
16400do_neon_rev (void)
16401{
037e8744 16402 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16403 struct neon_type_el et = neon_check_type (2, rs,
16404 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16405 unsigned op = (inst.instruction >> 7) & 3;
16406 /* N (width of reversed regions) is encoded as part of the bitmask. We
16407 extract it here to check the elements to be reversed are smaller.
16408 Otherwise we'd get a reserved instruction. */
16409 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16410 gas_assert (elsize != 0);
5287ad62 16411 constraint (et.size >= elsize,
477330fc 16412 _("elements must be smaller than reversal region"));
037e8744 16413 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16414}
16415
16416static void
16417do_neon_dup (void)
16418{
16419 if (inst.operands[1].isscalar)
16420 {
037e8744 16421 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16422 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16423 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16424 unsigned sizebits = et.size >> 3;
dcbf9037 16425 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16426 int logsize = neon_logbits (et.size);
dcbf9037 16427 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16428
16429 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16430 return;
037e8744 16431
88714cb8 16432 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16433 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16434 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16435 inst.instruction |= LOW4 (dm);
16436 inst.instruction |= HI1 (dm) << 5;
037e8744 16437 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16438 inst.instruction |= x << 17;
16439 inst.instruction |= sizebits << 16;
5f4273c7 16440
88714cb8 16441 neon_dp_fixup (&inst);
5287ad62
JB
16442 }
16443 else
16444 {
037e8744
JB
16445 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16446 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16447 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16448 /* Duplicate ARM register to lanes of vector. */
88714cb8 16449 NEON_ENCODE (ARMREG, inst);
5287ad62 16450 switch (et.size)
477330fc
RM
16451 {
16452 case 8: inst.instruction |= 0x400000; break;
16453 case 16: inst.instruction |= 0x000020; break;
16454 case 32: inst.instruction |= 0x000000; break;
16455 default: break;
16456 }
5287ad62
JB
16457 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16458 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16459 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16460 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16461 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16462 variants, except for the condition field. */
037e8744 16463 do_vfp_cond_or_thumb ();
5287ad62
JB
16464 }
16465}
16466
16467/* VMOV has particularly many variations. It can be one of:
16468 0. VMOV<c><q> <Qd>, <Qm>
16469 1. VMOV<c><q> <Dd>, <Dm>
16470 (Register operations, which are VORR with Rm = Rn.)
16471 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16472 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16473 (Immediate loads.)
16474 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16475 (ARM register to scalar.)
16476 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16477 (Two ARM registers to vector.)
16478 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16479 (Scalar to ARM register.)
16480 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16481 (Vector to two ARM registers.)
037e8744
JB
16482 8. VMOV.F32 <Sd>, <Sm>
16483 9. VMOV.F64 <Dd>, <Dm>
16484 (VFP register moves.)
16485 10. VMOV.F32 <Sd>, #imm
16486 11. VMOV.F64 <Dd>, #imm
16487 (VFP float immediate load.)
16488 12. VMOV <Rd>, <Sm>
16489 (VFP single to ARM reg.)
16490 13. VMOV <Sd>, <Rm>
16491 (ARM reg to VFP single.)
16492 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16493 (Two ARM regs to two VFP singles.)
16494 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16495 (Two VFP singles to two ARM regs.)
5f4273c7 16496
037e8744
JB
16497 These cases can be disambiguated using neon_select_shape, except cases 1/9
16498 and 3/11 which depend on the operand type too.
5f4273c7 16499
5287ad62 16500 All the encoded bits are hardcoded by this function.
5f4273c7 16501
b7fc2769
JB
16502 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16503 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16504
5287ad62 16505 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16506 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16507
16508static void
16509do_neon_mov (void)
16510{
037e8744 16511 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16512 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16513 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16514 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16515 struct neon_type_el et;
16516 const char *ldconst = 0;
5287ad62 16517
037e8744 16518 switch (rs)
5287ad62 16519 {
037e8744
JB
16520 case NS_DD: /* case 1/9. */
16521 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16522 /* It is not an error here if no type is given. */
16523 inst.error = NULL;
16524 if (et.type == NT_float && et.size == 64)
477330fc
RM
16525 {
16526 do_vfp_nsyn_opcode ("fcpyd");
16527 break;
16528 }
037e8744 16529 /* fall through. */
5287ad62 16530
037e8744
JB
16531 case NS_QQ: /* case 0/1. */
16532 {
477330fc
RM
16533 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16534 return;
16535 /* The architecture manual I have doesn't explicitly state which
16536 value the U bit should have for register->register moves, but
16537 the equivalent VORR instruction has U = 0, so do that. */
16538 inst.instruction = 0x0200110;
16539 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16540 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16541 inst.instruction |= LOW4 (inst.operands[1].reg);
16542 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16543 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16544 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16545 inst.instruction |= neon_quad (rs) << 6;
16546
16547 neon_dp_fixup (&inst);
037e8744
JB
16548 }
16549 break;
5f4273c7 16550
037e8744
JB
16551 case NS_DI: /* case 3/11. */
16552 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16553 inst.error = NULL;
16554 if (et.type == NT_float && et.size == 64)
477330fc
RM
16555 {
16556 /* case 11 (fconstd). */
16557 ldconst = "fconstd";
16558 goto encode_fconstd;
16559 }
037e8744
JB
16560 /* fall through. */
16561
16562 case NS_QI: /* case 2/3. */
16563 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16564 return;
037e8744
JB
16565 inst.instruction = 0x0800010;
16566 neon_move_immediate ();
88714cb8 16567 neon_dp_fixup (&inst);
5287ad62 16568 break;
5f4273c7 16569
037e8744
JB
16570 case NS_SR: /* case 4. */
16571 {
477330fc
RM
16572 unsigned bcdebits = 0;
16573 int logsize;
16574 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16575 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16576
05ac0ffb
JB
16577 /* .<size> is optional here, defaulting to .32. */
16578 if (inst.vectype.elems == 0
16579 && inst.operands[0].vectype.type == NT_invtype
16580 && inst.operands[1].vectype.type == NT_invtype)
16581 {
16582 inst.vectype.el[0].type = NT_untyped;
16583 inst.vectype.el[0].size = 32;
16584 inst.vectype.elems = 1;
16585 }
16586
477330fc
RM
16587 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16588 logsize = neon_logbits (et.size);
16589
16590 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16591 _(BAD_FPU));
16592 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16593 && et.size != 32, _(BAD_FPU));
16594 constraint (et.type == NT_invtype, _("bad type for scalar"));
16595 constraint (x >= 64 / et.size, _("scalar index out of range"));
16596
16597 switch (et.size)
16598 {
16599 case 8: bcdebits = 0x8; break;
16600 case 16: bcdebits = 0x1; break;
16601 case 32: bcdebits = 0x0; break;
16602 default: ;
16603 }
16604
16605 bcdebits |= x << logsize;
16606
16607 inst.instruction = 0xe000b10;
16608 do_vfp_cond_or_thumb ();
16609 inst.instruction |= LOW4 (dn) << 16;
16610 inst.instruction |= HI1 (dn) << 7;
16611 inst.instruction |= inst.operands[1].reg << 12;
16612 inst.instruction |= (bcdebits & 3) << 5;
16613 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16614 }
16615 break;
5f4273c7 16616
037e8744 16617 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16618 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16619 _(BAD_FPU));
b7fc2769 16620
037e8744
JB
16621 inst.instruction = 0xc400b10;
16622 do_vfp_cond_or_thumb ();
16623 inst.instruction |= LOW4 (inst.operands[0].reg);
16624 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16625 inst.instruction |= inst.operands[1].reg << 12;
16626 inst.instruction |= inst.operands[2].reg << 16;
16627 break;
5f4273c7 16628
037e8744
JB
16629 case NS_RS: /* case 6. */
16630 {
477330fc
RM
16631 unsigned logsize;
16632 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16633 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16634 unsigned abcdebits = 0;
037e8744 16635
05ac0ffb
JB
16636 /* .<dt> is optional here, defaulting to .32. */
16637 if (inst.vectype.elems == 0
16638 && inst.operands[0].vectype.type == NT_invtype
16639 && inst.operands[1].vectype.type == NT_invtype)
16640 {
16641 inst.vectype.el[0].type = NT_untyped;
16642 inst.vectype.el[0].size = 32;
16643 inst.vectype.elems = 1;
16644 }
16645
91d6fa6a
NC
16646 et = neon_check_type (2, NS_NULL,
16647 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16648 logsize = neon_logbits (et.size);
16649
16650 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16651 _(BAD_FPU));
16652 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16653 && et.size != 32, _(BAD_FPU));
16654 constraint (et.type == NT_invtype, _("bad type for scalar"));
16655 constraint (x >= 64 / et.size, _("scalar index out of range"));
16656
16657 switch (et.size)
16658 {
16659 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16660 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16661 case 32: abcdebits = 0x00; break;
16662 default: ;
16663 }
16664
16665 abcdebits |= x << logsize;
16666 inst.instruction = 0xe100b10;
16667 do_vfp_cond_or_thumb ();
16668 inst.instruction |= LOW4 (dn) << 16;
16669 inst.instruction |= HI1 (dn) << 7;
16670 inst.instruction |= inst.operands[0].reg << 12;
16671 inst.instruction |= (abcdebits & 3) << 5;
16672 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16673 }
16674 break;
5f4273c7 16675
037e8744
JB
16676 case NS_RRD: /* case 7 (fmrrd). */
16677 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16678 _(BAD_FPU));
037e8744
JB
16679
16680 inst.instruction = 0xc500b10;
16681 do_vfp_cond_or_thumb ();
16682 inst.instruction |= inst.operands[0].reg << 12;
16683 inst.instruction |= inst.operands[1].reg << 16;
16684 inst.instruction |= LOW4 (inst.operands[2].reg);
16685 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16686 break;
5f4273c7 16687
037e8744
JB
16688 case NS_FF: /* case 8 (fcpys). */
16689 do_vfp_nsyn_opcode ("fcpys");
16690 break;
5f4273c7 16691
9db2f6b4 16692 case NS_HI:
037e8744
JB
16693 case NS_FI: /* case 10 (fconsts). */
16694 ldconst = "fconsts";
16695 encode_fconstd:
58ed5c38
TC
16696 if (!inst.operands[1].immisfloat)
16697 {
16698 /* Immediate has to fit in 8 bits so float is enough. */
16699 float imm = (float)inst.operands[1].imm;
16700 memcpy (&inst.operands[1].imm, &imm, sizeof (float));
16701 inst.operands[1].immisfloat = 1;
16702 }
16703
037e8744 16704 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16705 {
16706 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16707 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16708
16709 /* ARMv8.2 fp16 vmov.f16 instruction. */
16710 if (rs == NS_HI)
16711 do_scalar_fp16_v82_encode ();
477330fc 16712 }
5287ad62 16713 else
477330fc 16714 first_error (_("immediate out of range"));
037e8744 16715 break;
5f4273c7 16716
9db2f6b4 16717 case NS_RH:
037e8744
JB
16718 case NS_RF: /* case 12 (fmrs). */
16719 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16720 /* ARMv8.2 fp16 vmov.f16 instruction. */
16721 if (rs == NS_RH)
16722 do_scalar_fp16_v82_encode ();
037e8744 16723 break;
5f4273c7 16724
9db2f6b4 16725 case NS_HR:
037e8744
JB
16726 case NS_FR: /* case 13 (fmsr). */
16727 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16728 /* ARMv8.2 fp16 vmov.f16 instruction. */
16729 if (rs == NS_HR)
16730 do_scalar_fp16_v82_encode ();
037e8744 16731 break;
5f4273c7 16732
037e8744
JB
16733 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16734 (one of which is a list), but we have parsed four. Do some fiddling to
16735 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16736 expect. */
16737 case NS_RRFF: /* case 14 (fmrrs). */
16738 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16739 _("VFP registers must be adjacent"));
037e8744
JB
16740 inst.operands[2].imm = 2;
16741 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16742 do_vfp_nsyn_opcode ("fmrrs");
16743 break;
5f4273c7 16744
037e8744
JB
16745 case NS_FFRR: /* case 15 (fmsrr). */
16746 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16747 _("VFP registers must be adjacent"));
037e8744
JB
16748 inst.operands[1] = inst.operands[2];
16749 inst.operands[2] = inst.operands[3];
16750 inst.operands[0].imm = 2;
16751 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16752 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16753 break;
5f4273c7 16754
4c261dff
NC
16755 case NS_NULL:
16756 /* neon_select_shape has determined that the instruction
16757 shape is wrong and has already set the error message. */
16758 break;
16759
5287ad62
JB
16760 default:
16761 abort ();
16762 }
16763}
16764
16765static void
16766do_neon_rshift_round_imm (void)
16767{
037e8744 16768 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16769 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16770 int imm = inst.operands[2].imm;
16771
16772 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16773 if (imm == 0)
16774 {
16775 inst.operands[2].present = 0;
16776 do_neon_mov ();
16777 return;
16778 }
16779
16780 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16781 _("immediate out of range for shift"));
037e8744 16782 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16783 et.size - imm);
5287ad62
JB
16784}
16785
9db2f6b4
RL
16786static void
16787do_neon_movhf (void)
16788{
16789 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16790 constraint (rs != NS_HH, _("invalid suffix"));
16791
16792 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16793 _(BAD_FPU));
16794
7bdf778b
ASDV
16795 if (inst.cond != COND_ALWAYS)
16796 {
16797 if (thumb_mode)
16798 {
16799 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
16800 " the behaviour is UNPREDICTABLE"));
16801 }
16802 else
16803 {
16804 inst.error = BAD_COND;
16805 return;
16806 }
16807 }
16808
9db2f6b4
RL
16809 do_vfp_sp_monadic ();
16810
16811 inst.is_neon = 1;
16812 inst.instruction |= 0xf0000000;
16813}
16814
5287ad62
JB
16815static void
16816do_neon_movl (void)
16817{
16818 struct neon_type_el et = neon_check_type (2, NS_QD,
16819 N_EQK | N_DBL, N_SU_32 | N_KEY);
16820 unsigned sizebits = et.size >> 3;
16821 inst.instruction |= sizebits << 19;
16822 neon_two_same (0, et.type == NT_unsigned, -1);
16823}
16824
16825static void
16826do_neon_trn (void)
16827{
037e8744 16828 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16829 struct neon_type_el et = neon_check_type (2, rs,
16830 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16831 NEON_ENCODE (INTEGER, inst);
037e8744 16832 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16833}
16834
16835static void
16836do_neon_zip_uzp (void)
16837{
037e8744 16838 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16839 struct neon_type_el et = neon_check_type (2, rs,
16840 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16841 if (rs == NS_DD && et.size == 32)
16842 {
16843 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16844 inst.instruction = N_MNEM_vtrn;
16845 do_neon_trn ();
16846 return;
16847 }
037e8744 16848 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16849}
16850
16851static void
16852do_neon_sat_abs_neg (void)
16853{
037e8744 16854 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16855 struct neon_type_el et = neon_check_type (2, rs,
16856 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16857 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16858}
16859
16860static void
16861do_neon_pair_long (void)
16862{
037e8744 16863 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16864 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16865 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16866 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16867 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16868}
16869
16870static void
16871do_neon_recip_est (void)
16872{
037e8744 16873 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16874 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16875 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16876 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16877 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16878}
16879
16880static void
16881do_neon_cls (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,
16885 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16886 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16887}
16888
16889static void
16890do_neon_clz (void)
16891{
037e8744 16892 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16893 struct neon_type_el et = neon_check_type (2, rs,
16894 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16895 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16896}
16897
16898static void
16899do_neon_cnt (void)
16900{
037e8744 16901 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16902 struct neon_type_el et = neon_check_type (2, rs,
16903 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16904 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16905}
16906
16907static void
16908do_neon_swp (void)
16909{
037e8744
JB
16910 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16911 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16912}
16913
16914static void
16915do_neon_tbl_tbx (void)
16916{
16917 unsigned listlenbits;
dcbf9037 16918 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16919
5287ad62
JB
16920 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16921 {
dcbf9037 16922 first_error (_("bad list length for table lookup"));
5287ad62
JB
16923 return;
16924 }
5f4273c7 16925
5287ad62
JB
16926 listlenbits = inst.operands[1].imm - 1;
16927 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16928 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16929 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16930 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16931 inst.instruction |= LOW4 (inst.operands[2].reg);
16932 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16933 inst.instruction |= listlenbits << 8;
5f4273c7 16934
88714cb8 16935 neon_dp_fixup (&inst);
5287ad62
JB
16936}
16937
16938static void
16939do_neon_ldm_stm (void)
16940{
16941 /* P, U and L bits are part of bitmask. */
16942 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16943 unsigned offsetbits = inst.operands[1].imm * 2;
16944
037e8744
JB
16945 if (inst.operands[1].issingle)
16946 {
16947 do_vfp_nsyn_ldm_stm (is_dbmode);
16948 return;
16949 }
16950
5287ad62 16951 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16952 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16953
16954 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16955 _("register list must contain at least 1 and at most 16 "
16956 "registers"));
5287ad62
JB
16957
16958 inst.instruction |= inst.operands[0].reg << 16;
16959 inst.instruction |= inst.operands[0].writeback << 21;
16960 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16961 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16962
16963 inst.instruction |= offsetbits;
5f4273c7 16964
037e8744 16965 do_vfp_cond_or_thumb ();
5287ad62
JB
16966}
16967
16968static void
16969do_neon_ldr_str (void)
16970{
5287ad62 16971 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16972
6844b2c2
MGD
16973 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16974 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16975 if (!is_ldr
6844b2c2 16976 && inst.operands[1].reg == REG_PC
ba86b375 16977 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16978 {
94dcf8bf 16979 if (thumb_mode)
6844b2c2 16980 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16981 else if (warn_on_deprecated)
5c3696f8 16982 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16983 }
16984
037e8744
JB
16985 if (inst.operands[0].issingle)
16986 {
cd2f129f 16987 if (is_ldr)
477330fc 16988 do_vfp_nsyn_opcode ("flds");
cd2f129f 16989 else
477330fc 16990 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16991
16992 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16993 if (inst.vectype.el[0].size == 16)
16994 do_scalar_fp16_v82_encode ();
5287ad62
JB
16995 }
16996 else
5287ad62 16997 {
cd2f129f 16998 if (is_ldr)
477330fc 16999 do_vfp_nsyn_opcode ("fldd");
5287ad62 17000 else
477330fc 17001 do_vfp_nsyn_opcode ("fstd");
5287ad62 17002 }
5287ad62
JB
17003}
17004
17005/* "interleave" version also handles non-interleaving register VLD1/VST1
17006 instructions. */
17007
17008static void
17009do_neon_ld_st_interleave (void)
17010{
037e8744 17011 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 17012 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
17013 unsigned alignbits = 0;
17014 unsigned idx;
17015 /* The bits in this table go:
17016 0: register stride of one (0) or two (1)
17017 1,2: register list length, minus one (1, 2, 3, 4).
17018 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
17019 We use -1 for invalid entries. */
17020 const int typetable[] =
17021 {
17022 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
17023 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
17024 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
17025 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
17026 };
17027 int typebits;
17028
dcbf9037
JB
17029 if (et.type == NT_invtype)
17030 return;
17031
5287ad62
JB
17032 if (inst.operands[1].immisalign)
17033 switch (inst.operands[1].imm >> 8)
17034 {
17035 case 64: alignbits = 1; break;
17036 case 128:
477330fc 17037 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 17038 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
17039 goto bad_alignment;
17040 alignbits = 2;
17041 break;
5287ad62 17042 case 256:
477330fc
RM
17043 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
17044 goto bad_alignment;
17045 alignbits = 3;
17046 break;
5287ad62
JB
17047 default:
17048 bad_alignment:
477330fc
RM
17049 first_error (_("bad alignment"));
17050 return;
5287ad62
JB
17051 }
17052
17053 inst.instruction |= alignbits << 4;
17054 inst.instruction |= neon_logbits (et.size) << 6;
17055
17056 /* Bits [4:6] of the immediate in a list specifier encode register stride
17057 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
17058 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
17059 up the right value for "type" in a table based on this value and the given
17060 list style, then stick it back. */
17061 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 17062 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
17063
17064 typebits = typetable[idx];
5f4273c7 17065
5287ad62 17066 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
17067 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
17068 _("bad element type for instruction"));
5287ad62
JB
17069
17070 inst.instruction &= ~0xf00;
17071 inst.instruction |= typebits << 8;
17072}
17073
17074/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
17075 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
17076 otherwise. The variable arguments are a list of pairs of legal (size, align)
17077 values, terminated with -1. */
17078
17079static int
aa8a0863 17080neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
17081{
17082 va_list ap;
17083 int result = FAIL, thissize, thisalign;
5f4273c7 17084
5287ad62
JB
17085 if (!inst.operands[1].immisalign)
17086 {
aa8a0863 17087 *do_alignment = 0;
5287ad62
JB
17088 return SUCCESS;
17089 }
5f4273c7 17090
aa8a0863 17091 va_start (ap, do_alignment);
5287ad62
JB
17092
17093 do
17094 {
17095 thissize = va_arg (ap, int);
17096 if (thissize == -1)
477330fc 17097 break;
5287ad62
JB
17098 thisalign = va_arg (ap, int);
17099
17100 if (size == thissize && align == thisalign)
477330fc 17101 result = SUCCESS;
5287ad62
JB
17102 }
17103 while (result != SUCCESS);
17104
17105 va_end (ap);
17106
17107 if (result == SUCCESS)
aa8a0863 17108 *do_alignment = 1;
5287ad62 17109 else
dcbf9037 17110 first_error (_("unsupported alignment for instruction"));
5f4273c7 17111
5287ad62
JB
17112 return result;
17113}
17114
17115static void
17116do_neon_ld_st_lane (void)
17117{
037e8744 17118 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17119 int align_good, do_alignment = 0;
5287ad62
JB
17120 int logsize = neon_logbits (et.size);
17121 int align = inst.operands[1].imm >> 8;
17122 int n = (inst.instruction >> 8) & 3;
17123 int max_el = 64 / et.size;
5f4273c7 17124
dcbf9037
JB
17125 if (et.type == NT_invtype)
17126 return;
5f4273c7 17127
5287ad62 17128 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 17129 _("bad list length"));
5287ad62 17130 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 17131 _("scalar index out of range"));
5287ad62 17132 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
17133 && et.size == 8,
17134 _("stride of 2 unavailable when element size is 8"));
5f4273c7 17135
5287ad62
JB
17136 switch (n)
17137 {
17138 case 0: /* VLD1 / VST1. */
aa8a0863 17139 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 17140 32, 32, -1);
5287ad62 17141 if (align_good == FAIL)
477330fc 17142 return;
aa8a0863 17143 if (do_alignment)
477330fc
RM
17144 {
17145 unsigned alignbits = 0;
17146 switch (et.size)
17147 {
17148 case 16: alignbits = 0x1; break;
17149 case 32: alignbits = 0x3; break;
17150 default: ;
17151 }
17152 inst.instruction |= alignbits << 4;
17153 }
5287ad62
JB
17154 break;
17155
17156 case 1: /* VLD2 / VST2. */
aa8a0863
TS
17157 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
17158 16, 32, 32, 64, -1);
5287ad62 17159 if (align_good == FAIL)
477330fc 17160 return;
aa8a0863 17161 if (do_alignment)
477330fc 17162 inst.instruction |= 1 << 4;
5287ad62
JB
17163 break;
17164
17165 case 2: /* VLD3 / VST3. */
17166 constraint (inst.operands[1].immisalign,
477330fc 17167 _("can't use alignment with this instruction"));
5287ad62
JB
17168 break;
17169
17170 case 3: /* VLD4 / VST4. */
aa8a0863 17171 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 17172 16, 64, 32, 64, 32, 128, -1);
5287ad62 17173 if (align_good == FAIL)
477330fc 17174 return;
aa8a0863 17175 if (do_alignment)
477330fc
RM
17176 {
17177 unsigned alignbits = 0;
17178 switch (et.size)
17179 {
17180 case 8: alignbits = 0x1; break;
17181 case 16: alignbits = 0x1; break;
17182 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
17183 default: ;
17184 }
17185 inst.instruction |= alignbits << 4;
17186 }
5287ad62
JB
17187 break;
17188
17189 default: ;
17190 }
17191
17192 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
17193 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17194 inst.instruction |= 1 << (4 + logsize);
5f4273c7 17195
5287ad62
JB
17196 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
17197 inst.instruction |= logsize << 10;
17198}
17199
17200/* Encode single n-element structure to all lanes VLD<n> instructions. */
17201
17202static void
17203do_neon_ld_dup (void)
17204{
037e8744 17205 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17206 int align_good, do_alignment = 0;
5287ad62 17207
dcbf9037
JB
17208 if (et.type == NT_invtype)
17209 return;
17210
5287ad62
JB
17211 switch ((inst.instruction >> 8) & 3)
17212 {
17213 case 0: /* VLD1. */
9c2799c2 17214 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 17215 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 17216 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 17217 if (align_good == FAIL)
477330fc 17218 return;
5287ad62 17219 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
17220 {
17221 case 1: break;
17222 case 2: inst.instruction |= 1 << 5; break;
17223 default: first_error (_("bad list length")); return;
17224 }
5287ad62
JB
17225 inst.instruction |= neon_logbits (et.size) << 6;
17226 break;
17227
17228 case 1: /* VLD2. */
17229 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
17230 &do_alignment, 8, 16, 16, 32, 32, 64,
17231 -1);
5287ad62 17232 if (align_good == FAIL)
477330fc 17233 return;
5287ad62 17234 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 17235 _("bad list length"));
5287ad62 17236 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17237 inst.instruction |= 1 << 5;
5287ad62
JB
17238 inst.instruction |= neon_logbits (et.size) << 6;
17239 break;
17240
17241 case 2: /* VLD3. */
17242 constraint (inst.operands[1].immisalign,
477330fc 17243 _("can't use alignment with this instruction"));
5287ad62 17244 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 17245 _("bad list length"));
5287ad62 17246 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17247 inst.instruction |= 1 << 5;
5287ad62
JB
17248 inst.instruction |= neon_logbits (et.size) << 6;
17249 break;
17250
17251 case 3: /* VLD4. */
17252 {
477330fc 17253 int align = inst.operands[1].imm >> 8;
aa8a0863 17254 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17255 16, 64, 32, 64, 32, 128, -1);
17256 if (align_good == FAIL)
17257 return;
17258 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17259 _("bad list length"));
17260 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17261 inst.instruction |= 1 << 5;
17262 if (et.size == 32 && align == 128)
17263 inst.instruction |= 0x3 << 6;
17264 else
17265 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
17266 }
17267 break;
17268
17269 default: ;
17270 }
17271
aa8a0863 17272 inst.instruction |= do_alignment << 4;
5287ad62
JB
17273}
17274
17275/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17276 apart from bits [11:4]. */
17277
17278static void
17279do_neon_ldx_stx (void)
17280{
b1a769ed
DG
17281 if (inst.operands[1].isreg)
17282 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17283
5287ad62
JB
17284 switch (NEON_LANE (inst.operands[0].imm))
17285 {
17286 case NEON_INTERLEAVE_LANES:
88714cb8 17287 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
17288 do_neon_ld_st_interleave ();
17289 break;
5f4273c7 17290
5287ad62 17291 case NEON_ALL_LANES:
88714cb8 17292 NEON_ENCODE (DUP, inst);
2d51fb74
JB
17293 if (inst.instruction == N_INV)
17294 {
17295 first_error ("only loads support such operands");
17296 break;
17297 }
5287ad62
JB
17298 do_neon_ld_dup ();
17299 break;
5f4273c7 17300
5287ad62 17301 default:
88714cb8 17302 NEON_ENCODE (LANE, inst);
5287ad62
JB
17303 do_neon_ld_st_lane ();
17304 }
17305
17306 /* L bit comes from bit mask. */
17307 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17308 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17309 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17310
5287ad62
JB
17311 if (inst.operands[1].postind)
17312 {
17313 int postreg = inst.operands[1].imm & 0xf;
17314 constraint (!inst.operands[1].immisreg,
477330fc 17315 _("post-index must be a register"));
5287ad62 17316 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17317 _("bad register for post-index"));
5287ad62
JB
17318 inst.instruction |= postreg;
17319 }
4f2374c7 17320 else
5287ad62 17321 {
4f2374c7
WN
17322 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17323 constraint (inst.reloc.exp.X_op != O_constant
17324 || inst.reloc.exp.X_add_number != 0,
17325 BAD_ADDR_MODE);
17326
17327 if (inst.operands[1].writeback)
17328 {
17329 inst.instruction |= 0xd;
17330 }
17331 else
17332 inst.instruction |= 0xf;
5287ad62 17333 }
5f4273c7 17334
5287ad62
JB
17335 if (thumb_mode)
17336 inst.instruction |= 0xf9000000;
17337 else
17338 inst.instruction |= 0xf4000000;
17339}
33399f07
MGD
17340
17341/* FP v8. */
17342static void
17343do_vfp_nsyn_fpv8 (enum neon_shape rs)
17344{
a715796b
TG
17345 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17346 D register operands. */
17347 if (neon_shape_class[rs] == SC_DOUBLE)
17348 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17349 _(BAD_FPU));
17350
33399f07
MGD
17351 NEON_ENCODE (FPV8, inst);
17352
9db2f6b4
RL
17353 if (rs == NS_FFF || rs == NS_HHH)
17354 {
17355 do_vfp_sp_dyadic ();
17356
17357 /* ARMv8.2 fp16 instruction. */
17358 if (rs == NS_HHH)
17359 do_scalar_fp16_v82_encode ();
17360 }
33399f07
MGD
17361 else
17362 do_vfp_dp_rd_rn_rm ();
17363
17364 if (rs == NS_DDD)
17365 inst.instruction |= 0x100;
17366
17367 inst.instruction |= 0xf0000000;
17368}
17369
17370static void
17371do_vsel (void)
17372{
17373 set_it_insn_type (OUTSIDE_IT_INSN);
17374
17375 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17376 first_error (_("invalid instruction shape"));
17377}
17378
73924fbc
MGD
17379static void
17380do_vmaxnm (void)
17381{
17382 set_it_insn_type (OUTSIDE_IT_INSN);
17383
17384 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17385 return;
17386
17387 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17388 return;
17389
cc933301 17390 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17391}
17392
30bdf752
MGD
17393static void
17394do_vrint_1 (enum neon_cvt_mode mode)
17395{
9db2f6b4 17396 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17397 struct neon_type_el et;
17398
17399 if (rs == NS_NULL)
17400 return;
17401
a715796b
TG
17402 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17403 D register operands. */
17404 if (neon_shape_class[rs] == SC_DOUBLE)
17405 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17406 _(BAD_FPU));
17407
9db2f6b4
RL
17408 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17409 | N_VFP);
30bdf752
MGD
17410 if (et.type != NT_invtype)
17411 {
17412 /* VFP encodings. */
17413 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17414 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17415 set_it_insn_type (OUTSIDE_IT_INSN);
17416
17417 NEON_ENCODE (FPV8, inst);
9db2f6b4 17418 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17419 do_vfp_sp_monadic ();
17420 else
17421 do_vfp_dp_rd_rm ();
17422
17423 switch (mode)
17424 {
17425 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17426 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17427 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17428 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17429 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17430 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17431 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17432 default: abort ();
17433 }
17434
17435 inst.instruction |= (rs == NS_DD) << 8;
17436 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17437
17438 /* ARMv8.2 fp16 vrint instruction. */
17439 if (rs == NS_HH)
17440 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17441 }
17442 else
17443 {
17444 /* Neon encodings (or something broken...). */
17445 inst.error = NULL;
cc933301 17446 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17447
17448 if (et.type == NT_invtype)
17449 return;
17450
17451 set_it_insn_type (OUTSIDE_IT_INSN);
17452 NEON_ENCODE (FLOAT, inst);
17453
17454 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17455 return;
17456
17457 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17458 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17459 inst.instruction |= LOW4 (inst.operands[1].reg);
17460 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17461 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17462 /* Mask off the original size bits and reencode them. */
17463 inst.instruction = ((inst.instruction & 0xfff3ffff)
17464 | neon_logbits (et.size) << 18);
17465
30bdf752
MGD
17466 switch (mode)
17467 {
17468 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17469 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17470 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17471 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17472 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17473 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17474 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17475 default: abort ();
17476 }
17477
17478 if (thumb_mode)
17479 inst.instruction |= 0xfc000000;
17480 else
17481 inst.instruction |= 0xf0000000;
17482 }
17483}
17484
17485static void
17486do_vrintx (void)
17487{
17488 do_vrint_1 (neon_cvt_mode_x);
17489}
17490
17491static void
17492do_vrintz (void)
17493{
17494 do_vrint_1 (neon_cvt_mode_z);
17495}
17496
17497static void
17498do_vrintr (void)
17499{
17500 do_vrint_1 (neon_cvt_mode_r);
17501}
17502
17503static void
17504do_vrinta (void)
17505{
17506 do_vrint_1 (neon_cvt_mode_a);
17507}
17508
17509static void
17510do_vrintn (void)
17511{
17512 do_vrint_1 (neon_cvt_mode_n);
17513}
17514
17515static void
17516do_vrintp (void)
17517{
17518 do_vrint_1 (neon_cvt_mode_p);
17519}
17520
17521static void
17522do_vrintm (void)
17523{
17524 do_vrint_1 (neon_cvt_mode_m);
17525}
17526
c28eeff2
SN
17527static unsigned
17528neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17529{
17530 unsigned regno = NEON_SCALAR_REG (opnd);
17531 unsigned elno = NEON_SCALAR_INDEX (opnd);
17532
17533 if (elsize == 16 && elno < 2 && regno < 16)
17534 return regno | (elno << 4);
17535 else if (elsize == 32 && elno == 0)
17536 return regno;
17537
17538 first_error (_("scalar out of range"));
17539 return 0;
17540}
17541
17542static void
17543do_vcmla (void)
17544{
17545 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17546 _(BAD_FPU));
17547 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17548 unsigned rot = inst.reloc.exp.X_add_number;
17549 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17550 _("immediate out of range"));
17551 rot /= 90;
17552 if (inst.operands[2].isscalar)
17553 {
17554 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17555 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17556 N_KEY | N_F16 | N_F32).size;
17557 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17558 inst.is_neon = 1;
17559 inst.instruction = 0xfe000800;
17560 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17561 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17562 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17563 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17564 inst.instruction |= LOW4 (m);
17565 inst.instruction |= HI1 (m) << 5;
17566 inst.instruction |= neon_quad (rs) << 6;
17567 inst.instruction |= rot << 20;
17568 inst.instruction |= (size == 32) << 23;
17569 }
17570 else
17571 {
17572 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17573 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17574 N_KEY | N_F16 | N_F32).size;
17575 neon_three_same (neon_quad (rs), 0, -1);
17576 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17577 inst.instruction |= 0xfc200800;
17578 inst.instruction |= rot << 23;
17579 inst.instruction |= (size == 32) << 20;
17580 }
17581}
17582
17583static void
17584do_vcadd (void)
17585{
17586 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17587 _(BAD_FPU));
17588 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17589 unsigned rot = inst.reloc.exp.X_add_number;
17590 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17591 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17592 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17593 N_KEY | N_F16 | N_F32).size;
17594 neon_three_same (neon_quad (rs), 0, -1);
17595 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17596 inst.instruction |= 0xfc800800;
17597 inst.instruction |= (rot == 270) << 24;
17598 inst.instruction |= (size == 32) << 20;
17599}
17600
c604a79a
JW
17601/* Dot Product instructions encoding support. */
17602
17603static void
17604do_neon_dotproduct (int unsigned_p)
17605{
17606 enum neon_shape rs;
17607 unsigned scalar_oprd2 = 0;
17608 int high8;
17609
17610 if (inst.cond != COND_ALWAYS)
17611 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
17612 "is UNPREDICTABLE"));
17613
17614 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17615 _(BAD_FPU));
17616
17617 /* Dot Product instructions are in three-same D/Q register format or the third
17618 operand can be a scalar index register. */
17619 if (inst.operands[2].isscalar)
17620 {
17621 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
17622 high8 = 0xfe000000;
17623 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17624 }
17625 else
17626 {
17627 high8 = 0xfc000000;
17628 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17629 }
17630
17631 if (unsigned_p)
17632 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
17633 else
17634 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
17635
17636 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
17637 Product instruction, so we pass 0 as the "ubit" parameter. And the
17638 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
17639 neon_three_same (neon_quad (rs), 0, 32);
17640
17641 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
17642 different NEON three-same encoding. */
17643 inst.instruction &= 0x00ffffff;
17644 inst.instruction |= high8;
17645 /* Encode 'U' bit which indicates signedness. */
17646 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
17647 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
17648 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
17649 the instruction encoding. */
17650 if (inst.operands[2].isscalar)
17651 {
17652 inst.instruction &= 0xffffffd0;
17653 inst.instruction |= LOW4 (scalar_oprd2);
17654 inst.instruction |= HI1 (scalar_oprd2) << 5;
17655 }
17656}
17657
17658/* Dot Product instructions for signed integer. */
17659
17660static void
17661do_neon_dotproduct_s (void)
17662{
17663 return do_neon_dotproduct (0);
17664}
17665
17666/* Dot Product instructions for unsigned integer. */
17667
17668static void
17669do_neon_dotproduct_u (void)
17670{
17671 return do_neon_dotproduct (1);
17672}
17673
91ff7894
MGD
17674/* Crypto v1 instructions. */
17675static void
17676do_crypto_2op_1 (unsigned elttype, int op)
17677{
17678 set_it_insn_type (OUTSIDE_IT_INSN);
17679
17680 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17681 == NT_invtype)
17682 return;
17683
17684 inst.error = NULL;
17685
17686 NEON_ENCODE (INTEGER, inst);
17687 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17688 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17689 inst.instruction |= LOW4 (inst.operands[1].reg);
17690 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17691 if (op != -1)
17692 inst.instruction |= op << 6;
17693
17694 if (thumb_mode)
17695 inst.instruction |= 0xfc000000;
17696 else
17697 inst.instruction |= 0xf0000000;
17698}
17699
48adcd8e
MGD
17700static void
17701do_crypto_3op_1 (int u, int op)
17702{
17703 set_it_insn_type (OUTSIDE_IT_INSN);
17704
17705 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17706 N_32 | N_UNT | N_KEY).type == NT_invtype)
17707 return;
17708
17709 inst.error = NULL;
17710
17711 NEON_ENCODE (INTEGER, inst);
17712 neon_three_same (1, u, 8 << op);
17713}
17714
91ff7894
MGD
17715static void
17716do_aese (void)
17717{
17718 do_crypto_2op_1 (N_8, 0);
17719}
17720
17721static void
17722do_aesd (void)
17723{
17724 do_crypto_2op_1 (N_8, 1);
17725}
17726
17727static void
17728do_aesmc (void)
17729{
17730 do_crypto_2op_1 (N_8, 2);
17731}
17732
17733static void
17734do_aesimc (void)
17735{
17736 do_crypto_2op_1 (N_8, 3);
17737}
17738
48adcd8e
MGD
17739static void
17740do_sha1c (void)
17741{
17742 do_crypto_3op_1 (0, 0);
17743}
17744
17745static void
17746do_sha1p (void)
17747{
17748 do_crypto_3op_1 (0, 1);
17749}
17750
17751static void
17752do_sha1m (void)
17753{
17754 do_crypto_3op_1 (0, 2);
17755}
17756
17757static void
17758do_sha1su0 (void)
17759{
17760 do_crypto_3op_1 (0, 3);
17761}
91ff7894 17762
48adcd8e
MGD
17763static void
17764do_sha256h (void)
17765{
17766 do_crypto_3op_1 (1, 0);
17767}
17768
17769static void
17770do_sha256h2 (void)
17771{
17772 do_crypto_3op_1 (1, 1);
17773}
17774
17775static void
17776do_sha256su1 (void)
17777{
17778 do_crypto_3op_1 (1, 2);
17779}
3c9017d2
MGD
17780
17781static void
17782do_sha1h (void)
17783{
17784 do_crypto_2op_1 (N_32, -1);
17785}
17786
17787static void
17788do_sha1su1 (void)
17789{
17790 do_crypto_2op_1 (N_32, 0);
17791}
17792
17793static void
17794do_sha256su0 (void)
17795{
17796 do_crypto_2op_1 (N_32, 1);
17797}
dd5181d5
KT
17798
17799static void
17800do_crc32_1 (unsigned int poly, unsigned int sz)
17801{
17802 unsigned int Rd = inst.operands[0].reg;
17803 unsigned int Rn = inst.operands[1].reg;
17804 unsigned int Rm = inst.operands[2].reg;
17805
17806 set_it_insn_type (OUTSIDE_IT_INSN);
17807 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17808 inst.instruction |= LOW4 (Rn) << 16;
17809 inst.instruction |= LOW4 (Rm);
17810 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17811 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17812
17813 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17814 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
17815}
17816
17817static void
17818do_crc32b (void)
17819{
17820 do_crc32_1 (0, 0);
17821}
17822
17823static void
17824do_crc32h (void)
17825{
17826 do_crc32_1 (0, 1);
17827}
17828
17829static void
17830do_crc32w (void)
17831{
17832 do_crc32_1 (0, 2);
17833}
17834
17835static void
17836do_crc32cb (void)
17837{
17838 do_crc32_1 (1, 0);
17839}
17840
17841static void
17842do_crc32ch (void)
17843{
17844 do_crc32_1 (1, 1);
17845}
17846
17847static void
17848do_crc32cw (void)
17849{
17850 do_crc32_1 (1, 2);
17851}
17852
49e8a725
SN
17853static void
17854do_vjcvt (void)
17855{
17856 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17857 _(BAD_FPU));
17858 neon_check_type (2, NS_FD, N_S32, N_F64);
17859 do_vfp_sp_dp_cvt ();
17860 do_vfp_cond_or_thumb ();
17861}
17862
5287ad62
JB
17863\f
17864/* Overall per-instruction processing. */
17865
17866/* We need to be able to fix up arbitrary expressions in some statements.
17867 This is so that we can handle symbols that are an arbitrary distance from
17868 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17869 which returns part of an address in a form which will be valid for
17870 a data instruction. We do this by pushing the expression into a symbol
17871 in the expr_section, and creating a fix for that. */
17872
17873static void
17874fix_new_arm (fragS * frag,
17875 int where,
17876 short int size,
17877 expressionS * exp,
17878 int pc_rel,
17879 int reloc)
17880{
17881 fixS * new_fix;
17882
17883 switch (exp->X_op)
17884 {
17885 case O_constant:
6e7ce2cd
PB
17886 if (pc_rel)
17887 {
17888 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17889 refer to in the object file. Unfortunately for us, gas's
17890 generic expression parsing will already have folded out
17891 any use of .set foo/.type foo %function that may have
17892 been used to set type information of the target location,
17893 that's being specified symbolically. We have to presume
17894 the user knows what they are doing. */
6e7ce2cd
PB
17895 char name[16 + 8];
17896 symbolS *symbol;
17897
17898 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17899
17900 symbol = symbol_find_or_make (name);
17901 S_SET_SEGMENT (symbol, absolute_section);
17902 symbol_set_frag (symbol, &zero_address_frag);
17903 S_SET_VALUE (symbol, exp->X_add_number);
17904 exp->X_op = O_symbol;
17905 exp->X_add_symbol = symbol;
17906 exp->X_add_number = 0;
17907 }
17908 /* FALLTHROUGH */
5287ad62
JB
17909 case O_symbol:
17910 case O_add:
17911 case O_subtract:
21d799b5 17912 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17913 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17914 break;
17915
17916 default:
21d799b5 17917 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17918 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17919 break;
17920 }
17921
17922 /* Mark whether the fix is to a THUMB instruction, or an ARM
17923 instruction. */
17924 new_fix->tc_fix_data = thumb_mode;
17925}
17926
17927/* Create a frg for an instruction requiring relaxation. */
17928static void
17929output_relax_insn (void)
17930{
17931 char * to;
17932 symbolS *sym;
0110f2b8
PB
17933 int offset;
17934
6e1cb1a6
PB
17935 /* The size of the instruction is unknown, so tie the debug info to the
17936 start of the instruction. */
17937 dwarf2_emit_insn (0);
6e1cb1a6 17938
0110f2b8
PB
17939 switch (inst.reloc.exp.X_op)
17940 {
17941 case O_symbol:
17942 sym = inst.reloc.exp.X_add_symbol;
17943 offset = inst.reloc.exp.X_add_number;
17944 break;
17945 case O_constant:
17946 sym = NULL;
17947 offset = inst.reloc.exp.X_add_number;
17948 break;
17949 default:
17950 sym = make_expr_symbol (&inst.reloc.exp);
17951 offset = 0;
17952 break;
17953 }
17954 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17955 inst.relax, sym, offset, NULL/*offset, opcode*/);
17956 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17957}
17958
17959/* Write a 32-bit thumb instruction to buf. */
17960static void
17961put_thumb32_insn (char * buf, unsigned long insn)
17962{
17963 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17964 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17965}
17966
b99bd4ef 17967static void
c19d1205 17968output_inst (const char * str)
b99bd4ef 17969{
c19d1205 17970 char * to = NULL;
b99bd4ef 17971
c19d1205 17972 if (inst.error)
b99bd4ef 17973 {
c19d1205 17974 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17975 return;
17976 }
5f4273c7
NC
17977 if (inst.relax)
17978 {
17979 output_relax_insn ();
0110f2b8 17980 return;
5f4273c7 17981 }
c19d1205
ZW
17982 if (inst.size == 0)
17983 return;
b99bd4ef 17984
c19d1205 17985 to = frag_more (inst.size);
8dc2430f
NC
17986 /* PR 9814: Record the thumb mode into the current frag so that we know
17987 what type of NOP padding to use, if necessary. We override any previous
17988 setting so that if the mode has changed then the NOPS that we use will
17989 match the encoding of the last instruction in the frag. */
cd000bff 17990 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17991
17992 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17993 {
9c2799c2 17994 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17995 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17996 }
c19d1205 17997 else if (inst.size > INSN_SIZE)
b99bd4ef 17998 {
9c2799c2 17999 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
18000 md_number_to_chars (to, inst.instruction, INSN_SIZE);
18001 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 18002 }
c19d1205
ZW
18003 else
18004 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 18005
c19d1205
ZW
18006 if (inst.reloc.type != BFD_RELOC_UNUSED)
18007 fix_new_arm (frag_now, to - frag_now->fr_literal,
18008 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
18009 inst.reloc.type);
b99bd4ef 18010
c19d1205 18011 dwarf2_emit_insn (inst.size);
c19d1205 18012}
b99bd4ef 18013
e07e6e58
NC
18014static char *
18015output_it_inst (int cond, int mask, char * to)
18016{
18017 unsigned long instruction = 0xbf00;
18018
18019 mask &= 0xf;
18020 instruction |= mask;
18021 instruction |= cond << 4;
18022
18023 if (to == NULL)
18024 {
18025 to = frag_more (2);
18026#ifdef OBJ_ELF
18027 dwarf2_emit_insn (2);
18028#endif
18029 }
18030
18031 md_number_to_chars (to, instruction, 2);
18032
18033 return to;
18034}
18035
c19d1205
ZW
18036/* Tag values used in struct asm_opcode's tag field. */
18037enum opcode_tag
18038{
18039 OT_unconditional, /* Instruction cannot be conditionalized.
18040 The ARM condition field is still 0xE. */
18041 OT_unconditionalF, /* Instruction cannot be conditionalized
18042 and carries 0xF in its ARM condition field. */
18043 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 18044 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
18045 suffix, others place 0xF where the condition field
18046 would be. */
c19d1205
ZW
18047 OT_cinfix3, /* Instruction takes a conditional infix,
18048 beginning at character index 3. (In
18049 unified mode, it becomes a suffix.) */
088fa78e
KH
18050 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
18051 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
18052 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
18053 character index 3, even in unified mode. Used for
18054 legacy instructions where suffix and infix forms
18055 may be ambiguous. */
c19d1205 18056 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 18057 suffix or an infix at character index 3. */
c19d1205
ZW
18058 OT_odd_infix_unc, /* This is the unconditional variant of an
18059 instruction that takes a conditional infix
18060 at an unusual position. In unified mode,
18061 this variant will accept a suffix. */
18062 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
18063 are the conditional variants of instructions that
18064 take conditional infixes in unusual positions.
18065 The infix appears at character index
18066 (tag - OT_odd_infix_0). These are not accepted
18067 in unified mode. */
18068};
b99bd4ef 18069
c19d1205
ZW
18070/* Subroutine of md_assemble, responsible for looking up the primary
18071 opcode from the mnemonic the user wrote. STR points to the
18072 beginning of the mnemonic.
18073
18074 This is not simply a hash table lookup, because of conditional
18075 variants. Most instructions have conditional variants, which are
18076 expressed with a _conditional affix_ to the mnemonic. If we were
18077 to encode each conditional variant as a literal string in the opcode
18078 table, it would have approximately 20,000 entries.
18079
18080 Most mnemonics take this affix as a suffix, and in unified syntax,
18081 'most' is upgraded to 'all'. However, in the divided syntax, some
18082 instructions take the affix as an infix, notably the s-variants of
18083 the arithmetic instructions. Of those instructions, all but six
18084 have the infix appear after the third character of the mnemonic.
18085
18086 Accordingly, the algorithm for looking up primary opcodes given
18087 an identifier is:
18088
18089 1. Look up the identifier in the opcode table.
18090 If we find a match, go to step U.
18091
18092 2. Look up the last two characters of the identifier in the
18093 conditions table. If we find a match, look up the first N-2
18094 characters of the identifier in the opcode table. If we
18095 find a match, go to step CE.
18096
18097 3. Look up the fourth and fifth characters of the identifier in
18098 the conditions table. If we find a match, extract those
18099 characters from the identifier, and look up the remaining
18100 characters in the opcode table. If we find a match, go
18101 to step CM.
18102
18103 4. Fail.
18104
18105 U. Examine the tag field of the opcode structure, in case this is
18106 one of the six instructions with its conditional infix in an
18107 unusual place. If it is, the tag tells us where to find the
18108 infix; look it up in the conditions table and set inst.cond
18109 accordingly. Otherwise, this is an unconditional instruction.
18110 Again set inst.cond accordingly. Return the opcode structure.
18111
18112 CE. Examine the tag field to make sure this is an instruction that
18113 should receive a conditional suffix. If it is not, fail.
18114 Otherwise, set inst.cond from the suffix we already looked up,
18115 and return the opcode structure.
18116
18117 CM. Examine the tag field to make sure this is an instruction that
18118 should receive a conditional infix after the third character.
18119 If it is not, fail. Otherwise, undo the edits to the current
18120 line of input and proceed as for case CE. */
18121
18122static const struct asm_opcode *
18123opcode_lookup (char **str)
18124{
18125 char *end, *base;
18126 char *affix;
18127 const struct asm_opcode *opcode;
18128 const struct asm_cond *cond;
e3cb604e 18129 char save[2];
c19d1205
ZW
18130
18131 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 18132 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 18133 for (base = end = *str; *end != '\0'; end++)
721a8186 18134 if (*end == ' ' || *end == '.')
c19d1205 18135 break;
b99bd4ef 18136
c19d1205 18137 if (end == base)
c921be7d 18138 return NULL;
b99bd4ef 18139
5287ad62 18140 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 18141 if (end[0] == '.')
b99bd4ef 18142 {
5287ad62 18143 int offset = 2;
5f4273c7 18144
267d2029 18145 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 18146 use. */
267d2029 18147 if (unified_syntax && end[1] == 'w')
c19d1205 18148 inst.size_req = 4;
267d2029 18149 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
18150 inst.size_req = 2;
18151 else
477330fc 18152 offset = 0;
5287ad62
JB
18153
18154 inst.vectype.elems = 0;
18155
18156 *str = end + offset;
b99bd4ef 18157
5f4273c7 18158 if (end[offset] == '.')
5287ad62 18159 {
267d2029 18160 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
18161 non-unified ARM syntax mode). */
18162 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 18163 return NULL;
477330fc 18164 }
5287ad62 18165 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 18166 return NULL;
b99bd4ef 18167 }
c19d1205
ZW
18168 else
18169 *str = end;
b99bd4ef 18170
c19d1205 18171 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 18172 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18173 end - base);
c19d1205 18174 if (opcode)
b99bd4ef 18175 {
c19d1205
ZW
18176 /* step U */
18177 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 18178 {
c19d1205
ZW
18179 inst.cond = COND_ALWAYS;
18180 return opcode;
b99bd4ef 18181 }
b99bd4ef 18182
278df34e 18183 if (warn_on_deprecated && unified_syntax)
5c3696f8 18184 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 18185 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 18186 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 18187 gas_assert (cond);
b99bd4ef 18188
c19d1205
ZW
18189 inst.cond = cond->value;
18190 return opcode;
18191 }
b99bd4ef 18192
c19d1205
ZW
18193 /* Cannot have a conditional suffix on a mnemonic of less than two
18194 characters. */
18195 if (end - base < 3)
c921be7d 18196 return NULL;
b99bd4ef 18197
c19d1205
ZW
18198 /* Look for suffixed mnemonic. */
18199 affix = end - 2;
21d799b5
NC
18200 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18201 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18202 affix - base);
c19d1205
ZW
18203 if (opcode && cond)
18204 {
18205 /* step CE */
18206 switch (opcode->tag)
18207 {
e3cb604e
PB
18208 case OT_cinfix3_legacy:
18209 /* Ignore conditional suffixes matched on infix only mnemonics. */
18210 break;
18211
c19d1205 18212 case OT_cinfix3:
088fa78e 18213 case OT_cinfix3_deprecated:
c19d1205
ZW
18214 case OT_odd_infix_unc:
18215 if (!unified_syntax)
0198d5e6 18216 return NULL;
1a0670f3 18217 /* Fall through. */
c19d1205
ZW
18218
18219 case OT_csuffix:
477330fc 18220 case OT_csuffixF:
c19d1205
ZW
18221 case OT_csuf_or_in3:
18222 inst.cond = cond->value;
18223 return opcode;
18224
18225 case OT_unconditional:
18226 case OT_unconditionalF:
dfa9f0d5 18227 if (thumb_mode)
c921be7d 18228 inst.cond = cond->value;
dfa9f0d5
PB
18229 else
18230 {
c921be7d 18231 /* Delayed diagnostic. */
dfa9f0d5
PB
18232 inst.error = BAD_COND;
18233 inst.cond = COND_ALWAYS;
18234 }
c19d1205 18235 return opcode;
b99bd4ef 18236
c19d1205 18237 default:
c921be7d 18238 return NULL;
c19d1205
ZW
18239 }
18240 }
b99bd4ef 18241
c19d1205
ZW
18242 /* Cannot have a usual-position infix on a mnemonic of less than
18243 six characters (five would be a suffix). */
18244 if (end - base < 6)
c921be7d 18245 return NULL;
b99bd4ef 18246
c19d1205
ZW
18247 /* Look for infixed mnemonic in the usual position. */
18248 affix = base + 3;
21d799b5 18249 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 18250 if (!cond)
c921be7d 18251 return NULL;
e3cb604e
PB
18252
18253 memcpy (save, affix, 2);
18254 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 18255 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18256 (end - base) - 2);
e3cb604e
PB
18257 memmove (affix + 2, affix, (end - affix) - 2);
18258 memcpy (affix, save, 2);
18259
088fa78e
KH
18260 if (opcode
18261 && (opcode->tag == OT_cinfix3
18262 || opcode->tag == OT_cinfix3_deprecated
18263 || opcode->tag == OT_csuf_or_in3
18264 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 18265 {
c921be7d 18266 /* Step CM. */
278df34e 18267 if (warn_on_deprecated && unified_syntax
088fa78e
KH
18268 && (opcode->tag == OT_cinfix3
18269 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 18270 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
18271
18272 inst.cond = cond->value;
18273 return opcode;
b99bd4ef
NC
18274 }
18275
c921be7d 18276 return NULL;
b99bd4ef
NC
18277}
18278
e07e6e58
NC
18279/* This function generates an initial IT instruction, leaving its block
18280 virtually open for the new instructions. Eventually,
18281 the mask will be updated by now_it_add_mask () each time
18282 a new instruction needs to be included in the IT block.
18283 Finally, the block is closed with close_automatic_it_block ().
18284 The block closure can be requested either from md_assemble (),
18285 a tencode (), or due to a label hook. */
18286
18287static void
18288new_automatic_it_block (int cond)
18289{
18290 now_it.state = AUTOMATIC_IT_BLOCK;
18291 now_it.mask = 0x18;
18292 now_it.cc = cond;
18293 now_it.block_length = 1;
cd000bff 18294 mapping_state (MAP_THUMB);
e07e6e58 18295 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
18296 now_it.warn_deprecated = FALSE;
18297 now_it.insn_cond = TRUE;
e07e6e58
NC
18298}
18299
18300/* Close an automatic IT block.
18301 See comments in new_automatic_it_block (). */
18302
18303static void
18304close_automatic_it_block (void)
18305{
18306 now_it.mask = 0x10;
18307 now_it.block_length = 0;
18308}
18309
18310/* Update the mask of the current automatically-generated IT
18311 instruction. See comments in new_automatic_it_block (). */
18312
18313static void
18314now_it_add_mask (int cond)
18315{
18316#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
18317#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 18318 | ((bitvalue) << (nbit)))
e07e6e58 18319 const int resulting_bit = (cond & 1);
c921be7d 18320
e07e6e58
NC
18321 now_it.mask &= 0xf;
18322 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18323 resulting_bit,
18324 (5 - now_it.block_length));
e07e6e58 18325 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18326 1,
18327 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
18328 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18329
18330#undef CLEAR_BIT
18331#undef SET_BIT_VALUE
e07e6e58
NC
18332}
18333
18334/* The IT blocks handling machinery is accessed through the these functions:
18335 it_fsm_pre_encode () from md_assemble ()
18336 set_it_insn_type () optional, from the tencode functions
18337 set_it_insn_type_last () ditto
18338 in_it_block () ditto
18339 it_fsm_post_encode () from md_assemble ()
33eaf5de 18340 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
18341
18342 Rationale:
18343 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
18344 initializing the IT insn type with a generic initial value depending
18345 on the inst.condition.
e07e6e58 18346 2) During the tencode function, two things may happen:
477330fc
RM
18347 a) The tencode function overrides the IT insn type by
18348 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18349 b) The tencode function queries the IT block state by
18350 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18351
18352 Both set_it_insn_type and in_it_block run the internal FSM state
18353 handling function (handle_it_state), because: a) setting the IT insn
18354 type may incur in an invalid state (exiting the function),
18355 and b) querying the state requires the FSM to be updated.
18356 Specifically we want to avoid creating an IT block for conditional
18357 branches, so it_fsm_pre_encode is actually a guess and we can't
18358 determine whether an IT block is required until the tencode () routine
18359 has decided what type of instruction this actually it.
18360 Because of this, if set_it_insn_type and in_it_block have to be used,
18361 set_it_insn_type has to be called first.
18362
18363 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18364 determines the insn IT type depending on the inst.cond code.
18365 When a tencode () routine encodes an instruction that can be
18366 either outside an IT block, or, in the case of being inside, has to be
18367 the last one, set_it_insn_type_last () will determine the proper
18368 IT instruction type based on the inst.cond code. Otherwise,
18369 set_it_insn_type can be called for overriding that logic or
18370 for covering other cases.
18371
18372 Calling handle_it_state () may not transition the IT block state to
2b0f3761 18373 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
477330fc
RM
18374 still queried. Instead, if the FSM determines that the state should
18375 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18376 after the tencode () function: that's what it_fsm_post_encode () does.
18377
18378 Since in_it_block () calls the state handling function to get an
18379 updated state, an error may occur (due to invalid insns combination).
18380 In that case, inst.error is set.
18381 Therefore, inst.error has to be checked after the execution of
18382 the tencode () routine.
e07e6e58
NC
18383
18384 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
18385 any pending state change (if any) that didn't take place in
18386 handle_it_state () as explained above. */
e07e6e58
NC
18387
18388static void
18389it_fsm_pre_encode (void)
18390{
18391 if (inst.cond != COND_ALWAYS)
18392 inst.it_insn_type = INSIDE_IT_INSN;
18393 else
18394 inst.it_insn_type = OUTSIDE_IT_INSN;
18395
18396 now_it.state_handled = 0;
18397}
18398
18399/* IT state FSM handling function. */
18400
18401static int
18402handle_it_state (void)
18403{
18404 now_it.state_handled = 1;
5a01bb1d 18405 now_it.insn_cond = FALSE;
e07e6e58
NC
18406
18407 switch (now_it.state)
18408 {
18409 case OUTSIDE_IT_BLOCK:
18410 switch (inst.it_insn_type)
18411 {
18412 case OUTSIDE_IT_INSN:
18413 break;
18414
18415 case INSIDE_IT_INSN:
18416 case INSIDE_IT_LAST_INSN:
18417 if (thumb_mode == 0)
18418 {
c921be7d 18419 if (unified_syntax
e07e6e58
NC
18420 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18421 as_tsktsk (_("Warning: conditional outside an IT block"\
18422 " for Thumb."));
18423 }
18424 else
18425 {
18426 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 18427 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
18428 {
18429 /* Automatically generate the IT instruction. */
18430 new_automatic_it_block (inst.cond);
18431 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18432 close_automatic_it_block ();
18433 }
18434 else
18435 {
18436 inst.error = BAD_OUT_IT;
18437 return FAIL;
18438 }
18439 }
18440 break;
18441
18442 case IF_INSIDE_IT_LAST_INSN:
18443 case NEUTRAL_IT_INSN:
18444 break;
18445
18446 case IT_INSN:
18447 now_it.state = MANUAL_IT_BLOCK;
18448 now_it.block_length = 0;
18449 break;
18450 }
18451 break;
18452
18453 case AUTOMATIC_IT_BLOCK:
18454 /* Three things may happen now:
18455 a) We should increment current it block size;
18456 b) We should close current it block (closing insn or 4 insns);
18457 c) We should close current it block and start a new one (due
18458 to incompatible conditions or
18459 4 insns-length block reached). */
18460
18461 switch (inst.it_insn_type)
18462 {
18463 case OUTSIDE_IT_INSN:
2b0f3761 18464 /* The closure of the block shall happen immediately,
e07e6e58
NC
18465 so any in_it_block () call reports the block as closed. */
18466 force_automatic_it_block_close ();
18467 break;
18468
18469 case INSIDE_IT_INSN:
18470 case INSIDE_IT_LAST_INSN:
18471 case IF_INSIDE_IT_LAST_INSN:
18472 now_it.block_length++;
18473
18474 if (now_it.block_length > 4
18475 || !now_it_compatible (inst.cond))
18476 {
18477 force_automatic_it_block_close ();
18478 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18479 new_automatic_it_block (inst.cond);
18480 }
18481 else
18482 {
5a01bb1d 18483 now_it.insn_cond = TRUE;
e07e6e58
NC
18484 now_it_add_mask (inst.cond);
18485 }
18486
18487 if (now_it.state == AUTOMATIC_IT_BLOCK
18488 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18489 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18490 close_automatic_it_block ();
18491 break;
18492
18493 case NEUTRAL_IT_INSN:
18494 now_it.block_length++;
5a01bb1d 18495 now_it.insn_cond = TRUE;
e07e6e58
NC
18496
18497 if (now_it.block_length > 4)
18498 force_automatic_it_block_close ();
18499 else
18500 now_it_add_mask (now_it.cc & 1);
18501 break;
18502
18503 case IT_INSN:
18504 close_automatic_it_block ();
18505 now_it.state = MANUAL_IT_BLOCK;
18506 break;
18507 }
18508 break;
18509
18510 case MANUAL_IT_BLOCK:
18511 {
18512 /* Check conditional suffixes. */
18513 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18514 int is_last;
18515 now_it.mask <<= 1;
18516 now_it.mask &= 0x1f;
18517 is_last = (now_it.mask == 0x10);
5a01bb1d 18518 now_it.insn_cond = TRUE;
e07e6e58
NC
18519
18520 switch (inst.it_insn_type)
18521 {
18522 case OUTSIDE_IT_INSN:
18523 inst.error = BAD_NOT_IT;
18524 return FAIL;
18525
18526 case INSIDE_IT_INSN:
18527 if (cond != inst.cond)
18528 {
18529 inst.error = BAD_IT_COND;
18530 return FAIL;
18531 }
18532 break;
18533
18534 case INSIDE_IT_LAST_INSN:
18535 case IF_INSIDE_IT_LAST_INSN:
18536 if (cond != inst.cond)
18537 {
18538 inst.error = BAD_IT_COND;
18539 return FAIL;
18540 }
18541 if (!is_last)
18542 {
18543 inst.error = BAD_BRANCH;
18544 return FAIL;
18545 }
18546 break;
18547
18548 case NEUTRAL_IT_INSN:
18549 /* The BKPT instruction is unconditional even in an IT block. */
18550 break;
18551
18552 case IT_INSN:
18553 inst.error = BAD_IT_IT;
18554 return FAIL;
18555 }
18556 }
18557 break;
18558 }
18559
18560 return SUCCESS;
18561}
18562
5a01bb1d
MGD
18563struct depr_insn_mask
18564{
18565 unsigned long pattern;
18566 unsigned long mask;
18567 const char* description;
18568};
18569
18570/* List of 16-bit instruction patterns deprecated in an IT block in
18571 ARMv8. */
18572static const struct depr_insn_mask depr_it_insns[] = {
18573 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18574 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18575 { 0xa000, 0xb800, N_("ADR") },
18576 { 0x4800, 0xf800, N_("Literal loads") },
18577 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18578 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18579 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18580 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18581 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18582 { 0, 0, NULL }
18583};
18584
e07e6e58
NC
18585static void
18586it_fsm_post_encode (void)
18587{
18588 int is_last;
18589
18590 if (!now_it.state_handled)
18591 handle_it_state ();
18592
5a01bb1d
MGD
18593 if (now_it.insn_cond
18594 && !now_it.warn_deprecated
18595 && warn_on_deprecated
df9909b8
TP
18596 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
18597 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
5a01bb1d
MGD
18598 {
18599 if (inst.instruction >= 0x10000)
18600 {
5c3696f8 18601 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
df9909b8 18602 "performance deprecated in ARMv8-A and ARMv8-R"));
5a01bb1d
MGD
18603 now_it.warn_deprecated = TRUE;
18604 }
18605 else
18606 {
18607 const struct depr_insn_mask *p = depr_it_insns;
18608
18609 while (p->mask != 0)
18610 {
18611 if ((inst.instruction & p->mask) == p->pattern)
18612 {
df9909b8
TP
18613 as_tsktsk (_("IT blocks containing 16-bit Thumb "
18614 "instructions of the following class are "
18615 "performance deprecated in ARMv8-A and "
18616 "ARMv8-R: %s"), p->description);
5a01bb1d
MGD
18617 now_it.warn_deprecated = TRUE;
18618 break;
18619 }
18620
18621 ++p;
18622 }
18623 }
18624
18625 if (now_it.block_length > 1)
18626 {
5c3696f8 18627 as_tsktsk (_("IT blocks containing more than one conditional "
df9909b8
TP
18628 "instruction are performance deprecated in ARMv8-A and "
18629 "ARMv8-R"));
5a01bb1d
MGD
18630 now_it.warn_deprecated = TRUE;
18631 }
18632 }
18633
e07e6e58
NC
18634 is_last = (now_it.mask == 0x10);
18635 if (is_last)
18636 {
18637 now_it.state = OUTSIDE_IT_BLOCK;
18638 now_it.mask = 0;
18639 }
18640}
18641
18642static void
18643force_automatic_it_block_close (void)
18644{
18645 if (now_it.state == AUTOMATIC_IT_BLOCK)
18646 {
18647 close_automatic_it_block ();
18648 now_it.state = OUTSIDE_IT_BLOCK;
18649 now_it.mask = 0;
18650 }
18651}
18652
18653static int
18654in_it_block (void)
18655{
18656 if (!now_it.state_handled)
18657 handle_it_state ();
18658
18659 return now_it.state != OUTSIDE_IT_BLOCK;
18660}
18661
ff8646ee
TP
18662/* Whether OPCODE only has T32 encoding. Since this function is only used by
18663 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18664 here, hence the "known" in the function name. */
fc289b0a
TP
18665
18666static bfd_boolean
ff8646ee 18667known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18668{
18669 /* Original Thumb-1 wide instruction. */
18670 if (opcode->tencode == do_t_blx
18671 || opcode->tencode == do_t_branch23
18672 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18673 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18674 return TRUE;
18675
16a1fa25
TP
18676 /* Wide-only instruction added to ARMv8-M Baseline. */
18677 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18678 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18679 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18680 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18681 return TRUE;
18682
18683 return FALSE;
18684}
18685
18686/* Whether wide instruction variant can be used if available for a valid OPCODE
18687 in ARCH. */
18688
18689static bfd_boolean
18690t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18691{
18692 if (known_t32_only_insn (opcode))
18693 return TRUE;
18694
18695 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18696 of variant T3 of B.W is checked in do_t_branch. */
18697 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18698 && opcode->tencode == do_t_branch)
18699 return TRUE;
18700
bada4342
JW
18701 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18702 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18703 && opcode->tencode == do_t_mov_cmp
18704 /* Make sure CMP instruction is not affected. */
18705 && opcode->aencode == do_mov)
18706 return TRUE;
18707
ff8646ee
TP
18708 /* Wide instruction variants of all instructions with narrow *and* wide
18709 variants become available with ARMv6t2. Other opcodes are either
18710 narrow-only or wide-only and are thus available if OPCODE is valid. */
18711 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18712 return TRUE;
18713
18714 /* OPCODE with narrow only instruction variant or wide variant not
18715 available. */
fc289b0a
TP
18716 return FALSE;
18717}
18718
c19d1205
ZW
18719void
18720md_assemble (char *str)
b99bd4ef 18721{
c19d1205
ZW
18722 char *p = str;
18723 const struct asm_opcode * opcode;
b99bd4ef 18724
c19d1205
ZW
18725 /* Align the previous label if needed. */
18726 if (last_label_seen != NULL)
b99bd4ef 18727 {
c19d1205
ZW
18728 symbol_set_frag (last_label_seen, frag_now);
18729 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18730 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18731 }
18732
c19d1205
ZW
18733 memset (&inst, '\0', sizeof (inst));
18734 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18735
c19d1205
ZW
18736 opcode = opcode_lookup (&p);
18737 if (!opcode)
b99bd4ef 18738 {
c19d1205 18739 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18740 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18741 if (! create_register_alias (str, p)
477330fc 18742 && ! create_neon_reg_alias (str, p))
c19d1205 18743 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18744
b99bd4ef
NC
18745 return;
18746 }
18747
278df34e 18748 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18749 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18750
037e8744
JB
18751 /* The value which unconditional instructions should have in place of the
18752 condition field. */
18753 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18754
c19d1205 18755 if (thumb_mode)
b99bd4ef 18756 {
e74cfd16 18757 arm_feature_set variant;
8f06b2d8
PB
18758
18759 variant = cpu_variant;
18760 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18761 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18762 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18763 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18764 if (!opcode->tvariant
18765 || (thumb_mode == 1
18766 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18767 {
173205ca
TP
18768 if (opcode->tencode == do_t_swi)
18769 as_bad (_("SVC is not permitted on this architecture"));
18770 else
18771 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18772 return;
18773 }
c19d1205
ZW
18774 if (inst.cond != COND_ALWAYS && !unified_syntax
18775 && opcode->tencode != do_t_branch)
b99bd4ef 18776 {
c19d1205 18777 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18778 return;
18779 }
18780
fc289b0a
TP
18781 /* Two things are addressed here:
18782 1) Implicit require narrow instructions on Thumb-1.
18783 This avoids relaxation accidentally introducing Thumb-2
18784 instructions.
18785 2) Reject wide instructions in non Thumb-2 cores.
18786
18787 Only instructions with narrow and wide variants need to be handled
18788 but selecting all non wide-only instructions is easier. */
18789 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18790 && !t32_insn_ok (variant, opcode))
076d447c 18791 {
fc289b0a
TP
18792 if (inst.size_req == 0)
18793 inst.size_req = 2;
18794 else if (inst.size_req == 4)
752d5da4 18795 {
ff8646ee
TP
18796 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18797 as_bad (_("selected processor does not support 32bit wide "
18798 "variant of instruction `%s'"), str);
18799 else
18800 as_bad (_("selected processor does not support `%s' in "
18801 "Thumb-2 mode"), str);
fc289b0a 18802 return;
752d5da4 18803 }
076d447c
PB
18804 }
18805
c19d1205
ZW
18806 inst.instruction = opcode->tvalue;
18807
5be8be5d 18808 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18809 {
18810 /* Prepare the it_insn_type for those encodings that don't set
18811 it. */
18812 it_fsm_pre_encode ();
c19d1205 18813
477330fc 18814 opcode->tencode ();
e07e6e58 18815
477330fc
RM
18816 it_fsm_post_encode ();
18817 }
e27ec89e 18818
0110f2b8 18819 if (!(inst.error || inst.relax))
b99bd4ef 18820 {
9c2799c2 18821 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18822 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18823 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18824 {
c19d1205 18825 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18826 return;
18827 }
18828 }
076d447c
PB
18829
18830 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18831 instruction. */
9c2799c2 18832 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18833
e74cfd16
PB
18834 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18835 *opcode->tvariant);
ee065d83 18836 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18837 set those bits when Thumb-2 32-bit instructions are seen. The impact
18838 of relaxable instructions will be considered later after we finish all
18839 relaxation. */
ff8646ee
TP
18840 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18841 variant = arm_arch_none;
18842 else
18843 variant = cpu_variant;
18844 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18845 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18846 arm_ext_v6t2);
cd000bff 18847
88714cb8
DG
18848 check_neon_suffixes;
18849
cd000bff 18850 if (!inst.error)
c877a2f2
NC
18851 {
18852 mapping_state (MAP_THUMB);
18853 }
c19d1205 18854 }
3e9e4fcf 18855 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18856 {
845b51d6
PB
18857 bfd_boolean is_bx;
18858
18859 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18860 is_bx = (opcode->aencode == do_bx);
18861
c19d1205 18862 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18863 if (!(is_bx && fix_v4bx)
18864 && !(opcode->avariant &&
18865 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18866 {
84b52b66 18867 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18868 return;
b99bd4ef 18869 }
c19d1205 18870 if (inst.size_req)
b99bd4ef 18871 {
c19d1205
ZW
18872 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18873 return;
b99bd4ef
NC
18874 }
18875
c19d1205
ZW
18876 inst.instruction = opcode->avalue;
18877 if (opcode->tag == OT_unconditionalF)
eff0bc54 18878 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18879 else
18880 inst.instruction |= inst.cond << 28;
18881 inst.size = INSN_SIZE;
5be8be5d 18882 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18883 {
18884 it_fsm_pre_encode ();
18885 opcode->aencode ();
18886 it_fsm_post_encode ();
18887 }
ee065d83 18888 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18889 on a hypothetical non-thumb v5 core. */
845b51d6 18890 if (is_bx)
e74cfd16 18891 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18892 else
e74cfd16
PB
18893 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18894 *opcode->avariant);
88714cb8
DG
18895
18896 check_neon_suffixes;
18897
cd000bff 18898 if (!inst.error)
c877a2f2
NC
18899 {
18900 mapping_state (MAP_ARM);
18901 }
b99bd4ef 18902 }
3e9e4fcf
JB
18903 else
18904 {
18905 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18906 "-- `%s'"), str);
18907 return;
18908 }
c19d1205
ZW
18909 output_inst (str);
18910}
b99bd4ef 18911
e07e6e58
NC
18912static void
18913check_it_blocks_finished (void)
18914{
18915#ifdef OBJ_ELF
18916 asection *sect;
18917
18918 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18919 if (seg_info (sect)->tc_segment_info_data.current_it.state
18920 == MANUAL_IT_BLOCK)
18921 {
18922 as_warn (_("section '%s' finished with an open IT block."),
18923 sect->name);
18924 }
18925#else
18926 if (now_it.state == MANUAL_IT_BLOCK)
18927 as_warn (_("file finished with an open IT block."));
18928#endif
18929}
18930
c19d1205
ZW
18931/* Various frobbings of labels and their addresses. */
18932
18933void
18934arm_start_line_hook (void)
18935{
18936 last_label_seen = NULL;
b99bd4ef
NC
18937}
18938
c19d1205
ZW
18939void
18940arm_frob_label (symbolS * sym)
b99bd4ef 18941{
c19d1205 18942 last_label_seen = sym;
b99bd4ef 18943
c19d1205 18944 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18945
c19d1205
ZW
18946#if defined OBJ_COFF || defined OBJ_ELF
18947 ARM_SET_INTERWORK (sym, support_interwork);
18948#endif
b99bd4ef 18949
e07e6e58
NC
18950 force_automatic_it_block_close ();
18951
5f4273c7 18952 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18953 as Thumb functions. This is because these labels, whilst
18954 they exist inside Thumb code, are not the entry points for
18955 possible ARM->Thumb calls. Also, these labels can be used
18956 as part of a computed goto or switch statement. eg gcc
18957 can generate code that looks like this:
b99bd4ef 18958
c19d1205
ZW
18959 ldr r2, [pc, .Laaa]
18960 lsl r3, r3, #2
18961 ldr r2, [r3, r2]
18962 mov pc, r2
b99bd4ef 18963
c19d1205
ZW
18964 .Lbbb: .word .Lxxx
18965 .Lccc: .word .Lyyy
18966 ..etc...
18967 .Laaa: .word Lbbb
b99bd4ef 18968
c19d1205
ZW
18969 The first instruction loads the address of the jump table.
18970 The second instruction converts a table index into a byte offset.
18971 The third instruction gets the jump address out of the table.
18972 The fourth instruction performs the jump.
b99bd4ef 18973
c19d1205
ZW
18974 If the address stored at .Laaa is that of a symbol which has the
18975 Thumb_Func bit set, then the linker will arrange for this address
18976 to have the bottom bit set, which in turn would mean that the
18977 address computation performed by the third instruction would end
18978 up with the bottom bit set. Since the ARM is capable of unaligned
18979 word loads, the instruction would then load the incorrect address
18980 out of the jump table, and chaos would ensue. */
18981 if (label_is_thumb_function_name
18982 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18983 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18984 {
c19d1205
ZW
18985 /* When the address of a Thumb function is taken the bottom
18986 bit of that address should be set. This will allow
18987 interworking between Arm and Thumb functions to work
18988 correctly. */
b99bd4ef 18989
c19d1205 18990 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18991
c19d1205 18992 label_is_thumb_function_name = FALSE;
b99bd4ef 18993 }
07a53e5c 18994
07a53e5c 18995 dwarf2_emit_label (sym);
b99bd4ef
NC
18996}
18997
c921be7d 18998bfd_boolean
c19d1205 18999arm_data_in_code (void)
b99bd4ef 19000{
c19d1205 19001 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 19002 {
c19d1205
ZW
19003 *input_line_pointer = '/';
19004 input_line_pointer += 5;
19005 *input_line_pointer = 0;
c921be7d 19006 return TRUE;
b99bd4ef
NC
19007 }
19008
c921be7d 19009 return FALSE;
b99bd4ef
NC
19010}
19011
c19d1205
ZW
19012char *
19013arm_canonicalize_symbol_name (char * name)
b99bd4ef 19014{
c19d1205 19015 int len;
b99bd4ef 19016
c19d1205
ZW
19017 if (thumb_mode && (len = strlen (name)) > 5
19018 && streq (name + len - 5, "/data"))
19019 *(name + len - 5) = 0;
b99bd4ef 19020
c19d1205 19021 return name;
b99bd4ef 19022}
c19d1205
ZW
19023\f
19024/* Table of all register names defined by default. The user can
19025 define additional names with .req. Note that all register names
19026 should appear in both upper and lowercase variants. Some registers
19027 also have mixed-case names. */
b99bd4ef 19028
dcbf9037 19029#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 19030#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 19031#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
19032#define REGSET(p,t) \
19033 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
19034 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
19035 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
19036 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
19037#define REGSETH(p,t) \
19038 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
19039 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
19040 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
19041 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
19042#define REGSET2(p,t) \
19043 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
19044 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
19045 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
19046 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
19047#define SPLRBANK(base,bank,t) \
19048 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
19049 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
19050 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
19051 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
19052 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
19053 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 19054
c19d1205 19055static const struct reg_entry reg_names[] =
7ed4c4c5 19056{
c19d1205
ZW
19057 /* ARM integer registers. */
19058 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 19059
c19d1205
ZW
19060 /* ATPCS synonyms. */
19061 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
19062 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
19063 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 19064
c19d1205
ZW
19065 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
19066 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
19067 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 19068
c19d1205
ZW
19069 /* Well-known aliases. */
19070 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
19071 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
19072
19073 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
19074 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
19075
19076 /* Coprocessor numbers. */
19077 REGSET(p, CP), REGSET(P, CP),
19078
19079 /* Coprocessor register numbers. The "cr" variants are for backward
19080 compatibility. */
19081 REGSET(c, CN), REGSET(C, CN),
19082 REGSET(cr, CN), REGSET(CR, CN),
19083
90ec0d68
MGD
19084 /* ARM banked registers. */
19085 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
19086 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
19087 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
19088 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
19089 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
19090 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
19091 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
19092
19093 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
19094 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
19095 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
19096 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
19097 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 19098 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
19099 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
19100 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
19101
19102 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
19103 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
19104 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
19105 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
19106 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
19107 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
19108 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 19109 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
19110 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
19111
c19d1205
ZW
19112 /* FPA registers. */
19113 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
19114 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
19115
19116 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
19117 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
19118
19119 /* VFP SP registers. */
5287ad62
JB
19120 REGSET(s,VFS), REGSET(S,VFS),
19121 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
19122
19123 /* VFP DP Registers. */
5287ad62
JB
19124 REGSET(d,VFD), REGSET(D,VFD),
19125 /* Extra Neon DP registers. */
19126 REGSETH(d,VFD), REGSETH(D,VFD),
19127
19128 /* Neon QP registers. */
19129 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
19130
19131 /* VFP control registers. */
19132 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
19133 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
19134 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
19135 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
19136 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
19137 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 19138 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
c19d1205
ZW
19139
19140 /* Maverick DSP coprocessor registers. */
19141 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
19142 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
19143
19144 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
19145 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
19146 REGDEF(dspsc,0,DSPSC),
19147
19148 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
19149 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
19150 REGDEF(DSPSC,0,DSPSC),
19151
19152 /* iWMMXt data registers - p0, c0-15. */
19153 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
19154
19155 /* iWMMXt control registers - p1, c0-3. */
19156 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
19157 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
19158 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
19159 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
19160
19161 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
19162 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
19163 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
19164 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
19165 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
19166
19167 /* XScale accumulator registers. */
19168 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
19169};
19170#undef REGDEF
19171#undef REGNUM
19172#undef REGSET
7ed4c4c5 19173
c19d1205
ZW
19174/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
19175 within psr_required_here. */
19176static const struct asm_psr psrs[] =
19177{
19178 /* Backward compatibility notation. Note that "all" is no longer
19179 truly all possible PSR bits. */
19180 {"all", PSR_c | PSR_f},
19181 {"flg", PSR_f},
19182 {"ctl", PSR_c},
19183
19184 /* Individual flags. */
19185 {"f", PSR_f},
19186 {"c", PSR_c},
19187 {"x", PSR_x},
19188 {"s", PSR_s},
59b42a0d 19189
c19d1205
ZW
19190 /* Combinations of flags. */
19191 {"fs", PSR_f | PSR_s},
19192 {"fx", PSR_f | PSR_x},
19193 {"fc", PSR_f | PSR_c},
19194 {"sf", PSR_s | PSR_f},
19195 {"sx", PSR_s | PSR_x},
19196 {"sc", PSR_s | PSR_c},
19197 {"xf", PSR_x | PSR_f},
19198 {"xs", PSR_x | PSR_s},
19199 {"xc", PSR_x | PSR_c},
19200 {"cf", PSR_c | PSR_f},
19201 {"cs", PSR_c | PSR_s},
19202 {"cx", PSR_c | PSR_x},
19203 {"fsx", PSR_f | PSR_s | PSR_x},
19204 {"fsc", PSR_f | PSR_s | PSR_c},
19205 {"fxs", PSR_f | PSR_x | PSR_s},
19206 {"fxc", PSR_f | PSR_x | PSR_c},
19207 {"fcs", PSR_f | PSR_c | PSR_s},
19208 {"fcx", PSR_f | PSR_c | PSR_x},
19209 {"sfx", PSR_s | PSR_f | PSR_x},
19210 {"sfc", PSR_s | PSR_f | PSR_c},
19211 {"sxf", PSR_s | PSR_x | PSR_f},
19212 {"sxc", PSR_s | PSR_x | PSR_c},
19213 {"scf", PSR_s | PSR_c | PSR_f},
19214 {"scx", PSR_s | PSR_c | PSR_x},
19215 {"xfs", PSR_x | PSR_f | PSR_s},
19216 {"xfc", PSR_x | PSR_f | PSR_c},
19217 {"xsf", PSR_x | PSR_s | PSR_f},
19218 {"xsc", PSR_x | PSR_s | PSR_c},
19219 {"xcf", PSR_x | PSR_c | PSR_f},
19220 {"xcs", PSR_x | PSR_c | PSR_s},
19221 {"cfs", PSR_c | PSR_f | PSR_s},
19222 {"cfx", PSR_c | PSR_f | PSR_x},
19223 {"csf", PSR_c | PSR_s | PSR_f},
19224 {"csx", PSR_c | PSR_s | PSR_x},
19225 {"cxf", PSR_c | PSR_x | PSR_f},
19226 {"cxs", PSR_c | PSR_x | PSR_s},
19227 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
19228 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
19229 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
19230 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
19231 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
19232 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
19233 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
19234 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
19235 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
19236 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
19237 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
19238 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
19239 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
19240 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
19241 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
19242 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
19243 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
19244 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
19245 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
19246 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
19247 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
19248 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
19249 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
19250 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
19251};
19252
62b3e311
PB
19253/* Table of V7M psr names. */
19254static const struct asm_psr v7m_psrs[] =
19255{
1a336194
TP
19256 {"apsr", 0x0 }, {"APSR", 0x0 },
19257 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
19258 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
19259 {"psr", 0x3 }, {"PSR", 0x3 },
19260 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
19261 {"ipsr", 0x5 }, {"IPSR", 0x5 },
19262 {"epsr", 0x6 }, {"EPSR", 0x6 },
19263 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
19264 {"msp", 0x8 }, {"MSP", 0x8 },
19265 {"psp", 0x9 }, {"PSP", 0x9 },
19266 {"msplim", 0xa }, {"MSPLIM", 0xa },
19267 {"psplim", 0xb }, {"PSPLIM", 0xb },
19268 {"primask", 0x10}, {"PRIMASK", 0x10},
19269 {"basepri", 0x11}, {"BASEPRI", 0x11},
19270 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
19271 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
19272 {"control", 0x14}, {"CONTROL", 0x14},
19273 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
19274 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
19275 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
19276 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
19277 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
19278 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
19279 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
19280 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
19281 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
19282};
19283
c19d1205
ZW
19284/* Table of all shift-in-operand names. */
19285static const struct asm_shift_name shift_names [] =
b99bd4ef 19286{
c19d1205
ZW
19287 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
19288 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
19289 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
19290 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
19291 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
19292 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
19293};
b99bd4ef 19294
c19d1205
ZW
19295/* Table of all explicit relocation names. */
19296#ifdef OBJ_ELF
19297static struct reloc_entry reloc_names[] =
19298{
19299 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
19300 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
19301 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
19302 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
19303 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
19304 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
19305 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
19306 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
19307 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
19308 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 19309 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
19310 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
19311 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 19312 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 19313 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 19314 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 19315 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
188fd7ae
CL
19316 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
19317 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
19318 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
19319 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
19320 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
19321 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
5c5a4843
CL
19322 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
19323 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
19324 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
19325 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
c19d1205
ZW
19326};
19327#endif
b99bd4ef 19328
c19d1205
ZW
19329/* Table of all conditional affixes. 0xF is not defined as a condition code. */
19330static const struct asm_cond conds[] =
19331{
19332 {"eq", 0x0},
19333 {"ne", 0x1},
19334 {"cs", 0x2}, {"hs", 0x2},
19335 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
19336 {"mi", 0x4},
19337 {"pl", 0x5},
19338 {"vs", 0x6},
19339 {"vc", 0x7},
19340 {"hi", 0x8},
19341 {"ls", 0x9},
19342 {"ge", 0xa},
19343 {"lt", 0xb},
19344 {"gt", 0xc},
19345 {"le", 0xd},
19346 {"al", 0xe}
19347};
bfae80f2 19348
e797f7e0 19349#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
19350 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19351 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 19352
62b3e311
PB
19353static struct asm_barrier_opt barrier_opt_names[] =
19354{
e797f7e0
MGD
19355 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19356 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19357 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19358 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19359 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19360 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19361 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19362 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19363 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19364 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19365 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19366 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19367 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19368 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19369 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19370 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
19371};
19372
e797f7e0
MGD
19373#undef UL_BARRIER
19374
c19d1205
ZW
19375/* Table of ARM-format instructions. */
19376
19377/* Macros for gluing together operand strings. N.B. In all cases
19378 other than OPS0, the trailing OP_stop comes from default
19379 zero-initialization of the unspecified elements of the array. */
19380#define OPS0() { OP_stop, }
19381#define OPS1(a) { OP_##a, }
19382#define OPS2(a,b) { OP_##a,OP_##b, }
19383#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19384#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19385#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19386#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19387
5be8be5d
DG
19388/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19389 This is useful when mixing operands for ARM and THUMB, i.e. using the
19390 MIX_ARM_THUMB_OPERANDS macro.
19391 In order to use these macros, prefix the number of operands with _
19392 e.g. _3. */
19393#define OPS_1(a) { a, }
19394#define OPS_2(a,b) { a,b, }
19395#define OPS_3(a,b,c) { a,b,c, }
19396#define OPS_4(a,b,c,d) { a,b,c,d, }
19397#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19398#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19399
c19d1205
ZW
19400/* These macros abstract out the exact format of the mnemonic table and
19401 save some repeated characters. */
19402
19403/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19404#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19405 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 19406 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19407
19408/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19409 a T_MNEM_xyz enumerator. */
19410#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19411 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19412#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19413 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
19414
19415/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19416 infix after the third character. */
19417#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 19418 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 19419 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 19420#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 19421 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 19422 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19423#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19424 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 19425#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19426 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19427#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19428 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 19429#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19430 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 19431
c19d1205 19432/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
19433 field is still 0xE. Many of the Thumb variants can be executed
19434 conditionally, so this is checked separately. */
c19d1205 19435#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19436 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19437 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19438
dd5181d5
KT
19439/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19440 Used by mnemonics that have very minimal differences in the encoding for
19441 ARM and Thumb variants and can be handled in a common function. */
19442#define TUEc(mnem, op, top, nops, ops, en) \
19443 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19444 THUMB_VARIANT, do_##en, do_##en }
19445
c19d1205
ZW
19446/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19447 condition code field. */
19448#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 19449 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19450 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19451
19452/* ARM-only variants of all the above. */
6a86118a 19453#define CE(mnem, op, nops, ops, ae) \
21d799b5 19454 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
19455
19456#define C3(mnem, op, nops, ops, ae) \
19457 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19458
cf3cf39d
TP
19459/* Thumb-only variants of TCE and TUE. */
19460#define ToC(mnem, top, nops, ops, te) \
19461 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
19462 do_##te }
cf3cf39d
TP
19463
19464#define ToU(mnem, top, nops, ops, te) \
19465 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
19466 NULL, do_##te }
cf3cf39d 19467
e3cb604e
PB
19468/* Legacy mnemonics that always have conditional infix after the third
19469 character. */
19470#define CL(mnem, op, nops, ops, ae) \
21d799b5 19471 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19472 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19473
8f06b2d8
PB
19474/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19475#define cCE(mnem, op, nops, ops, ae) \
21d799b5 19476 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19477
e3cb604e
PB
19478/* Legacy coprocessor instructions where conditional infix and conditional
19479 suffix are ambiguous. For consistency this includes all FPA instructions,
19480 not just the potentially ambiguous ones. */
19481#define cCL(mnem, op, nops, ops, ae) \
21d799b5 19482 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19483 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19484
19485/* Coprocessor, takes either a suffix or a position-3 infix
19486 (for an FPA corner case). */
19487#define C3E(mnem, op, nops, ops, ae) \
21d799b5 19488 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19489 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19490
6a86118a 19491#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19492 { m1 #m2 m3, OPS##nops ops, \
19493 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19494 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19495
19496#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19497 xCM_ (m1, , m2, op, nops, ops, ae), \
19498 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19499 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19500 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19501 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19502 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19503 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19504 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19505 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19506 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19507 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19508 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19509 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19510 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19511 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19512 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19513 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19514 xCM_ (m1, le, m2, op, nops, ops, ae), \
19515 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19516
19517#define UE(mnem, op, nops, ops, ae) \
19518 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19519
19520#define UF(mnem, op, nops, ops, ae) \
19521 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19522
5287ad62
JB
19523/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19524 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19525 use the same encoding function for each. */
19526#define NUF(mnem, op, nops, ops, enc) \
19527 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19528 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19529
19530/* Neon data processing, version which indirects through neon_enc_tab for
19531 the various overloaded versions of opcodes. */
19532#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19533 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19534 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19535
19536/* Neon insn with conditional suffix for the ARM version, non-overloaded
19537 version. */
037e8744
JB
19538#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19539 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19540 THUMB_VARIANT, do_##enc, do_##enc }
19541
037e8744 19542#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19543 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19544
19545#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19546 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19547
5287ad62 19548/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19549#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19550 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19551 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19552
037e8744 19553#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19554 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19555
19556#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19557 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19558
c19d1205
ZW
19559#define do_0 0
19560
c19d1205 19561static const struct asm_opcode insns[] =
bfae80f2 19562{
74db7efb
NC
19563#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19564#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19565 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19566 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19567 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19568 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19569 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19570 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19571 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19572 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19573 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19574 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19575 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19576 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19577 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19578 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19579 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19580 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19581
19582 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19583 for setting PSR flag bits. They are obsolete in V6 and do not
19584 have Thumb equivalents. */
21d799b5
NC
19585 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19586 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19587 CL("tstp", 110f000, 2, (RR, SH), cmp),
19588 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19589 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19590 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19591 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19592 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19593 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19594
19595 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19596 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19597 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19598 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19599
19600 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19601 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19602 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19603 OP_RRnpc),
19604 OP_ADDRGLDR),ldst, t_ldst),
19605 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19606
19607 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19608 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19609 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19610 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19611 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19612 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19613
21d799b5
NC
19614 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19615 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19616
c19d1205 19617 /* Pseudo ops. */
21d799b5 19618 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19619 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19620 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19621 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19622
19623 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19624 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19625 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19626 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19627 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19628 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19629 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19630 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19631 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19632 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19633 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19634 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19635 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19636
16a4cf17 19637 /* These may simplify to neg. */
21d799b5
NC
19638 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19639 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19640
173205ca
TP
19641#undef THUMB_VARIANT
19642#define THUMB_VARIANT & arm_ext_os
19643
19644 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19645 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19646
c921be7d
NC
19647#undef THUMB_VARIANT
19648#define THUMB_VARIANT & arm_ext_v6
19649
21d799b5 19650 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19651
19652 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19653#undef THUMB_VARIANT
19654#define THUMB_VARIANT & arm_ext_v6t2
19655
21d799b5
NC
19656 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19657 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19658 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19659
5be8be5d
DG
19660 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19661 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19662 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19663 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19664
21d799b5
NC
19665 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19666 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19667
21d799b5
NC
19668 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19669 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19670
19671 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19672 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19673 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19674
19675 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19676 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19677 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19678 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19679 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19680 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19681 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19682 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19683
c921be7d
NC
19684#undef ARM_VARIANT
19685#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19686#undef THUMB_VARIANT
19687#define THUMB_VARIANT & arm_ext_v4t
19688
21d799b5
NC
19689 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19690 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19691
c921be7d
NC
19692#undef THUMB_VARIANT
19693#define THUMB_VARIANT & arm_ext_v6t2
19694
21d799b5 19695 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19696 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19697
19698 /* Generic coprocessor instructions. */
21d799b5
NC
19699 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19700 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19701 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19702 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19703 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19704 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19705 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19706
c921be7d
NC
19707#undef ARM_VARIANT
19708#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19709
21d799b5 19710 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19711 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19712
c921be7d
NC
19713#undef ARM_VARIANT
19714#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19715#undef THUMB_VARIANT
19716#define THUMB_VARIANT & arm_ext_msr
19717
d2cd1205
JB
19718 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19719 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19720
c921be7d
NC
19721#undef ARM_VARIANT
19722#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19723#undef THUMB_VARIANT
19724#define THUMB_VARIANT & arm_ext_v6t2
19725
21d799b5
NC
19726 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19727 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19728 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19729 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19730 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19731 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19732 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19733 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19734
c921be7d
NC
19735#undef ARM_VARIANT
19736#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19737#undef THUMB_VARIANT
19738#define THUMB_VARIANT & arm_ext_v4t
19739
5be8be5d
DG
19740 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19741 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19742 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19743 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19744 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19745 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19746
c921be7d
NC
19747#undef ARM_VARIANT
19748#define ARM_VARIANT & arm_ext_v4t_5
19749
c19d1205
ZW
19750 /* ARM Architecture 4T. */
19751 /* Note: bx (and blx) are required on V5, even if the processor does
19752 not support Thumb. */
21d799b5 19753 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19754
c921be7d
NC
19755#undef ARM_VARIANT
19756#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19757#undef THUMB_VARIANT
19758#define THUMB_VARIANT & arm_ext_v5t
19759
c19d1205
ZW
19760 /* Note: blx has 2 variants; the .value coded here is for
19761 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19762 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19763 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19764
c921be7d
NC
19765#undef THUMB_VARIANT
19766#define THUMB_VARIANT & arm_ext_v6t2
19767
21d799b5
NC
19768 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19769 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19770 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19771 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19772 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19773 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19774 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19775 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19776
c921be7d 19777#undef ARM_VARIANT
74db7efb
NC
19778#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19779#undef THUMB_VARIANT
19780#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19781
21d799b5
NC
19782 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19783 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19784 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19785 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19786
21d799b5
NC
19787 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19788 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19789
21d799b5
NC
19790 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19791 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19792 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19793 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19794
21d799b5
NC
19795 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19796 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19797 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19798 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19799
21d799b5
NC
19800 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19801 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19802
03ee1b7f
NC
19803 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19804 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19805 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19806 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19807
c921be7d 19808#undef ARM_VARIANT
74db7efb
NC
19809#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19810#undef THUMB_VARIANT
19811#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19812
21d799b5 19813 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19814 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19815 ldrd, t_ldstd),
19816 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19817 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19818
21d799b5
NC
19819 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19820 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19821
c921be7d
NC
19822#undef ARM_VARIANT
19823#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19824
21d799b5 19825 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19826
c921be7d
NC
19827#undef ARM_VARIANT
19828#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19829#undef THUMB_VARIANT
19830#define THUMB_VARIANT & arm_ext_v6
19831
21d799b5
NC
19832 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19833 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19834 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19835 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19836 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19837 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19838 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19839 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19840 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19841 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19842
c921be7d 19843#undef THUMB_VARIANT
ff8646ee 19844#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19845
5be8be5d
DG
19846 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19847 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19848 strex, t_strex),
ff8646ee
TP
19849#undef THUMB_VARIANT
19850#define THUMB_VARIANT & arm_ext_v6t2
19851
21d799b5
NC
19852 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19853 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19854
21d799b5
NC
19855 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19856 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19857
9e3c6df6 19858/* ARM V6 not included in V7M. */
c921be7d
NC
19859#undef THUMB_VARIANT
19860#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19861 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19862 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19863 UF(rfeib, 9900a00, 1, (RRw), rfe),
19864 UF(rfeda, 8100a00, 1, (RRw), rfe),
19865 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19866 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19867 UF(rfefa, 8100a00, 1, (RRw), rfe),
19868 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19869 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19870 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19871 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19872 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19873 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19874 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19875 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19876 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19877 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19878 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19879 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19880
9e3c6df6
PB
19881/* ARM V6 not included in V7M (eg. integer SIMD). */
19882#undef THUMB_VARIANT
19883#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19884 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19885 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19886 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19887 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19888 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19889 /* Old name for QASX. */
74db7efb 19890 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19891 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19892 /* Old name for QSAX. */
74db7efb 19893 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19894 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19895 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19896 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19897 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19898 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19899 /* Old name for SASX. */
74db7efb 19900 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19901 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19902 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19903 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19904 /* Old name for SHASX. */
21d799b5 19905 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19906 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19907 /* Old name for SHSAX. */
21d799b5
NC
19908 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19909 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19910 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19911 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19912 /* Old name for SSAX. */
74db7efb 19913 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19914 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19915 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19916 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19917 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19918 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19919 /* Old name for UASX. */
74db7efb 19920 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19921 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19922 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19923 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19924 /* Old name for UHASX. */
21d799b5
NC
19925 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19926 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19927 /* Old name for UHSAX. */
21d799b5
NC
19928 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19929 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19930 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19931 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19932 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19933 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19934 /* Old name for UQASX. */
21d799b5
NC
19935 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19936 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19937 /* Old name for UQSAX. */
21d799b5
NC
19938 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19939 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19940 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19941 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19942 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19943 /* Old name for USAX. */
74db7efb 19944 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19945 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19946 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19947 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19948 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19949 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19950 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19951 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19952 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19953 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19954 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19955 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19956 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19957 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19958 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19959 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19960 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19961 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19962 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19963 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19964 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19965 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19966 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19967 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19968 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19969 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19970 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19971 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19972 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19973 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19974 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19975 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19976 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19977 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19978
c921be7d
NC
19979#undef ARM_VARIANT
19980#define ARM_VARIANT & arm_ext_v6k
19981#undef THUMB_VARIANT
19982#define THUMB_VARIANT & arm_ext_v6k
19983
21d799b5
NC
19984 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19985 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19986 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19987 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19988
c921be7d
NC
19989#undef THUMB_VARIANT
19990#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19991 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19992 ldrexd, t_ldrexd),
19993 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19994 RRnpcb), strexd, t_strexd),
ebdca51a 19995
c921be7d 19996#undef THUMB_VARIANT
ff8646ee 19997#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19998 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19999 rd_rn, rd_rn),
20000 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
20001 rd_rn, rd_rn),
20002 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 20003 strex, t_strexbh),
5be8be5d 20004 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 20005 strex, t_strexbh),
21d799b5 20006 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 20007
c921be7d 20008#undef ARM_VARIANT
f4c65163 20009#define ARM_VARIANT & arm_ext_sec
74db7efb 20010#undef THUMB_VARIANT
f4c65163 20011#define THUMB_VARIANT & arm_ext_sec
c921be7d 20012
21d799b5 20013 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 20014
90ec0d68
MGD
20015#undef ARM_VARIANT
20016#define ARM_VARIANT & arm_ext_virt
20017#undef THUMB_VARIANT
20018#define THUMB_VARIANT & arm_ext_virt
20019
20020 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
20021 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
20022
ddfded2f
MW
20023#undef ARM_VARIANT
20024#define ARM_VARIANT & arm_ext_pan
20025#undef THUMB_VARIANT
20026#define THUMB_VARIANT & arm_ext_pan
20027
20028 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
20029
c921be7d 20030#undef ARM_VARIANT
74db7efb 20031#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
20032#undef THUMB_VARIANT
20033#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 20034
21d799b5
NC
20035 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
20036 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
20037 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
20038 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 20039
21d799b5 20040 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 20041 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 20042
5be8be5d
DG
20043 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20044 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20045 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20046 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 20047
91d8b670
JG
20048#undef ARM_VARIANT
20049#define ARM_VARIANT & arm_ext_v3
20050#undef THUMB_VARIANT
20051#define THUMB_VARIANT & arm_ext_v6t2
20052
20053 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
20054
20055#undef ARM_VARIANT
20056#define ARM_VARIANT & arm_ext_v6t2
ff8646ee
TP
20057#undef THUMB_VARIANT
20058#define THUMB_VARIANT & arm_ext_v6t2_v8m
20059 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
20060 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
20061
bf3eeda7 20062 /* Thumb-only instructions. */
74db7efb 20063#undef ARM_VARIANT
bf3eeda7
NS
20064#define ARM_VARIANT NULL
20065 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
20066 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
20067
20068 /* ARM does not really have an IT instruction, so always allow it.
20069 The opcode is copied from Thumb in order to allow warnings in
20070 -mimplicit-it=[never | arm] modes. */
20071#undef ARM_VARIANT
20072#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
20073#undef THUMB_VARIANT
20074#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 20075
21d799b5
NC
20076 TUE("it", bf08, bf08, 1, (COND), it, t_it),
20077 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
20078 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
20079 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
20080 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
20081 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
20082 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
20083 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
20084 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
20085 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
20086 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
20087 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
20088 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
20089 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
20090 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 20091 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
20092 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
20093 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 20094
92e90b6e 20095 /* Thumb2 only instructions. */
c921be7d
NC
20096#undef ARM_VARIANT
20097#define ARM_VARIANT NULL
92e90b6e 20098
21d799b5
NC
20099 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20100 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20101 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
20102 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
20103 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
20104 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 20105
eea54501
MGD
20106 /* Hardware division instructions. */
20107#undef ARM_VARIANT
20108#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
20109#undef THUMB_VARIANT
20110#define THUMB_VARIANT & arm_ext_div
20111
eea54501
MGD
20112 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
20113 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 20114
7e806470 20115 /* ARM V6M/V7 instructions. */
c921be7d
NC
20116#undef ARM_VARIANT
20117#define ARM_VARIANT & arm_ext_barrier
20118#undef THUMB_VARIANT
20119#define THUMB_VARIANT & arm_ext_barrier
20120
ccb84d65
JB
20121 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
20122 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
20123 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 20124
62b3e311 20125 /* ARM V7 instructions. */
c921be7d
NC
20126#undef ARM_VARIANT
20127#define ARM_VARIANT & arm_ext_v7
20128#undef THUMB_VARIANT
20129#define THUMB_VARIANT & arm_ext_v7
20130
21d799b5
NC
20131 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
20132 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 20133
74db7efb 20134#undef ARM_VARIANT
60e5ef9f 20135#define ARM_VARIANT & arm_ext_mp
74db7efb 20136#undef THUMB_VARIANT
60e5ef9f
MGD
20137#define THUMB_VARIANT & arm_ext_mp
20138
20139 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
20140
53c4b28b
MGD
20141 /* AArchv8 instructions. */
20142#undef ARM_VARIANT
20143#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
20144
20145/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 20146#undef THUMB_VARIANT
4ed7ed8d 20147#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 20148
4ed7ed8d
TP
20149 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20150 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20151 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20152 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20153 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20154 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 20155 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
20156 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
20157 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20158 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
20159 stlex, t_stlex),
4b8c8c02
RE
20160 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
20161 stlex, t_stlex),
20162 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
20163 stlex, t_stlex),
4ed7ed8d
TP
20164#undef THUMB_VARIANT
20165#define THUMB_VARIANT & arm_ext_v8
53c4b28b 20166
4ed7ed8d
TP
20167 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
20168 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
20169 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
20170 ldrexd, t_ldrexd),
20171 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
20172 strexd, t_strexd),
8884b720 20173 /* ARMv8 T32 only. */
74db7efb 20174#undef ARM_VARIANT
b79f7053
MGD
20175#define ARM_VARIANT NULL
20176 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
20177 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
20178 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
20179
33399f07
MGD
20180 /* FP for ARMv8. */
20181#undef ARM_VARIANT
a715796b 20182#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 20183#undef THUMB_VARIANT
a715796b 20184#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
20185
20186 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
20187 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
20188 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
20189 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
20190 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
20191 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
20192 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
20193 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
20194 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
20195 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
20196 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
20197 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
20198 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
20199 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
20200 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
20201 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
20202 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 20203
91ff7894
MGD
20204 /* Crypto v1 extensions. */
20205#undef ARM_VARIANT
20206#define ARM_VARIANT & fpu_crypto_ext_armv8
20207#undef THUMB_VARIANT
20208#define THUMB_VARIANT & fpu_crypto_ext_armv8
20209
20210 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
20211 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
20212 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
20213 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
20214 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
20215 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
20216 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
20217 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
20218 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
20219 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
20220 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
20221 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
20222 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
20223 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 20224
dd5181d5 20225#undef ARM_VARIANT
74db7efb 20226#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
20227#undef THUMB_VARIANT
20228#define THUMB_VARIANT & crc_ext_armv8
20229 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
20230 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
20231 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
20232 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
20233 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
20234 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
20235
105bde57
MW
20236 /* ARMv8.2 RAS extension. */
20237#undef ARM_VARIANT
4d1464f2 20238#define ARM_VARIANT & arm_ext_ras
105bde57 20239#undef THUMB_VARIANT
4d1464f2 20240#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
20241 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
20242
49e8a725
SN
20243#undef ARM_VARIANT
20244#define ARM_VARIANT & arm_ext_v8_3
20245#undef THUMB_VARIANT
20246#define THUMB_VARIANT & arm_ext_v8_3
20247 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
20248 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
20249 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 20250
c604a79a
JW
20251#undef ARM_VARIANT
20252#define ARM_VARIANT & fpu_neon_ext_dotprod
20253#undef THUMB_VARIANT
20254#define THUMB_VARIANT & fpu_neon_ext_dotprod
20255 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
20256 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
20257
c921be7d
NC
20258#undef ARM_VARIANT
20259#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
20260#undef THUMB_VARIANT
20261#define THUMB_VARIANT NULL
c921be7d 20262
21d799b5
NC
20263 cCE("wfs", e200110, 1, (RR), rd),
20264 cCE("rfs", e300110, 1, (RR), rd),
20265 cCE("wfc", e400110, 1, (RR), rd),
20266 cCE("rfc", e500110, 1, (RR), rd),
20267
20268 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
20269 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
20270 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
20271 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
20272
20273 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
20274 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
20275 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
20276 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
20277
20278 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
20279 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
20280 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
20281 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
20282 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
20283 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
20284 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
20285 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
20286 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
20287 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
20288 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
20289 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
20290
20291 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
20292 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
20293 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
20294 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
20295 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
20296 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
20297 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
20298 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
20299 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
20300 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
20301 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
20302 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
20303
20304 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
20305 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
20306 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
20307 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
20308 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
20309 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
20310 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
20311 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
20312 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
20313 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
20314 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
20315 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
20316
20317 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
20318 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
20319 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
20320 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
20321 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
20322 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
20323 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
20324 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
20325 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
20326 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
20327 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
20328 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
20329
20330 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
20331 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
20332 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
20333 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
20334 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
20335 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
20336 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
20337 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
20338 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
20339 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
20340 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
20341 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
20342
20343 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
20344 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
20345 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
20346 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
20347 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
20348 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
20349 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
20350 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
20351 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
20352 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
20353 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
20354 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
20355
20356 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
20357 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
20358 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
20359 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
20360 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
20361 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
20362 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
20363 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
20364 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
20365 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
20366 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
20367 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
20368
20369 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
20370 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20371 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20372 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20373 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20374 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20375 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20376 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20377 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20378 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20379 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20380 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20381
20382 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20383 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20384 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20385 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20386 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20387 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20388 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20389 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20390 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20391 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20392 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20393 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20394
20395 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20396 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20397 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20398 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20399 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20400 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20401 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20402 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20403 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20404 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20405 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20406 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20407
20408 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20409 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20410 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20411 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20412 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20413 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20414 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20415 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20416 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20417 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20418 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20419 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20420
20421 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20422 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20423 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20424 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20425 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20426 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20427 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20428 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20429 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20430 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20431 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20432 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20433
20434 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20435 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20436 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20437 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20438 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20439 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20440 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20441 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20442 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20443 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20444 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20445 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20446
20447 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20448 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20449 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20450 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20451 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20452 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20453 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20454 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20455 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20456 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20457 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20458 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20459
20460 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20461 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20462 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20463 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20464 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20465 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20466 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20467 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20468 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20469 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20470 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20471 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20472
20473 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20474 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20475 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20476 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20477 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20478 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20479 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20480 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20481 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20482 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20483 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20484 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20485
20486 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20487 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20488 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20489 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20490 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20491 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20492 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20493 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20494 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20495 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20496 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20497 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20498
20499 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20500 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20501 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20502 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20503 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20504 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20505 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20506 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20507 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20508 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20509 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20510 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20511
20512 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20513 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20514 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20515 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20516 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20517 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20518 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20519 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20520 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20521 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20522 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20523 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20524
20525 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20526 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20527 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20528 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20529 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20530 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20531 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20532 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20533 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20534 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20535 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20536 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20537
20538 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20539 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20540 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20541 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20542 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20543 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20544 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20545 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20546 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20547 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20548 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20549 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20550
20551 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20552 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20553 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20554 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20555 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20556 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20557 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20558 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20559 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20560 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20561 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20562 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20563
20564 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20565 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20566 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20567 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20568 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20569 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20570 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20571 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20572 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20573 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20574 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20575 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20576
20577 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20578 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20579 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20580 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20581 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20582 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20583 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20584 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20585 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20586 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20587 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20588 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20589
20590 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20591 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20592 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20593 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20594 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20595 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20596 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20597 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20598 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20599 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20600 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20601 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20602
20603 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20604 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20605 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20606 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20607 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20608 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20609 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20610 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20611 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20612 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20613 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20614 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20615
20616 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20617 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20618 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20619 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20620 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20621 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20622 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20623 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20624 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20625 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20626 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20627 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20628
20629 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20630 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20631 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20632 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20633 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20634 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20635 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20636 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20637 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20638 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20639 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20640 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20641
20642 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20643 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20644 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20645 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20646 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20647 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20648 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20649 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20650 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20651 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20652 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20653 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20654
20655 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20656 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20657 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20658 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20659
20660 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20661 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20662 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20663 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20664 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20665 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20666 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20667 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20668 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20669 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20670 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20671 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20672
c19d1205
ZW
20673 /* The implementation of the FIX instruction is broken on some
20674 assemblers, in that it accepts a precision specifier as well as a
20675 rounding specifier, despite the fact that this is meaningless.
20676 To be more compatible, we accept it as well, though of course it
20677 does not set any bits. */
21d799b5
NC
20678 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20679 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20680 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20681 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20682 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20683 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20684 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20685 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20686 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20687 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20688 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20689 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20690 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20691
c19d1205 20692 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20693#undef ARM_VARIANT
20694#define ARM_VARIANT & fpu_fpa_ext_v2
20695
21d799b5
NC
20696 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20697 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20698 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20699 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20700 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20701 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20702
c921be7d
NC
20703#undef ARM_VARIANT
20704#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20705
c19d1205 20706 /* Moves and type conversions. */
21d799b5
NC
20707 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20708 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20709 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20710 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20711 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20712 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20713 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20714 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20715 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20716 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20717 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20718 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20719 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20720 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20721
20722 /* Memory operations. */
21d799b5
NC
20723 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20724 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20725 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20726 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20727 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20728 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20729 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20730 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20731 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20732 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20733 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20734 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20735 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20736 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20737 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20738 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20739 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20740 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20741
c19d1205 20742 /* Monadic operations. */
21d799b5
NC
20743 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20744 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20745 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20746
20747 /* Dyadic operations. */
21d799b5
NC
20748 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20749 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20750 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20751 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20752 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20753 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20754 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20755 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20756 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20757
c19d1205 20758 /* Comparisons. */
21d799b5
NC
20759 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20760 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20761 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20762 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20763
62f3b8c8
PB
20764 /* Double precision load/store are still present on single precision
20765 implementations. */
20766 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20767 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20768 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20769 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20770 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20771 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20772 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20773 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20774 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20775 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20776
c921be7d
NC
20777#undef ARM_VARIANT
20778#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20779
c19d1205 20780 /* Moves and type conversions. */
21d799b5
NC
20781 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20782 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20783 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20784 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20785 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20786 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20787 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20788 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20789 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20790 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20791 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20792 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20793 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20794
c19d1205 20795 /* Monadic operations. */
21d799b5
NC
20796 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20797 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20798 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20799
20800 /* Dyadic operations. */
21d799b5
NC
20801 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20802 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20803 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20804 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20805 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20806 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20807 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20808 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20809 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20810
c19d1205 20811 /* Comparisons. */
21d799b5
NC
20812 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20813 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20814 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20815 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20816
c921be7d
NC
20817#undef ARM_VARIANT
20818#define ARM_VARIANT & fpu_vfp_ext_v2
20819
21d799b5
NC
20820 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20821 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20822 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20823 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20824
037e8744
JB
20825/* Instructions which may belong to either the Neon or VFP instruction sets.
20826 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20827#undef ARM_VARIANT
20828#define ARM_VARIANT & fpu_vfp_ext_v1xd
20829#undef THUMB_VARIANT
20830#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20831
037e8744
JB
20832 /* These mnemonics are unique to VFP. */
20833 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20834 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20835 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20836 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20837 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20838 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20839 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20840 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20841 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20842 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20843
20844 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20845 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20846 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20847 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20848
21d799b5
NC
20849 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20850 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20851
20852 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20853 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20854
55881a11
MGD
20855 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20856 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20857 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20858 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20859 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20860 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20861 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20862 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20863
5f1af56b 20864 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20865 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20866 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20867 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20868
037e8744
JB
20869
20870 /* NOTE: All VMOV encoding is special-cased! */
20871 NCE(vmov, 0, 1, (VMOV), neon_mov),
20872 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20873
9db2f6b4
RL
20874#undef ARM_VARIANT
20875#define ARM_VARIANT & arm_ext_fp16
20876#undef THUMB_VARIANT
20877#define THUMB_VARIANT & arm_ext_fp16
20878 /* New instructions added from v8.2, allowing the extraction and insertion of
20879 the upper 16 bits of a 32-bit vector register. */
20880 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20881 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20882
dec41383
JW
20883 /* New backported fma/fms instructions optional in v8.2. */
20884 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
20885 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
20886
c921be7d
NC
20887#undef THUMB_VARIANT
20888#define THUMB_VARIANT & fpu_neon_ext_v1
20889#undef ARM_VARIANT
20890#define ARM_VARIANT & fpu_neon_ext_v1
20891
5287ad62
JB
20892 /* Data processing with three registers of the same length. */
20893 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20894 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20895 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20896 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20897 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20898 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20899 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20900 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20901 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20902 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20903 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20904 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20905 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20906 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20907 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20908 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20909 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20910 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20911 /* If not immediate, fall back to neon_dyadic_i64_su.
20912 shl_imm should accept I8 I16 I32 I64,
20913 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20914 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20915 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20916 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20917 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20918 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20919 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20920 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20921 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20922 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20923 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20924 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20925 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20926 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20927 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20928 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20929 /* Bitfield ops, untyped. */
20930 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20931 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20932 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20933 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20934 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20935 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20936 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20937 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20938 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20939 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20940 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20941 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20942 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20943 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20944 back to neon_dyadic_if_su. */
21d799b5
NC
20945 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20946 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20947 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20948 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20949 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20950 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20951 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20952 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20953 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20954 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20955 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20956 /* As above, D registers only. */
21d799b5
NC
20957 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20958 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20959 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20960 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20961 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20962 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20963 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20964 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20965 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20966 /* vtst takes sizes 8, 16, 32. */
20967 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20968 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20969 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20970 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20971 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20972 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20973 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20974 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20975 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20976 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20977 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20978 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20979 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20980 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20981 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20982 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20983 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20984 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20985 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20986 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20987 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20988 /* ARM v8.1 extension. */
643afb90
MW
20989 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20990 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20991 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20992 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20993
20994 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20995 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20996 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20997
20998 /* Data processing with two registers and a shift amount. */
20999 /* Right shifts, and variants with rounding.
21000 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
21001 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
21002 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
21003 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
21004 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
21005 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
21006 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
21007 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
21008 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
21009 /* Shift and insert. Sizes accepted 8 16 32 64. */
21010 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
21011 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
21012 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
21013 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
21014 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
21015 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
21016 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
21017 /* Right shift immediate, saturating & narrowing, with rounding variants.
21018 Types accepted S16 S32 S64 U16 U32 U64. */
21019 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
21020 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
21021 /* As above, unsigned. Types accepted S16 S32 S64. */
21022 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
21023 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
21024 /* Right shift narrowing. Types accepted I16 I32 I64. */
21025 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
21026 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
21027 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 21028 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 21029 /* CVT with optional immediate for fixed-point variant. */
21d799b5 21030 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 21031
4316f0d2
DG
21032 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
21033 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
21034
21035 /* Data processing, three registers of different lengths. */
21036 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
21037 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
21038 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
21039 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
21040 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
21041 /* If not scalar, fall back to neon_dyadic_long.
21042 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
21043 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
21044 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
21045 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
21046 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
21047 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
21048 /* Dyadic, narrowing insns. Types I16 I32 I64. */
21049 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21050 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21051 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21052 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21053 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
21054 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21055 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21056 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
21057 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
21058 S16 S32 U16 U32. */
21d799b5 21059 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
21060
21061 /* Extract. Size 8. */
3b8d421e
PB
21062 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
21063 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
21064
21065 /* Two registers, miscellaneous. */
21066 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
21067 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
21068 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
21069 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
21070 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
21071 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
21072 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
21073 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
21074 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
21075 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
21076 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
21077 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
21078 /* VMOVN. Types I16 I32 I64. */
21d799b5 21079 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 21080 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 21081 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 21082 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 21083 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
21084 /* VZIP / VUZP. Sizes 8 16 32. */
21085 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
21086 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
21087 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
21088 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
21089 /* VQABS / VQNEG. Types S8 S16 S32. */
21090 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21091 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
21092 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21093 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
21094 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
21095 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
21096 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
21097 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
21098 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 21099 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
21100 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
21101 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
21102 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
21103 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
21104 /* VCLS. Types S8 S16 S32. */
21105 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
21106 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
21107 /* VCLZ. Types I8 I16 I32. */
21108 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
21109 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
21110 /* VCNT. Size 8. */
21111 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
21112 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
21113 /* Two address, untyped. */
21114 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
21115 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
21116 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
21117 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
21118 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
21119
21120 /* Table lookup. Size 8. */
21121 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21122 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21123
c921be7d
NC
21124#undef THUMB_VARIANT
21125#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
21126#undef ARM_VARIANT
21127#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
21128
5287ad62 21129 /* Neon element/structure load/store. */
21d799b5
NC
21130 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21131 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21132 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21133 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21134 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21135 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21136 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
21137 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 21138
c921be7d 21139#undef THUMB_VARIANT
74db7efb
NC
21140#define THUMB_VARIANT & fpu_vfp_ext_v3xd
21141#undef ARM_VARIANT
21142#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
21143 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
21144 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21145 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21146 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21147 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21148 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21149 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21150 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21151 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21152
74db7efb 21153#undef THUMB_VARIANT
c921be7d
NC
21154#define THUMB_VARIANT & fpu_vfp_ext_v3
21155#undef ARM_VARIANT
21156#define ARM_VARIANT & fpu_vfp_ext_v3
21157
21d799b5 21158 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 21159 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21160 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21161 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21162 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21163 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21164 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21165 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21166 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 21167
74db7efb
NC
21168#undef ARM_VARIANT
21169#define ARM_VARIANT & fpu_vfp_ext_fma
21170#undef THUMB_VARIANT
21171#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
21172 /* Mnemonics shared by Neon and VFP. These are included in the
21173 VFP FMA variant; NEON and VFP FMA always includes the NEON
21174 FMA instructions. */
21175 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21176 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21177 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
21178 the v form should always be used. */
21179 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21180 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21181 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21182 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21183 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21184 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21185
5287ad62 21186#undef THUMB_VARIANT
c921be7d
NC
21187#undef ARM_VARIANT
21188#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
21189
21d799b5
NC
21190 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21191 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21192 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21193 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21194 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21195 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21196 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
21197 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 21198
c921be7d
NC
21199#undef ARM_VARIANT
21200#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
21201
21d799b5
NC
21202 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
21203 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
21204 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
21205 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
21206 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
21207 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
21208 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
21209 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
21210 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
21211 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21212 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21213 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21214 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21215 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21216 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
21217 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21218 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21219 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21220 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
21221 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
21222 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21223 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21224 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21225 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21226 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21227 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
21228 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
21229 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
21230 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
21231 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
21232 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
21233 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
21234 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
21235 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
21236 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
21237 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
21238 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
21239 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21240 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21241 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21242 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21243 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21244 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21245 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21246 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21247 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21248 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
21249 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21250 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21251 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21252 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21253 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21254 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21255 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21256 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21257 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21258 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21259 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21260 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21261 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21262 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21263 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21264 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21265 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21266 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21267 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21268 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21269 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21270 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21271 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21272 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21273 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21274 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21275 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21276 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21277 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21278 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21279 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21280 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21281 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21282 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21283 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21284 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21285 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21286 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21287 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21288 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21289 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21290 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
21291 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21292 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21293 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21294 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21295 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21296 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21297 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21298 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21299 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21300 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21301 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21302 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21303 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21304 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21305 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21306 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21307 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21308 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21309 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21310 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21311 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21312 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
21313 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21314 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21315 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21316 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21317 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21318 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21319 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21320 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21321 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21322 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21323 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21324 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21325 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21326 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21327 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21328 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21329 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21330 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21331 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21332 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21333 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21334 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21335 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21336 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21337 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21338 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21339 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21340 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21341 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21342 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21343 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21344 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
21345 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
21346 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
21347 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
21348 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
21349 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
21350 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21351 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21352 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21353 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
21354 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
21355 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
21356 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
21357 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
21358 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
21359 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21360 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21361 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21362 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21363 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 21364
c921be7d
NC
21365#undef ARM_VARIANT
21366#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
21367
21d799b5
NC
21368 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
21369 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
21370 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
21371 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
21372 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
21373 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
21374 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21375 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21376 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21377 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21378 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21379 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21380 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21381 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21382 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21383 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21384 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21385 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21386 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21387 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21388 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21389 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21390 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21391 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21392 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21393 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21394 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21395 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21396 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21397 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21398 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21399 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21400 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21401 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21402 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21403 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21404 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21405 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21406 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21407 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21408 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21409 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21410 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21411 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21412 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21413 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21414 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21415 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21416 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21417 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21418 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21419 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21420 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21421 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21422 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21423 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21424 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 21425
c921be7d
NC
21426#undef ARM_VARIANT
21427#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21428
21d799b5
NC
21429 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21430 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21431 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21432 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21433 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21434 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21435 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21436 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21437 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21438 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21439 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21440 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21441 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21442 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
21443 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21444 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21445 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21446 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21447 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21448 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21449 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21450 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21451 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21452 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
21453 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21454 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21455 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21456 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
21457 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21458 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
21459 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21460 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21461 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21462 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
21463 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21464 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21465 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21466 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21467 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21468 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
21469 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21470 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
21471 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21472 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
21473 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21474 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21475 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21476 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21477 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21478 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21479 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21480 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21481 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21482 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21483 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21484 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21485 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21486 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21487 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21488 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21489 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21490 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21491 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21492 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21493 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21494 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21495 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21496 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21497 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21498 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21499 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21500 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
21501 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21502 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
21503 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21504 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 21505
16a1fa25 21506 /* ARMv8-M instructions. */
4ed7ed8d
TP
21507#undef ARM_VARIANT
21508#define ARM_VARIANT NULL
21509#undef THUMB_VARIANT
21510#define THUMB_VARIANT & arm_ext_v8m
cf3cf39d
TP
21511 ToU("sg", e97fe97f, 0, (), noargs),
21512 ToC("blxns", 4784, 1, (RRnpc), t_blx),
21513 ToC("bxns", 4704, 1, (RRnpc), t_bx),
21514 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
21515 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
21516 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
21517 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
16a1fa25
TP
21518
21519 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21520 instructions behave as nop if no VFP is present. */
21521#undef THUMB_VARIANT
21522#define THUMB_VARIANT & arm_ext_v8m_main
cf3cf39d
TP
21523 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
21524 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
c19d1205
ZW
21525};
21526#undef ARM_VARIANT
21527#undef THUMB_VARIANT
21528#undef TCE
c19d1205
ZW
21529#undef TUE
21530#undef TUF
21531#undef TCC
8f06b2d8 21532#undef cCE
e3cb604e
PB
21533#undef cCL
21534#undef C3E
c19d1205
ZW
21535#undef CE
21536#undef CM
21537#undef UE
21538#undef UF
21539#undef UT
5287ad62
JB
21540#undef NUF
21541#undef nUF
21542#undef NCE
21543#undef nCE
c19d1205
ZW
21544#undef OPS0
21545#undef OPS1
21546#undef OPS2
21547#undef OPS3
21548#undef OPS4
21549#undef OPS5
21550#undef OPS6
21551#undef do_0
21552\f
21553/* MD interface: bits in the object file. */
bfae80f2 21554
c19d1205
ZW
21555/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21556 for use in the a.out file, and stores them in the array pointed to by buf.
21557 This knows about the endian-ness of the target machine and does
21558 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21559 2 (short) and 4 (long) Floating numbers are put out as a series of
21560 LITTLENUMS (shorts, here at least). */
b99bd4ef 21561
c19d1205
ZW
21562void
21563md_number_to_chars (char * buf, valueT val, int n)
21564{
21565 if (target_big_endian)
21566 number_to_chars_bigendian (buf, val, n);
21567 else
21568 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21569}
21570
c19d1205
ZW
21571static valueT
21572md_chars_to_number (char * buf, int n)
bfae80f2 21573{
c19d1205
ZW
21574 valueT result = 0;
21575 unsigned char * where = (unsigned char *) buf;
bfae80f2 21576
c19d1205 21577 if (target_big_endian)
b99bd4ef 21578 {
c19d1205
ZW
21579 while (n--)
21580 {
21581 result <<= 8;
21582 result |= (*where++ & 255);
21583 }
b99bd4ef 21584 }
c19d1205 21585 else
b99bd4ef 21586 {
c19d1205
ZW
21587 while (n--)
21588 {
21589 result <<= 8;
21590 result |= (where[n] & 255);
21591 }
bfae80f2 21592 }
b99bd4ef 21593
c19d1205 21594 return result;
bfae80f2 21595}
b99bd4ef 21596
c19d1205 21597/* MD interface: Sections. */
b99bd4ef 21598
fa94de6b
RM
21599/* Calculate the maximum variable size (i.e., excluding fr_fix)
21600 that an rs_machine_dependent frag may reach. */
21601
21602unsigned int
21603arm_frag_max_var (fragS *fragp)
21604{
21605 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21606 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21607
21608 Note that we generate relaxable instructions even for cases that don't
21609 really need it, like an immediate that's a trivial constant. So we're
21610 overestimating the instruction size for some of those cases. Rather
21611 than putting more intelligence here, it would probably be better to
21612 avoid generating a relaxation frag in the first place when it can be
21613 determined up front that a short instruction will suffice. */
21614
21615 gas_assert (fragp->fr_type == rs_machine_dependent);
21616 return INSN_SIZE;
21617}
21618
0110f2b8
PB
21619/* Estimate the size of a frag before relaxing. Assume everything fits in
21620 2 bytes. */
21621
c19d1205 21622int
0110f2b8 21623md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21624 segT segtype ATTRIBUTE_UNUSED)
21625{
0110f2b8
PB
21626 fragp->fr_var = 2;
21627 return 2;
21628}
21629
21630/* Convert a machine dependent frag. */
21631
21632void
21633md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21634{
21635 unsigned long insn;
21636 unsigned long old_op;
21637 char *buf;
21638 expressionS exp;
21639 fixS *fixp;
21640 int reloc_type;
21641 int pc_rel;
21642 int opcode;
21643
21644 buf = fragp->fr_literal + fragp->fr_fix;
21645
21646 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21647 if (fragp->fr_symbol)
21648 {
0110f2b8
PB
21649 exp.X_op = O_symbol;
21650 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21651 }
21652 else
21653 {
0110f2b8 21654 exp.X_op = O_constant;
5f4273c7 21655 }
0110f2b8
PB
21656 exp.X_add_number = fragp->fr_offset;
21657 opcode = fragp->fr_subtype;
21658 switch (opcode)
21659 {
21660 case T_MNEM_ldr_pc:
21661 case T_MNEM_ldr_pc2:
21662 case T_MNEM_ldr_sp:
21663 case T_MNEM_str_sp:
21664 case T_MNEM_ldr:
21665 case T_MNEM_ldrb:
21666 case T_MNEM_ldrh:
21667 case T_MNEM_str:
21668 case T_MNEM_strb:
21669 case T_MNEM_strh:
21670 if (fragp->fr_var == 4)
21671 {
5f4273c7 21672 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21673 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21674 {
21675 insn |= (old_op & 0x700) << 4;
21676 }
21677 else
21678 {
21679 insn |= (old_op & 7) << 12;
21680 insn |= (old_op & 0x38) << 13;
21681 }
21682 insn |= 0x00000c00;
21683 put_thumb32_insn (buf, insn);
21684 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21685 }
21686 else
21687 {
21688 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21689 }
21690 pc_rel = (opcode == T_MNEM_ldr_pc2);
21691 break;
21692 case T_MNEM_adr:
21693 if (fragp->fr_var == 4)
21694 {
21695 insn = THUMB_OP32 (opcode);
21696 insn |= (old_op & 0xf0) << 4;
21697 put_thumb32_insn (buf, insn);
21698 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21699 }
21700 else
21701 {
21702 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21703 exp.X_add_number -= 4;
21704 }
21705 pc_rel = 1;
21706 break;
21707 case T_MNEM_mov:
21708 case T_MNEM_movs:
21709 case T_MNEM_cmp:
21710 case T_MNEM_cmn:
21711 if (fragp->fr_var == 4)
21712 {
21713 int r0off = (opcode == T_MNEM_mov
21714 || opcode == T_MNEM_movs) ? 0 : 8;
21715 insn = THUMB_OP32 (opcode);
21716 insn = (insn & 0xe1ffffff) | 0x10000000;
21717 insn |= (old_op & 0x700) << r0off;
21718 put_thumb32_insn (buf, insn);
21719 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21720 }
21721 else
21722 {
21723 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21724 }
21725 pc_rel = 0;
21726 break;
21727 case T_MNEM_b:
21728 if (fragp->fr_var == 4)
21729 {
21730 insn = THUMB_OP32(opcode);
21731 put_thumb32_insn (buf, insn);
21732 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21733 }
21734 else
21735 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21736 pc_rel = 1;
21737 break;
21738 case T_MNEM_bcond:
21739 if (fragp->fr_var == 4)
21740 {
21741 insn = THUMB_OP32(opcode);
21742 insn |= (old_op & 0xf00) << 14;
21743 put_thumb32_insn (buf, insn);
21744 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21745 }
21746 else
21747 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21748 pc_rel = 1;
21749 break;
21750 case T_MNEM_add_sp:
21751 case T_MNEM_add_pc:
21752 case T_MNEM_inc_sp:
21753 case T_MNEM_dec_sp:
21754 if (fragp->fr_var == 4)
21755 {
21756 /* ??? Choose between add and addw. */
21757 insn = THUMB_OP32 (opcode);
21758 insn |= (old_op & 0xf0) << 4;
21759 put_thumb32_insn (buf, insn);
16805f35
PB
21760 if (opcode == T_MNEM_add_pc)
21761 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21762 else
21763 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21764 }
21765 else
21766 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21767 pc_rel = 0;
21768 break;
21769
21770 case T_MNEM_addi:
21771 case T_MNEM_addis:
21772 case T_MNEM_subi:
21773 case T_MNEM_subis:
21774 if (fragp->fr_var == 4)
21775 {
21776 insn = THUMB_OP32 (opcode);
21777 insn |= (old_op & 0xf0) << 4;
21778 insn |= (old_op & 0xf) << 16;
21779 put_thumb32_insn (buf, insn);
16805f35
PB
21780 if (insn & (1 << 20))
21781 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21782 else
21783 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21784 }
21785 else
21786 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21787 pc_rel = 0;
21788 break;
21789 default:
5f4273c7 21790 abort ();
0110f2b8
PB
21791 }
21792 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21793 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21794 fixp->fx_file = fragp->fr_file;
21795 fixp->fx_line = fragp->fr_line;
21796 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21797
21798 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21799 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21800 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21801 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21802}
21803
21804/* Return the size of a relaxable immediate operand instruction.
21805 SHIFT and SIZE specify the form of the allowable immediate. */
21806static int
21807relax_immediate (fragS *fragp, int size, int shift)
21808{
21809 offsetT offset;
21810 offsetT mask;
21811 offsetT low;
21812
21813 /* ??? Should be able to do better than this. */
21814 if (fragp->fr_symbol)
21815 return 4;
21816
21817 low = (1 << shift) - 1;
21818 mask = (1 << (shift + size)) - (1 << shift);
21819 offset = fragp->fr_offset;
21820 /* Force misaligned offsets to 32-bit variant. */
21821 if (offset & low)
5e77afaa 21822 return 4;
0110f2b8
PB
21823 if (offset & ~mask)
21824 return 4;
21825 return 2;
21826}
21827
5e77afaa
PB
21828/* Get the address of a symbol during relaxation. */
21829static addressT
5f4273c7 21830relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21831{
21832 fragS *sym_frag;
21833 addressT addr;
21834 symbolS *sym;
21835
21836 sym = fragp->fr_symbol;
21837 sym_frag = symbol_get_frag (sym);
21838 know (S_GET_SEGMENT (sym) != absolute_section
21839 || sym_frag == &zero_address_frag);
21840 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21841
21842 /* If frag has yet to be reached on this pass, assume it will
21843 move by STRETCH just as we did. If this is not so, it will
21844 be because some frag between grows, and that will force
21845 another pass. */
21846
21847 if (stretch != 0
21848 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21849 {
21850 fragS *f;
21851
21852 /* Adjust stretch for any alignment frag. Note that if have
21853 been expanding the earlier code, the symbol may be
21854 defined in what appears to be an earlier frag. FIXME:
21855 This doesn't handle the fr_subtype field, which specifies
21856 a maximum number of bytes to skip when doing an
21857 alignment. */
21858 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21859 {
21860 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21861 {
21862 if (stretch < 0)
21863 stretch = - ((- stretch)
21864 & ~ ((1 << (int) f->fr_offset) - 1));
21865 else
21866 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21867 if (stretch == 0)
21868 break;
21869 }
21870 }
21871 if (f != NULL)
21872 addr += stretch;
21873 }
5e77afaa
PB
21874
21875 return addr;
21876}
21877
0110f2b8
PB
21878/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21879 load. */
21880static int
5e77afaa 21881relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21882{
21883 addressT addr;
21884 offsetT val;
21885
21886 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21887 if (fragp->fr_symbol == NULL
21888 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21889 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21890 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21891 return 4;
21892
5f4273c7 21893 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21894 addr = fragp->fr_address + fragp->fr_fix;
21895 addr = (addr + 4) & ~3;
5e77afaa 21896 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21897 if (val & 3)
5e77afaa 21898 return 4;
0110f2b8
PB
21899 val -= addr;
21900 if (val < 0 || val > 1020)
21901 return 4;
21902 return 2;
21903}
21904
21905/* Return the size of a relaxable add/sub immediate instruction. */
21906static int
21907relax_addsub (fragS *fragp, asection *sec)
21908{
21909 char *buf;
21910 int op;
21911
21912 buf = fragp->fr_literal + fragp->fr_fix;
21913 op = bfd_get_16(sec->owner, buf);
21914 if ((op & 0xf) == ((op >> 4) & 0xf))
21915 return relax_immediate (fragp, 8, 0);
21916 else
21917 return relax_immediate (fragp, 3, 0);
21918}
21919
e83a675f
RE
21920/* Return TRUE iff the definition of symbol S could be pre-empted
21921 (overridden) at link or load time. */
21922static bfd_boolean
21923symbol_preemptible (symbolS *s)
21924{
21925 /* Weak symbols can always be pre-empted. */
21926 if (S_IS_WEAK (s))
21927 return TRUE;
21928
21929 /* Non-global symbols cannot be pre-empted. */
21930 if (! S_IS_EXTERNAL (s))
21931 return FALSE;
21932
21933#ifdef OBJ_ELF
21934 /* In ELF, a global symbol can be marked protected, or private. In that
21935 case it can't be pre-empted (other definitions in the same link unit
21936 would violate the ODR). */
21937 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21938 return FALSE;
21939#endif
21940
21941 /* Other global symbols might be pre-empted. */
21942 return TRUE;
21943}
0110f2b8
PB
21944
21945/* Return the size of a relaxable branch instruction. BITS is the
21946 size of the offset field in the narrow instruction. */
21947
21948static int
5e77afaa 21949relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21950{
21951 addressT addr;
21952 offsetT val;
21953 offsetT limit;
21954
21955 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21956 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21957 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21958 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21959 return 4;
21960
267bf995 21961#ifdef OBJ_ELF
e83a675f 21962 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21963 if (S_IS_DEFINED (fragp->fr_symbol)
21964 && ARM_IS_FUNC (fragp->fr_symbol))
21965 return 4;
e83a675f 21966#endif
0d9b4b55 21967
e83a675f 21968 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21969 return 4;
267bf995 21970
5f4273c7 21971 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21972 addr = fragp->fr_address + fragp->fr_fix + 4;
21973 val -= addr;
21974
21975 /* Offset is a signed value *2 */
21976 limit = 1 << bits;
21977 if (val >= limit || val < -limit)
21978 return 4;
21979 return 2;
21980}
21981
21982
21983/* Relax a machine dependent frag. This returns the amount by which
21984 the current size of the frag should change. */
21985
21986int
5e77afaa 21987arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21988{
21989 int oldsize;
21990 int newsize;
21991
21992 oldsize = fragp->fr_var;
21993 switch (fragp->fr_subtype)
21994 {
21995 case T_MNEM_ldr_pc2:
5f4273c7 21996 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21997 break;
21998 case T_MNEM_ldr_pc:
21999 case T_MNEM_ldr_sp:
22000 case T_MNEM_str_sp:
5f4273c7 22001 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
22002 break;
22003 case T_MNEM_ldr:
22004 case T_MNEM_str:
5f4273c7 22005 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
22006 break;
22007 case T_MNEM_ldrh:
22008 case T_MNEM_strh:
5f4273c7 22009 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
22010 break;
22011 case T_MNEM_ldrb:
22012 case T_MNEM_strb:
5f4273c7 22013 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
22014 break;
22015 case T_MNEM_adr:
5f4273c7 22016 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
22017 break;
22018 case T_MNEM_mov:
22019 case T_MNEM_movs:
22020 case T_MNEM_cmp:
22021 case T_MNEM_cmn:
5f4273c7 22022 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
22023 break;
22024 case T_MNEM_b:
5f4273c7 22025 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
22026 break;
22027 case T_MNEM_bcond:
5f4273c7 22028 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
22029 break;
22030 case T_MNEM_add_sp:
22031 case T_MNEM_add_pc:
22032 newsize = relax_immediate (fragp, 8, 2);
22033 break;
22034 case T_MNEM_inc_sp:
22035 case T_MNEM_dec_sp:
22036 newsize = relax_immediate (fragp, 7, 2);
22037 break;
22038 case T_MNEM_addi:
22039 case T_MNEM_addis:
22040 case T_MNEM_subi:
22041 case T_MNEM_subis:
22042 newsize = relax_addsub (fragp, sec);
22043 break;
22044 default:
5f4273c7 22045 abort ();
0110f2b8 22046 }
5e77afaa
PB
22047
22048 fragp->fr_var = newsize;
22049 /* Freeze wide instructions that are at or before the same location as
22050 in the previous pass. This avoids infinite loops.
5f4273c7
NC
22051 Don't freeze them unconditionally because targets may be artificially
22052 misaligned by the expansion of preceding frags. */
5e77afaa 22053 if (stretch <= 0 && newsize > 2)
0110f2b8 22054 {
0110f2b8 22055 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 22056 frag_wane (fragp);
0110f2b8 22057 }
5e77afaa 22058
0110f2b8 22059 return newsize - oldsize;
c19d1205 22060}
b99bd4ef 22061
c19d1205 22062/* Round up a section size to the appropriate boundary. */
b99bd4ef 22063
c19d1205
ZW
22064valueT
22065md_section_align (segT segment ATTRIBUTE_UNUSED,
22066 valueT size)
22067{
6844c0cc 22068 return size;
bfae80f2 22069}
b99bd4ef 22070
c19d1205
ZW
22071/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
22072 of an rs_align_code fragment. */
22073
22074void
22075arm_handle_align (fragS * fragP)
bfae80f2 22076{
d9235011 22077 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
22078 {
22079 { /* ARMv1 */
22080 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
22081 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
22082 },
22083 { /* ARMv6k */
22084 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
22085 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
22086 },
22087 };
d9235011 22088 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
22089 {
22090 { /* Thumb-1 */
22091 {0xc0, 0x46}, /* LE */
22092 {0x46, 0xc0}, /* BE */
22093 },
22094 { /* Thumb-2 */
22095 {0x00, 0xbf}, /* LE */
22096 {0xbf, 0x00} /* BE */
22097 }
22098 };
d9235011 22099 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
22100 { /* Wide Thumb-2 */
22101 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
22102 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
22103 };
c921be7d 22104
e7495e45 22105 unsigned bytes, fix, noop_size;
c19d1205 22106 char * p;
d9235011
TS
22107 const unsigned char * noop;
22108 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
22109#ifdef OBJ_ELF
22110 enum mstate state;
22111#endif
bfae80f2 22112
c19d1205 22113 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
22114 return;
22115
c19d1205
ZW
22116 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
22117 p = fragP->fr_literal + fragP->fr_fix;
22118 fix = 0;
bfae80f2 22119
c19d1205
ZW
22120 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
22121 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 22122
cd000bff 22123 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 22124
cd000bff 22125 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 22126 {
7f78eb34
JW
22127 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22128 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
22129 {
22130 narrow_noop = thumb_noop[1][target_big_endian];
22131 noop = wide_thumb_noop[target_big_endian];
22132 }
c19d1205 22133 else
e7495e45
NS
22134 noop = thumb_noop[0][target_big_endian];
22135 noop_size = 2;
cd000bff
DJ
22136#ifdef OBJ_ELF
22137 state = MAP_THUMB;
22138#endif
7ed4c4c5
NC
22139 }
22140 else
22141 {
7f78eb34
JW
22142 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22143 ? selected_cpu : arm_arch_none,
22144 arm_ext_v6k) != 0]
e7495e45
NS
22145 [target_big_endian];
22146 noop_size = 4;
cd000bff
DJ
22147#ifdef OBJ_ELF
22148 state = MAP_ARM;
22149#endif
7ed4c4c5 22150 }
c921be7d 22151
e7495e45 22152 fragP->fr_var = noop_size;
c921be7d 22153
c19d1205 22154 if (bytes & (noop_size - 1))
7ed4c4c5 22155 {
c19d1205 22156 fix = bytes & (noop_size - 1);
cd000bff
DJ
22157#ifdef OBJ_ELF
22158 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
22159#endif
c19d1205
ZW
22160 memset (p, 0, fix);
22161 p += fix;
22162 bytes -= fix;
a737bd4d 22163 }
a737bd4d 22164
e7495e45
NS
22165 if (narrow_noop)
22166 {
22167 if (bytes & noop_size)
22168 {
22169 /* Insert a narrow noop. */
22170 memcpy (p, narrow_noop, noop_size);
22171 p += noop_size;
22172 bytes -= noop_size;
22173 fix += noop_size;
22174 }
22175
22176 /* Use wide noops for the remainder */
22177 noop_size = 4;
22178 }
22179
c19d1205 22180 while (bytes >= noop_size)
a737bd4d 22181 {
c19d1205
ZW
22182 memcpy (p, noop, noop_size);
22183 p += noop_size;
22184 bytes -= noop_size;
22185 fix += noop_size;
a737bd4d
NC
22186 }
22187
c19d1205 22188 fragP->fr_fix += fix;
a737bd4d
NC
22189}
22190
c19d1205
ZW
22191/* Called from md_do_align. Used to create an alignment
22192 frag in a code section. */
22193
22194void
22195arm_frag_align_code (int n, int max)
bfae80f2 22196{
c19d1205 22197 char * p;
7ed4c4c5 22198
c19d1205 22199 /* We assume that there will never be a requirement
6ec8e702 22200 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 22201 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
22202 {
22203 char err_msg[128];
22204
fa94de6b 22205 sprintf (err_msg,
477330fc
RM
22206 _("alignments greater than %d bytes not supported in .text sections."),
22207 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 22208 as_fatal ("%s", err_msg);
6ec8e702 22209 }
bfae80f2 22210
c19d1205
ZW
22211 p = frag_var (rs_align_code,
22212 MAX_MEM_FOR_RS_ALIGN_CODE,
22213 1,
22214 (relax_substateT) max,
22215 (symbolS *) NULL,
22216 (offsetT) n,
22217 (char *) NULL);
22218 *p = 0;
22219}
bfae80f2 22220
8dc2430f
NC
22221/* Perform target specific initialisation of a frag.
22222 Note - despite the name this initialisation is not done when the frag
22223 is created, but only when its type is assigned. A frag can be created
22224 and used a long time before its type is set, so beware of assuming that
33eaf5de 22225 this initialisation is performed first. */
bfae80f2 22226
cd000bff
DJ
22227#ifndef OBJ_ELF
22228void
22229arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
22230{
22231 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 22232 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
22233}
22234
22235#else /* OBJ_ELF is defined. */
c19d1205 22236void
cd000bff 22237arm_init_frag (fragS * fragP, int max_chars)
c19d1205 22238{
e8d84ca1 22239 bfd_boolean frag_thumb_mode;
b968d18a 22240
8dc2430f
NC
22241 /* If the current ARM vs THUMB mode has not already
22242 been recorded into this frag then do so now. */
cd000bff 22243 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
22244 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22245
e8d84ca1
NC
22246 /* PR 21809: Do not set a mapping state for debug sections
22247 - it just confuses other tools. */
22248 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
22249 return;
22250
b968d18a 22251 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 22252
f9c1b181
RL
22253 /* Record a mapping symbol for alignment frags. We will delete this
22254 later if the alignment ends up empty. */
22255 switch (fragP->fr_type)
22256 {
22257 case rs_align:
22258 case rs_align_test:
22259 case rs_fill:
22260 mapping_state_2 (MAP_DATA, max_chars);
22261 break;
22262 case rs_align_code:
b968d18a 22263 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
22264 break;
22265 default:
22266 break;
cd000bff 22267 }
bfae80f2
RE
22268}
22269
c19d1205
ZW
22270/* When we change sections we need to issue a new mapping symbol. */
22271
22272void
22273arm_elf_change_section (void)
bfae80f2 22274{
c19d1205
ZW
22275 /* Link an unlinked unwind index table section to the .text section. */
22276 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
22277 && elf_linked_to_section (now_seg) == NULL)
22278 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
22279}
22280
c19d1205
ZW
22281int
22282arm_elf_section_type (const char * str, size_t len)
e45d0630 22283{
c19d1205
ZW
22284 if (len == 5 && strncmp (str, "exidx", 5) == 0)
22285 return SHT_ARM_EXIDX;
e45d0630 22286
c19d1205
ZW
22287 return -1;
22288}
22289\f
22290/* Code to deal with unwinding tables. */
e45d0630 22291
c19d1205 22292static void add_unwind_adjustsp (offsetT);
e45d0630 22293
5f4273c7 22294/* Generate any deferred unwind frame offset. */
e45d0630 22295
bfae80f2 22296static void
c19d1205 22297flush_pending_unwind (void)
bfae80f2 22298{
c19d1205 22299 offsetT offset;
bfae80f2 22300
c19d1205
ZW
22301 offset = unwind.pending_offset;
22302 unwind.pending_offset = 0;
22303 if (offset != 0)
22304 add_unwind_adjustsp (offset);
bfae80f2
RE
22305}
22306
c19d1205
ZW
22307/* Add an opcode to this list for this function. Two-byte opcodes should
22308 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
22309 order. */
22310
bfae80f2 22311static void
c19d1205 22312add_unwind_opcode (valueT op, int length)
bfae80f2 22313{
c19d1205
ZW
22314 /* Add any deferred stack adjustment. */
22315 if (unwind.pending_offset)
22316 flush_pending_unwind ();
bfae80f2 22317
c19d1205 22318 unwind.sp_restored = 0;
bfae80f2 22319
c19d1205 22320 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 22321 {
c19d1205
ZW
22322 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
22323 if (unwind.opcodes)
325801bd
TS
22324 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
22325 unwind.opcode_alloc);
c19d1205 22326 else
325801bd 22327 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 22328 }
c19d1205 22329 while (length > 0)
bfae80f2 22330 {
c19d1205
ZW
22331 length--;
22332 unwind.opcodes[unwind.opcode_count] = op & 0xff;
22333 op >>= 8;
22334 unwind.opcode_count++;
bfae80f2 22335 }
bfae80f2
RE
22336}
22337
c19d1205
ZW
22338/* Add unwind opcodes to adjust the stack pointer. */
22339
bfae80f2 22340static void
c19d1205 22341add_unwind_adjustsp (offsetT offset)
bfae80f2 22342{
c19d1205 22343 valueT op;
bfae80f2 22344
c19d1205 22345 if (offset > 0x200)
bfae80f2 22346 {
c19d1205
ZW
22347 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
22348 char bytes[5];
22349 int n;
22350 valueT o;
bfae80f2 22351
c19d1205
ZW
22352 /* Long form: 0xb2, uleb128. */
22353 /* This might not fit in a word so add the individual bytes,
22354 remembering the list is built in reverse order. */
22355 o = (valueT) ((offset - 0x204) >> 2);
22356 if (o == 0)
22357 add_unwind_opcode (0, 1);
bfae80f2 22358
c19d1205
ZW
22359 /* Calculate the uleb128 encoding of the offset. */
22360 n = 0;
22361 while (o)
22362 {
22363 bytes[n] = o & 0x7f;
22364 o >>= 7;
22365 if (o)
22366 bytes[n] |= 0x80;
22367 n++;
22368 }
22369 /* Add the insn. */
22370 for (; n; n--)
22371 add_unwind_opcode (bytes[n - 1], 1);
22372 add_unwind_opcode (0xb2, 1);
22373 }
22374 else if (offset > 0x100)
bfae80f2 22375 {
c19d1205
ZW
22376 /* Two short opcodes. */
22377 add_unwind_opcode (0x3f, 1);
22378 op = (offset - 0x104) >> 2;
22379 add_unwind_opcode (op, 1);
bfae80f2 22380 }
c19d1205
ZW
22381 else if (offset > 0)
22382 {
22383 /* Short opcode. */
22384 op = (offset - 4) >> 2;
22385 add_unwind_opcode (op, 1);
22386 }
22387 else if (offset < 0)
bfae80f2 22388 {
c19d1205
ZW
22389 offset = -offset;
22390 while (offset > 0x100)
bfae80f2 22391 {
c19d1205
ZW
22392 add_unwind_opcode (0x7f, 1);
22393 offset -= 0x100;
bfae80f2 22394 }
c19d1205
ZW
22395 op = ((offset - 4) >> 2) | 0x40;
22396 add_unwind_opcode (op, 1);
bfae80f2 22397 }
bfae80f2
RE
22398}
22399
c19d1205 22400/* Finish the list of unwind opcodes for this function. */
0198d5e6 22401
c19d1205
ZW
22402static void
22403finish_unwind_opcodes (void)
bfae80f2 22404{
c19d1205 22405 valueT op;
bfae80f2 22406
c19d1205 22407 if (unwind.fp_used)
bfae80f2 22408 {
708587a4 22409 /* Adjust sp as necessary. */
c19d1205
ZW
22410 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22411 flush_pending_unwind ();
bfae80f2 22412
c19d1205
ZW
22413 /* After restoring sp from the frame pointer. */
22414 op = 0x90 | unwind.fp_reg;
22415 add_unwind_opcode (op, 1);
22416 }
22417 else
22418 flush_pending_unwind ();
bfae80f2
RE
22419}
22420
bfae80f2 22421
c19d1205
ZW
22422/* Start an exception table entry. If idx is nonzero this is an index table
22423 entry. */
bfae80f2
RE
22424
22425static void
c19d1205 22426start_unwind_section (const segT text_seg, int idx)
bfae80f2 22427{
c19d1205
ZW
22428 const char * text_name;
22429 const char * prefix;
22430 const char * prefix_once;
22431 const char * group_name;
c19d1205 22432 char * sec_name;
c19d1205
ZW
22433 int type;
22434 int flags;
22435 int linkonce;
bfae80f2 22436
c19d1205 22437 if (idx)
bfae80f2 22438 {
c19d1205
ZW
22439 prefix = ELF_STRING_ARM_unwind;
22440 prefix_once = ELF_STRING_ARM_unwind_once;
22441 type = SHT_ARM_EXIDX;
bfae80f2 22442 }
c19d1205 22443 else
bfae80f2 22444 {
c19d1205
ZW
22445 prefix = ELF_STRING_ARM_unwind_info;
22446 prefix_once = ELF_STRING_ARM_unwind_info_once;
22447 type = SHT_PROGBITS;
bfae80f2
RE
22448 }
22449
c19d1205
ZW
22450 text_name = segment_name (text_seg);
22451 if (streq (text_name, ".text"))
22452 text_name = "";
22453
22454 if (strncmp (text_name, ".gnu.linkonce.t.",
22455 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 22456 {
c19d1205
ZW
22457 prefix = prefix_once;
22458 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
22459 }
22460
29a2809e 22461 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 22462
c19d1205
ZW
22463 flags = SHF_ALLOC;
22464 linkonce = 0;
22465 group_name = 0;
bfae80f2 22466
c19d1205
ZW
22467 /* Handle COMDAT group. */
22468 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 22469 {
c19d1205
ZW
22470 group_name = elf_group_name (text_seg);
22471 if (group_name == NULL)
22472 {
bd3ba5d1 22473 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
22474 segment_name (text_seg));
22475 ignore_rest_of_line ();
22476 return;
22477 }
22478 flags |= SHF_GROUP;
22479 linkonce = 1;
bfae80f2
RE
22480 }
22481
a91e1603
L
22482 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
22483 linkonce, 0);
bfae80f2 22484
5f4273c7 22485 /* Set the section link for index tables. */
c19d1205
ZW
22486 if (idx)
22487 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
22488}
22489
bfae80f2 22490
c19d1205
ZW
22491/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22492 personality routine data. Returns zero, or the index table value for
cad0da33 22493 an inline entry. */
c19d1205
ZW
22494
22495static valueT
22496create_unwind_entry (int have_data)
bfae80f2 22497{
c19d1205
ZW
22498 int size;
22499 addressT where;
22500 char *ptr;
22501 /* The current word of data. */
22502 valueT data;
22503 /* The number of bytes left in this word. */
22504 int n;
bfae80f2 22505
c19d1205 22506 finish_unwind_opcodes ();
bfae80f2 22507
c19d1205
ZW
22508 /* Remember the current text section. */
22509 unwind.saved_seg = now_seg;
22510 unwind.saved_subseg = now_subseg;
bfae80f2 22511
c19d1205 22512 start_unwind_section (now_seg, 0);
bfae80f2 22513
c19d1205 22514 if (unwind.personality_routine == NULL)
bfae80f2 22515 {
c19d1205
ZW
22516 if (unwind.personality_index == -2)
22517 {
22518 if (have_data)
5f4273c7 22519 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22520 return 1; /* EXIDX_CANTUNWIND. */
22521 }
bfae80f2 22522
c19d1205
ZW
22523 /* Use a default personality routine if none is specified. */
22524 if (unwind.personality_index == -1)
22525 {
22526 if (unwind.opcode_count > 3)
22527 unwind.personality_index = 1;
22528 else
22529 unwind.personality_index = 0;
22530 }
bfae80f2 22531
c19d1205
ZW
22532 /* Space for the personality routine entry. */
22533 if (unwind.personality_index == 0)
22534 {
22535 if (unwind.opcode_count > 3)
22536 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22537
c19d1205
ZW
22538 if (!have_data)
22539 {
22540 /* All the data is inline in the index table. */
22541 data = 0x80;
22542 n = 3;
22543 while (unwind.opcode_count > 0)
22544 {
22545 unwind.opcode_count--;
22546 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22547 n--;
22548 }
bfae80f2 22549
c19d1205
ZW
22550 /* Pad with "finish" opcodes. */
22551 while (n--)
22552 data = (data << 8) | 0xb0;
bfae80f2 22553
c19d1205
ZW
22554 return data;
22555 }
22556 size = 0;
22557 }
22558 else
22559 /* We get two opcodes "free" in the first word. */
22560 size = unwind.opcode_count - 2;
22561 }
22562 else
5011093d 22563 {
cad0da33
NC
22564 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22565 if (unwind.personality_index != -1)
22566 {
22567 as_bad (_("attempt to recreate an unwind entry"));
22568 return 1;
22569 }
5011093d
NC
22570
22571 /* An extra byte is required for the opcode count. */
22572 size = unwind.opcode_count + 1;
22573 }
bfae80f2 22574
c19d1205
ZW
22575 size = (size + 3) >> 2;
22576 if (size > 0xff)
22577 as_bad (_("too many unwind opcodes"));
bfae80f2 22578
c19d1205
ZW
22579 frag_align (2, 0, 0);
22580 record_alignment (now_seg, 2);
22581 unwind.table_entry = expr_build_dot ();
22582
22583 /* Allocate the table entry. */
22584 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22585 /* PR 13449: Zero the table entries in case some of them are not used. */
22586 memset (ptr, 0, (size << 2) + 4);
c19d1205 22587 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22588
c19d1205 22589 switch (unwind.personality_index)
bfae80f2 22590 {
c19d1205
ZW
22591 case -1:
22592 /* ??? Should this be a PLT generating relocation? */
22593 /* Custom personality routine. */
22594 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22595 BFD_RELOC_ARM_PREL31);
bfae80f2 22596
c19d1205
ZW
22597 where += 4;
22598 ptr += 4;
bfae80f2 22599
c19d1205 22600 /* Set the first byte to the number of additional words. */
5011093d 22601 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22602 n = 3;
22603 break;
bfae80f2 22604
c19d1205
ZW
22605 /* ABI defined personality routines. */
22606 case 0:
22607 /* Three opcodes bytes are packed into the first word. */
22608 data = 0x80;
22609 n = 3;
22610 break;
bfae80f2 22611
c19d1205
ZW
22612 case 1:
22613 case 2:
22614 /* The size and first two opcode bytes go in the first word. */
22615 data = ((0x80 + unwind.personality_index) << 8) | size;
22616 n = 2;
22617 break;
bfae80f2 22618
c19d1205
ZW
22619 default:
22620 /* Should never happen. */
22621 abort ();
22622 }
bfae80f2 22623
c19d1205
ZW
22624 /* Pack the opcodes into words (MSB first), reversing the list at the same
22625 time. */
22626 while (unwind.opcode_count > 0)
22627 {
22628 if (n == 0)
22629 {
22630 md_number_to_chars (ptr, data, 4);
22631 ptr += 4;
22632 n = 4;
22633 data = 0;
22634 }
22635 unwind.opcode_count--;
22636 n--;
22637 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22638 }
22639
22640 /* Finish off the last word. */
22641 if (n < 4)
22642 {
22643 /* Pad with "finish" opcodes. */
22644 while (n--)
22645 data = (data << 8) | 0xb0;
22646
22647 md_number_to_chars (ptr, data, 4);
22648 }
22649
22650 if (!have_data)
22651 {
22652 /* Add an empty descriptor if there is no user-specified data. */
22653 ptr = frag_more (4);
22654 md_number_to_chars (ptr, 0, 4);
22655 }
22656
22657 return 0;
bfae80f2
RE
22658}
22659
f0927246
NC
22660
22661/* Initialize the DWARF-2 unwind information for this procedure. */
22662
22663void
22664tc_arm_frame_initial_instructions (void)
22665{
22666 cfi_add_CFA_def_cfa (REG_SP, 0);
22667}
22668#endif /* OBJ_ELF */
22669
c19d1205
ZW
22670/* Convert REGNAME to a DWARF-2 register number. */
22671
22672int
1df69f4f 22673tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22674{
1df69f4f 22675 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22676 if (reg != FAIL)
22677 return reg;
c19d1205 22678
1f5afe1c
NC
22679 /* PR 16694: Allow VFP registers as well. */
22680 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22681 if (reg != FAIL)
22682 return 64 + reg;
c19d1205 22683
1f5afe1c
NC
22684 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22685 if (reg != FAIL)
22686 return reg + 256;
22687
0198d5e6 22688 return FAIL;
bfae80f2
RE
22689}
22690
f0927246 22691#ifdef TE_PE
c19d1205 22692void
f0927246 22693tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22694{
91d6fa6a 22695 expressionS exp;
bfae80f2 22696
91d6fa6a
NC
22697 exp.X_op = O_secrel;
22698 exp.X_add_symbol = symbol;
22699 exp.X_add_number = 0;
22700 emit_expr (&exp, size);
f0927246
NC
22701}
22702#endif
bfae80f2 22703
c19d1205 22704/* MD interface: Symbol and relocation handling. */
bfae80f2 22705
2fc8bdac
ZW
22706/* Return the address within the segment that a PC-relative fixup is
22707 relative to. For ARM, PC-relative fixups applied to instructions
22708 are generally relative to the location of the fixup plus 8 bytes.
22709 Thumb branches are offset by 4, and Thumb loads relative to PC
22710 require special handling. */
bfae80f2 22711
c19d1205 22712long
2fc8bdac 22713md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22714{
2fc8bdac
ZW
22715 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22716
22717 /* If this is pc-relative and we are going to emit a relocation
22718 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22719 will need. Otherwise we want to use the calculated base.
22720 For WinCE we skip the bias for externals as well, since this
22721 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22722 if (fixP->fx_pcrel
2fc8bdac 22723 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22724 || (arm_force_relocation (fixP)
22725#ifdef TE_WINCE
22726 && !S_IS_EXTERNAL (fixP->fx_addsy)
22727#endif
22728 )))
2fc8bdac 22729 base = 0;
bfae80f2 22730
267bf995 22731
c19d1205 22732 switch (fixP->fx_r_type)
bfae80f2 22733 {
2fc8bdac
ZW
22734 /* PC relative addressing on the Thumb is slightly odd as the
22735 bottom two bits of the PC are forced to zero for the
22736 calculation. This happens *after* application of the
22737 pipeline offset. However, Thumb adrl already adjusts for
22738 this, so we need not do it again. */
c19d1205 22739 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22740 return base & ~3;
c19d1205
ZW
22741
22742 case BFD_RELOC_ARM_THUMB_OFFSET:
22743 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22744 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22745 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22746 return (base + 4) & ~3;
c19d1205 22747
2fc8bdac
ZW
22748 /* Thumb branches are simply offset by +4. */
22749 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22750 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22751 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22752 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22753 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22754 return base + 4;
bfae80f2 22755
267bf995 22756 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22757 if (fixP->fx_addsy
22758 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22759 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22760 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22761 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22762 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22763 return base + 4;
22764
00adf2d4
JB
22765 /* BLX is like branches above, but forces the low two bits of PC to
22766 zero. */
486499d0
CL
22767 case BFD_RELOC_THUMB_PCREL_BLX:
22768 if (fixP->fx_addsy
22769 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22770 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22771 && THUMB_IS_FUNC (fixP->fx_addsy)
22772 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22773 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22774 return (base + 4) & ~3;
22775
2fc8bdac
ZW
22776 /* ARM mode branches are offset by +8. However, the Windows CE
22777 loader expects the relocation not to take this into account. */
267bf995 22778 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22779 if (fixP->fx_addsy
22780 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22781 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22782 && ARM_IS_FUNC (fixP->fx_addsy)
22783 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22784 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22785 return base + 8;
267bf995 22786
486499d0
CL
22787 case BFD_RELOC_ARM_PCREL_CALL:
22788 if (fixP->fx_addsy
22789 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22790 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22791 && THUMB_IS_FUNC (fixP->fx_addsy)
22792 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22793 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22794 return base + 8;
267bf995 22795
2fc8bdac 22796 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22797 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22798 case BFD_RELOC_ARM_PLT32:
c19d1205 22799#ifdef TE_WINCE
5f4273c7 22800 /* When handling fixups immediately, because we have already
477330fc 22801 discovered the value of a symbol, or the address of the frag involved
53baae48 22802 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22803 see fixup_segment() in write.c
22804 The S_IS_EXTERNAL test handles the case of global symbols.
22805 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22806 if (fixP->fx_pcrel
22807 && fixP->fx_addsy != NULL
22808 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22809 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22810 return base + 8;
2fc8bdac 22811 return base;
c19d1205 22812#else
2fc8bdac 22813 return base + 8;
c19d1205 22814#endif
2fc8bdac 22815
267bf995 22816
2fc8bdac
ZW
22817 /* ARM mode loads relative to PC are also offset by +8. Unlike
22818 branches, the Windows CE loader *does* expect the relocation
22819 to take this into account. */
22820 case BFD_RELOC_ARM_OFFSET_IMM:
22821 case BFD_RELOC_ARM_OFFSET_IMM8:
22822 case BFD_RELOC_ARM_HWLITERAL:
22823 case BFD_RELOC_ARM_LITERAL:
22824 case BFD_RELOC_ARM_CP_OFF_IMM:
22825 return base + 8;
22826
22827
22828 /* Other PC-relative relocations are un-offset. */
22829 default:
22830 return base;
22831 }
bfae80f2
RE
22832}
22833
8b2d793c
NC
22834static bfd_boolean flag_warn_syms = TRUE;
22835
ae8714c2
NC
22836bfd_boolean
22837arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22838{
8b2d793c
NC
22839 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22840 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22841 does mean that the resulting code might be very confusing to the reader.
22842 Also this warning can be triggered if the user omits an operand before
22843 an immediate address, eg:
22844
22845 LDR =foo
22846
22847 GAS treats this as an assignment of the value of the symbol foo to a
22848 symbol LDR, and so (without this code) it will not issue any kind of
22849 warning or error message.
22850
22851 Note - ARM instructions are case-insensitive but the strings in the hash
22852 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22853 lower case too. */
22854 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22855 {
22856 char * nbuf = strdup (name);
22857 char * p;
22858
22859 for (p = nbuf; *p; p++)
22860 *p = TOLOWER (*p);
22861 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22862 {
22863 static struct hash_control * already_warned = NULL;
22864
22865 if (already_warned == NULL)
22866 already_warned = hash_new ();
22867 /* Only warn about the symbol once. To keep the code
22868 simple we let hash_insert do the lookup for us. */
22869 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22870 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22871 }
22872 else
22873 free (nbuf);
22874 }
3739860c 22875
ae8714c2
NC
22876 return FALSE;
22877}
22878
22879/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22880 Otherwise we have no need to default values of symbols. */
22881
22882symbolS *
22883md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22884{
22885#ifdef OBJ_ELF
22886 if (name[0] == '_' && name[1] == 'G'
22887 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22888 {
22889 if (!GOT_symbol)
22890 {
22891 if (symbol_find (name))
22892 as_bad (_("GOT already in the symbol table"));
22893
22894 GOT_symbol = symbol_new (name, undefined_section,
22895 (valueT) 0, & zero_address_frag);
22896 }
22897
22898 return GOT_symbol;
22899 }
22900#endif
22901
c921be7d 22902 return NULL;
bfae80f2
RE
22903}
22904
55cf6793 22905/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22906 computed as two separate immediate values, added together. We
22907 already know that this value cannot be computed by just one ARM
22908 instruction. */
22909
22910static unsigned int
22911validate_immediate_twopart (unsigned int val,
22912 unsigned int * highpart)
bfae80f2 22913{
c19d1205
ZW
22914 unsigned int a;
22915 unsigned int i;
bfae80f2 22916
c19d1205
ZW
22917 for (i = 0; i < 32; i += 2)
22918 if (((a = rotate_left (val, i)) & 0xff) != 0)
22919 {
22920 if (a & 0xff00)
22921 {
22922 if (a & ~ 0xffff)
22923 continue;
22924 * highpart = (a >> 8) | ((i + 24) << 7);
22925 }
22926 else if (a & 0xff0000)
22927 {
22928 if (a & 0xff000000)
22929 continue;
22930 * highpart = (a >> 16) | ((i + 16) << 7);
22931 }
22932 else
22933 {
9c2799c2 22934 gas_assert (a & 0xff000000);
c19d1205
ZW
22935 * highpart = (a >> 24) | ((i + 8) << 7);
22936 }
bfae80f2 22937
c19d1205
ZW
22938 return (a & 0xff) | (i << 7);
22939 }
bfae80f2 22940
c19d1205 22941 return FAIL;
bfae80f2
RE
22942}
22943
c19d1205
ZW
22944static int
22945validate_offset_imm (unsigned int val, int hwse)
22946{
22947 if ((hwse && val > 255) || val > 4095)
22948 return FAIL;
22949 return val;
22950}
bfae80f2 22951
55cf6793 22952/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22953 negative immediate constant by altering the instruction. A bit of
22954 a hack really.
22955 MOV <-> MVN
22956 AND <-> BIC
22957 ADC <-> SBC
22958 by inverting the second operand, and
22959 ADD <-> SUB
22960 CMP <-> CMN
22961 by negating the second operand. */
bfae80f2 22962
c19d1205
ZW
22963static int
22964negate_data_op (unsigned long * instruction,
22965 unsigned long value)
bfae80f2 22966{
c19d1205
ZW
22967 int op, new_inst;
22968 unsigned long negated, inverted;
bfae80f2 22969
c19d1205
ZW
22970 negated = encode_arm_immediate (-value);
22971 inverted = encode_arm_immediate (~value);
bfae80f2 22972
c19d1205
ZW
22973 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22974 switch (op)
bfae80f2 22975 {
c19d1205
ZW
22976 /* First negates. */
22977 case OPCODE_SUB: /* ADD <-> SUB */
22978 new_inst = OPCODE_ADD;
22979 value = negated;
22980 break;
bfae80f2 22981
c19d1205
ZW
22982 case OPCODE_ADD:
22983 new_inst = OPCODE_SUB;
22984 value = negated;
22985 break;
bfae80f2 22986
c19d1205
ZW
22987 case OPCODE_CMP: /* CMP <-> CMN */
22988 new_inst = OPCODE_CMN;
22989 value = negated;
22990 break;
bfae80f2 22991
c19d1205
ZW
22992 case OPCODE_CMN:
22993 new_inst = OPCODE_CMP;
22994 value = negated;
22995 break;
bfae80f2 22996
c19d1205
ZW
22997 /* Now Inverted ops. */
22998 case OPCODE_MOV: /* MOV <-> MVN */
22999 new_inst = OPCODE_MVN;
23000 value = inverted;
23001 break;
bfae80f2 23002
c19d1205
ZW
23003 case OPCODE_MVN:
23004 new_inst = OPCODE_MOV;
23005 value = inverted;
23006 break;
bfae80f2 23007
c19d1205
ZW
23008 case OPCODE_AND: /* AND <-> BIC */
23009 new_inst = OPCODE_BIC;
23010 value = inverted;
23011 break;
bfae80f2 23012
c19d1205
ZW
23013 case OPCODE_BIC:
23014 new_inst = OPCODE_AND;
23015 value = inverted;
23016 break;
bfae80f2 23017
c19d1205
ZW
23018 case OPCODE_ADC: /* ADC <-> SBC */
23019 new_inst = OPCODE_SBC;
23020 value = inverted;
23021 break;
bfae80f2 23022
c19d1205
ZW
23023 case OPCODE_SBC:
23024 new_inst = OPCODE_ADC;
23025 value = inverted;
23026 break;
bfae80f2 23027
c19d1205
ZW
23028 /* We cannot do anything. */
23029 default:
23030 return FAIL;
b99bd4ef
NC
23031 }
23032
c19d1205
ZW
23033 if (value == (unsigned) FAIL)
23034 return FAIL;
23035
23036 *instruction &= OPCODE_MASK;
23037 *instruction |= new_inst << DATA_OP_SHIFT;
23038 return value;
b99bd4ef
NC
23039}
23040
ef8d22e6
PB
23041/* Like negate_data_op, but for Thumb-2. */
23042
23043static unsigned int
16dd5e42 23044thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
23045{
23046 int op, new_inst;
23047 int rd;
16dd5e42 23048 unsigned int negated, inverted;
ef8d22e6
PB
23049
23050 negated = encode_thumb32_immediate (-value);
23051 inverted = encode_thumb32_immediate (~value);
23052
23053 rd = (*instruction >> 8) & 0xf;
23054 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
23055 switch (op)
23056 {
23057 /* ADD <-> SUB. Includes CMP <-> CMN. */
23058 case T2_OPCODE_SUB:
23059 new_inst = T2_OPCODE_ADD;
23060 value = negated;
23061 break;
23062
23063 case T2_OPCODE_ADD:
23064 new_inst = T2_OPCODE_SUB;
23065 value = negated;
23066 break;
23067
23068 /* ORR <-> ORN. Includes MOV <-> MVN. */
23069 case T2_OPCODE_ORR:
23070 new_inst = T2_OPCODE_ORN;
23071 value = inverted;
23072 break;
23073
23074 case T2_OPCODE_ORN:
23075 new_inst = T2_OPCODE_ORR;
23076 value = inverted;
23077 break;
23078
23079 /* AND <-> BIC. TST has no inverted equivalent. */
23080 case T2_OPCODE_AND:
23081 new_inst = T2_OPCODE_BIC;
23082 if (rd == 15)
23083 value = FAIL;
23084 else
23085 value = inverted;
23086 break;
23087
23088 case T2_OPCODE_BIC:
23089 new_inst = T2_OPCODE_AND;
23090 value = inverted;
23091 break;
23092
23093 /* ADC <-> SBC */
23094 case T2_OPCODE_ADC:
23095 new_inst = T2_OPCODE_SBC;
23096 value = inverted;
23097 break;
23098
23099 case T2_OPCODE_SBC:
23100 new_inst = T2_OPCODE_ADC;
23101 value = inverted;
23102 break;
23103
23104 /* We cannot do anything. */
23105 default:
23106 return FAIL;
23107 }
23108
16dd5e42 23109 if (value == (unsigned int)FAIL)
ef8d22e6
PB
23110 return FAIL;
23111
23112 *instruction &= T2_OPCODE_MASK;
23113 *instruction |= new_inst << T2_DATA_OP_SHIFT;
23114 return value;
23115}
23116
8f06b2d8 23117/* Read a 32-bit thumb instruction from buf. */
0198d5e6 23118
8f06b2d8
PB
23119static unsigned long
23120get_thumb32_insn (char * buf)
23121{
23122 unsigned long insn;
23123 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
23124 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23125
23126 return insn;
23127}
23128
a8bc6c78
PB
23129/* We usually want to set the low bit on the address of thumb function
23130 symbols. In particular .word foo - . should have the low bit set.
23131 Generic code tries to fold the difference of two symbols to
23132 a constant. Prevent this and force a relocation when the first symbols
23133 is a thumb function. */
c921be7d
NC
23134
23135bfd_boolean
a8bc6c78
PB
23136arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
23137{
23138 if (op == O_subtract
23139 && l->X_op == O_symbol
23140 && r->X_op == O_symbol
23141 && THUMB_IS_FUNC (l->X_add_symbol))
23142 {
23143 l->X_op = O_subtract;
23144 l->X_op_symbol = r->X_add_symbol;
23145 l->X_add_number -= r->X_add_number;
c921be7d 23146 return TRUE;
a8bc6c78 23147 }
c921be7d 23148
a8bc6c78 23149 /* Process as normal. */
c921be7d 23150 return FALSE;
a8bc6c78
PB
23151}
23152
4a42ebbc
RR
23153/* Encode Thumb2 unconditional branches and calls. The encoding
23154 for the 2 are identical for the immediate values. */
23155
23156static void
23157encode_thumb2_b_bl_offset (char * buf, offsetT value)
23158{
23159#define T2I1I2MASK ((1 << 13) | (1 << 11))
23160 offsetT newval;
23161 offsetT newval2;
23162 addressT S, I1, I2, lo, hi;
23163
23164 S = (value >> 24) & 0x01;
23165 I1 = (value >> 23) & 0x01;
23166 I2 = (value >> 22) & 0x01;
23167 hi = (value >> 12) & 0x3ff;
fa94de6b 23168 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
23169 newval = md_chars_to_number (buf, THUMB_SIZE);
23170 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23171 newval |= (S << 10) | hi;
23172 newval2 &= ~T2I1I2MASK;
23173 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
23174 md_number_to_chars (buf, newval, THUMB_SIZE);
23175 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23176}
23177
c19d1205 23178void
55cf6793 23179md_apply_fix (fixS * fixP,
c19d1205
ZW
23180 valueT * valP,
23181 segT seg)
23182{
23183 offsetT value = * valP;
23184 offsetT newval;
23185 unsigned int newimm;
23186 unsigned long temp;
23187 int sign;
23188 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 23189
9c2799c2 23190 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 23191
c19d1205 23192 /* Note whether this will delete the relocation. */
4962c51a 23193
c19d1205
ZW
23194 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
23195 fixP->fx_done = 1;
b99bd4ef 23196
adbaf948 23197 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 23198 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
23199 for emit_reloc. */
23200 value &= 0xffffffff;
23201 value ^= 0x80000000;
5f4273c7 23202 value -= 0x80000000;
adbaf948
ZW
23203
23204 *valP = value;
c19d1205 23205 fixP->fx_addnumber = value;
b99bd4ef 23206
adbaf948
ZW
23207 /* Same treatment for fixP->fx_offset. */
23208 fixP->fx_offset &= 0xffffffff;
23209 fixP->fx_offset ^= 0x80000000;
23210 fixP->fx_offset -= 0x80000000;
23211
c19d1205 23212 switch (fixP->fx_r_type)
b99bd4ef 23213 {
c19d1205
ZW
23214 case BFD_RELOC_NONE:
23215 /* This will need to go in the object file. */
23216 fixP->fx_done = 0;
23217 break;
b99bd4ef 23218
c19d1205
ZW
23219 case BFD_RELOC_ARM_IMMEDIATE:
23220 /* We claim that this fixup has been processed here,
23221 even if in fact we generate an error because we do
23222 not have a reloc for it, so tc_gen_reloc will reject it. */
23223 fixP->fx_done = 1;
b99bd4ef 23224
77db8e2e 23225 if (fixP->fx_addsy)
b99bd4ef 23226 {
77db8e2e 23227 const char *msg = 0;
b99bd4ef 23228
77db8e2e
NC
23229 if (! S_IS_DEFINED (fixP->fx_addsy))
23230 msg = _("undefined symbol %s used as an immediate value");
23231 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23232 msg = _("symbol %s is in a different section");
23233 else if (S_IS_WEAK (fixP->fx_addsy))
23234 msg = _("symbol %s is weak and may be overridden later");
23235
23236 if (msg)
23237 {
23238 as_bad_where (fixP->fx_file, fixP->fx_line,
23239 msg, S_GET_NAME (fixP->fx_addsy));
23240 break;
23241 }
42e5fcbf
AS
23242 }
23243
c19d1205
ZW
23244 temp = md_chars_to_number (buf, INSN_SIZE);
23245
5e73442d
SL
23246 /* If the offset is negative, we should use encoding A2 for ADR. */
23247 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
23248 newimm = negate_data_op (&temp, value);
23249 else
23250 {
23251 newimm = encode_arm_immediate (value);
23252
23253 /* If the instruction will fail, see if we can fix things up by
23254 changing the opcode. */
23255 if (newimm == (unsigned int) FAIL)
23256 newimm = negate_data_op (&temp, value);
bada4342
JW
23257 /* MOV accepts both ARM modified immediate (A1 encoding) and
23258 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
23259 When disassembling, MOV is preferred when there is no encoding
23260 overlap. */
23261 if (newimm == (unsigned int) FAIL
23262 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
23263 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
23264 && !((temp >> SBIT_SHIFT) & 0x1)
23265 && value >= 0 && value <= 0xffff)
23266 {
23267 /* Clear bits[23:20] to change encoding from A1 to A2. */
23268 temp &= 0xff0fffff;
23269 /* Encoding high 4bits imm. Code below will encode the remaining
23270 low 12bits. */
23271 temp |= (value & 0x0000f000) << 4;
23272 newimm = value & 0x00000fff;
23273 }
5e73442d
SL
23274 }
23275
23276 if (newimm == (unsigned int) FAIL)
b99bd4ef 23277 {
c19d1205
ZW
23278 as_bad_where (fixP->fx_file, fixP->fx_line,
23279 _("invalid constant (%lx) after fixup"),
23280 (unsigned long) value);
23281 break;
b99bd4ef 23282 }
b99bd4ef 23283
c19d1205
ZW
23284 newimm |= (temp & 0xfffff000);
23285 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
23286 break;
b99bd4ef 23287
c19d1205
ZW
23288 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23289 {
23290 unsigned int highpart = 0;
23291 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 23292
77db8e2e 23293 if (fixP->fx_addsy)
42e5fcbf 23294 {
77db8e2e 23295 const char *msg = 0;
42e5fcbf 23296
77db8e2e
NC
23297 if (! S_IS_DEFINED (fixP->fx_addsy))
23298 msg = _("undefined symbol %s used as an immediate value");
23299 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23300 msg = _("symbol %s is in a different section");
23301 else if (S_IS_WEAK (fixP->fx_addsy))
23302 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 23303
77db8e2e
NC
23304 if (msg)
23305 {
23306 as_bad_where (fixP->fx_file, fixP->fx_line,
23307 msg, S_GET_NAME (fixP->fx_addsy));
23308 break;
23309 }
23310 }
fa94de6b 23311
c19d1205
ZW
23312 newimm = encode_arm_immediate (value);
23313 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 23314
c19d1205
ZW
23315 /* If the instruction will fail, see if we can fix things up by
23316 changing the opcode. */
23317 if (newimm == (unsigned int) FAIL
23318 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
23319 {
23320 /* No ? OK - try using two ADD instructions to generate
23321 the value. */
23322 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 23323
c19d1205
ZW
23324 /* Yes - then make sure that the second instruction is
23325 also an add. */
23326 if (newimm != (unsigned int) FAIL)
23327 newinsn = temp;
23328 /* Still No ? Try using a negated value. */
23329 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
23330 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
23331 /* Otherwise - give up. */
23332 else
23333 {
23334 as_bad_where (fixP->fx_file, fixP->fx_line,
23335 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
23336 (long) value);
23337 break;
23338 }
b99bd4ef 23339
c19d1205
ZW
23340 /* Replace the first operand in the 2nd instruction (which
23341 is the PC) with the destination register. We have
23342 already added in the PC in the first instruction and we
23343 do not want to do it again. */
23344 newinsn &= ~ 0xf0000;
23345 newinsn |= ((newinsn & 0x0f000) << 4);
23346 }
b99bd4ef 23347
c19d1205
ZW
23348 newimm |= (temp & 0xfffff000);
23349 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 23350
c19d1205
ZW
23351 highpart |= (newinsn & 0xfffff000);
23352 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
23353 }
23354 break;
b99bd4ef 23355
c19d1205 23356 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23357 if (!fixP->fx_done && seg->use_rela_p)
23358 value = 0;
1a0670f3 23359 /* Fall through. */
00a97672 23360
c19d1205 23361 case BFD_RELOC_ARM_LITERAL:
26d97720 23362 sign = value > 0;
b99bd4ef 23363
c19d1205
ZW
23364 if (value < 0)
23365 value = - value;
b99bd4ef 23366
c19d1205 23367 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 23368 {
c19d1205
ZW
23369 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23370 as_bad_where (fixP->fx_file, fixP->fx_line,
23371 _("invalid literal constant: pool needs to be closer"));
23372 else
23373 as_bad_where (fixP->fx_file, fixP->fx_line,
23374 _("bad immediate value for offset (%ld)"),
23375 (long) value);
23376 break;
f03698e6
RE
23377 }
23378
c19d1205 23379 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23380 if (value == 0)
23381 newval &= 0xfffff000;
23382 else
23383 {
23384 newval &= 0xff7ff000;
23385 newval |= value | (sign ? INDEX_UP : 0);
23386 }
c19d1205
ZW
23387 md_number_to_chars (buf, newval, INSN_SIZE);
23388 break;
b99bd4ef 23389
c19d1205
ZW
23390 case BFD_RELOC_ARM_OFFSET_IMM8:
23391 case BFD_RELOC_ARM_HWLITERAL:
26d97720 23392 sign = value > 0;
b99bd4ef 23393
c19d1205
ZW
23394 if (value < 0)
23395 value = - value;
b99bd4ef 23396
c19d1205 23397 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 23398 {
c19d1205
ZW
23399 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23400 as_bad_where (fixP->fx_file, fixP->fx_line,
23401 _("invalid literal constant: pool needs to be closer"));
23402 else
427d0db6
RM
23403 as_bad_where (fixP->fx_file, fixP->fx_line,
23404 _("bad immediate value for 8-bit offset (%ld)"),
23405 (long) value);
c19d1205 23406 break;
b99bd4ef
NC
23407 }
23408
c19d1205 23409 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23410 if (value == 0)
23411 newval &= 0xfffff0f0;
23412 else
23413 {
23414 newval &= 0xff7ff0f0;
23415 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23416 }
c19d1205
ZW
23417 md_number_to_chars (buf, newval, INSN_SIZE);
23418 break;
b99bd4ef 23419
c19d1205
ZW
23420 case BFD_RELOC_ARM_T32_OFFSET_U8:
23421 if (value < 0 || value > 1020 || value % 4 != 0)
23422 as_bad_where (fixP->fx_file, fixP->fx_line,
23423 _("bad immediate value for offset (%ld)"), (long) value);
23424 value /= 4;
b99bd4ef 23425
c19d1205 23426 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
23427 newval |= value;
23428 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23429 break;
b99bd4ef 23430
c19d1205
ZW
23431 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23432 /* This is a complicated relocation used for all varieties of Thumb32
23433 load/store instruction with immediate offset:
23434
23435 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 23436 *4, optional writeback(W)
c19d1205
ZW
23437 (doubleword load/store)
23438
23439 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23440 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23441 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23442 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23443 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23444
23445 Uppercase letters indicate bits that are already encoded at
23446 this point. Lowercase letters are our problem. For the
23447 second block of instructions, the secondary opcode nybble
23448 (bits 8..11) is present, and bit 23 is zero, even if this is
23449 a PC-relative operation. */
23450 newval = md_chars_to_number (buf, THUMB_SIZE);
23451 newval <<= 16;
23452 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 23453
c19d1205 23454 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 23455 {
c19d1205
ZW
23456 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23457 if (value >= 0)
23458 newval |= (1 << 23);
23459 else
23460 value = -value;
23461 if (value % 4 != 0)
23462 {
23463 as_bad_where (fixP->fx_file, fixP->fx_line,
23464 _("offset not a multiple of 4"));
23465 break;
23466 }
23467 value /= 4;
216d22bc 23468 if (value > 0xff)
c19d1205
ZW
23469 {
23470 as_bad_where (fixP->fx_file, fixP->fx_line,
23471 _("offset out of range"));
23472 break;
23473 }
23474 newval &= ~0xff;
b99bd4ef 23475 }
c19d1205 23476 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 23477 {
c19d1205
ZW
23478 /* PC-relative, 12-bit offset. */
23479 if (value >= 0)
23480 newval |= (1 << 23);
23481 else
23482 value = -value;
216d22bc 23483 if (value > 0xfff)
c19d1205
ZW
23484 {
23485 as_bad_where (fixP->fx_file, fixP->fx_line,
23486 _("offset out of range"));
23487 break;
23488 }
23489 newval &= ~0xfff;
b99bd4ef 23490 }
c19d1205 23491 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 23492 {
c19d1205
ZW
23493 /* Writeback: 8-bit, +/- offset. */
23494 if (value >= 0)
23495 newval |= (1 << 9);
23496 else
23497 value = -value;
216d22bc 23498 if (value > 0xff)
c19d1205
ZW
23499 {
23500 as_bad_where (fixP->fx_file, fixP->fx_line,
23501 _("offset out of range"));
23502 break;
23503 }
23504 newval &= ~0xff;
b99bd4ef 23505 }
c19d1205 23506 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 23507 {
c19d1205 23508 /* T-instruction: positive 8-bit offset. */
216d22bc 23509 if (value < 0 || value > 0xff)
b99bd4ef 23510 {
c19d1205
ZW
23511 as_bad_where (fixP->fx_file, fixP->fx_line,
23512 _("offset out of range"));
23513 break;
b99bd4ef 23514 }
c19d1205
ZW
23515 newval &= ~0xff;
23516 newval |= value;
b99bd4ef
NC
23517 }
23518 else
b99bd4ef 23519 {
c19d1205
ZW
23520 /* Positive 12-bit or negative 8-bit offset. */
23521 int limit;
23522 if (value >= 0)
b99bd4ef 23523 {
c19d1205
ZW
23524 newval |= (1 << 23);
23525 limit = 0xfff;
23526 }
23527 else
23528 {
23529 value = -value;
23530 limit = 0xff;
23531 }
23532 if (value > limit)
23533 {
23534 as_bad_where (fixP->fx_file, fixP->fx_line,
23535 _("offset out of range"));
23536 break;
b99bd4ef 23537 }
c19d1205 23538 newval &= ~limit;
b99bd4ef 23539 }
b99bd4ef 23540
c19d1205
ZW
23541 newval |= value;
23542 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23543 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23544 break;
404ff6b5 23545
c19d1205
ZW
23546 case BFD_RELOC_ARM_SHIFT_IMM:
23547 newval = md_chars_to_number (buf, INSN_SIZE);
23548 if (((unsigned long) value) > 32
23549 || (value == 32
23550 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23551 {
23552 as_bad_where (fixP->fx_file, fixP->fx_line,
23553 _("shift expression is too large"));
23554 break;
23555 }
404ff6b5 23556
c19d1205
ZW
23557 if (value == 0)
23558 /* Shifts of zero must be done as lsl. */
23559 newval &= ~0x60;
23560 else if (value == 32)
23561 value = 0;
23562 newval &= 0xfffff07f;
23563 newval |= (value & 0x1f) << 7;
23564 md_number_to_chars (buf, newval, INSN_SIZE);
23565 break;
404ff6b5 23566
c19d1205 23567 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23568 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23569 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23570 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23571 /* We claim that this fixup has been processed here,
23572 even if in fact we generate an error because we do
23573 not have a reloc for it, so tc_gen_reloc will reject it. */
23574 fixP->fx_done = 1;
404ff6b5 23575
c19d1205
ZW
23576 if (fixP->fx_addsy
23577 && ! S_IS_DEFINED (fixP->fx_addsy))
23578 {
23579 as_bad_where (fixP->fx_file, fixP->fx_line,
23580 _("undefined symbol %s used as an immediate value"),
23581 S_GET_NAME (fixP->fx_addsy));
23582 break;
23583 }
404ff6b5 23584
c19d1205
ZW
23585 newval = md_chars_to_number (buf, THUMB_SIZE);
23586 newval <<= 16;
23587 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23588
16805f35 23589 newimm = FAIL;
bada4342
JW
23590 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23591 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23592 Thumb2 modified immediate encoding (T2). */
23593 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 23594 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23595 {
23596 newimm = encode_thumb32_immediate (value);
23597 if (newimm == (unsigned int) FAIL)
23598 newimm = thumb32_negate_data_op (&newval, value);
23599 }
bada4342 23600 if (newimm == (unsigned int) FAIL)
92e90b6e 23601 {
bada4342 23602 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 23603 {
bada4342
JW
23604 /* Turn add/sum into addw/subw. */
23605 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23606 newval = (newval & 0xfeffffff) | 0x02000000;
23607 /* No flat 12-bit imm encoding for addsw/subsw. */
23608 if ((newval & 0x00100000) == 0)
40f246e3 23609 {
bada4342
JW
23610 /* 12 bit immediate for addw/subw. */
23611 if (value < 0)
23612 {
23613 value = -value;
23614 newval ^= 0x00a00000;
23615 }
23616 if (value > 0xfff)
23617 newimm = (unsigned int) FAIL;
23618 else
23619 newimm = value;
23620 }
23621 }
23622 else
23623 {
23624 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23625 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23626 disassembling, MOV is preferred when there is no encoding
db7bf105 23627 overlap. */
bada4342 23628 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
db7bf105
NC
23629 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
23630 but with the Rn field [19:16] set to 1111. */
23631 && (((newval >> 16) & 0xf) == 0xf)
bada4342
JW
23632 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23633 && !((newval >> T2_SBIT_SHIFT) & 0x1)
db7bf105 23634 && value >= 0 && value <= 0xffff)
bada4342
JW
23635 {
23636 /* Toggle bit[25] to change encoding from T2 to T3. */
23637 newval ^= 1 << 25;
23638 /* Clear bits[19:16]. */
23639 newval &= 0xfff0ffff;
23640 /* Encoding high 4bits imm. Code below will encode the
23641 remaining low 12bits. */
23642 newval |= (value & 0x0000f000) << 4;
23643 newimm = value & 0x00000fff;
40f246e3 23644 }
e9f89963 23645 }
92e90b6e 23646 }
cc8a6dd0 23647
c19d1205 23648 if (newimm == (unsigned int)FAIL)
3631a3c8 23649 {
c19d1205
ZW
23650 as_bad_where (fixP->fx_file, fixP->fx_line,
23651 _("invalid constant (%lx) after fixup"),
23652 (unsigned long) value);
23653 break;
3631a3c8
NC
23654 }
23655
c19d1205
ZW
23656 newval |= (newimm & 0x800) << 15;
23657 newval |= (newimm & 0x700) << 4;
23658 newval |= (newimm & 0x0ff);
cc8a6dd0 23659
c19d1205
ZW
23660 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23661 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23662 break;
a737bd4d 23663
3eb17e6b 23664 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23665 if (((unsigned long) value) > 0xffff)
23666 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23667 _("invalid smc expression"));
2fc8bdac 23668 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23669 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23670 md_number_to_chars (buf, newval, INSN_SIZE);
23671 break;
a737bd4d 23672
90ec0d68
MGD
23673 case BFD_RELOC_ARM_HVC:
23674 if (((unsigned long) value) > 0xffff)
23675 as_bad_where (fixP->fx_file, fixP->fx_line,
23676 _("invalid hvc expression"));
23677 newval = md_chars_to_number (buf, INSN_SIZE);
23678 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23679 md_number_to_chars (buf, newval, INSN_SIZE);
23680 break;
23681
c19d1205 23682 case BFD_RELOC_ARM_SWI:
adbaf948 23683 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23684 {
23685 if (((unsigned long) value) > 0xff)
23686 as_bad_where (fixP->fx_file, fixP->fx_line,
23687 _("invalid swi expression"));
2fc8bdac 23688 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23689 newval |= value;
23690 md_number_to_chars (buf, newval, THUMB_SIZE);
23691 }
23692 else
23693 {
23694 if (((unsigned long) value) > 0x00ffffff)
23695 as_bad_where (fixP->fx_file, fixP->fx_line,
23696 _("invalid swi expression"));
2fc8bdac 23697 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23698 newval |= value;
23699 md_number_to_chars (buf, newval, INSN_SIZE);
23700 }
23701 break;
a737bd4d 23702
c19d1205
ZW
23703 case BFD_RELOC_ARM_MULTI:
23704 if (((unsigned long) value) > 0xffff)
23705 as_bad_where (fixP->fx_file, fixP->fx_line,
23706 _("invalid expression in load/store multiple"));
23707 newval = value | md_chars_to_number (buf, INSN_SIZE);
23708 md_number_to_chars (buf, newval, INSN_SIZE);
23709 break;
a737bd4d 23710
c19d1205 23711#ifdef OBJ_ELF
39b41c9c 23712 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23713
23714 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23715 && fixP->fx_addsy
34e77a92 23716 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23717 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23718 && THUMB_IS_FUNC (fixP->fx_addsy))
23719 /* Flip the bl to blx. This is a simple flip
23720 bit here because we generate PCREL_CALL for
23721 unconditional bls. */
23722 {
23723 newval = md_chars_to_number (buf, INSN_SIZE);
23724 newval = newval | 0x10000000;
23725 md_number_to_chars (buf, newval, INSN_SIZE);
23726 temp = 1;
23727 fixP->fx_done = 1;
23728 }
39b41c9c
PB
23729 else
23730 temp = 3;
23731 goto arm_branch_common;
23732
23733 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23734 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23735 && fixP->fx_addsy
34e77a92 23736 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23737 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23738 && THUMB_IS_FUNC (fixP->fx_addsy))
23739 {
23740 /* This would map to a bl<cond>, b<cond>,
23741 b<always> to a Thumb function. We
23742 need to force a relocation for this particular
23743 case. */
23744 newval = md_chars_to_number (buf, INSN_SIZE);
23745 fixP->fx_done = 0;
23746 }
1a0670f3 23747 /* Fall through. */
267bf995 23748
2fc8bdac 23749 case BFD_RELOC_ARM_PLT32:
c19d1205 23750#endif
39b41c9c
PB
23751 case BFD_RELOC_ARM_PCREL_BRANCH:
23752 temp = 3;
23753 goto arm_branch_common;
a737bd4d 23754
39b41c9c 23755 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23756
39b41c9c 23757 temp = 1;
267bf995
RR
23758 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23759 && fixP->fx_addsy
34e77a92 23760 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23761 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23762 && ARM_IS_FUNC (fixP->fx_addsy))
23763 {
23764 /* Flip the blx to a bl and warn. */
23765 const char *name = S_GET_NAME (fixP->fx_addsy);
23766 newval = 0xeb000000;
23767 as_warn_where (fixP->fx_file, fixP->fx_line,
23768 _("blx to '%s' an ARM ISA state function changed to bl"),
23769 name);
23770 md_number_to_chars (buf, newval, INSN_SIZE);
23771 temp = 3;
23772 fixP->fx_done = 1;
23773 }
23774
23775#ifdef OBJ_ELF
23776 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23777 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23778#endif
23779
39b41c9c 23780 arm_branch_common:
c19d1205 23781 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23782 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23783 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 23784 also be clear. */
39b41c9c 23785 if (value & temp)
c19d1205 23786 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23787 _("misaligned branch destination"));
23788 if ((value & (offsetT)0xfe000000) != (offsetT)0
23789 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23790 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23791
2fc8bdac 23792 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23793 {
2fc8bdac
ZW
23794 newval = md_chars_to_number (buf, INSN_SIZE);
23795 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23796 /* Set the H bit on BLX instructions. */
23797 if (temp == 1)
23798 {
23799 if (value & 2)
23800 newval |= 0x01000000;
23801 else
23802 newval &= ~0x01000000;
23803 }
2fc8bdac 23804 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23805 }
c19d1205 23806 break;
a737bd4d 23807
25fe350b
MS
23808 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23809 /* CBZ can only branch forward. */
a737bd4d 23810
738755b0 23811 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23812 (which, strictly speaking, are prohibited) will be turned into
23813 no-ops.
738755b0
MS
23814
23815 FIXME: It may be better to remove the instruction completely and
23816 perform relaxation. */
23817 if (value == -2)
2fc8bdac
ZW
23818 {
23819 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23820 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23821 md_number_to_chars (buf, newval, THUMB_SIZE);
23822 }
738755b0
MS
23823 else
23824 {
23825 if (value & ~0x7e)
08f10d51 23826 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23827
477330fc 23828 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23829 {
23830 newval = md_chars_to_number (buf, THUMB_SIZE);
23831 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23832 md_number_to_chars (buf, newval, THUMB_SIZE);
23833 }
23834 }
c19d1205 23835 break;
a737bd4d 23836
c19d1205 23837 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23838 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23839 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23840
2fc8bdac
ZW
23841 if (fixP->fx_done || !seg->use_rela_p)
23842 {
23843 newval = md_chars_to_number (buf, THUMB_SIZE);
23844 newval |= (value & 0x1ff) >> 1;
23845 md_number_to_chars (buf, newval, THUMB_SIZE);
23846 }
c19d1205 23847 break;
a737bd4d 23848
c19d1205 23849 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23850 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23851 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23852
2fc8bdac
ZW
23853 if (fixP->fx_done || !seg->use_rela_p)
23854 {
23855 newval = md_chars_to_number (buf, THUMB_SIZE);
23856 newval |= (value & 0xfff) >> 1;
23857 md_number_to_chars (buf, newval, THUMB_SIZE);
23858 }
c19d1205 23859 break;
a737bd4d 23860
c19d1205 23861 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23862 if (fixP->fx_addsy
23863 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23864 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23865 && ARM_IS_FUNC (fixP->fx_addsy)
23866 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23867 {
23868 /* Force a relocation for a branch 20 bits wide. */
23869 fixP->fx_done = 0;
23870 }
08f10d51 23871 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23872 as_bad_where (fixP->fx_file, fixP->fx_line,
23873 _("conditional branch out of range"));
404ff6b5 23874
2fc8bdac
ZW
23875 if (fixP->fx_done || !seg->use_rela_p)
23876 {
23877 offsetT newval2;
23878 addressT S, J1, J2, lo, hi;
404ff6b5 23879
2fc8bdac
ZW
23880 S = (value & 0x00100000) >> 20;
23881 J2 = (value & 0x00080000) >> 19;
23882 J1 = (value & 0x00040000) >> 18;
23883 hi = (value & 0x0003f000) >> 12;
23884 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23885
2fc8bdac
ZW
23886 newval = md_chars_to_number (buf, THUMB_SIZE);
23887 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23888 newval |= (S << 10) | hi;
23889 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23890 md_number_to_chars (buf, newval, THUMB_SIZE);
23891 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23892 }
c19d1205 23893 break;
6c43fab6 23894
c19d1205 23895 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23896 /* If there is a blx from a thumb state function to
23897 another thumb function flip this to a bl and warn
23898 about it. */
23899
23900 if (fixP->fx_addsy
34e77a92 23901 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23902 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23903 && THUMB_IS_FUNC (fixP->fx_addsy))
23904 {
23905 const char *name = S_GET_NAME (fixP->fx_addsy);
23906 as_warn_where (fixP->fx_file, fixP->fx_line,
23907 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23908 name);
23909 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23910 newval = newval | 0x1000;
23911 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23912 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23913 fixP->fx_done = 1;
23914 }
23915
23916
23917 goto thumb_bl_common;
23918
c19d1205 23919 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23920 /* A bl from Thumb state ISA to an internal ARM state function
23921 is converted to a blx. */
23922 if (fixP->fx_addsy
23923 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23924 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23925 && ARM_IS_FUNC (fixP->fx_addsy)
23926 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23927 {
23928 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23929 newval = newval & ~0x1000;
23930 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23931 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23932 fixP->fx_done = 1;
23933 }
23934
23935 thumb_bl_common:
23936
2fc8bdac
ZW
23937 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23938 /* For a BLX instruction, make sure that the relocation is rounded up
23939 to a word boundary. This follows the semantics of the instruction
23940 which specifies that bit 1 of the target address will come from bit
23941 1 of the base address. */
d406f3e4
JB
23942 value = (value + 3) & ~ 3;
23943
23944#ifdef OBJ_ELF
23945 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23946 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23947 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23948#endif
404ff6b5 23949
2b2f5df9
NC
23950 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23951 {
fc289b0a 23952 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23953 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23954 else if ((value & ~0x1ffffff)
23955 && ((value & ~0x1ffffff) != ~0x1ffffff))
23956 as_bad_where (fixP->fx_file, fixP->fx_line,
23957 _("Thumb2 branch out of range"));
23958 }
4a42ebbc
RR
23959
23960 if (fixP->fx_done || !seg->use_rela_p)
23961 encode_thumb2_b_bl_offset (buf, value);
23962
c19d1205 23963 break;
404ff6b5 23964
c19d1205 23965 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23966 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23967 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23968
2fc8bdac 23969 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23970 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23971
2fc8bdac 23972 break;
a737bd4d 23973
2fc8bdac
ZW
23974 case BFD_RELOC_8:
23975 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23976 *buf = value;
c19d1205 23977 break;
a737bd4d 23978
c19d1205 23979 case BFD_RELOC_16:
2fc8bdac 23980 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23981 md_number_to_chars (buf, value, 2);
c19d1205 23982 break;
a737bd4d 23983
c19d1205 23984#ifdef OBJ_ELF
0855e32b
NS
23985 case BFD_RELOC_ARM_TLS_CALL:
23986 case BFD_RELOC_ARM_THM_TLS_CALL:
23987 case BFD_RELOC_ARM_TLS_DESCSEQ:
23988 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23989 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23990 case BFD_RELOC_ARM_TLS_GD32:
23991 case BFD_RELOC_ARM_TLS_LE32:
23992 case BFD_RELOC_ARM_TLS_IE32:
23993 case BFD_RELOC_ARM_TLS_LDM32:
23994 case BFD_RELOC_ARM_TLS_LDO32:
23995 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23996 break;
6c43fab6 23997
5c5a4843
CL
23998 /* Same handling as above, but with the arm_fdpic guard. */
23999 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
24000 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
24001 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
24002 if (arm_fdpic)
24003 {
24004 S_SET_THREAD_LOCAL (fixP->fx_addsy);
24005 }
24006 else
24007 {
24008 as_bad_where (fixP->fx_file, fixP->fx_line,
24009 _("Relocation supported only in FDPIC mode"));
24010 }
24011 break;
24012
c19d1205
ZW
24013 case BFD_RELOC_ARM_GOT32:
24014 case BFD_RELOC_ARM_GOTOFF:
c19d1205 24015 break;
b43420e6
NC
24016
24017 case BFD_RELOC_ARM_GOT_PREL:
24018 if (fixP->fx_done || !seg->use_rela_p)
477330fc 24019 md_number_to_chars (buf, value, 4);
b43420e6
NC
24020 break;
24021
9a6f4e97
NS
24022 case BFD_RELOC_ARM_TARGET2:
24023 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
24024 addend here for REL targets, because it won't be written out
24025 during reloc processing later. */
9a6f4e97
NS
24026 if (fixP->fx_done || !seg->use_rela_p)
24027 md_number_to_chars (buf, fixP->fx_offset, 4);
24028 break;
188fd7ae
CL
24029
24030 /* Relocations for FDPIC. */
24031 case BFD_RELOC_ARM_GOTFUNCDESC:
24032 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
24033 case BFD_RELOC_ARM_FUNCDESC:
24034 if (arm_fdpic)
24035 {
24036 if (fixP->fx_done || !seg->use_rela_p)
24037 md_number_to_chars (buf, 0, 4);
24038 }
24039 else
24040 {
24041 as_bad_where (fixP->fx_file, fixP->fx_line,
24042 _("Relocation supported only in FDPIC mode"));
24043 }
24044 break;
c19d1205 24045#endif
6c43fab6 24046
c19d1205
ZW
24047 case BFD_RELOC_RVA:
24048 case BFD_RELOC_32:
24049 case BFD_RELOC_ARM_TARGET1:
24050 case BFD_RELOC_ARM_ROSEGREL32:
24051 case BFD_RELOC_ARM_SBREL32:
24052 case BFD_RELOC_32_PCREL:
f0927246
NC
24053#ifdef TE_PE
24054 case BFD_RELOC_32_SECREL:
24055#endif
2fc8bdac 24056 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
24057#ifdef TE_WINCE
24058 /* For WinCE we only do this for pcrel fixups. */
24059 if (fixP->fx_done || fixP->fx_pcrel)
24060#endif
24061 md_number_to_chars (buf, value, 4);
c19d1205 24062 break;
6c43fab6 24063
c19d1205
ZW
24064#ifdef OBJ_ELF
24065 case BFD_RELOC_ARM_PREL31:
2fc8bdac 24066 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
24067 {
24068 newval = md_chars_to_number (buf, 4) & 0x80000000;
24069 if ((value ^ (value >> 1)) & 0x40000000)
24070 {
24071 as_bad_where (fixP->fx_file, fixP->fx_line,
24072 _("rel31 relocation overflow"));
24073 }
24074 newval |= value & 0x7fffffff;
24075 md_number_to_chars (buf, newval, 4);
24076 }
24077 break;
c19d1205 24078#endif
a737bd4d 24079
c19d1205 24080 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 24081 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
24082 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
24083 newval = md_chars_to_number (buf, INSN_SIZE);
24084 else
24085 newval = get_thumb32_insn (buf);
24086 if ((newval & 0x0f200f00) == 0x0d000900)
24087 {
24088 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
24089 has permitted values that are multiples of 2, in the range 0
24090 to 510. */
24091 if (value < -510 || value > 510 || (value & 1))
24092 as_bad_where (fixP->fx_file, fixP->fx_line,
24093 _("co-processor offset out of range"));
24094 }
24095 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
24096 as_bad_where (fixP->fx_file, fixP->fx_line,
24097 _("co-processor offset out of range"));
24098 cp_off_common:
26d97720 24099 sign = value > 0;
c19d1205
ZW
24100 if (value < 0)
24101 value = -value;
8f06b2d8
PB
24102 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24103 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24104 newval = md_chars_to_number (buf, INSN_SIZE);
24105 else
24106 newval = get_thumb32_insn (buf);
26d97720
NS
24107 if (value == 0)
24108 newval &= 0xffffff00;
24109 else
24110 {
24111 newval &= 0xff7fff00;
9db2f6b4
RL
24112 if ((newval & 0x0f200f00) == 0x0d000900)
24113 {
24114 /* This is a fp16 vstr/vldr.
24115
24116 It requires the immediate offset in the instruction is shifted
24117 left by 1 to be a half-word offset.
24118
24119 Here, left shift by 1 first, and later right shift by 2
24120 should get the right offset. */
24121 value <<= 1;
24122 }
26d97720
NS
24123 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
24124 }
8f06b2d8
PB
24125 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24126 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24127 md_number_to_chars (buf, newval, INSN_SIZE);
24128 else
24129 put_thumb32_insn (buf, newval);
c19d1205 24130 break;
a737bd4d 24131
c19d1205 24132 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 24133 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
24134 if (value < -255 || value > 255)
24135 as_bad_where (fixP->fx_file, fixP->fx_line,
24136 _("co-processor offset out of range"));
df7849c5 24137 value *= 4;
c19d1205 24138 goto cp_off_common;
6c43fab6 24139
c19d1205
ZW
24140 case BFD_RELOC_ARM_THUMB_OFFSET:
24141 newval = md_chars_to_number (buf, THUMB_SIZE);
24142 /* Exactly what ranges, and where the offset is inserted depends
24143 on the type of instruction, we can establish this from the
24144 top 4 bits. */
24145 switch (newval >> 12)
24146 {
24147 case 4: /* PC load. */
24148 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
24149 forced to zero for these loads; md_pcrel_from has already
24150 compensated for this. */
24151 if (value & 3)
24152 as_bad_where (fixP->fx_file, fixP->fx_line,
24153 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
24154 (((unsigned long) fixP->fx_frag->fr_address
24155 + (unsigned long) fixP->fx_where) & ~3)
24156 + (unsigned long) value);
a737bd4d 24157
c19d1205
ZW
24158 if (value & ~0x3fc)
24159 as_bad_where (fixP->fx_file, fixP->fx_line,
24160 _("invalid offset, value too big (0x%08lX)"),
24161 (long) value);
a737bd4d 24162
c19d1205
ZW
24163 newval |= value >> 2;
24164 break;
a737bd4d 24165
c19d1205
ZW
24166 case 9: /* SP load/store. */
24167 if (value & ~0x3fc)
24168 as_bad_where (fixP->fx_file, fixP->fx_line,
24169 _("invalid offset, value too big (0x%08lX)"),
24170 (long) value);
24171 newval |= value >> 2;
24172 break;
6c43fab6 24173
c19d1205
ZW
24174 case 6: /* Word load/store. */
24175 if (value & ~0x7c)
24176 as_bad_where (fixP->fx_file, fixP->fx_line,
24177 _("invalid offset, value too big (0x%08lX)"),
24178 (long) value);
24179 newval |= value << 4; /* 6 - 2. */
24180 break;
a737bd4d 24181
c19d1205
ZW
24182 case 7: /* Byte load/store. */
24183 if (value & ~0x1f)
24184 as_bad_where (fixP->fx_file, fixP->fx_line,
24185 _("invalid offset, value too big (0x%08lX)"),
24186 (long) value);
24187 newval |= value << 6;
24188 break;
a737bd4d 24189
c19d1205
ZW
24190 case 8: /* Halfword load/store. */
24191 if (value & ~0x3e)
24192 as_bad_where (fixP->fx_file, fixP->fx_line,
24193 _("invalid offset, value too big (0x%08lX)"),
24194 (long) value);
24195 newval |= value << 5; /* 6 - 1. */
24196 break;
a737bd4d 24197
c19d1205
ZW
24198 default:
24199 as_bad_where (fixP->fx_file, fixP->fx_line,
24200 "Unable to process relocation for thumb opcode: %lx",
24201 (unsigned long) newval);
24202 break;
24203 }
24204 md_number_to_chars (buf, newval, THUMB_SIZE);
24205 break;
a737bd4d 24206
c19d1205
ZW
24207 case BFD_RELOC_ARM_THUMB_ADD:
24208 /* This is a complicated relocation, since we use it for all of
24209 the following immediate relocations:
a737bd4d 24210
c19d1205
ZW
24211 3bit ADD/SUB
24212 8bit ADD/SUB
24213 9bit ADD/SUB SP word-aligned
24214 10bit ADD PC/SP word-aligned
a737bd4d 24215
c19d1205
ZW
24216 The type of instruction being processed is encoded in the
24217 instruction field:
a737bd4d 24218
c19d1205
ZW
24219 0x8000 SUB
24220 0x00F0 Rd
24221 0x000F Rs
24222 */
24223 newval = md_chars_to_number (buf, THUMB_SIZE);
24224 {
24225 int rd = (newval >> 4) & 0xf;
24226 int rs = newval & 0xf;
24227 int subtract = !!(newval & 0x8000);
a737bd4d 24228
c19d1205
ZW
24229 /* Check for HI regs, only very restricted cases allowed:
24230 Adjusting SP, and using PC or SP to get an address. */
24231 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
24232 || (rs > 7 && rs != REG_SP && rs != REG_PC))
24233 as_bad_where (fixP->fx_file, fixP->fx_line,
24234 _("invalid Hi register with immediate"));
a737bd4d 24235
c19d1205
ZW
24236 /* If value is negative, choose the opposite instruction. */
24237 if (value < 0)
24238 {
24239 value = -value;
24240 subtract = !subtract;
24241 if (value < 0)
24242 as_bad_where (fixP->fx_file, fixP->fx_line,
24243 _("immediate value out of range"));
24244 }
a737bd4d 24245
c19d1205
ZW
24246 if (rd == REG_SP)
24247 {
75c11999 24248 if (value & ~0x1fc)
c19d1205
ZW
24249 as_bad_where (fixP->fx_file, fixP->fx_line,
24250 _("invalid immediate for stack address calculation"));
24251 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
24252 newval |= value >> 2;
24253 }
24254 else if (rs == REG_PC || rs == REG_SP)
24255 {
c12d2c9d
NC
24256 /* PR gas/18541. If the addition is for a defined symbol
24257 within range of an ADR instruction then accept it. */
24258 if (subtract
24259 && value == 4
24260 && fixP->fx_addsy != NULL)
24261 {
24262 subtract = 0;
24263
24264 if (! S_IS_DEFINED (fixP->fx_addsy)
24265 || S_GET_SEGMENT (fixP->fx_addsy) != seg
24266 || S_IS_WEAK (fixP->fx_addsy))
24267 {
24268 as_bad_where (fixP->fx_file, fixP->fx_line,
24269 _("address calculation needs a strongly defined nearby symbol"));
24270 }
24271 else
24272 {
24273 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
24274
24275 /* Round up to the next 4-byte boundary. */
24276 if (v & 3)
24277 v = (v + 3) & ~ 3;
24278 else
24279 v += 4;
24280 v = S_GET_VALUE (fixP->fx_addsy) - v;
24281
24282 if (v & ~0x3fc)
24283 {
24284 as_bad_where (fixP->fx_file, fixP->fx_line,
24285 _("symbol too far away"));
24286 }
24287 else
24288 {
24289 fixP->fx_done = 1;
24290 value = v;
24291 }
24292 }
24293 }
24294
c19d1205
ZW
24295 if (subtract || value & ~0x3fc)
24296 as_bad_where (fixP->fx_file, fixP->fx_line,
24297 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 24298 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
24299 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
24300 newval |= rd << 8;
24301 newval |= value >> 2;
24302 }
24303 else if (rs == rd)
24304 {
24305 if (value & ~0xff)
24306 as_bad_where (fixP->fx_file, fixP->fx_line,
24307 _("immediate value out of range"));
24308 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
24309 newval |= (rd << 8) | value;
24310 }
24311 else
24312 {
24313 if (value & ~0x7)
24314 as_bad_where (fixP->fx_file, fixP->fx_line,
24315 _("immediate value out of range"));
24316 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
24317 newval |= rd | (rs << 3) | (value << 6);
24318 }
24319 }
24320 md_number_to_chars (buf, newval, THUMB_SIZE);
24321 break;
a737bd4d 24322
c19d1205
ZW
24323 case BFD_RELOC_ARM_THUMB_IMM:
24324 newval = md_chars_to_number (buf, THUMB_SIZE);
24325 if (value < 0 || value > 255)
24326 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 24327 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
24328 (long) value);
24329 newval |= value;
24330 md_number_to_chars (buf, newval, THUMB_SIZE);
24331 break;
a737bd4d 24332
c19d1205
ZW
24333 case BFD_RELOC_ARM_THUMB_SHIFT:
24334 /* 5bit shift value (0..32). LSL cannot take 32. */
24335 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
24336 temp = newval & 0xf800;
24337 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
24338 as_bad_where (fixP->fx_file, fixP->fx_line,
24339 _("invalid shift value: %ld"), (long) value);
24340 /* Shifts of zero must be encoded as LSL. */
24341 if (value == 0)
24342 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
24343 /* Shifts of 32 are encoded as zero. */
24344 else if (value == 32)
24345 value = 0;
24346 newval |= value << 6;
24347 md_number_to_chars (buf, newval, THUMB_SIZE);
24348 break;
a737bd4d 24349
c19d1205
ZW
24350 case BFD_RELOC_VTABLE_INHERIT:
24351 case BFD_RELOC_VTABLE_ENTRY:
24352 fixP->fx_done = 0;
24353 return;
6c43fab6 24354
b6895b4f
PB
24355 case BFD_RELOC_ARM_MOVW:
24356 case BFD_RELOC_ARM_MOVT:
24357 case BFD_RELOC_ARM_THUMB_MOVW:
24358 case BFD_RELOC_ARM_THUMB_MOVT:
24359 if (fixP->fx_done || !seg->use_rela_p)
24360 {
24361 /* REL format relocations are limited to a 16-bit addend. */
24362 if (!fixP->fx_done)
24363 {
39623e12 24364 if (value < -0x8000 || value > 0x7fff)
b6895b4f 24365 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 24366 _("offset out of range"));
b6895b4f
PB
24367 }
24368 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24369 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24370 {
24371 value >>= 16;
24372 }
24373
24374 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24375 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24376 {
24377 newval = get_thumb32_insn (buf);
24378 newval &= 0xfbf08f00;
24379 newval |= (value & 0xf000) << 4;
24380 newval |= (value & 0x0800) << 15;
24381 newval |= (value & 0x0700) << 4;
24382 newval |= (value & 0x00ff);
24383 put_thumb32_insn (buf, newval);
24384 }
24385 else
24386 {
24387 newval = md_chars_to_number (buf, 4);
24388 newval &= 0xfff0f000;
24389 newval |= value & 0x0fff;
24390 newval |= (value & 0xf000) << 4;
24391 md_number_to_chars (buf, newval, 4);
24392 }
24393 }
24394 return;
24395
72d98d16
MG
24396 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24397 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24398 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24399 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24400 gas_assert (!fixP->fx_done);
24401 {
24402 bfd_vma insn;
24403 bfd_boolean is_mov;
24404 bfd_vma encoded_addend = value;
24405
24406 /* Check that addend can be encoded in instruction. */
24407 if (!seg->use_rela_p && (value < 0 || value > 255))
24408 as_bad_where (fixP->fx_file, fixP->fx_line,
24409 _("the offset 0x%08lX is not representable"),
24410 (unsigned long) encoded_addend);
24411
24412 /* Extract the instruction. */
24413 insn = md_chars_to_number (buf, THUMB_SIZE);
24414 is_mov = (insn & 0xf800) == 0x2000;
24415
24416 /* Encode insn. */
24417 if (is_mov)
24418 {
24419 if (!seg->use_rela_p)
24420 insn |= encoded_addend;
24421 }
24422 else
24423 {
24424 int rd, rs;
24425
24426 /* Extract the instruction. */
24427 /* Encoding is the following
24428 0x8000 SUB
24429 0x00F0 Rd
24430 0x000F Rs
24431 */
24432 /* The following conditions must be true :
24433 - ADD
24434 - Rd == Rs
24435 - Rd <= 7
24436 */
24437 rd = (insn >> 4) & 0xf;
24438 rs = insn & 0xf;
24439 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24440 as_bad_where (fixP->fx_file, fixP->fx_line,
24441 _("Unable to process relocation for thumb opcode: %lx"),
24442 (unsigned long) insn);
24443
24444 /* Encode as ADD immediate8 thumb 1 code. */
24445 insn = 0x3000 | (rd << 8);
24446
24447 /* Place the encoded addend into the first 8 bits of the
24448 instruction. */
24449 if (!seg->use_rela_p)
24450 insn |= encoded_addend;
24451 }
24452
24453 /* Update the instruction. */
24454 md_number_to_chars (buf, insn, THUMB_SIZE);
24455 }
24456 break;
24457
4962c51a
MS
24458 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24459 case BFD_RELOC_ARM_ALU_PC_G0:
24460 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24461 case BFD_RELOC_ARM_ALU_PC_G1:
24462 case BFD_RELOC_ARM_ALU_PC_G2:
24463 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24464 case BFD_RELOC_ARM_ALU_SB_G0:
24465 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24466 case BFD_RELOC_ARM_ALU_SB_G1:
24467 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 24468 gas_assert (!fixP->fx_done);
4962c51a
MS
24469 if (!seg->use_rela_p)
24470 {
477330fc
RM
24471 bfd_vma insn;
24472 bfd_vma encoded_addend;
24473 bfd_vma addend_abs = abs (value);
24474
24475 /* Check that the absolute value of the addend can be
24476 expressed as an 8-bit constant plus a rotation. */
24477 encoded_addend = encode_arm_immediate (addend_abs);
24478 if (encoded_addend == (unsigned int) FAIL)
4962c51a 24479 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24480 _("the offset 0x%08lX is not representable"),
24481 (unsigned long) addend_abs);
24482
24483 /* Extract the instruction. */
24484 insn = md_chars_to_number (buf, INSN_SIZE);
24485
24486 /* If the addend is positive, use an ADD instruction.
24487 Otherwise use a SUB. Take care not to destroy the S bit. */
24488 insn &= 0xff1fffff;
24489 if (value < 0)
24490 insn |= 1 << 22;
24491 else
24492 insn |= 1 << 23;
24493
24494 /* Place the encoded addend into the first 12 bits of the
24495 instruction. */
24496 insn &= 0xfffff000;
24497 insn |= encoded_addend;
24498
24499 /* Update the instruction. */
24500 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
24501 }
24502 break;
24503
24504 case BFD_RELOC_ARM_LDR_PC_G0:
24505 case BFD_RELOC_ARM_LDR_PC_G1:
24506 case BFD_RELOC_ARM_LDR_PC_G2:
24507 case BFD_RELOC_ARM_LDR_SB_G0:
24508 case BFD_RELOC_ARM_LDR_SB_G1:
24509 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 24510 gas_assert (!fixP->fx_done);
4962c51a 24511 if (!seg->use_rela_p)
477330fc
RM
24512 {
24513 bfd_vma insn;
24514 bfd_vma addend_abs = abs (value);
4962c51a 24515
477330fc
RM
24516 /* Check that the absolute value of the addend can be
24517 encoded in 12 bits. */
24518 if (addend_abs >= 0x1000)
4962c51a 24519 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24520 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24521 (unsigned long) addend_abs);
24522
24523 /* Extract the instruction. */
24524 insn = md_chars_to_number (buf, INSN_SIZE);
24525
24526 /* If the addend is negative, clear bit 23 of the instruction.
24527 Otherwise set it. */
24528 if (value < 0)
24529 insn &= ~(1 << 23);
24530 else
24531 insn |= 1 << 23;
24532
24533 /* Place the absolute value of the addend into the first 12 bits
24534 of the instruction. */
24535 insn &= 0xfffff000;
24536 insn |= addend_abs;
24537
24538 /* Update the instruction. */
24539 md_number_to_chars (buf, insn, INSN_SIZE);
24540 }
4962c51a
MS
24541 break;
24542
24543 case BFD_RELOC_ARM_LDRS_PC_G0:
24544 case BFD_RELOC_ARM_LDRS_PC_G1:
24545 case BFD_RELOC_ARM_LDRS_PC_G2:
24546 case BFD_RELOC_ARM_LDRS_SB_G0:
24547 case BFD_RELOC_ARM_LDRS_SB_G1:
24548 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 24549 gas_assert (!fixP->fx_done);
4962c51a 24550 if (!seg->use_rela_p)
477330fc
RM
24551 {
24552 bfd_vma insn;
24553 bfd_vma addend_abs = abs (value);
4962c51a 24554
477330fc
RM
24555 /* Check that the absolute value of the addend can be
24556 encoded in 8 bits. */
24557 if (addend_abs >= 0x100)
4962c51a 24558 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24559 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24560 (unsigned long) addend_abs);
24561
24562 /* Extract the instruction. */
24563 insn = md_chars_to_number (buf, INSN_SIZE);
24564
24565 /* If the addend is negative, clear bit 23 of the instruction.
24566 Otherwise set it. */
24567 if (value < 0)
24568 insn &= ~(1 << 23);
24569 else
24570 insn |= 1 << 23;
24571
24572 /* Place the first four bits of the absolute value of the addend
24573 into the first 4 bits of the instruction, and the remaining
24574 four into bits 8 .. 11. */
24575 insn &= 0xfffff0f0;
24576 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24577
24578 /* Update the instruction. */
24579 md_number_to_chars (buf, insn, INSN_SIZE);
24580 }
4962c51a
MS
24581 break;
24582
24583 case BFD_RELOC_ARM_LDC_PC_G0:
24584 case BFD_RELOC_ARM_LDC_PC_G1:
24585 case BFD_RELOC_ARM_LDC_PC_G2:
24586 case BFD_RELOC_ARM_LDC_SB_G0:
24587 case BFD_RELOC_ARM_LDC_SB_G1:
24588 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 24589 gas_assert (!fixP->fx_done);
4962c51a 24590 if (!seg->use_rela_p)
477330fc
RM
24591 {
24592 bfd_vma insn;
24593 bfd_vma addend_abs = abs (value);
4962c51a 24594
477330fc
RM
24595 /* Check that the absolute value of the addend is a multiple of
24596 four and, when divided by four, fits in 8 bits. */
24597 if (addend_abs & 0x3)
4962c51a 24598 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24599 _("bad offset 0x%08lX (must be word-aligned)"),
24600 (unsigned long) addend_abs);
4962c51a 24601
477330fc 24602 if ((addend_abs >> 2) > 0xff)
4962c51a 24603 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24604 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24605 (unsigned long) addend_abs);
24606
24607 /* Extract the instruction. */
24608 insn = md_chars_to_number (buf, INSN_SIZE);
24609
24610 /* If the addend is negative, clear bit 23 of the instruction.
24611 Otherwise set it. */
24612 if (value < 0)
24613 insn &= ~(1 << 23);
24614 else
24615 insn |= 1 << 23;
24616
24617 /* Place the addend (divided by four) into the first eight
24618 bits of the instruction. */
24619 insn &= 0xfffffff0;
24620 insn |= addend_abs >> 2;
24621
24622 /* Update the instruction. */
24623 md_number_to_chars (buf, insn, INSN_SIZE);
24624 }
4962c51a
MS
24625 break;
24626
845b51d6
PB
24627 case BFD_RELOC_ARM_V4BX:
24628 /* This will need to go in the object file. */
24629 fixP->fx_done = 0;
24630 break;
24631
c19d1205
ZW
24632 case BFD_RELOC_UNUSED:
24633 default:
24634 as_bad_where (fixP->fx_file, fixP->fx_line,
24635 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24636 }
6c43fab6
RE
24637}
24638
c19d1205
ZW
24639/* Translate internal representation of relocation info to BFD target
24640 format. */
a737bd4d 24641
c19d1205 24642arelent *
00a97672 24643tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24644{
c19d1205
ZW
24645 arelent * reloc;
24646 bfd_reloc_code_real_type code;
a737bd4d 24647
325801bd 24648 reloc = XNEW (arelent);
a737bd4d 24649
325801bd 24650 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24651 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24652 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24653
2fc8bdac 24654 if (fixp->fx_pcrel)
00a97672
RS
24655 {
24656 if (section->use_rela_p)
24657 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24658 else
24659 fixp->fx_offset = reloc->address;
24660 }
c19d1205 24661 reloc->addend = fixp->fx_offset;
a737bd4d 24662
c19d1205 24663 switch (fixp->fx_r_type)
a737bd4d 24664 {
c19d1205
ZW
24665 case BFD_RELOC_8:
24666 if (fixp->fx_pcrel)
24667 {
24668 code = BFD_RELOC_8_PCREL;
24669 break;
24670 }
1a0670f3 24671 /* Fall through. */
a737bd4d 24672
c19d1205
ZW
24673 case BFD_RELOC_16:
24674 if (fixp->fx_pcrel)
24675 {
24676 code = BFD_RELOC_16_PCREL;
24677 break;
24678 }
1a0670f3 24679 /* Fall through. */
6c43fab6 24680
c19d1205
ZW
24681 case BFD_RELOC_32:
24682 if (fixp->fx_pcrel)
24683 {
24684 code = BFD_RELOC_32_PCREL;
24685 break;
24686 }
1a0670f3 24687 /* Fall through. */
a737bd4d 24688
b6895b4f
PB
24689 case BFD_RELOC_ARM_MOVW:
24690 if (fixp->fx_pcrel)
24691 {
24692 code = BFD_RELOC_ARM_MOVW_PCREL;
24693 break;
24694 }
1a0670f3 24695 /* Fall through. */
b6895b4f
PB
24696
24697 case BFD_RELOC_ARM_MOVT:
24698 if (fixp->fx_pcrel)
24699 {
24700 code = BFD_RELOC_ARM_MOVT_PCREL;
24701 break;
24702 }
1a0670f3 24703 /* Fall through. */
b6895b4f
PB
24704
24705 case BFD_RELOC_ARM_THUMB_MOVW:
24706 if (fixp->fx_pcrel)
24707 {
24708 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24709 break;
24710 }
1a0670f3 24711 /* Fall through. */
b6895b4f
PB
24712
24713 case BFD_RELOC_ARM_THUMB_MOVT:
24714 if (fixp->fx_pcrel)
24715 {
24716 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24717 break;
24718 }
1a0670f3 24719 /* Fall through. */
b6895b4f 24720
c19d1205
ZW
24721 case BFD_RELOC_NONE:
24722 case BFD_RELOC_ARM_PCREL_BRANCH:
24723 case BFD_RELOC_ARM_PCREL_BLX:
24724 case BFD_RELOC_RVA:
24725 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24726 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24727 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24728 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24729 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24730 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24731 case BFD_RELOC_VTABLE_ENTRY:
24732 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24733#ifdef TE_PE
24734 case BFD_RELOC_32_SECREL:
24735#endif
c19d1205
ZW
24736 code = fixp->fx_r_type;
24737 break;
a737bd4d 24738
00adf2d4
JB
24739 case BFD_RELOC_THUMB_PCREL_BLX:
24740#ifdef OBJ_ELF
24741 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24742 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24743 else
24744#endif
24745 code = BFD_RELOC_THUMB_PCREL_BLX;
24746 break;
24747
c19d1205
ZW
24748 case BFD_RELOC_ARM_LITERAL:
24749 case BFD_RELOC_ARM_HWLITERAL:
24750 /* If this is called then the a literal has
24751 been referenced across a section boundary. */
24752 as_bad_where (fixp->fx_file, fixp->fx_line,
24753 _("literal referenced across section boundary"));
24754 return NULL;
a737bd4d 24755
c19d1205 24756#ifdef OBJ_ELF
0855e32b
NS
24757 case BFD_RELOC_ARM_TLS_CALL:
24758 case BFD_RELOC_ARM_THM_TLS_CALL:
24759 case BFD_RELOC_ARM_TLS_DESCSEQ:
24760 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24761 case BFD_RELOC_ARM_GOT32:
24762 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24763 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24764 case BFD_RELOC_ARM_PLT32:
24765 case BFD_RELOC_ARM_TARGET1:
24766 case BFD_RELOC_ARM_ROSEGREL32:
24767 case BFD_RELOC_ARM_SBREL32:
24768 case BFD_RELOC_ARM_PREL31:
24769 case BFD_RELOC_ARM_TARGET2:
c19d1205 24770 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24771 case BFD_RELOC_ARM_PCREL_CALL:
24772 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24773 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24774 case BFD_RELOC_ARM_ALU_PC_G0:
24775 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24776 case BFD_RELOC_ARM_ALU_PC_G1:
24777 case BFD_RELOC_ARM_ALU_PC_G2:
24778 case BFD_RELOC_ARM_LDR_PC_G0:
24779 case BFD_RELOC_ARM_LDR_PC_G1:
24780 case BFD_RELOC_ARM_LDR_PC_G2:
24781 case BFD_RELOC_ARM_LDRS_PC_G0:
24782 case BFD_RELOC_ARM_LDRS_PC_G1:
24783 case BFD_RELOC_ARM_LDRS_PC_G2:
24784 case BFD_RELOC_ARM_LDC_PC_G0:
24785 case BFD_RELOC_ARM_LDC_PC_G1:
24786 case BFD_RELOC_ARM_LDC_PC_G2:
24787 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24788 case BFD_RELOC_ARM_ALU_SB_G0:
24789 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24790 case BFD_RELOC_ARM_ALU_SB_G1:
24791 case BFD_RELOC_ARM_ALU_SB_G2:
24792 case BFD_RELOC_ARM_LDR_SB_G0:
24793 case BFD_RELOC_ARM_LDR_SB_G1:
24794 case BFD_RELOC_ARM_LDR_SB_G2:
24795 case BFD_RELOC_ARM_LDRS_SB_G0:
24796 case BFD_RELOC_ARM_LDRS_SB_G1:
24797 case BFD_RELOC_ARM_LDRS_SB_G2:
24798 case BFD_RELOC_ARM_LDC_SB_G0:
24799 case BFD_RELOC_ARM_LDC_SB_G1:
24800 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24801 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24802 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24803 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24804 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24805 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
188fd7ae
CL
24806 case BFD_RELOC_ARM_GOTFUNCDESC:
24807 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
24808 case BFD_RELOC_ARM_FUNCDESC:
c19d1205
ZW
24809 code = fixp->fx_r_type;
24810 break;
a737bd4d 24811
0855e32b 24812 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24813 case BFD_RELOC_ARM_TLS_GD32:
5c5a4843 24814 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
75c11999 24815 case BFD_RELOC_ARM_TLS_LE32:
c19d1205 24816 case BFD_RELOC_ARM_TLS_IE32:
5c5a4843 24817 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
c19d1205 24818 case BFD_RELOC_ARM_TLS_LDM32:
5c5a4843 24819 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
c19d1205
ZW
24820 /* BFD will include the symbol's address in the addend.
24821 But we don't want that, so subtract it out again here. */
24822 if (!S_IS_COMMON (fixp->fx_addsy))
24823 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24824 code = fixp->fx_r_type;
24825 break;
24826#endif
a737bd4d 24827
c19d1205
ZW
24828 case BFD_RELOC_ARM_IMMEDIATE:
24829 as_bad_where (fixp->fx_file, fixp->fx_line,
24830 _("internal relocation (type: IMMEDIATE) not fixed up"));
24831 return NULL;
a737bd4d 24832
c19d1205
ZW
24833 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24834 as_bad_where (fixp->fx_file, fixp->fx_line,
24835 _("ADRL used for a symbol not defined in the same file"));
24836 return NULL;
a737bd4d 24837
c19d1205 24838 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24839 if (section->use_rela_p)
24840 {
24841 code = fixp->fx_r_type;
24842 break;
24843 }
24844
c19d1205
ZW
24845 if (fixp->fx_addsy != NULL
24846 && !S_IS_DEFINED (fixp->fx_addsy)
24847 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24848 {
c19d1205
ZW
24849 as_bad_where (fixp->fx_file, fixp->fx_line,
24850 _("undefined local label `%s'"),
24851 S_GET_NAME (fixp->fx_addsy));
24852 return NULL;
a737bd4d
NC
24853 }
24854
c19d1205
ZW
24855 as_bad_where (fixp->fx_file, fixp->fx_line,
24856 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24857 return NULL;
a737bd4d 24858
c19d1205
ZW
24859 default:
24860 {
e0471c16 24861 const char * type;
6c43fab6 24862
c19d1205
ZW
24863 switch (fixp->fx_r_type)
24864 {
24865 case BFD_RELOC_NONE: type = "NONE"; break;
24866 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24867 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24868 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24869 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24870 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24871 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24872 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24873 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24874 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24875 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24876 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24877 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24878 default: type = _("<unknown>"); break;
24879 }
24880 as_bad_where (fixp->fx_file, fixp->fx_line,
24881 _("cannot represent %s relocation in this object file format"),
24882 type);
24883 return NULL;
24884 }
a737bd4d 24885 }
6c43fab6 24886
c19d1205
ZW
24887#ifdef OBJ_ELF
24888 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24889 && GOT_symbol
24890 && fixp->fx_addsy == GOT_symbol)
24891 {
24892 code = BFD_RELOC_ARM_GOTPC;
24893 reloc->addend = fixp->fx_offset = reloc->address;
24894 }
24895#endif
6c43fab6 24896
c19d1205 24897 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24898
c19d1205
ZW
24899 if (reloc->howto == NULL)
24900 {
24901 as_bad_where (fixp->fx_file, fixp->fx_line,
24902 _("cannot represent %s relocation in this object file format"),
24903 bfd_get_reloc_code_name (code));
24904 return NULL;
24905 }
6c43fab6 24906
c19d1205
ZW
24907 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24908 vtable entry to be used in the relocation's section offset. */
24909 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24910 reloc->address = fixp->fx_offset;
6c43fab6 24911
c19d1205 24912 return reloc;
6c43fab6
RE
24913}
24914
c19d1205 24915/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24916
c19d1205
ZW
24917void
24918cons_fix_new_arm (fragS * frag,
24919 int where,
24920 int size,
62ebcb5c
AM
24921 expressionS * exp,
24922 bfd_reloc_code_real_type reloc)
6c43fab6 24923{
c19d1205 24924 int pcrel = 0;
6c43fab6 24925
c19d1205
ZW
24926 /* Pick a reloc.
24927 FIXME: @@ Should look at CPU word size. */
24928 switch (size)
24929 {
24930 case 1:
62ebcb5c 24931 reloc = BFD_RELOC_8;
c19d1205
ZW
24932 break;
24933 case 2:
62ebcb5c 24934 reloc = BFD_RELOC_16;
c19d1205
ZW
24935 break;
24936 case 4:
24937 default:
62ebcb5c 24938 reloc = BFD_RELOC_32;
c19d1205
ZW
24939 break;
24940 case 8:
62ebcb5c 24941 reloc = BFD_RELOC_64;
c19d1205
ZW
24942 break;
24943 }
6c43fab6 24944
f0927246
NC
24945#ifdef TE_PE
24946 if (exp->X_op == O_secrel)
24947 {
24948 exp->X_op = O_symbol;
62ebcb5c 24949 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24950 }
24951#endif
24952
62ebcb5c 24953 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24954}
6c43fab6 24955
4343666d 24956#if defined (OBJ_COFF)
c19d1205
ZW
24957void
24958arm_validate_fix (fixS * fixP)
6c43fab6 24959{
c19d1205
ZW
24960 /* If the destination of the branch is a defined symbol which does not have
24961 the THUMB_FUNC attribute, then we must be calling a function which has
24962 the (interfacearm) attribute. We look for the Thumb entry point to that
24963 function and change the branch to refer to that function instead. */
24964 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24965 && fixP->fx_addsy != NULL
24966 && S_IS_DEFINED (fixP->fx_addsy)
24967 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24968 {
c19d1205 24969 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24970 }
c19d1205
ZW
24971}
24972#endif
6c43fab6 24973
267bf995 24974
c19d1205
ZW
24975int
24976arm_force_relocation (struct fix * fixp)
24977{
24978#if defined (OBJ_COFF) && defined (TE_PE)
24979 if (fixp->fx_r_type == BFD_RELOC_RVA)
24980 return 1;
24981#endif
6c43fab6 24982
267bf995
RR
24983 /* In case we have a call or a branch to a function in ARM ISA mode from
24984 a thumb function or vice-versa force the relocation. These relocations
24985 are cleared off for some cores that might have blx and simple transformations
24986 are possible. */
24987
24988#ifdef OBJ_ELF
24989 switch (fixp->fx_r_type)
24990 {
24991 case BFD_RELOC_ARM_PCREL_JUMP:
24992 case BFD_RELOC_ARM_PCREL_CALL:
24993 case BFD_RELOC_THUMB_PCREL_BLX:
24994 if (THUMB_IS_FUNC (fixp->fx_addsy))
24995 return 1;
24996 break;
24997
24998 case BFD_RELOC_ARM_PCREL_BLX:
24999 case BFD_RELOC_THUMB_PCREL_BRANCH25:
25000 case BFD_RELOC_THUMB_PCREL_BRANCH20:
25001 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25002 if (ARM_IS_FUNC (fixp->fx_addsy))
25003 return 1;
25004 break;
25005
25006 default:
25007 break;
25008 }
25009#endif
25010
b5884301
PB
25011 /* Resolve these relocations even if the symbol is extern or weak.
25012 Technically this is probably wrong due to symbol preemption.
25013 In practice these relocations do not have enough range to be useful
25014 at dynamic link time, and some code (e.g. in the Linux kernel)
25015 expects these references to be resolved. */
c19d1205
ZW
25016 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
25017 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 25018 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 25019 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
25020 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
25021 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
25022 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 25023 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
25024 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
25025 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
25026 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
25027 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
25028 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
25029 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 25030 return 0;
a737bd4d 25031
4962c51a
MS
25032 /* Always leave these relocations for the linker. */
25033 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25034 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25035 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
25036 return 1;
25037
f0291e4c
PB
25038 /* Always generate relocations against function symbols. */
25039 if (fixp->fx_r_type == BFD_RELOC_32
25040 && fixp->fx_addsy
25041 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
25042 return 1;
25043
c19d1205 25044 return generic_force_reloc (fixp);
404ff6b5
AH
25045}
25046
0ffdc86c 25047#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
25048/* Relocations against function names must be left unadjusted,
25049 so that the linker can use this information to generate interworking
25050 stubs. The MIPS version of this function
c19d1205
ZW
25051 also prevents relocations that are mips-16 specific, but I do not
25052 know why it does this.
404ff6b5 25053
c19d1205
ZW
25054 FIXME:
25055 There is one other problem that ought to be addressed here, but
25056 which currently is not: Taking the address of a label (rather
25057 than a function) and then later jumping to that address. Such
25058 addresses also ought to have their bottom bit set (assuming that
25059 they reside in Thumb code), but at the moment they will not. */
404ff6b5 25060
c19d1205
ZW
25061bfd_boolean
25062arm_fix_adjustable (fixS * fixP)
404ff6b5 25063{
c19d1205
ZW
25064 if (fixP->fx_addsy == NULL)
25065 return 1;
404ff6b5 25066
e28387c3
PB
25067 /* Preserve relocations against symbols with function type. */
25068 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 25069 return FALSE;
e28387c3 25070
c19d1205
ZW
25071 if (THUMB_IS_FUNC (fixP->fx_addsy)
25072 && fixP->fx_subsy == NULL)
c921be7d 25073 return FALSE;
a737bd4d 25074
c19d1205
ZW
25075 /* We need the symbol name for the VTABLE entries. */
25076 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
25077 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 25078 return FALSE;
404ff6b5 25079
c19d1205
ZW
25080 /* Don't allow symbols to be discarded on GOT related relocs. */
25081 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
25082 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
25083 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
25084 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
5c5a4843 25085 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
c19d1205
ZW
25086 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
25087 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
5c5a4843 25088 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
c19d1205 25089 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
5c5a4843 25090 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
c19d1205 25091 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
25092 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
25093 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
25094 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
25095 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
25096 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 25097 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 25098 return FALSE;
a737bd4d 25099
4962c51a
MS
25100 /* Similarly for group relocations. */
25101 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25102 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25103 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 25104 return FALSE;
4962c51a 25105
79947c54
CD
25106 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
25107 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
25108 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
25109 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
25110 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
25111 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
25112 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
25113 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
25114 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 25115 return FALSE;
79947c54 25116
72d98d16
MG
25117 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
25118 offsets, so keep these symbols. */
25119 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
25120 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
25121 return FALSE;
25122
c921be7d 25123 return TRUE;
a737bd4d 25124}
0ffdc86c
NC
25125#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
25126
25127#ifdef OBJ_ELF
c19d1205
ZW
25128const char *
25129elf32_arm_target_format (void)
404ff6b5 25130{
c19d1205
ZW
25131#ifdef TE_SYMBIAN
25132 return (target_big_endian
25133 ? "elf32-bigarm-symbian"
25134 : "elf32-littlearm-symbian");
25135#elif defined (TE_VXWORKS)
25136 return (target_big_endian
25137 ? "elf32-bigarm-vxworks"
25138 : "elf32-littlearm-vxworks");
b38cadfb
NC
25139#elif defined (TE_NACL)
25140 return (target_big_endian
25141 ? "elf32-bigarm-nacl"
25142 : "elf32-littlearm-nacl");
c19d1205 25143#else
18a20338
CL
25144 if (arm_fdpic)
25145 {
25146 if (target_big_endian)
25147 return "elf32-bigarm-fdpic";
25148 else
25149 return "elf32-littlearm-fdpic";
25150 }
c19d1205 25151 else
18a20338
CL
25152 {
25153 if (target_big_endian)
25154 return "elf32-bigarm";
25155 else
25156 return "elf32-littlearm";
25157 }
c19d1205 25158#endif
404ff6b5
AH
25159}
25160
c19d1205
ZW
25161void
25162armelf_frob_symbol (symbolS * symp,
25163 int * puntp)
404ff6b5 25164{
c19d1205
ZW
25165 elf_frob_symbol (symp, puntp);
25166}
25167#endif
404ff6b5 25168
c19d1205 25169/* MD interface: Finalization. */
a737bd4d 25170
c19d1205
ZW
25171void
25172arm_cleanup (void)
25173{
25174 literal_pool * pool;
a737bd4d 25175
e07e6e58
NC
25176 /* Ensure that all the IT blocks are properly closed. */
25177 check_it_blocks_finished ();
25178
c19d1205
ZW
25179 for (pool = list_of_pools; pool; pool = pool->next)
25180 {
5f4273c7 25181 /* Put it at the end of the relevant section. */
c19d1205
ZW
25182 subseg_set (pool->section, pool->sub_section);
25183#ifdef OBJ_ELF
25184 arm_elf_change_section ();
25185#endif
25186 s_ltorg (0);
25187 }
404ff6b5
AH
25188}
25189
cd000bff
DJ
25190#ifdef OBJ_ELF
25191/* Remove any excess mapping symbols generated for alignment frags in
25192 SEC. We may have created a mapping symbol before a zero byte
25193 alignment; remove it if there's a mapping symbol after the
25194 alignment. */
25195static void
25196check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
25197 void *dummy ATTRIBUTE_UNUSED)
25198{
25199 segment_info_type *seginfo = seg_info (sec);
25200 fragS *fragp;
25201
25202 if (seginfo == NULL || seginfo->frchainP == NULL)
25203 return;
25204
25205 for (fragp = seginfo->frchainP->frch_root;
25206 fragp != NULL;
25207 fragp = fragp->fr_next)
25208 {
25209 symbolS *sym = fragp->tc_frag_data.last_map;
25210 fragS *next = fragp->fr_next;
25211
25212 /* Variable-sized frags have been converted to fixed size by
25213 this point. But if this was variable-sized to start with,
25214 there will be a fixed-size frag after it. So don't handle
25215 next == NULL. */
25216 if (sym == NULL || next == NULL)
25217 continue;
25218
25219 if (S_GET_VALUE (sym) < next->fr_address)
25220 /* Not at the end of this frag. */
25221 continue;
25222 know (S_GET_VALUE (sym) == next->fr_address);
25223
25224 do
25225 {
25226 if (next->tc_frag_data.first_map != NULL)
25227 {
25228 /* Next frag starts with a mapping symbol. Discard this
25229 one. */
25230 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25231 break;
25232 }
25233
25234 if (next->fr_next == NULL)
25235 {
25236 /* This mapping symbol is at the end of the section. Discard
25237 it. */
25238 know (next->fr_fix == 0 && next->fr_var == 0);
25239 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25240 break;
25241 }
25242
25243 /* As long as we have empty frags without any mapping symbols,
25244 keep looking. */
25245 /* If the next frag is non-empty and does not start with a
25246 mapping symbol, then this mapping symbol is required. */
25247 if (next->fr_address != next->fr_next->fr_address)
25248 break;
25249
25250 next = next->fr_next;
25251 }
25252 while (next != NULL);
25253 }
25254}
25255#endif
25256
c19d1205
ZW
25257/* Adjust the symbol table. This marks Thumb symbols as distinct from
25258 ARM ones. */
404ff6b5 25259
c19d1205
ZW
25260void
25261arm_adjust_symtab (void)
404ff6b5 25262{
c19d1205
ZW
25263#ifdef OBJ_COFF
25264 symbolS * sym;
404ff6b5 25265
c19d1205
ZW
25266 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
25267 {
25268 if (ARM_IS_THUMB (sym))
25269 {
25270 if (THUMB_IS_FUNC (sym))
25271 {
25272 /* Mark the symbol as a Thumb function. */
25273 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
25274 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
25275 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 25276
c19d1205
ZW
25277 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
25278 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
25279 else
25280 as_bad (_("%s: unexpected function type: %d"),
25281 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
25282 }
25283 else switch (S_GET_STORAGE_CLASS (sym))
25284 {
25285 case C_EXT:
25286 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
25287 break;
25288 case C_STAT:
25289 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
25290 break;
25291 case C_LABEL:
25292 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
25293 break;
25294 default:
25295 /* Do nothing. */
25296 break;
25297 }
25298 }
a737bd4d 25299
c19d1205
ZW
25300 if (ARM_IS_INTERWORK (sym))
25301 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 25302 }
c19d1205
ZW
25303#endif
25304#ifdef OBJ_ELF
25305 symbolS * sym;
25306 char bind;
404ff6b5 25307
c19d1205 25308 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 25309 {
c19d1205
ZW
25310 if (ARM_IS_THUMB (sym))
25311 {
25312 elf_symbol_type * elf_sym;
404ff6b5 25313
c19d1205
ZW
25314 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
25315 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 25316
b0796911
PB
25317 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
25318 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
25319 {
25320 /* If it's a .thumb_func, declare it as so,
25321 otherwise tag label as .code 16. */
25322 if (THUMB_IS_FUNC (sym))
39d911fc
TP
25323 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
25324 ST_BRANCH_TO_THUMB);
3ba67470 25325 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
25326 elf_sym->internal_elf_sym.st_info =
25327 ELF_ST_INFO (bind, STT_ARM_16BIT);
25328 }
25329 }
25330 }
cd000bff
DJ
25331
25332 /* Remove any overlapping mapping symbols generated by alignment frags. */
25333 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
25334 /* Now do generic ELF adjustments. */
25335 elf_adjust_symtab ();
c19d1205 25336#endif
404ff6b5
AH
25337}
25338
c19d1205 25339/* MD interface: Initialization. */
404ff6b5 25340
a737bd4d 25341static void
c19d1205 25342set_constant_flonums (void)
a737bd4d 25343{
c19d1205 25344 int i;
404ff6b5 25345
c19d1205
ZW
25346 for (i = 0; i < NUM_FLOAT_VALS; i++)
25347 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
25348 abort ();
a737bd4d 25349}
404ff6b5 25350
3e9e4fcf
JB
25351/* Auto-select Thumb mode if it's the only available instruction set for the
25352 given architecture. */
25353
25354static void
25355autoselect_thumb_from_cpu_variant (void)
25356{
25357 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
25358 opcode_select (16);
25359}
25360
c19d1205
ZW
25361void
25362md_begin (void)
a737bd4d 25363{
c19d1205
ZW
25364 unsigned mach;
25365 unsigned int i;
404ff6b5 25366
c19d1205
ZW
25367 if ( (arm_ops_hsh = hash_new ()) == NULL
25368 || (arm_cond_hsh = hash_new ()) == NULL
25369 || (arm_shift_hsh = hash_new ()) == NULL
25370 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 25371 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 25372 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
25373 || (arm_reloc_hsh = hash_new ()) == NULL
25374 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
25375 as_fatal (_("virtual memory exhausted"));
25376
25377 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 25378 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 25379 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 25380 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 25381 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 25382 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 25383 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25384 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 25385 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25386 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 25387 (void *) (v7m_psrs + i));
c19d1205 25388 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 25389 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
25390 for (i = 0;
25391 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
25392 i++)
d3ce72d0 25393 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 25394 (void *) (barrier_opt_names + i));
c19d1205 25395#ifdef OBJ_ELF
3da1d841
NC
25396 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
25397 {
25398 struct reloc_entry * entry = reloc_names + i;
25399
25400 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
25401 /* This makes encode_branch() use the EABI versions of this relocation. */
25402 entry->reloc = BFD_RELOC_UNUSED;
25403
25404 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
25405 }
c19d1205
ZW
25406#endif
25407
25408 set_constant_flonums ();
404ff6b5 25409
c19d1205
ZW
25410 /* Set the cpu variant based on the command-line options. We prefer
25411 -mcpu= over -march= if both are set (as for GCC); and we prefer
25412 -mfpu= over any other way of setting the floating point unit.
25413 Use of legacy options with new options are faulted. */
e74cfd16 25414 if (legacy_cpu)
404ff6b5 25415 {
e74cfd16 25416 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
25417 as_bad (_("use of old and new-style options to set CPU type"));
25418
4d354d8b 25419 selected_arch = *legacy_cpu;
404ff6b5 25420 }
4d354d8b
TP
25421 else if (mcpu_cpu_opt)
25422 {
25423 selected_arch = *mcpu_cpu_opt;
25424 selected_ext = *mcpu_ext_opt;
25425 }
25426 else if (march_cpu_opt)
c168ce07 25427 {
4d354d8b
TP
25428 selected_arch = *march_cpu_opt;
25429 selected_ext = *march_ext_opt;
c168ce07 25430 }
4d354d8b 25431 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
404ff6b5 25432
e74cfd16 25433 if (legacy_fpu)
c19d1205 25434 {
e74cfd16 25435 if (mfpu_opt)
c19d1205 25436 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f 25437
4d354d8b 25438 selected_fpu = *legacy_fpu;
03b1477f 25439 }
4d354d8b
TP
25440 else if (mfpu_opt)
25441 selected_fpu = *mfpu_opt;
25442 else
03b1477f 25443 {
45eb4c1b
NS
25444#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25445 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
25446 /* Some environments specify a default FPU. If they don't, infer it
25447 from the processor. */
e74cfd16 25448 if (mcpu_fpu_opt)
4d354d8b 25449 selected_fpu = *mcpu_fpu_opt;
e7da50fa 25450 else if (march_fpu_opt)
4d354d8b 25451 selected_fpu = *march_fpu_opt;
39c2da32 25452#else
4d354d8b 25453 selected_fpu = fpu_default;
39c2da32 25454#endif
03b1477f
RE
25455 }
25456
4d354d8b 25457 if (ARM_FEATURE_ZERO (selected_fpu))
03b1477f 25458 {
4d354d8b
TP
25459 if (!no_cpu_selected ())
25460 selected_fpu = fpu_default;
03b1477f 25461 else
4d354d8b 25462 selected_fpu = fpu_arch_fpa;
03b1477f
RE
25463 }
25464
ee065d83 25465#ifdef CPU_DEFAULT
4d354d8b 25466 if (ARM_FEATURE_ZERO (selected_arch))
ee065d83 25467 {
4d354d8b
TP
25468 selected_arch = cpu_default;
25469 selected_cpu = selected_arch;
ee065d83 25470 }
4d354d8b 25471 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
e74cfd16 25472#else
4d354d8b
TP
25473 /* Autodection of feature mode: allow all features in cpu_variant but leave
25474 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
25475 after all instruction have been processed and we can decide what CPU
25476 should be selected. */
25477 if (ARM_FEATURE_ZERO (selected_arch))
25478 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
ee065d83 25479 else
4d354d8b 25480 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83 25481#endif
03b1477f 25482
3e9e4fcf
JB
25483 autoselect_thumb_from_cpu_variant ();
25484
e74cfd16 25485 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 25486
f17c130b 25487#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 25488 {
7cc69913
NC
25489 unsigned int flags = 0;
25490
25491#if defined OBJ_ELF
25492 flags = meabi_flags;
d507cf36
PB
25493
25494 switch (meabi_flags)
33a392fb 25495 {
d507cf36 25496 case EF_ARM_EABI_UNKNOWN:
7cc69913 25497#endif
d507cf36
PB
25498 /* Set the flags in the private structure. */
25499 if (uses_apcs_26) flags |= F_APCS26;
25500 if (support_interwork) flags |= F_INTERWORK;
25501 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 25502 if (pic_code) flags |= F_PIC;
e74cfd16 25503 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
25504 flags |= F_SOFT_FLOAT;
25505
d507cf36
PB
25506 switch (mfloat_abi_opt)
25507 {
25508 case ARM_FLOAT_ABI_SOFT:
25509 case ARM_FLOAT_ABI_SOFTFP:
25510 flags |= F_SOFT_FLOAT;
25511 break;
33a392fb 25512
d507cf36
PB
25513 case ARM_FLOAT_ABI_HARD:
25514 if (flags & F_SOFT_FLOAT)
25515 as_bad (_("hard-float conflicts with specified fpu"));
25516 break;
25517 }
03b1477f 25518
e74cfd16
PB
25519 /* Using pure-endian doubles (even if soft-float). */
25520 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 25521 flags |= F_VFP_FLOAT;
f17c130b 25522
fde78edd 25523#if defined OBJ_ELF
e74cfd16 25524 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 25525 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
25526 break;
25527
8cb51566 25528 case EF_ARM_EABI_VER4:
3a4a14e9 25529 case EF_ARM_EABI_VER5:
c19d1205 25530 /* No additional flags to set. */
d507cf36
PB
25531 break;
25532
25533 default:
25534 abort ();
25535 }
7cc69913 25536#endif
b99bd4ef
NC
25537 bfd_set_private_flags (stdoutput, flags);
25538
25539 /* We have run out flags in the COFF header to encode the
25540 status of ATPCS support, so instead we create a dummy,
c19d1205 25541 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
25542 if (atpcs)
25543 {
25544 asection * sec;
25545
25546 sec = bfd_make_section (stdoutput, ".arm.atpcs");
25547
25548 if (sec != NULL)
25549 {
25550 bfd_set_section_flags
25551 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
25552 bfd_set_section_size (stdoutput, sec, 0);
25553 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
25554 }
25555 }
7cc69913 25556 }
f17c130b 25557#endif
b99bd4ef
NC
25558
25559 /* Record the CPU type as well. */
2d447fca
JM
25560 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
25561 mach = bfd_mach_arm_iWMMXt2;
25562 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 25563 mach = bfd_mach_arm_iWMMXt;
e74cfd16 25564 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 25565 mach = bfd_mach_arm_XScale;
e74cfd16 25566 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 25567 mach = bfd_mach_arm_ep9312;
e74cfd16 25568 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 25569 mach = bfd_mach_arm_5TE;
e74cfd16 25570 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 25571 {
e74cfd16 25572 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25573 mach = bfd_mach_arm_5T;
25574 else
25575 mach = bfd_mach_arm_5;
25576 }
e74cfd16 25577 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 25578 {
e74cfd16 25579 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25580 mach = bfd_mach_arm_4T;
25581 else
25582 mach = bfd_mach_arm_4;
25583 }
e74cfd16 25584 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 25585 mach = bfd_mach_arm_3M;
e74cfd16
PB
25586 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25587 mach = bfd_mach_arm_3;
25588 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25589 mach = bfd_mach_arm_2a;
25590 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25591 mach = bfd_mach_arm_2;
25592 else
25593 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
25594
25595 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25596}
25597
c19d1205 25598/* Command line processing. */
b99bd4ef 25599
c19d1205
ZW
25600/* md_parse_option
25601 Invocation line includes a switch not recognized by the base assembler.
25602 See if it's a processor-specific option.
b99bd4ef 25603
c19d1205
ZW
25604 This routine is somewhat complicated by the need for backwards
25605 compatibility (since older releases of gcc can't be changed).
25606 The new options try to make the interface as compatible as
25607 possible with GCC.
b99bd4ef 25608
c19d1205 25609 New options (supported) are:
b99bd4ef 25610
c19d1205
ZW
25611 -mcpu=<cpu name> Assemble for selected processor
25612 -march=<architecture name> Assemble for selected architecture
25613 -mfpu=<fpu architecture> Assemble for selected FPU.
25614 -EB/-mbig-endian Big-endian
25615 -EL/-mlittle-endian Little-endian
25616 -k Generate PIC code
25617 -mthumb Start in Thumb mode
25618 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 25619
278df34e 25620 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 25621 -m[no-]warn-syms Warn when symbols match instructions
267bf995 25622
c19d1205 25623 For now we will also provide support for:
b99bd4ef 25624
c19d1205
ZW
25625 -mapcs-32 32-bit Program counter
25626 -mapcs-26 26-bit Program counter
25627 -macps-float Floats passed in FP registers
25628 -mapcs-reentrant Reentrant code
25629 -matpcs
25630 (sometime these will probably be replaced with -mapcs=<list of options>
25631 and -matpcs=<list of options>)
b99bd4ef 25632
c19d1205
ZW
25633 The remaining options are only supported for back-wards compatibility.
25634 Cpu variants, the arm part is optional:
25635 -m[arm]1 Currently not supported.
25636 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25637 -m[arm]3 Arm 3 processor
25638 -m[arm]6[xx], Arm 6 processors
25639 -m[arm]7[xx][t][[d]m] Arm 7 processors
25640 -m[arm]8[10] Arm 8 processors
25641 -m[arm]9[20][tdmi] Arm 9 processors
25642 -mstrongarm[110[0]] StrongARM processors
25643 -mxscale XScale processors
25644 -m[arm]v[2345[t[e]]] Arm architectures
25645 -mall All (except the ARM1)
25646 FP variants:
25647 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25648 -mfpe-old (No float load/store multiples)
25649 -mvfpxd VFP Single precision
25650 -mvfp All VFP
25651 -mno-fpu Disable all floating point instructions
b99bd4ef 25652
c19d1205
ZW
25653 The following CPU names are recognized:
25654 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25655 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25656 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25657 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25658 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25659 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25660 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25661
c19d1205 25662 */
b99bd4ef 25663
c19d1205 25664const char * md_shortopts = "m:k";
b99bd4ef 25665
c19d1205
ZW
25666#ifdef ARM_BI_ENDIAN
25667#define OPTION_EB (OPTION_MD_BASE + 0)
25668#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25669#else
c19d1205
ZW
25670#if TARGET_BYTES_BIG_ENDIAN
25671#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25672#else
c19d1205
ZW
25673#define OPTION_EL (OPTION_MD_BASE + 1)
25674#endif
b99bd4ef 25675#endif
845b51d6 25676#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
18a20338 25677#define OPTION_FDPIC (OPTION_MD_BASE + 3)
b99bd4ef 25678
c19d1205 25679struct option md_longopts[] =
b99bd4ef 25680{
c19d1205
ZW
25681#ifdef OPTION_EB
25682 {"EB", no_argument, NULL, OPTION_EB},
25683#endif
25684#ifdef OPTION_EL
25685 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25686#endif
845b51d6 25687 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
18a20338
CL
25688#ifdef OBJ_ELF
25689 {"fdpic", no_argument, NULL, OPTION_FDPIC},
25690#endif
c19d1205
ZW
25691 {NULL, no_argument, NULL, 0}
25692};
b99bd4ef 25693
c19d1205 25694size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25695
c19d1205 25696struct arm_option_table
b99bd4ef 25697{
0198d5e6
TC
25698 const char * option; /* Option name to match. */
25699 const char * help; /* Help information. */
25700 int * var; /* Variable to change. */
25701 int value; /* What to change it to. */
25702 const char * deprecated; /* If non-null, print this message. */
c19d1205 25703};
b99bd4ef 25704
c19d1205
ZW
25705struct arm_option_table arm_opts[] =
25706{
25707 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25708 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25709 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25710 &support_interwork, 1, NULL},
25711 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25712 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25713 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25714 1, NULL},
25715 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25716 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25717 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25718 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25719 NULL},
b99bd4ef 25720
c19d1205
ZW
25721 /* These are recognized by the assembler, but have no affect on code. */
25722 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25723 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25724
25725 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25726 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25727 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25728 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25729 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25730 {NULL, NULL, NULL, 0, NULL}
25731};
25732
25733struct arm_legacy_option_table
25734{
0198d5e6
TC
25735 const char * option; /* Option name to match. */
25736 const arm_feature_set ** var; /* Variable to change. */
25737 const arm_feature_set value; /* What to change it to. */
25738 const char * deprecated; /* If non-null, print this message. */
e74cfd16 25739};
b99bd4ef 25740
e74cfd16
PB
25741const struct arm_legacy_option_table arm_legacy_opts[] =
25742{
c19d1205
ZW
25743 /* DON'T add any new processors to this list -- we want the whole list
25744 to go away... Add them to the processors table instead. */
e74cfd16
PB
25745 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25746 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25747 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25748 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25749 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25750 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25751 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25752 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25753 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25754 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25755 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25756 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25757 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25758 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25759 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25760 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25761 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25762 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25763 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25764 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25765 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25766 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25767 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25768 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25769 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25770 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25771 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25772 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25773 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25774 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25775 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25776 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25777 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25778 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25779 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25780 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25781 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25782 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25783 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25784 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25785 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25786 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25787 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25788 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25789 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25790 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25791 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25792 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25793 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25794 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25795 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25796 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25797 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25798 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25799 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25800 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25801 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25802 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25803 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25804 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25805 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25806 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25807 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25808 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25809 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25810 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25811 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25812 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25813 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25814 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25815 N_("use -mcpu=strongarm110")},
e74cfd16 25816 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25817 N_("use -mcpu=strongarm1100")},
e74cfd16 25818 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25819 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25820 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25821 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25822 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25823
c19d1205 25824 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25825 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25826 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25827 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25828 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25829 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25830 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25831 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25832 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25833 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25834 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25835 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25836 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25837 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25838 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25839 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25840 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25841 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25842 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25843
c19d1205 25844 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
25845 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25846 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25847 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25848 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25849 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25850
e74cfd16 25851 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25852};
7ed4c4c5 25853
c19d1205 25854struct arm_cpu_option_table
7ed4c4c5 25855{
0198d5e6
TC
25856 const char * name;
25857 size_t name_len;
25858 const arm_feature_set value;
25859 const arm_feature_set ext;
c19d1205
ZW
25860 /* For some CPUs we assume an FPU unless the user explicitly sets
25861 -mfpu=... */
0198d5e6 25862 const arm_feature_set default_fpu;
ee065d83
PB
25863 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25864 case. */
0198d5e6 25865 const char * canonical_name;
c19d1205 25866};
7ed4c4c5 25867
c19d1205
ZW
25868/* This list should, at a minimum, contain all the cpu names
25869 recognized by GCC. */
996b5569 25870#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 25871
e74cfd16 25872static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25873{
996b5569
TP
25874 ARM_CPU_OPT ("all", NULL, ARM_ANY,
25875 ARM_ARCH_NONE,
25876 FPU_ARCH_FPA),
25877 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
25878 ARM_ARCH_NONE,
25879 FPU_ARCH_FPA),
25880 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
25881 ARM_ARCH_NONE,
25882 FPU_ARCH_FPA),
25883 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
25884 ARM_ARCH_NONE,
25885 FPU_ARCH_FPA),
25886 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
25887 ARM_ARCH_NONE,
25888 FPU_ARCH_FPA),
25889 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
25890 ARM_ARCH_NONE,
25891 FPU_ARCH_FPA),
25892 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
25893 ARM_ARCH_NONE,
25894 FPU_ARCH_FPA),
25895 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
25896 ARM_ARCH_NONE,
25897 FPU_ARCH_FPA),
25898 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
25899 ARM_ARCH_NONE,
25900 FPU_ARCH_FPA),
25901 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
25902 ARM_ARCH_NONE,
25903 FPU_ARCH_FPA),
25904 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
25905 ARM_ARCH_NONE,
25906 FPU_ARCH_FPA),
25907 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
25908 ARM_ARCH_NONE,
25909 FPU_ARCH_FPA),
25910 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
25911 ARM_ARCH_NONE,
25912 FPU_ARCH_FPA),
25913 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
25914 ARM_ARCH_NONE,
25915 FPU_ARCH_FPA),
25916 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
25917 ARM_ARCH_NONE,
25918 FPU_ARCH_FPA),
25919 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
25920 ARM_ARCH_NONE,
25921 FPU_ARCH_FPA),
25922 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
25923 ARM_ARCH_NONE,
25924 FPU_ARCH_FPA),
25925 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
25926 ARM_ARCH_NONE,
25927 FPU_ARCH_FPA),
25928 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
25929 ARM_ARCH_NONE,
25930 FPU_ARCH_FPA),
25931 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
25932 ARM_ARCH_NONE,
25933 FPU_ARCH_FPA),
25934 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
25935 ARM_ARCH_NONE,
25936 FPU_ARCH_FPA),
25937 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
25938 ARM_ARCH_NONE,
25939 FPU_ARCH_FPA),
25940 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
25941 ARM_ARCH_NONE,
25942 FPU_ARCH_FPA),
25943 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
25944 ARM_ARCH_NONE,
25945 FPU_ARCH_FPA),
25946 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
25947 ARM_ARCH_NONE,
25948 FPU_ARCH_FPA),
25949 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
25950 ARM_ARCH_NONE,
25951 FPU_ARCH_FPA),
25952 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
25953 ARM_ARCH_NONE,
25954 FPU_ARCH_FPA),
25955 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
25956 ARM_ARCH_NONE,
25957 FPU_ARCH_FPA),
25958 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
25959 ARM_ARCH_NONE,
25960 FPU_ARCH_FPA),
25961 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
25962 ARM_ARCH_NONE,
25963 FPU_ARCH_FPA),
25964 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
25965 ARM_ARCH_NONE,
25966 FPU_ARCH_FPA),
25967 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
25968 ARM_ARCH_NONE,
25969 FPU_ARCH_FPA),
25970 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
25971 ARM_ARCH_NONE,
25972 FPU_ARCH_FPA),
25973 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
25974 ARM_ARCH_NONE,
25975 FPU_ARCH_FPA),
25976 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
25977 ARM_ARCH_NONE,
25978 FPU_ARCH_FPA),
25979 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
25980 ARM_ARCH_NONE,
25981 FPU_ARCH_FPA),
25982 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
25983 ARM_ARCH_NONE,
25984 FPU_ARCH_FPA),
25985 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
25986 ARM_ARCH_NONE,
25987 FPU_ARCH_FPA),
25988 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
25989 ARM_ARCH_NONE,
25990 FPU_ARCH_FPA),
25991 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
25992 ARM_ARCH_NONE,
25993 FPU_ARCH_FPA),
25994 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
25995 ARM_ARCH_NONE,
25996 FPU_ARCH_FPA),
25997 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
25998 ARM_ARCH_NONE,
25999 FPU_ARCH_FPA),
26000 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
26001 ARM_ARCH_NONE,
26002 FPU_ARCH_FPA),
26003 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
26004 ARM_ARCH_NONE,
26005 FPU_ARCH_FPA),
26006 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
26007 ARM_ARCH_NONE,
26008 FPU_ARCH_FPA),
26009 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
26010 ARM_ARCH_NONE,
26011 FPU_ARCH_FPA),
26012
c19d1205
ZW
26013 /* For V5 or later processors we default to using VFP; but the user
26014 should really set the FPU type explicitly. */
996b5569
TP
26015 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
26016 ARM_ARCH_NONE,
26017 FPU_ARCH_VFP_V2),
26018 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
26019 ARM_ARCH_NONE,
26020 FPU_ARCH_VFP_V2),
26021 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
26022 ARM_ARCH_NONE,
26023 FPU_ARCH_VFP_V2),
26024 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
26025 ARM_ARCH_NONE,
26026 FPU_ARCH_VFP_V2),
26027 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
26028 ARM_ARCH_NONE,
26029 FPU_ARCH_VFP_V2),
26030 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
26031 ARM_ARCH_NONE,
26032 FPU_ARCH_VFP_V2),
26033 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
26034 ARM_ARCH_NONE,
26035 FPU_ARCH_VFP_V2),
26036 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
26037 ARM_ARCH_NONE,
26038 FPU_ARCH_VFP_V2),
26039 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
26040 ARM_ARCH_NONE,
26041 FPU_ARCH_VFP_V2),
26042 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
26043 ARM_ARCH_NONE,
26044 FPU_ARCH_VFP_V2),
26045 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
26046 ARM_ARCH_NONE,
26047 FPU_ARCH_VFP_V2),
26048 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
26049 ARM_ARCH_NONE,
26050 FPU_ARCH_VFP_V2),
26051 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
26052 ARM_ARCH_NONE,
26053 FPU_ARCH_VFP_V1),
26054 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
26055 ARM_ARCH_NONE,
26056 FPU_ARCH_VFP_V1),
26057 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
26058 ARM_ARCH_NONE,
26059 FPU_ARCH_VFP_V2),
26060 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
26061 ARM_ARCH_NONE,
26062 FPU_ARCH_VFP_V2),
26063 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
26064 ARM_ARCH_NONE,
26065 FPU_ARCH_VFP_V1),
26066 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
26067 ARM_ARCH_NONE,
26068 FPU_ARCH_VFP_V2),
26069 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
26070 ARM_ARCH_NONE,
26071 FPU_ARCH_VFP_V2),
26072 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
26073 ARM_ARCH_NONE,
26074 FPU_ARCH_VFP_V2),
26075 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
26076 ARM_ARCH_NONE,
26077 FPU_ARCH_VFP_V2),
26078 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
26079 ARM_ARCH_NONE,
26080 FPU_ARCH_VFP_V2),
26081 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
26082 ARM_ARCH_NONE,
26083 FPU_ARCH_VFP_V2),
26084 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
26085 ARM_ARCH_NONE,
26086 FPU_ARCH_VFP_V2),
26087 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
26088 ARM_ARCH_NONE,
26089 FPU_ARCH_VFP_V2),
26090 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
26091 ARM_ARCH_NONE,
26092 FPU_ARCH_VFP_V2),
26093 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
26094 ARM_ARCH_NONE,
26095 FPU_NONE),
26096 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
26097 ARM_ARCH_NONE,
26098 FPU_NONE),
26099 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
26100 ARM_ARCH_NONE,
26101 FPU_ARCH_VFP_V2),
26102 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
26103 ARM_ARCH_NONE,
26104 FPU_ARCH_VFP_V2),
26105 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
26106 ARM_ARCH_NONE,
26107 FPU_ARCH_VFP_V2),
26108 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
26109 ARM_ARCH_NONE,
26110 FPU_NONE),
26111 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
26112 ARM_ARCH_NONE,
26113 FPU_NONE),
26114 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
26115 ARM_ARCH_NONE,
26116 FPU_ARCH_VFP_V2),
26117 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
26118 ARM_ARCH_NONE,
26119 FPU_NONE),
26120 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
26121 ARM_ARCH_NONE,
26122 FPU_ARCH_VFP_V2),
26123 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
26124 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26125 FPU_NONE),
26126 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
26127 ARM_ARCH_NONE,
26128 FPU_ARCH_NEON_VFP_V4),
26129 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
26130 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
26131 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26132 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
26133 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26134 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26135 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
26136 ARM_ARCH_NONE,
26137 FPU_ARCH_NEON_VFP_V4),
26138 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
26139 ARM_ARCH_NONE,
26140 FPU_ARCH_NEON_VFP_V4),
26141 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
26142 ARM_ARCH_NONE,
26143 FPU_ARCH_NEON_VFP_V4),
26144 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
26145 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26146 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26147 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
26148 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26149 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26150 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
26151 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26152 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
26153 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
26154 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 26155 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
26156 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
26157 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26158 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26159 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
26160 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26161 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26162 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
26163 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26164 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
26165 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
26166 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 26167 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
7ebd1359 26168 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
26169 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26170 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
26171 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
26172 ARM_ARCH_NONE,
26173 FPU_NONE),
26174 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
26175 ARM_ARCH_NONE,
26176 FPU_ARCH_VFP_V3D16),
26177 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
26178 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26179 FPU_NONE),
26180 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
26181 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26182 FPU_ARCH_VFP_V3D16),
26183 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
26184 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26185 FPU_ARCH_VFP_V3D16),
0cda1e19
TP
26186 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
26187 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26188 FPU_ARCH_NEON_VFP_ARMV8),
996b5569
TP
26189 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
26190 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26191 FPU_NONE),
26192 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
26193 ARM_ARCH_NONE,
26194 FPU_NONE),
26195 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
26196 ARM_ARCH_NONE,
26197 FPU_NONE),
26198 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
26199 ARM_ARCH_NONE,
26200 FPU_NONE),
26201 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
26202 ARM_ARCH_NONE,
26203 FPU_NONE),
26204 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
26205 ARM_ARCH_NONE,
26206 FPU_NONE),
26207 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
26208 ARM_ARCH_NONE,
26209 FPU_NONE),
26210 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
26211 ARM_ARCH_NONE,
26212 FPU_NONE),
26213 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
26214 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26215 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
6b21c2bf 26216
c19d1205 26217 /* ??? XSCALE is really an architecture. */
996b5569
TP
26218 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
26219 ARM_ARCH_NONE,
26220 FPU_ARCH_VFP_V2),
26221
c19d1205 26222 /* ??? iwmmxt is not a processor. */
996b5569
TP
26223 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
26224 ARM_ARCH_NONE,
26225 FPU_ARCH_VFP_V2),
26226 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
26227 ARM_ARCH_NONE,
26228 FPU_ARCH_VFP_V2),
26229 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
26230 ARM_ARCH_NONE,
26231 FPU_ARCH_VFP_V2),
26232
0198d5e6 26233 /* Maverick. */
996b5569
TP
26234 ARM_CPU_OPT ("ep9312", "ARM920T",
26235 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
26236 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
26237
da4339ed 26238 /* Marvell processors. */
996b5569
TP
26239 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
26240 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26241 FPU_ARCH_VFP_V3D16),
26242 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
26243 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26244 FPU_ARCH_NEON_VFP_V4),
da4339ed 26245
996b5569
TP
26246 /* APM X-Gene family. */
26247 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
26248 ARM_ARCH_NONE,
26249 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26250 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
26251 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26252 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26253
26254 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 26255};
f3bad469 26256#undef ARM_CPU_OPT
7ed4c4c5 26257
c19d1205 26258struct arm_arch_option_table
7ed4c4c5 26259{
0198d5e6
TC
26260 const char * name;
26261 size_t name_len;
26262 const arm_feature_set value;
26263 const arm_feature_set default_fpu;
c19d1205 26264};
7ed4c4c5 26265
c19d1205
ZW
26266/* This list should, at a minimum, contain all the architecture names
26267 recognized by GCC. */
f3bad469 26268#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
0198d5e6 26269
e74cfd16 26270static const struct arm_arch_option_table arm_archs[] =
c19d1205 26271{
f3bad469
MGD
26272 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
26273 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
26274 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
26275 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
26276 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
26277 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
26278 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
26279 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
26280 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
26281 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
26282 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
26283 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
26284 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
26285 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
26286 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
26287 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
26288 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
26289 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
26290 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
26291 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
26292 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
26293 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
26294 kept to preserve existing behaviour. */
26295 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
26296 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
26297 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
26298 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
26299 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
26300 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
26301 kept to preserve existing behaviour. */
26302 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
26303 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
26304 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
26305 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
26306 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
26307 /* The official spelling of the ARMv7 profile variants is the dashed form.
26308 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 26309 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 26310 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
26311 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26312 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26313 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
26314 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26315 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26316 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 26317 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 26318 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 26319 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 26320 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 26321 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
a12fd8e1 26322 ARM_ARCH_OPT ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP),
ced40572 26323 ARM_ARCH_OPT ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP),
dec41383 26324 ARM_ARCH_OPT ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP),
f3bad469
MGD
26325 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
26326 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
26327 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
26328 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 26329};
f3bad469 26330#undef ARM_ARCH_OPT
7ed4c4c5 26331
69133863 26332/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 26333
69133863 26334struct arm_option_extension_value_table
c19d1205 26335{
0198d5e6
TC
26336 const char * name;
26337 size_t name_len;
26338 const arm_feature_set merge_value;
26339 const arm_feature_set clear_value;
d942732e
TP
26340 /* List of architectures for which an extension is available. ARM_ARCH_NONE
26341 indicates that an extension is available for all architectures while
26342 ARM_ANY marks an empty entry. */
0198d5e6 26343 const arm_feature_set allowed_archs[2];
c19d1205 26344};
7ed4c4c5 26345
0198d5e6
TC
26346/* The following table must be in alphabetical order with a NULL last entry. */
26347
d942732e
TP
26348#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
26349#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 26350
69133863 26351static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 26352{
823d2571
TG
26353 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26354 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 26355 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
26356 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
26357 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
26358 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
26359 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
26360 ARM_ARCH_V8_2A),
15afaa63
TP
26361 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26362 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26363 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
26364 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
26365 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
26366 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26367 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26368 ARM_ARCH_V8_2A),
01f48020
TC
26369 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
26370 | ARM_EXT2_FP16_FML),
26371 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
26372 | ARM_EXT2_FP16_FML),
26373 ARM_ARCH_V8_2A),
d942732e 26374 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 26375 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
26376 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26377 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
26378 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
26379 Thumb divide instruction. Due to this having the same name as the
26380 previous entry, this will be ignored when doing command-line parsing and
26381 only considered by build attribute selection code. */
26382 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26383 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26384 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 26385 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 26386 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 26387 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 26388 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 26389 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
26390 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
26391 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 26392 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
26393 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26394 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
26395 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26396 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26397 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
26398 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
26399 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 26400 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
4d1464f2
MW
26401 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
26402 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 26403 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
26404 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
26405 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 26406 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
d942732e 26407 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 26408 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
26409 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
26410 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
26411 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
26412 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
26413 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
26414 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
26415 | ARM_EXT_DIV),
26416 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
26417 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
26418 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
26419 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
26420 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 26421};
f3bad469 26422#undef ARM_EXT_OPT
69133863
MGD
26423
26424/* ISA floating-point and Advanced SIMD extensions. */
26425struct arm_option_fpu_value_table
26426{
0198d5e6
TC
26427 const char * name;
26428 const arm_feature_set value;
c19d1205 26429};
7ed4c4c5 26430
c19d1205
ZW
26431/* This list should, at a minimum, contain all the fpu names
26432 recognized by GCC. */
69133863 26433static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
26434{
26435 {"softfpa", FPU_NONE},
26436 {"fpe", FPU_ARCH_FPE},
26437 {"fpe2", FPU_ARCH_FPE},
26438 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
26439 {"fpa", FPU_ARCH_FPA},
26440 {"fpa10", FPU_ARCH_FPA},
26441 {"fpa11", FPU_ARCH_FPA},
26442 {"arm7500fe", FPU_ARCH_FPA},
26443 {"softvfp", FPU_ARCH_VFP},
26444 {"softvfp+vfp", FPU_ARCH_VFP_V2},
26445 {"vfp", FPU_ARCH_VFP_V2},
26446 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 26447 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
26448 {"vfp10", FPU_ARCH_VFP_V2},
26449 {"vfp10-r0", FPU_ARCH_VFP_V1},
26450 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
26451 {"vfpv2", FPU_ARCH_VFP_V2},
26452 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 26453 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 26454 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
26455 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
26456 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
26457 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
26458 {"arm1020t", FPU_ARCH_VFP_V1},
26459 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 26460 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
26461 {"arm1136jf-s", FPU_ARCH_VFP_V2},
26462 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 26463 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 26464 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 26465 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
26466 {"vfpv4", FPU_ARCH_VFP_V4},
26467 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 26468 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
26469 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
26470 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 26471 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
26472 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
26473 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
26474 {"crypto-neon-fp-armv8",
26475 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 26476 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
26477 {"crypto-neon-fp-armv8.1",
26478 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
26479 {NULL, ARM_ARCH_NONE}
26480};
26481
26482struct arm_option_value_table
26483{
e0471c16 26484 const char *name;
e74cfd16 26485 long value;
c19d1205 26486};
7ed4c4c5 26487
e74cfd16 26488static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
26489{
26490 {"hard", ARM_FLOAT_ABI_HARD},
26491 {"softfp", ARM_FLOAT_ABI_SOFTFP},
26492 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 26493 {NULL, 0}
c19d1205 26494};
7ed4c4c5 26495
c19d1205 26496#ifdef OBJ_ELF
3a4a14e9 26497/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 26498static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
26499{
26500 {"gnu", EF_ARM_EABI_UNKNOWN},
26501 {"4", EF_ARM_EABI_VER4},
3a4a14e9 26502 {"5", EF_ARM_EABI_VER5},
e74cfd16 26503 {NULL, 0}
c19d1205
ZW
26504};
26505#endif
7ed4c4c5 26506
c19d1205
ZW
26507struct arm_long_option_table
26508{
0198d5e6 26509 const char * option; /* Substring to match. */
e0471c16 26510 const char * help; /* Help information. */
17b9d67d 26511 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 26512 const char * deprecated; /* If non-null, print this message. */
c19d1205 26513};
7ed4c4c5 26514
c921be7d 26515static bfd_boolean
c168ce07 26516arm_parse_extension (const char *str, const arm_feature_set *opt_set,
4d354d8b 26517 arm_feature_set *ext_set)
7ed4c4c5 26518{
69133863 26519 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
26520 extensions being added before being removed. We achieve this by having
26521 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 26522 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 26523 or removing it (0) and only allowing it to change in the order
69133863
MGD
26524 -1 -> 1 -> 0. */
26525 const struct arm_option_extension_value_table * opt = NULL;
d942732e 26526 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26527 int adding_value = -1;
26528
c19d1205 26529 while (str != NULL && *str != 0)
7ed4c4c5 26530 {
82b8a785 26531 const char *ext;
f3bad469 26532 size_t len;
7ed4c4c5 26533
c19d1205
ZW
26534 if (*str != '+')
26535 {
26536 as_bad (_("invalid architectural extension"));
c921be7d 26537 return FALSE;
c19d1205 26538 }
7ed4c4c5 26539
c19d1205
ZW
26540 str++;
26541 ext = strchr (str, '+');
7ed4c4c5 26542
c19d1205 26543 if (ext != NULL)
f3bad469 26544 len = ext - str;
c19d1205 26545 else
f3bad469 26546 len = strlen (str);
7ed4c4c5 26547
f3bad469 26548 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
26549 {
26550 if (adding_value != 0)
26551 {
26552 adding_value = 0;
26553 opt = arm_extensions;
26554 }
26555
f3bad469 26556 len -= 2;
69133863
MGD
26557 str += 2;
26558 }
f3bad469 26559 else if (len > 0)
69133863
MGD
26560 {
26561 if (adding_value == -1)
26562 {
26563 adding_value = 1;
26564 opt = arm_extensions;
26565 }
26566 else if (adding_value != 1)
26567 {
26568 as_bad (_("must specify extensions to add before specifying "
26569 "those to remove"));
26570 return FALSE;
26571 }
26572 }
26573
f3bad469 26574 if (len == 0)
c19d1205
ZW
26575 {
26576 as_bad (_("missing architectural extension"));
c921be7d 26577 return FALSE;
c19d1205 26578 }
7ed4c4c5 26579
69133863
MGD
26580 gas_assert (adding_value != -1);
26581 gas_assert (opt != NULL);
26582
26583 /* Scan over the options table trying to find an exact match. */
26584 for (; opt->name != NULL; opt++)
f3bad469 26585 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26586 {
d942732e
TP
26587 int i, nb_allowed_archs =
26588 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 26589 /* Check we can apply the extension to this architecture. */
d942732e
TP
26590 for (i = 0; i < nb_allowed_archs; i++)
26591 {
26592 /* Empty entry. */
26593 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26594 continue;
c168ce07 26595 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
26596 break;
26597 }
26598 if (i == nb_allowed_archs)
69133863
MGD
26599 {
26600 as_bad (_("extension does not apply to the base architecture"));
26601 return FALSE;
26602 }
26603
26604 /* Add or remove the extension. */
26605 if (adding_value)
4d354d8b 26606 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 26607 else
4d354d8b 26608 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 26609
3d030cdb
TP
26610 /* Allowing Thumb division instructions for ARMv7 in autodetection
26611 rely on this break so that duplicate extensions (extensions
26612 with the same name as a previous extension in the list) are not
26613 considered for command-line parsing. */
c19d1205
ZW
26614 break;
26615 }
7ed4c4c5 26616
c19d1205
ZW
26617 if (opt->name == NULL)
26618 {
69133863
MGD
26619 /* Did we fail to find an extension because it wasn't specified in
26620 alphabetical order, or because it does not exist? */
26621
26622 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 26623 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
26624 break;
26625
26626 if (opt->name == NULL)
26627 as_bad (_("unknown architectural extension `%s'"), str);
26628 else
26629 as_bad (_("architectural extensions must be specified in "
26630 "alphabetical order"));
26631
c921be7d 26632 return FALSE;
c19d1205 26633 }
69133863
MGD
26634 else
26635 {
26636 /* We should skip the extension we've just matched the next time
26637 round. */
26638 opt++;
26639 }
7ed4c4c5 26640
c19d1205
ZW
26641 str = ext;
26642 };
7ed4c4c5 26643
c921be7d 26644 return TRUE;
c19d1205 26645}
7ed4c4c5 26646
c921be7d 26647static bfd_boolean
17b9d67d 26648arm_parse_cpu (const char *str)
7ed4c4c5 26649{
f3bad469 26650 const struct arm_cpu_option_table *opt;
82b8a785 26651 const char *ext = strchr (str, '+');
f3bad469 26652 size_t len;
7ed4c4c5 26653
c19d1205 26654 if (ext != NULL)
f3bad469 26655 len = ext - str;
7ed4c4c5 26656 else
f3bad469 26657 len = strlen (str);
7ed4c4c5 26658
f3bad469 26659 if (len == 0)
7ed4c4c5 26660 {
c19d1205 26661 as_bad (_("missing cpu name `%s'"), str);
c921be7d 26662 return FALSE;
7ed4c4c5
NC
26663 }
26664
c19d1205 26665 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 26666 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26667 {
c168ce07 26668 mcpu_cpu_opt = &opt->value;
4d354d8b
TP
26669 if (mcpu_ext_opt == NULL)
26670 mcpu_ext_opt = XNEW (arm_feature_set);
26671 *mcpu_ext_opt = opt->ext;
e74cfd16 26672 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 26673 if (opt->canonical_name)
ef8e6722
JW
26674 {
26675 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
26676 strcpy (selected_cpu_name, opt->canonical_name);
26677 }
ee065d83
PB
26678 else
26679 {
f3bad469 26680 size_t i;
c921be7d 26681
ef8e6722
JW
26682 if (len >= sizeof selected_cpu_name)
26683 len = (sizeof selected_cpu_name) - 1;
26684
f3bad469 26685 for (i = 0; i < len; i++)
ee065d83
PB
26686 selected_cpu_name[i] = TOUPPER (opt->name[i]);
26687 selected_cpu_name[i] = 0;
26688 }
7ed4c4c5 26689
c19d1205 26690 if (ext != NULL)
4d354d8b 26691 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt);
7ed4c4c5 26692
c921be7d 26693 return TRUE;
c19d1205 26694 }
7ed4c4c5 26695
c19d1205 26696 as_bad (_("unknown cpu `%s'"), str);
c921be7d 26697 return FALSE;
7ed4c4c5
NC
26698}
26699
c921be7d 26700static bfd_boolean
17b9d67d 26701arm_parse_arch (const char *str)
7ed4c4c5 26702{
e74cfd16 26703 const struct arm_arch_option_table *opt;
82b8a785 26704 const char *ext = strchr (str, '+');
f3bad469 26705 size_t len;
7ed4c4c5 26706
c19d1205 26707 if (ext != NULL)
f3bad469 26708 len = ext - str;
7ed4c4c5 26709 else
f3bad469 26710 len = strlen (str);
7ed4c4c5 26711
f3bad469 26712 if (len == 0)
7ed4c4c5 26713 {
c19d1205 26714 as_bad (_("missing architecture name `%s'"), str);
c921be7d 26715 return FALSE;
7ed4c4c5
NC
26716 }
26717
c19d1205 26718 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 26719 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26720 {
e74cfd16 26721 march_cpu_opt = &opt->value;
4d354d8b
TP
26722 if (march_ext_opt == NULL)
26723 march_ext_opt = XNEW (arm_feature_set);
26724 *march_ext_opt = arm_arch_none;
e74cfd16 26725 march_fpu_opt = &opt->default_fpu;
5f4273c7 26726 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 26727
c19d1205 26728 if (ext != NULL)
4d354d8b 26729 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt);
7ed4c4c5 26730
c921be7d 26731 return TRUE;
c19d1205
ZW
26732 }
26733
26734 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 26735 return FALSE;
7ed4c4c5 26736}
eb043451 26737
c921be7d 26738static bfd_boolean
17b9d67d 26739arm_parse_fpu (const char * str)
c19d1205 26740{
69133863 26741 const struct arm_option_fpu_value_table * opt;
b99bd4ef 26742
c19d1205
ZW
26743 for (opt = arm_fpus; opt->name != NULL; opt++)
26744 if (streq (opt->name, str))
26745 {
e74cfd16 26746 mfpu_opt = &opt->value;
c921be7d 26747 return TRUE;
c19d1205 26748 }
b99bd4ef 26749
c19d1205 26750 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 26751 return FALSE;
c19d1205
ZW
26752}
26753
c921be7d 26754static bfd_boolean
17b9d67d 26755arm_parse_float_abi (const char * str)
b99bd4ef 26756{
e74cfd16 26757 const struct arm_option_value_table * opt;
b99bd4ef 26758
c19d1205
ZW
26759 for (opt = arm_float_abis; opt->name != NULL; opt++)
26760 if (streq (opt->name, str))
26761 {
26762 mfloat_abi_opt = opt->value;
c921be7d 26763 return TRUE;
c19d1205 26764 }
cc8a6dd0 26765
c19d1205 26766 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 26767 return FALSE;
c19d1205 26768}
b99bd4ef 26769
c19d1205 26770#ifdef OBJ_ELF
c921be7d 26771static bfd_boolean
17b9d67d 26772arm_parse_eabi (const char * str)
c19d1205 26773{
e74cfd16 26774 const struct arm_option_value_table *opt;
cc8a6dd0 26775
c19d1205
ZW
26776 for (opt = arm_eabis; opt->name != NULL; opt++)
26777 if (streq (opt->name, str))
26778 {
26779 meabi_flags = opt->value;
c921be7d 26780 return TRUE;
c19d1205
ZW
26781 }
26782 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 26783 return FALSE;
c19d1205
ZW
26784}
26785#endif
cc8a6dd0 26786
c921be7d 26787static bfd_boolean
17b9d67d 26788arm_parse_it_mode (const char * str)
e07e6e58 26789{
c921be7d 26790 bfd_boolean ret = TRUE;
e07e6e58
NC
26791
26792 if (streq ("arm", str))
26793 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
26794 else if (streq ("thumb", str))
26795 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
26796 else if (streq ("always", str))
26797 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
26798 else if (streq ("never", str))
26799 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
26800 else
26801 {
26802 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 26803 "arm, thumb, always, or never."), str);
c921be7d 26804 ret = FALSE;
e07e6e58
NC
26805 }
26806
26807 return ret;
26808}
26809
2e6976a8 26810static bfd_boolean
17b9d67d 26811arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
26812{
26813 codecomposer_syntax = TRUE;
26814 arm_comment_chars[0] = ';';
26815 arm_line_separator_chars[0] = 0;
26816 return TRUE;
26817}
26818
c19d1205
ZW
26819struct arm_long_option_table arm_long_opts[] =
26820{
26821 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
26822 arm_parse_cpu, NULL},
26823 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
26824 arm_parse_arch, NULL},
26825 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
26826 arm_parse_fpu, NULL},
26827 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
26828 arm_parse_float_abi, NULL},
26829#ifdef OBJ_ELF
7fac0536 26830 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
26831 arm_parse_eabi, NULL},
26832#endif
e07e6e58
NC
26833 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
26834 arm_parse_it_mode, NULL},
2e6976a8
DG
26835 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
26836 arm_ccs_mode, NULL},
c19d1205
ZW
26837 {NULL, NULL, 0, NULL}
26838};
cc8a6dd0 26839
c19d1205 26840int
17b9d67d 26841md_parse_option (int c, const char * arg)
c19d1205
ZW
26842{
26843 struct arm_option_table *opt;
e74cfd16 26844 const struct arm_legacy_option_table *fopt;
c19d1205 26845 struct arm_long_option_table *lopt;
b99bd4ef 26846
c19d1205 26847 switch (c)
b99bd4ef 26848 {
c19d1205
ZW
26849#ifdef OPTION_EB
26850 case OPTION_EB:
26851 target_big_endian = 1;
26852 break;
26853#endif
cc8a6dd0 26854
c19d1205
ZW
26855#ifdef OPTION_EL
26856 case OPTION_EL:
26857 target_big_endian = 0;
26858 break;
26859#endif
b99bd4ef 26860
845b51d6
PB
26861 case OPTION_FIX_V4BX:
26862 fix_v4bx = TRUE;
26863 break;
26864
18a20338
CL
26865#ifdef OBJ_ELF
26866 case OPTION_FDPIC:
26867 arm_fdpic = TRUE;
26868 break;
26869#endif /* OBJ_ELF */
26870
c19d1205
ZW
26871 case 'a':
26872 /* Listing option. Just ignore these, we don't support additional
26873 ones. */
26874 return 0;
b99bd4ef 26875
c19d1205
ZW
26876 default:
26877 for (opt = arm_opts; opt->option != NULL; opt++)
26878 {
26879 if (c == opt->option[0]
26880 && ((arg == NULL && opt->option[1] == 0)
26881 || streq (arg, opt->option + 1)))
26882 {
c19d1205 26883 /* If the option is deprecated, tell the user. */
278df34e 26884 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
26885 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26886 arg ? arg : "", _(opt->deprecated));
b99bd4ef 26887
c19d1205
ZW
26888 if (opt->var != NULL)
26889 *opt->var = opt->value;
cc8a6dd0 26890
c19d1205
ZW
26891 return 1;
26892 }
26893 }
b99bd4ef 26894
e74cfd16
PB
26895 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26896 {
26897 if (c == fopt->option[0]
26898 && ((arg == NULL && fopt->option[1] == 0)
26899 || streq (arg, fopt->option + 1)))
26900 {
e74cfd16 26901 /* If the option is deprecated, tell the user. */
278df34e 26902 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
26903 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26904 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
26905
26906 if (fopt->var != NULL)
26907 *fopt->var = &fopt->value;
26908
26909 return 1;
26910 }
26911 }
26912
c19d1205
ZW
26913 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26914 {
26915 /* These options are expected to have an argument. */
26916 if (c == lopt->option[0]
26917 && arg != NULL
26918 && strncmp (arg, lopt->option + 1,
26919 strlen (lopt->option + 1)) == 0)
26920 {
c19d1205 26921 /* If the option is deprecated, tell the user. */
278df34e 26922 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
26923 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26924 _(lopt->deprecated));
b99bd4ef 26925
c19d1205
ZW
26926 /* Call the sup-option parser. */
26927 return lopt->func (arg + strlen (lopt->option) - 1);
26928 }
26929 }
a737bd4d 26930
c19d1205
ZW
26931 return 0;
26932 }
a394c00f 26933
c19d1205
ZW
26934 return 1;
26935}
a394c00f 26936
c19d1205
ZW
26937void
26938md_show_usage (FILE * fp)
a394c00f 26939{
c19d1205
ZW
26940 struct arm_option_table *opt;
26941 struct arm_long_option_table *lopt;
a394c00f 26942
c19d1205 26943 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 26944
c19d1205
ZW
26945 for (opt = arm_opts; opt->option != NULL; opt++)
26946 if (opt->help != NULL)
26947 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 26948
c19d1205
ZW
26949 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26950 if (lopt->help != NULL)
26951 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 26952
c19d1205
ZW
26953#ifdef OPTION_EB
26954 fprintf (fp, _("\
26955 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
26956#endif
26957
c19d1205
ZW
26958#ifdef OPTION_EL
26959 fprintf (fp, _("\
26960 -EL assemble code for a little-endian cpu\n"));
a737bd4d 26961#endif
845b51d6
PB
26962
26963 fprintf (fp, _("\
26964 --fix-v4bx Allow BX in ARMv4 code\n"));
18a20338
CL
26965
26966#ifdef OBJ_ELF
26967 fprintf (fp, _("\
26968 --fdpic generate an FDPIC object file\n"));
26969#endif /* OBJ_ELF */
c19d1205 26970}
ee065d83 26971
ee065d83 26972#ifdef OBJ_ELF
0198d5e6 26973
62b3e311
PB
26974typedef struct
26975{
26976 int val;
26977 arm_feature_set flags;
26978} cpu_arch_ver_table;
26979
2c6b98ea
TP
26980/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
26981 chronologically for architectures, with an exception for ARMv6-M and
26982 ARMv6S-M due to legacy reasons. No new architecture should have a
26983 special case. This allows for build attribute selection results to be
26984 stable when new architectures are added. */
62b3e311
PB
26985static const cpu_arch_ver_table cpu_arch_ver[] =
26986{
c0c468d5
TP
26987 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
26988 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
26989 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
26990 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
26991 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
26992 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
26993 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
26994 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
26995 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
26996 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
26997 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
26998 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
26999 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
27000 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
27001 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
27002 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
27003 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
27004 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
27005 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
27006 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
27007 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
27008 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
27009 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
27010 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
2c6b98ea
TP
27011
27012 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
27013 always selected build attributes to match those of ARMv6-M
27014 (resp. ARMv6S-M). However, due to these architectures being a strict
27015 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
27016 would be selected when fully respecting chronology of architectures.
27017 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
27018 move them before ARMv7 architectures. */
c0c468d5
TP
27019 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
27020 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
27021
27022 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
27023 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
27024 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
27025 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
27026 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
27027 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
27028 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
27029 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
27030 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
27031 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
27032 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
27033 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
27034 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
27035 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
27036 {-1, ARM_ARCH_NONE}
62b3e311
PB
27037};
27038
ee3c0378 27039/* Set an attribute if it has not already been set by the user. */
0198d5e6 27040
ee3c0378
AS
27041static void
27042aeabi_set_attribute_int (int tag, int value)
27043{
27044 if (tag < 1
27045 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
27046 || !attributes_set_explicitly[tag])
27047 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
27048}
27049
27050static void
27051aeabi_set_attribute_string (int tag, const char *value)
27052{
27053 if (tag < 1
27054 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
27055 || !attributes_set_explicitly[tag])
27056 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
27057}
27058
2c6b98ea
TP
27059/* Return whether features in the *NEEDED feature set are available via
27060 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 27061
2c6b98ea
TP
27062static bfd_boolean
27063have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
27064 const arm_feature_set *needed)
27065{
27066 int i, nb_allowed_archs;
27067 arm_feature_set ext_fset;
27068 const struct arm_option_extension_value_table *opt;
27069
27070 ext_fset = arm_arch_none;
27071 for (opt = arm_extensions; opt->name != NULL; opt++)
27072 {
27073 /* Extension does not provide any feature we need. */
27074 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
27075 continue;
27076
27077 nb_allowed_archs =
27078 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
27079 for (i = 0; i < nb_allowed_archs; i++)
27080 {
27081 /* Empty entry. */
27082 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
27083 break;
27084
27085 /* Extension is available, add it. */
27086 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
27087 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
27088 }
27089 }
27090
27091 /* Can we enable all features in *needed? */
27092 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
27093}
27094
27095/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
27096 a given architecture feature set *ARCH_EXT_FSET including extension feature
27097 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
27098 - if true, check for an exact match of the architecture modulo extensions;
27099 - otherwise, select build attribute value of the first superset
27100 architecture released so that results remains stable when new architectures
27101 are added.
27102 For -march/-mcpu=all the build attribute value of the most featureful
27103 architecture is returned. Tag_CPU_arch_profile result is returned in
27104 PROFILE. */
0198d5e6 27105
2c6b98ea
TP
27106static int
27107get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
27108 const arm_feature_set *ext_fset,
27109 char *profile, int exact_match)
27110{
27111 arm_feature_set arch_fset;
27112 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
27113
27114 /* Select most featureful architecture with all its extensions if building
27115 for -march=all as the feature sets used to set build attributes. */
27116 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
27117 {
27118 /* Force revisiting of decision for each new architecture. */
27119 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8M_MAIN);
27120 *profile = 'A';
27121 return TAG_CPU_ARCH_V8;
27122 }
27123
27124 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
27125
27126 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
27127 {
27128 arm_feature_set known_arch_fset;
27129
27130 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
27131 if (exact_match)
27132 {
27133 /* Base architecture match user-specified architecture and
27134 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
27135 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
27136 {
27137 p_ver_ret = p_ver;
27138 goto found;
27139 }
27140 /* Base architecture match user-specified architecture only
27141 (eg. ARMv6-M in the same case as above). Record it in case we
27142 find a match with above condition. */
27143 else if (p_ver_ret == NULL
27144 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
27145 p_ver_ret = p_ver;
27146 }
27147 else
27148 {
27149
27150 /* Architecture has all features wanted. */
27151 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
27152 {
27153 arm_feature_set added_fset;
27154
27155 /* Compute features added by this architecture over the one
27156 recorded in p_ver_ret. */
27157 if (p_ver_ret != NULL)
27158 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
27159 p_ver_ret->flags);
27160 /* First architecture that match incl. with extensions, or the
27161 only difference in features over the recorded match is
27162 features that were optional and are now mandatory. */
27163 if (p_ver_ret == NULL
27164 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
27165 {
27166 p_ver_ret = p_ver;
27167 goto found;
27168 }
27169 }
27170 else if (p_ver_ret == NULL)
27171 {
27172 arm_feature_set needed_ext_fset;
27173
27174 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
27175
27176 /* Architecture has all features needed when using some
27177 extensions. Record it and continue searching in case there
27178 exist an architecture providing all needed features without
27179 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
27180 OS extension). */
27181 if (have_ext_for_needed_feat_p (&known_arch_fset,
27182 &needed_ext_fset))
27183 p_ver_ret = p_ver;
27184 }
27185 }
27186 }
27187
27188 if (p_ver_ret == NULL)
27189 return -1;
27190
27191found:
27192 /* Tag_CPU_arch_profile. */
27193 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
27194 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
27195 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
27196 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
27197 *profile = 'A';
27198 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
27199 *profile = 'R';
27200 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
27201 *profile = 'M';
27202 else
27203 *profile = '\0';
27204 return p_ver_ret->val;
27205}
27206
ee065d83 27207/* Set the public EABI object attributes. */
0198d5e6 27208
c168ce07 27209static void
ee065d83
PB
27210aeabi_set_public_attributes (void)
27211{
b90d5ba0 27212 char profile = '\0';
2c6b98ea 27213 int arch = -1;
90ec0d68 27214 int virt_sec = 0;
bca38921 27215 int fp16_optional = 0;
2c6b98ea
TP
27216 int skip_exact_match = 0;
27217 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 27218
54bab281
TP
27219 /* Autodetection mode, choose the architecture based the instructions
27220 actually used. */
27221 if (no_cpu_selected ())
27222 {
27223 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 27224
54bab281
TP
27225 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
27226 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 27227
54bab281
TP
27228 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
27229 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 27230
54bab281 27231 /* Code run during relaxation relies on selected_cpu being set. */
4d354d8b
TP
27232 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
27233 flags_ext = arm_arch_none;
27234 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
27235 selected_ext = flags_ext;
54bab281
TP
27236 selected_cpu = flags;
27237 }
27238 /* Otherwise, choose the architecture based on the capabilities of the
27239 requested cpu. */
27240 else
4d354d8b
TP
27241 {
27242 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
27243 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
27244 flags_ext = selected_ext;
27245 flags = selected_cpu;
27246 }
27247 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
7f78eb34 27248
ddd7f988 27249 /* Allow the user to override the reported architecture. */
4d354d8b 27250 if (!ARM_FEATURE_ZERO (selected_object_arch))
7a1d4c38 27251 {
4d354d8b 27252 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
2c6b98ea 27253 flags_ext = arm_arch_none;
7a1d4c38 27254 }
2c6b98ea 27255 else
4d354d8b 27256 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
2c6b98ea
TP
27257
27258 /* When this function is run again after relaxation has happened there is no
27259 way to determine whether an architecture or CPU was specified by the user:
27260 - selected_cpu is set above for relaxation to work;
27261 - march_cpu_opt is not set if only -mcpu or .cpu is used;
27262 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
27263 Therefore, if not in -march=all case we first try an exact match and fall
27264 back to autodetection. */
27265 if (!skip_exact_match)
27266 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
27267 if (arch == -1)
27268 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
27269 if (arch == -1)
27270 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 27271
ee065d83
PB
27272 /* Tag_CPU_name. */
27273 if (selected_cpu_name[0])
27274 {
91d6fa6a 27275 char *q;
ee065d83 27276
91d6fa6a
NC
27277 q = selected_cpu_name;
27278 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
27279 {
27280 int i;
5f4273c7 27281
91d6fa6a
NC
27282 q += 4;
27283 for (i = 0; q[i]; i++)
27284 q[i] = TOUPPER (q[i]);
ee065d83 27285 }
91d6fa6a 27286 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 27287 }
62f3b8c8 27288
ee065d83 27289 /* Tag_CPU_arch. */
ee3c0378 27290 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 27291
62b3e311 27292 /* Tag_CPU_arch_profile. */
69239280
MGD
27293 if (profile != '\0')
27294 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 27295
15afaa63 27296 /* Tag_DSP_extension. */
4d354d8b 27297 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
6c290d53 27298 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 27299
2c6b98ea 27300 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 27301 /* Tag_ARM_ISA_use. */
ee3c0378 27302 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 27303 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 27304 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 27305
ee065d83 27306 /* Tag_THUMB_ISA_use. */
ee3c0378 27307 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 27308 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
27309 {
27310 int thumb_isa_use;
27311
27312 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 27313 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
27314 thumb_isa_use = 3;
27315 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
27316 thumb_isa_use = 2;
27317 else
27318 thumb_isa_use = 1;
27319 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
27320 }
62f3b8c8 27321
ee065d83 27322 /* Tag_VFP_arch. */
a715796b
TG
27323 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
27324 aeabi_set_attribute_int (Tag_VFP_arch,
27325 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27326 ? 7 : 8);
bca38921 27327 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
27328 aeabi_set_attribute_int (Tag_VFP_arch,
27329 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27330 ? 5 : 6);
27331 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
27332 {
27333 fp16_optional = 1;
27334 aeabi_set_attribute_int (Tag_VFP_arch, 3);
27335 }
ada65aa3 27336 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
27337 {
27338 aeabi_set_attribute_int (Tag_VFP_arch, 4);
27339 fp16_optional = 1;
27340 }
ee3c0378
AS
27341 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
27342 aeabi_set_attribute_int (Tag_VFP_arch, 2);
27343 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 27344 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 27345 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 27346
4547cb56
NC
27347 /* Tag_ABI_HardFP_use. */
27348 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
27349 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
27350 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
27351
ee065d83 27352 /* Tag_WMMX_arch. */
ee3c0378
AS
27353 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
27354 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
27355 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
27356 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 27357
ee3c0378 27358 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
27359 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
27360 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
27361 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
27362 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
27363 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
27364 {
27365 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
27366 {
27367 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
27368 }
27369 else
27370 {
27371 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
27372 fp16_optional = 1;
27373 }
27374 }
fa94de6b 27375
ee3c0378 27376 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 27377 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 27378 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 27379
69239280
MGD
27380 /* Tag_DIV_use.
27381
27382 We set Tag_DIV_use to two when integer divide instructions have been used
27383 in ARM state, or when Thumb integer divide instructions have been used,
27384 but we have no architecture profile set, nor have we any ARM instructions.
27385
4ed7ed8d
TP
27386 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
27387 by the base architecture.
bca38921 27388
69239280 27389 For new architectures we will have to check these tests. */
ced40572 27390 gas_assert (arch <= TAG_CPU_ARCH_V8M_MAIN);
4ed7ed8d
TP
27391 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
27392 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
27393 aeabi_set_attribute_int (Tag_DIV_use, 0);
27394 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
27395 || (profile == '\0'
27396 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
27397 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 27398 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
27399
27400 /* Tag_MP_extension_use. */
27401 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
27402 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
27403
27404 /* Tag Virtualization_use. */
27405 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
27406 virt_sec |= 1;
27407 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
27408 virt_sec |= 2;
27409 if (virt_sec != 0)
27410 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
27411}
27412
c168ce07
TP
27413/* Post relaxation hook. Recompute ARM attributes now that relaxation is
27414 finished and free extension feature bits which will not be used anymore. */
0198d5e6 27415
c168ce07
TP
27416void
27417arm_md_post_relax (void)
27418{
27419 aeabi_set_public_attributes ();
4d354d8b
TP
27420 XDELETE (mcpu_ext_opt);
27421 mcpu_ext_opt = NULL;
27422 XDELETE (march_ext_opt);
27423 march_ext_opt = NULL;
c168ce07
TP
27424}
27425
104d59d1 27426/* Add the default contents for the .ARM.attributes section. */
0198d5e6 27427
ee065d83
PB
27428void
27429arm_md_end (void)
27430{
ee065d83
PB
27431 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
27432 return;
27433
27434 aeabi_set_public_attributes ();
ee065d83 27435}
8463be01 27436#endif /* OBJ_ELF */
ee065d83 27437
ee065d83
PB
27438/* Parse a .cpu directive. */
27439
27440static void
27441s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
27442{
e74cfd16 27443 const struct arm_cpu_option_table *opt;
ee065d83
PB
27444 char *name;
27445 char saved_char;
27446
27447 name = input_line_pointer;
5f4273c7 27448 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27449 input_line_pointer++;
27450 saved_char = *input_line_pointer;
27451 *input_line_pointer = 0;
27452
27453 /* Skip the first "all" entry. */
27454 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
27455 if (streq (opt->name, name))
27456 {
4d354d8b
TP
27457 selected_arch = opt->value;
27458 selected_ext = opt->ext;
27459 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
ee065d83 27460 if (opt->canonical_name)
5f4273c7 27461 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
27462 else
27463 {
27464 int i;
27465 for (i = 0; opt->name[i]; i++)
27466 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 27467
ee065d83
PB
27468 selected_cpu_name[i] = 0;
27469 }
4d354d8b
TP
27470 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
27471
ee065d83
PB
27472 *input_line_pointer = saved_char;
27473 demand_empty_rest_of_line ();
27474 return;
27475 }
27476 as_bad (_("unknown cpu `%s'"), name);
27477 *input_line_pointer = saved_char;
27478 ignore_rest_of_line ();
27479}
27480
ee065d83
PB
27481/* Parse a .arch directive. */
27482
27483static void
27484s_arm_arch (int ignored ATTRIBUTE_UNUSED)
27485{
e74cfd16 27486 const struct arm_arch_option_table *opt;
ee065d83
PB
27487 char saved_char;
27488 char *name;
27489
27490 name = input_line_pointer;
5f4273c7 27491 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27492 input_line_pointer++;
27493 saved_char = *input_line_pointer;
27494 *input_line_pointer = 0;
27495
27496 /* Skip the first "all" entry. */
27497 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27498 if (streq (opt->name, name))
27499 {
4d354d8b
TP
27500 selected_arch = opt->value;
27501 selected_ext = arm_arch_none;
27502 selected_cpu = selected_arch;
5f4273c7 27503 strcpy (selected_cpu_name, opt->name);
4d354d8b 27504 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
27505 *input_line_pointer = saved_char;
27506 demand_empty_rest_of_line ();
27507 return;
27508 }
27509
27510 as_bad (_("unknown architecture `%s'\n"), name);
27511 *input_line_pointer = saved_char;
27512 ignore_rest_of_line ();
27513}
27514
7a1d4c38
PB
27515/* Parse a .object_arch directive. */
27516
27517static void
27518s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
27519{
27520 const struct arm_arch_option_table *opt;
27521 char saved_char;
27522 char *name;
27523
27524 name = input_line_pointer;
5f4273c7 27525 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
27526 input_line_pointer++;
27527 saved_char = *input_line_pointer;
27528 *input_line_pointer = 0;
27529
27530 /* Skip the first "all" entry. */
27531 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27532 if (streq (opt->name, name))
27533 {
4d354d8b 27534 selected_object_arch = opt->value;
7a1d4c38
PB
27535 *input_line_pointer = saved_char;
27536 demand_empty_rest_of_line ();
27537 return;
27538 }
27539
27540 as_bad (_("unknown architecture `%s'\n"), name);
27541 *input_line_pointer = saved_char;
27542 ignore_rest_of_line ();
27543}
27544
69133863
MGD
27545/* Parse a .arch_extension directive. */
27546
27547static void
27548s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
27549{
27550 const struct arm_option_extension_value_table *opt;
27551 char saved_char;
27552 char *name;
27553 int adding_value = 1;
27554
27555 name = input_line_pointer;
27556 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27557 input_line_pointer++;
27558 saved_char = *input_line_pointer;
27559 *input_line_pointer = 0;
27560
27561 if (strlen (name) >= 2
27562 && strncmp (name, "no", 2) == 0)
27563 {
27564 adding_value = 0;
27565 name += 2;
27566 }
27567
27568 for (opt = arm_extensions; opt->name != NULL; opt++)
27569 if (streq (opt->name, name))
27570 {
d942732e
TP
27571 int i, nb_allowed_archs =
27572 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
27573 for (i = 0; i < nb_allowed_archs; i++)
27574 {
27575 /* Empty entry. */
4d354d8b 27576 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
d942732e 27577 continue;
4d354d8b 27578 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
d942732e
TP
27579 break;
27580 }
27581
27582 if (i == nb_allowed_archs)
69133863
MGD
27583 {
27584 as_bad (_("architectural extension `%s' is not allowed for the "
27585 "current base architecture"), name);
27586 break;
27587 }
27588
27589 if (adding_value)
4d354d8b 27590 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
5a70a223 27591 opt->merge_value);
69133863 27592 else
4d354d8b 27593 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
69133863 27594
4d354d8b
TP
27595 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
27596 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
69133863
MGD
27597 *input_line_pointer = saved_char;
27598 demand_empty_rest_of_line ();
3d030cdb
TP
27599 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
27600 on this return so that duplicate extensions (extensions with the
27601 same name as a previous extension in the list) are not considered
27602 for command-line parsing. */
69133863
MGD
27603 return;
27604 }
27605
27606 if (opt->name == NULL)
e673710a 27607 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
27608
27609 *input_line_pointer = saved_char;
27610 ignore_rest_of_line ();
27611}
27612
ee065d83
PB
27613/* Parse a .fpu directive. */
27614
27615static void
27616s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
27617{
69133863 27618 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
27619 char saved_char;
27620 char *name;
27621
27622 name = input_line_pointer;
5f4273c7 27623 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27624 input_line_pointer++;
27625 saved_char = *input_line_pointer;
27626 *input_line_pointer = 0;
5f4273c7 27627
ee065d83
PB
27628 for (opt = arm_fpus; opt->name != NULL; opt++)
27629 if (streq (opt->name, name))
27630 {
4d354d8b
TP
27631 selected_fpu = opt->value;
27632#ifndef CPU_DEFAULT
27633 if (no_cpu_selected ())
27634 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
27635 else
27636#endif
27637 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
27638 *input_line_pointer = saved_char;
27639 demand_empty_rest_of_line ();
27640 return;
27641 }
27642
27643 as_bad (_("unknown floating point format `%s'\n"), name);
27644 *input_line_pointer = saved_char;
27645 ignore_rest_of_line ();
27646}
ee065d83 27647
794ba86a 27648/* Copy symbol information. */
f31fef98 27649
794ba86a
DJ
27650void
27651arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
27652{
27653 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
27654}
e04befd0 27655
f31fef98 27656#ifdef OBJ_ELF
e04befd0
AS
27657/* Given a symbolic attribute NAME, return the proper integer value.
27658 Returns -1 if the attribute is not known. */
f31fef98 27659
e04befd0
AS
27660int
27661arm_convert_symbolic_attribute (const char *name)
27662{
f31fef98
NC
27663 static const struct
27664 {
27665 const char * name;
27666 const int tag;
27667 }
27668 attribute_table[] =
27669 {
27670 /* When you modify this table you should
27671 also modify the list in doc/c-arm.texi. */
e04befd0 27672#define T(tag) {#tag, tag}
f31fef98
NC
27673 T (Tag_CPU_raw_name),
27674 T (Tag_CPU_name),
27675 T (Tag_CPU_arch),
27676 T (Tag_CPU_arch_profile),
27677 T (Tag_ARM_ISA_use),
27678 T (Tag_THUMB_ISA_use),
75375b3e 27679 T (Tag_FP_arch),
f31fef98
NC
27680 T (Tag_VFP_arch),
27681 T (Tag_WMMX_arch),
27682 T (Tag_Advanced_SIMD_arch),
27683 T (Tag_PCS_config),
27684 T (Tag_ABI_PCS_R9_use),
27685 T (Tag_ABI_PCS_RW_data),
27686 T (Tag_ABI_PCS_RO_data),
27687 T (Tag_ABI_PCS_GOT_use),
27688 T (Tag_ABI_PCS_wchar_t),
27689 T (Tag_ABI_FP_rounding),
27690 T (Tag_ABI_FP_denormal),
27691 T (Tag_ABI_FP_exceptions),
27692 T (Tag_ABI_FP_user_exceptions),
27693 T (Tag_ABI_FP_number_model),
75375b3e 27694 T (Tag_ABI_align_needed),
f31fef98 27695 T (Tag_ABI_align8_needed),
75375b3e 27696 T (Tag_ABI_align_preserved),
f31fef98
NC
27697 T (Tag_ABI_align8_preserved),
27698 T (Tag_ABI_enum_size),
27699 T (Tag_ABI_HardFP_use),
27700 T (Tag_ABI_VFP_args),
27701 T (Tag_ABI_WMMX_args),
27702 T (Tag_ABI_optimization_goals),
27703 T (Tag_ABI_FP_optimization_goals),
27704 T (Tag_compatibility),
27705 T (Tag_CPU_unaligned_access),
75375b3e 27706 T (Tag_FP_HP_extension),
f31fef98
NC
27707 T (Tag_VFP_HP_extension),
27708 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
27709 T (Tag_MPextension_use),
27710 T (Tag_DIV_use),
f31fef98
NC
27711 T (Tag_nodefaults),
27712 T (Tag_also_compatible_with),
27713 T (Tag_conformance),
27714 T (Tag_T2EE_use),
27715 T (Tag_Virtualization_use),
15afaa63 27716 T (Tag_DSP_extension),
cd21e546 27717 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 27718#undef T
f31fef98 27719 };
e04befd0
AS
27720 unsigned int i;
27721
27722 if (name == NULL)
27723 return -1;
27724
f31fef98 27725 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 27726 if (streq (name, attribute_table[i].name))
e04befd0
AS
27727 return attribute_table[i].tag;
27728
27729 return -1;
27730}
267bf995 27731
93ef582d
NC
27732/* Apply sym value for relocations only in the case that they are for
27733 local symbols in the same segment as the fixup and you have the
27734 respective architectural feature for blx and simple switches. */
0198d5e6 27735
267bf995 27736int
93ef582d 27737arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
27738{
27739 if (fixP->fx_addsy
27740 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
27741 /* PR 17444: If the local symbol is in a different section then a reloc
27742 will always be generated for it, so applying the symbol value now
27743 will result in a double offset being stored in the relocation. */
27744 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 27745 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
27746 {
27747 switch (fixP->fx_r_type)
27748 {
27749 case BFD_RELOC_ARM_PCREL_BLX:
27750 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27751 if (ARM_IS_FUNC (fixP->fx_addsy))
27752 return 1;
27753 break;
27754
27755 case BFD_RELOC_ARM_PCREL_CALL:
27756 case BFD_RELOC_THUMB_PCREL_BLX:
27757 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 27758 return 1;
267bf995
RR
27759 break;
27760
27761 default:
27762 break;
27763 }
27764
27765 }
27766 return 0;
27767}
f31fef98 27768#endif /* OBJ_ELF */